-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsmoke-conv-cli.js
47 lines (38 loc) · 1.39 KB
/
smoke-conv-cli.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
import fs from 'node:fs';
import {dirname, join} from 'node:path';
import {fileURLToPath} from 'node:url';
import minimist from 'minimist';
import {convert} from './lib/convert.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const help = `Usage: smoke-conv <input_mocks_or_collection> <output_file_or_folder>
Convert a single file mock collection to separate mock files and conversely.
If the input is a single file mock collection (.mocks.js), it will be converted
to separate mock files in <output_folder>.
If the input is a set of separate mock files, it will be converted to a single
file mock collection named <output_file>.mocks.js
Options:
-i, --ignore <glob> Files to ignore [default: none]
-d, --depth <N> Folder depth for mocks [default: 1]
-v, --version Show version
--help Show help
`;
export async function run(args) {
const options = minimist(args, {
number: ['depth'],
string: ['ignore'],
boolean: ['help', 'version'],
alias: {
v: 'version',
i: 'ignore',
d: 'depth',
},
});
if (options.version) {
const pkg = JSON.parse(fs.readFileSync(join(__dirname, 'package.json'), 'utf8'));
return console.log(pkg.version);
}
if (options.help || options._.length !== 2) {
return console.log(help);
}
await convert(options._[0], options._[1], options.ignore, options.depth);
}