-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·54 lines (49 loc) · 1.62 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
#!/usr/bin/env node
const fs = require('fs');
const semver = require('semver');
const path = require('path');
const { program } = require('commander');
const { Builder } = require('./src/builder');
program.version('0.0.8').description('A browser extension builder toolchain');
program
.command('build')
.option('--watch', 'run program in watch mode.')
.description('build bundle for browser to load from.')
.action(async (options) => {
try {
const manifestContent = fs.readFileSync(
`${process.cwd()}/manifest.json`,
'utf8'
);
const manifestJson = JSON.parse(manifestContent);
const builder = new Builder(manifestJson, options);
await builder.build();
} catch (e) {
throw new Error(e.message);
}
});
program
.command('version <type>')
.description('Bump the manifest.json version')
.action((type) => {
const validTypes = ['patch', 'minor', 'major'];
if (!validTypes.includes(type)) {
console.error(
'Invalid version type. Please specify "patch", "minor", or "major".'
);
process.exit(1);
}
const packageJsonPath = path.resolve(process.cwd(), './manifest.json');
const packageJson = require(packageJsonPath);
const currentVersion = packageJson.version;
const newVersion = semver.inc(currentVersion, type);
if (!semver.valid(newVersion)) {
console.error(
'Invalid version format. Please use format: major.minor.patch'
);
process.exit(1);
}
packageJson.version = newVersion;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
});
program.parse(process.argv);