|
6 | 6 | */ |
7 | 7 | import { flags } from "@oclif/command"; |
8 | 8 | import { OutputFlags } from "@oclif/parser"; |
9 | | -import fs from 'fs-extra' |
| 9 | +import fs from "fs-extra"; |
10 | 10 | import { execSync } from "child_process"; |
11 | 11 |
|
12 | | - |
13 | | - /** |
14 | | - * Find the differences between two directories containing API spec files. |
15 | | - * Only finds differences, does not classify using a ruleset. |
16 | | - * |
17 | | - * @param baseApis - Path to base API directory |
18 | | - * @param newApis - Path to new API directory |
19 | | - * @param flags - Parsed CLI flags passed to the command |
20 | | - */ |
| 12 | +/** |
| 13 | + * Find the differences between two directories containing API spec files. |
| 14 | + * Only finds differences, does not classify using a ruleset. |
| 15 | + * |
| 16 | + * @param baseApis - Path to base API directory |
| 17 | + * @param newApis - Path to new API directory |
| 18 | + * @param flags - Parsed CLI flags passed to the command |
| 19 | + */ |
21 | 20 | async function oasDiffDirs( |
22 | | - baseApis: string, |
23 | | - newApis: string, |
24 | | - flags |
25 | | - ): Promise<void> { |
26 | | - try { |
27 | | - |
28 | | - } catch (err) { |
29 | | - console.error(err.message, { exit: 2 }); |
30 | | - } |
31 | | - // if (apiCollectionChanges.hasChanges()) { |
32 | | - // this.exit(1); |
33 | | - // } |
| 21 | + baseApis: string, |
| 22 | + newApis: string, |
| 23 | + flags |
| 24 | +): Promise<void> { |
| 25 | + try { |
| 26 | + } catch (err) { |
| 27 | + console.error(err.message, { exit: 2 }); |
34 | 28 | } |
| 29 | +} |
35 | 30 |
|
36 | | - /** |
37 | | - * If a file is given, saves the changes to the file, as JSON by default. |
38 | | - * Otherwise, logs the changes to console, as text by default. |
39 | | - * |
40 | | - * @param changes - The changes to save or log |
41 | | - * @param flags - Parsed CLI flags passed to the command |
42 | | - */ |
43 | | -async function _saveOrLogOas( |
44 | | - changes: string, |
45 | | - flags |
46 | | - ): Promise<void> { |
47 | | - const file = flags["out-file"]; |
48 | | - if (file) { |
49 | | - console.log('Saving results to file') |
50 | | - if (flags.format === "json") { |
51 | | - console.log('Using json format') |
52 | | - await fs.writeJson(file, JSON.parse(changes)); |
53 | | - } else { |
54 | | - console.log('Using console format') |
55 | | - await fs.writeFile(file, changes); |
56 | | - } |
| 31 | +/** |
| 32 | + * If a file is given, saves the changes to the file, as JSON by default. |
| 33 | + * Otherwise, logs the changes to console, as text by default. |
| 34 | + * |
| 35 | + * @param changes - The changes to save or log |
| 36 | + * @param flags - Parsed CLI flags passed to the command |
| 37 | + */ |
| 38 | +async function _saveOrLogOas(changes: string, flags): Promise<void> { |
| 39 | + const file = flags["out-file"]; |
| 40 | + if (file) { |
| 41 | + console.log("Saving results to file"); |
| 42 | + if (flags.format === "json") { |
| 43 | + console.log("Using json format"); |
| 44 | + await fs.writeJson(file, JSON.parse(changes)); |
57 | 45 | } else { |
58 | | - console.log(changes); |
| 46 | + console.log("Using console format"); |
| 47 | + await fs.writeFile(file, changes); |
59 | 48 | } |
60 | | - } |
| 49 | + } else { |
| 50 | + console.log(changes); |
| 51 | + } |
| 52 | +} |
61 | 53 |
|
62 | 54 | export async function oasDiffChangelog(baseApi: string, newApi: string, flags) { |
63 | | - try { |
64 | | - console.log('Starting oasdiff') |
65 | | - |
66 | | - const jsonMode = flags.format === "json" ? '-f json' : ''; |
67 | | - const directoryMode = flags.dir ? '--composed' : ''; |
| 55 | + try { |
| 56 | + console.log("Starting oasdiff"); |
68 | 57 |
|
69 | | - // TODO: Do we want to support the other output formats? |
70 | | - // See https://github.com/oasdiff/oasdiff/blob/main/docs/BREAKING-CHANGES.md#output-formats |
| 58 | + const jsonMode = flags.format === "json" ? "-f json" : ""; |
| 59 | + const directoryMode = flags.dir ? "--composed" : ""; |
71 | 60 |
|
72 | | - // TODO: Do we want to support customizing severity levels? |
73 | | - // This would be akin to the raml rulesets |
74 | | - const oasdiffOutput = execSync(`oasdiff changelog ${jsonMode} ${directoryMode} ${baseApi} ${newApi}`).toString(); |
| 61 | + // TODO: Do we want to support the other output formats? |
| 62 | + // See https://github.com/oasdiff/oasdiff/blob/main/docs/BREAKING-CHANGES.md#output-formats |
75 | 63 |
|
76 | | - if (oasdiffOutput.trim().length === 0) { |
77 | | - console.log("No API changes reported by oasdiff"); |
78 | | - } else { |
79 | | - await _saveOrLogOas(oasdiffOutput, flags); |
80 | | - } |
| 64 | + // TODO: Do we want to support customizing severity levels? |
| 65 | + // This would be akin to the raml rulesets |
| 66 | + const oasdiffOutput = execSync( |
| 67 | + `oasdiff changelog ${jsonMode} ${directoryMode} ${baseApi} ${newApi}` |
| 68 | + ).toString(); |
81 | 69 |
|
82 | | - } catch (err) { |
83 | | - console.error(err); |
| 70 | + if (oasdiffOutput.trim().length === 0) { |
| 71 | + console.log("No API changes reported by oasdiff"); |
| 72 | + } else { |
| 73 | + await _saveOrLogOas(oasdiffOutput, flags); |
84 | 74 | } |
| 75 | + } catch (err) { |
| 76 | + console.error(err); |
| 77 | + } |
85 | 78 | } |
86 | | - |
0 commit comments