|
3 | 3 | * @description Adds a changelog entry to manifest.json |
4 | 4 | * @example add_clog_to_manifest.ts --version=1.18.3 |
5 | 5 | */ |
6 | | -import { writeFileSync } from "fs"; |
7 | | -import parseArgs from "minimist"; |
8 | | -import { resolve } from "path"; |
9 | | -import semverCompare from "semver-compare"; |
10 | | -import manifestJSON from "../manifest.json"; |
| 6 | +import { writeFileSync } from "fs" |
| 7 | +import parseArgs from "minimist" |
| 8 | +import { resolve } from "path" |
| 9 | +import semverCompare from "semver-compare" |
| 10 | +import manifestJSON from "../manifest.json" |
11 | 11 |
|
12 | 12 | /** |
13 | 13 | * Prints information for how to use this program and exits with status code 1 |
14 | 14 | */ |
15 | 15 | const usage = () => { |
16 | | - console.log("Usage: append_manifest.ts [--version=<version>]"); |
17 | | - console.log("Update manifest.json with a changelog"); |
18 | | - console.log("Arguments:"); |
19 | | - console.log(" <version>: A version string 'x.y.z'"); |
20 | | - process.exit(1); |
21 | | -}; |
| 16 | + console.log("Usage: append_manifest.ts [--version=<version>]") |
| 17 | + console.log("Update manifest.json with a changelog") |
| 18 | + console.log("Arguments:") |
| 19 | + console.log(" <version>: A version string 'x.y.z'") |
| 20 | + process.exit(1) |
| 21 | +} |
22 | 22 |
|
23 | 23 | interface Arguments { |
24 | 24 | /** A version string in the form of x.y.z. */ |
25 | | - version?: string; |
| 25 | + version?: string |
26 | 26 | } |
27 | 27 |
|
28 | 28 | /** |
29 | 29 | * Parses arguments |
30 | 30 | */ |
31 | 31 | const init = (): Arguments => { |
32 | | - const args = parseArgs(process.argv.slice(2)); |
33 | | - const result: Arguments = {}; |
| 32 | + const args = parseArgs(process.argv.slice(2)) |
| 33 | + const result: Arguments = {} |
34 | 34 | if (args.version && typeof args.version === "string") { |
35 | | - result.version = args.version; |
| 35 | + result.version = args.version |
36 | 36 | } |
37 | | - return result; |
38 | | -}; |
| 37 | + return result |
| 38 | +} |
39 | 39 |
|
40 | 40 | /** |
41 | 41 | * Appends manifest.json with a changelog entry using the provided version |
42 | 42 | */ |
43 | 43 | const appendClogManifest = (version: string): void => { |
44 | 44 | const clogIdx = manifestJSON.routes.findIndex( |
45 | 45 | (route) => route.path === "./changelog/index.md" |
46 | | - ); |
| 46 | + ) |
47 | 47 |
|
48 | 48 | if (clogIdx < 0) { |
49 | | - console.error("failed to parse manifest.json"); |
50 | | - process.exit(1); |
| 49 | + console.error("failed to parse manifest.json") |
| 50 | + process.exit(1) |
51 | 51 | } |
52 | 52 |
|
53 | | - (manifestJSON.routes[clogIdx].children as { path: string }[]).unshift({ |
| 53 | + ;(manifestJSON.routes[clogIdx].children as { path: string }[]).unshift({ |
54 | 54 | path: `./changelog/${version}.md`, |
55 | | - }); |
| 55 | + }) |
56 | 56 |
|
57 | 57 | // Capture the semver version from /(1.2.3).md |
58 | | - const filenameRegex = /\/([0-9\.]+)\.md$/gi; |
| 58 | + const filenameRegex = /\/([0-9\.]+)\.md$/gi |
59 | 59 |
|
60 | 60 | manifestJSON.routes[clogIdx].children.sort((a, b) => { |
61 | | - const versionA = a.path.match(filenameRegex); |
62 | | - const versionB = b.path.match(filenameRegex); |
| 61 | + const versionA = a.path.match(filenameRegex) |
| 62 | + const versionB = b.path.match(filenameRegex) |
63 | 63 | if ( |
64 | 64 | versionA === null || |
65 | 65 | versionA.length !== 1 || |
66 | 66 | versionB === null || |
67 | 67 | versionB.length !== 1 |
68 | 68 | ) { |
69 | | - console.error("failed to parse manifest.json"); |
70 | | - process.exit(1); |
| 69 | + console.error("failed to parse manifest.json") |
| 70 | + process.exit(1) |
71 | 71 | } |
72 | | - return -semverCompare(versionA[0], versionB[0]); |
73 | | - }); |
| 72 | + return -semverCompare(versionA[0], versionB[0]) |
| 73 | + }) |
74 | 74 |
|
75 | | - console.log("appending manifest.json with clog version: ", version); |
76 | | - const serializedJSON = JSON.stringify(manifestJSON, null, 2); |
77 | | - const manifestPath = resolve(__dirname, "../", "manifest.json"); |
78 | | - writeFileSync(manifestPath, serializedJSON, "utf8"); |
79 | | -}; |
| 75 | + console.log("appending manifest.json with clog version: ", version) |
| 76 | + const serializedJSON = JSON.stringify(manifestJSON, null, 2) |
| 77 | + const manifestPath = resolve(__dirname, "../", "manifest.json") |
| 78 | + writeFileSync(manifestPath, serializedJSON, "utf8") |
| 79 | +} |
80 | 80 |
|
81 | 81 | /** |
82 | 82 | * Main program |
83 | 83 | */ |
84 | 84 | const main = () => { |
85 | | - const args = init(); |
| 85 | + const args = init() |
86 | 86 | if (!args.version) { |
87 | | - console.error("version is a required argument"); |
88 | | - return usage(); |
| 87 | + console.error("version is a required argument") |
| 88 | + return usage() |
89 | 89 | } |
90 | | - appendClogManifest(args.version); |
91 | | - console.log("Done"); |
92 | | - console.info("tip: run yarn fmt:fix to prettify manifest.json"); |
93 | | - process.exit(0); |
94 | | -}; |
| 90 | + appendClogManifest(args.version) |
| 91 | + console.log("Done") |
| 92 | + console.info("tip: run yarn fmt:fix to prettify manifest.json") |
| 93 | + process.exit(0) |
| 94 | +} |
95 | 95 |
|
96 | | -main(); |
| 96 | +main() |
0 commit comments