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

pmcelhaney / counterfact / 9310610020

30 May 2024 11:42PM CUT coverage: 87.241%. Remained the same
9310610020

Pull #902

github

web-flow
Update dependency eslint to v9
Pull Request #902: Update dependency eslint to v9

984 of 1094 branches covered (89.95%)

Branch coverage included in aggregate %.

3228 of 3734 relevant lines covered (86.45%)

44.33 hits per line

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

90.91
/src/typescript-generator/generate.js
1
import { existsSync } from "node:fs";
2✔
2
import fs from "node:fs/promises";
2✔
3
import nodePath from "node:path";
2✔
4

2✔
5
import createDebug from "debug";
2✔
6

2✔
7
import { ensureDirectoryExists } from "../util/ensure-directory-exists.js";
2✔
8
import { OperationCoder } from "./operation-coder.js";
2✔
9
import { Repository } from "./repository.js";
2✔
10
import { Specification } from "./specification.js";
2✔
11

2✔
12
const debug = createDebug("counterfact:typescript-generator:generate");
2✔
13

2✔
14
async function buildCacheDirectory(destination) {
10✔
15
  const gitignorePath = nodePath.join(destination, ".gitignore");
10✔
16
  const cacheReadmePath = nodePath.join(destination, ".cache", "README.md");
10✔
17

10✔
18
  debug("ensuring the directory containing .gitgnore exists");
10✔
19

10✔
20
  await ensureDirectoryExists(gitignorePath);
10✔
21

10✔
22
  debug("creating the .gitignore file if it doesn't already exist");
10✔
23

10✔
24
  if (!existsSync(gitignorePath)) {
10✔
25
    await fs.writeFile(gitignorePath, ".cache\n", "utf8");
10✔
26
  }
10✔
27

10✔
28
  debug("creating the .cache/README.md file");
10✔
29

10✔
30
  ensureDirectoryExists(cacheReadmePath);
10✔
31
  await fs.writeFile(
10✔
32
    cacheReadmePath,
10✔
33
    "This directory contains compiled JS files from the paths directory. Do not edit these files directly.\n",
10✔
34
    "utf8",
10✔
35
  );
10✔
36
}
10✔
37

2✔
38
async function getPathsFromSpecification(specification) {
10✔
39
  try {
10✔
40
    return (await specification.requirementAt("#/paths")) ?? new Set();
10!
41
  } catch (error) {
10!
42
    process.stderr.write(
×
43
      `Could not find #/paths in the specification.\n${error}\n`,
×
44
    );
×
45

×
46
    return new Set();
×
47
  }
×
48
}
10✔
49

2✔
50
// eslint-disable-next-line max-statements, max-params
2✔
51
export async function generate(
2✔
52
  source,
10✔
53
  destination,
10✔
54
  generateOptions,
10✔
55
  repository = new Repository(),
10✔
56
) {
10✔
57
  debug("generating code from %s to %s", source, destination);
10✔
58

10✔
59
  debug("initializing the .cache directory");
10✔
60
  await buildCacheDirectory(destination);
10✔
61
  debug("done initializing the .cache directory");
10✔
62

10✔
63
  debug("creating specification from %s", source);
10✔
64

10✔
65
  const specification = new Specification(source);
10✔
66

10✔
67
  debug("created specification: $o", specification);
10✔
68

10✔
69
  debug("reading the #/paths from the specification");
10✔
70

10✔
71
  const paths = await getPathsFromSpecification(specification);
10✔
72

10✔
73
  debug("got %i paths", paths.size);
10✔
74

10✔
75
  const securityRequirement = await specification.requirementAt(
10✔
76
    "#/components/securitySchemes",
10✔
77
  );
10✔
78

10✔
79
  const securitySchemes = Object.values(securityRequirement?.data ?? {});
10✔
80

10✔
81
  paths.forEach((pathDefinition, key) => {
10✔
82
    debug("processing path %s", key);
34✔
83

34✔
84
    pathDefinition.forEach((operation, requestMethod) => {
34✔
85
      repository
46✔
86
        .get(`routes${key}.ts`)
46✔
87
        .export(new OperationCoder(operation, requestMethod, securitySchemes));
46✔
88
    });
46✔
89
  });
34✔
90

10✔
91
  debug("telling the repository to write the files to %s", destination);
10✔
92

10✔
93
  await repository.writeFiles(destination, generateOptions);
10✔
94

10✔
95
  debug("finished writing the files");
10✔
96
}
10✔
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