forked from Refinitiv/refinitiv-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
54 lines (46 loc) · 1.5 KB
/
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
48
49
50
51
52
53
54
#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const { PACKAGES_ROOT, errorHandler } = require('./scripts/helpers');
const argvNoBin = hideBin(process.argv);
const argv = yargs(argvNoBin)
.command('$0 <reflect> <package>', 'reflect the command', yargs => {
yargs.require('reflect')
yargs.positional('reflect', {
describe: 'npm command to reflect',
type: 'string'
})
yargs.require('package')
yargs.positional('package', {
describe: 'Package or element name',
type: 'string'
})
})
.demandCommand()
.help()
.argv
const options = argvNoBin.slice(2);
// Element or package
try {
const isElement = !fs.existsSync(path.resolve(PACKAGES_ROOT, argv.package));
const workspace = isElement ? 'elements' : argv.package;
const elementName = isElement ? argv.package : undefined;
// For workspace package real name is required
const package = fs.readFileSync(path.resolve(PACKAGES_ROOT, workspace, 'package.json'));
const packageName = JSON.parse(package).name;
const command = ['npm', 'run', argv.reflect, `--workspace=${packageName}`];
elementName && command.push(elementName);
options.length > 0 && command.push('--')
command.push(...options);
console.log(command.join(' '));
execSync(command.join(' '), {
stdio: 'inherit'
});
}
catch (error) {
errorHandler(error);
process.exit(1);
}