-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
68 lines (65 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node
// @ts-check
const process = require('process');
const fs = require('fs/promises');
const yargs = require('yargs');
const updaters = require('./updaters');
const parser = yargs(process.argv.slice(2))
.options({
'dep-name': {
type: 'string',
demandOption: true,
describe: 'The name of the updated dependency',
},
'current-version': {
type: 'string',
demandOption: true,
describe: 'The current version of the updated package',
},
'new-version': {
type: 'string',
demandOption: true,
describe: 'The new version of the updated package',
},
format: {
type: 'string',
describe: 'The changelog format',
default: 'keep-a-changelog',
choices: Object.keys(updaters),
},
'ignore-failure': {
type: 'boolean',
describe: 'Ignore errors',
default: false,
},
path: {
type: 'string',
describe: 'The changelog file location',
default: './CHANGELOG.md',
},
})
.example('$0 --dep-name my-updated-package --current-version 1.0.0 --new-version 2.0.0', '');
(async () => {
const { format, path, depName, newVersion, currentVersion, ignoreFailure } = await parser.argv;
let changelogBuffer;
try {
changelogBuffer = await fs.readFile(path);
} catch (e) {
if (!ignoreFailure) {
throw e;
} else {
return;
}
}
const changelogUpdater = updaters[format];
if (!changelogUpdater) {
throw new Error(`Unsupported changelog format "${format}"`);
}
try {
await fs.writeFile(path, changelogUpdater(changelogBuffer.toString(), depName, currentVersion, newVersion));
} catch (e) {
if (!ignoreFailure) {
throw e;
}
}
})();