-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
40 lines (34 loc) · 1.17 KB
/
cli.ts
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
#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import { program } from 'commander';
import LocalVersioner from './src/version-local';
import packageJSON from './package.json';
async function main() {
program
.name('deterministic-versions')
.description('Deterministic git-based versioning for applications')
.version(packageJSON.version, '-v, --version', 'Output the version of this CLI (not the target repository)')
.option('-r, --repo-path <char>', 'Path to the local git repository')
.option('-s, --silent', 'Run the program without any output')
.option(
'-d, --default-branch <char>',
'Name of the default branch of the repository'
)
.option(
'-o, --output-file <char>',
'If specified, writes the version number to the specified file'
);
program.parse();
const options = program.opts();
const v = new LocalVersioner({
pathToRepo: options.repoPath,
defaultBranch: options.defaultBranch,
});
const version = await v.getVersionForHead();
if (typeof options.outputFile === 'string') {
const out = path.resolve(options.outputFile);
fs.writeFileSync(out, version);
}
}
main();