• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmcelhaney / counterfact / 5837079355

11 Aug 2023 09:10PM CUT coverage: 87.031%. Remained the same
5837079355

push

github

web-flow
Merge pull request #494 from pmcelhaney/shebangs-shebangs

fix an issue where ts-node was not being used

407 of 434 branches covered (93.78%)

Branch coverage included in aggregate %.

1821 of 2126 relevant lines covered (85.65%)

21.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.22
/src/typescript-generator/repository.js
1
import nodePath from "node:path";
1✔
2
import fs from "node:fs/promises";
1✔
3
import { constants as fsConstants } from "node:fs";
1✔
4

1✔
5
import prettier from "prettier";
1✔
6

1✔
7
import { Script } from "./script.js";
1✔
8

1✔
9
// eslint-disable-next-line no-underscore-dangle
1✔
10
const __dirname = nodePath.dirname(new URL(import.meta.url).pathname);
1✔
11

1✔
12
async function ensureDirectoryExists(filePath) {
×
13
  const directory = nodePath.dirname(filePath);
×
14

×
15
  try {
×
16
    await fs.access(directory, fsConstants.W_OK);
×
17
  } catch {
×
18
    await fs.mkdir(directory, { recursive: true });
×
19
  }
×
20
}
×
21

1✔
22
export class Repository {
1✔
23
  constructor() {
1✔
24
    this.scripts = new Map();
9✔
25
  }
9✔
26

1✔
27
  get(path) {
1✔
28
    if (this.scripts.has(path)) {
92✔
29
      return this.scripts.get(path);
40✔
30
    }
40✔
31

52✔
32
    const script = new Script(this, path);
52✔
33

52✔
34
    this.scripts.set(path, script);
52✔
35

52✔
36
    return script;
52✔
37
  }
52✔
38

1✔
39
  async finished() {
1✔
40
    while (
1✔
41
      Array.from(this.scripts.values()).some((script) => script.isInProgress())
1✔
42
    ) {
1✔
43
      // eslint-disable-next-line no-await-in-loop
1✔
44
      await Promise.all(
1✔
45
        Array.from(this.scripts.values(), (script) => script.finished())
1✔
46
      );
1✔
47
    }
1✔
48
  }
1✔
49

1✔
50
  copyCoreFiles(destination) {
1✔
51
    const files = ["package.json", "response-builder-factory.ts"];
×
52

×
53
    return files.map((file) => {
×
54
      const path = nodePath.join(destination, file);
×
55

×
56
      process.stdout.write(`writing ${path}\n`);
×
57

×
58
      return fs.copyFile(
×
59
        nodePath.join(__dirname, `../../templates/${file}`),
×
60
        path
×
61
      );
×
62
    });
×
63
  }
×
64

1✔
65
  async writeFiles(destination) {
1✔
66
    await this.finished();
×
67

×
68
    const writeFiles = Array.from(
×
69
      this.scripts.entries(),
×
70
      async ([path, script]) => {
×
71
        const contents = prettier.format(script.contents(), {
×
72
          parser: "typescript",
×
73
        });
×
74

×
75
        const fullPath = nodePath.join(destination, path);
×
76

×
77
        await ensureDirectoryExists(fullPath);
×
78

×
79
        if (
×
80
          path.startsWith("paths") &&
×
81
          (await fs
×
82
            .stat(fullPath)
×
83
            .then((stat) => stat.isFile())
×
84
            .catch(() => false))
×
85
        ) {
×
86
          process.stdout.write(`not overwriting ${fullPath}\n`);
×
87

×
88
          return;
×
89
        }
×
90

×
91
        await fs.writeFile(fullPath, contents);
×
92

×
93
        process.stdout.write(`writing ${fullPath}\n`);
×
94
      }
×
95
    );
×
96

×
97
    await Promise.all(writeFiles);
×
98

×
99
    await this.copyCoreFiles(destination);
×
100
  }
×
101
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc