// // Copyright 2021 DXOS.org // import path from 'path'; import yargs, { Argv } from 'yargs'; import { hideBin } from 'yargs/helpers'; import { workflowModule, depsModule, kbaseModule, repoModule, rushModule, wikiModule } from './commands'; import { asyncExec } from './helpers'; const PACKAGE_NAME = '@dxos/x'; yargs(hideBin(process.argv)) .option('projects', { type: 'string', default: process.env.PROJECTS_HOME, describe: 'Root directory for projects (default PROJECTS_HOME env).' }) .option('shell-command', { default: '/tmp/dxtools-command.sh', description: 'Temporary file for shell directives.' }) .option('json', { type: 'boolean', default: false }) .option('verbose', { alias: 'v', type: 'boolean', default: false }) .version() .command({ command: 'debug', handler() { yargs.showVersion(version => { console.log({ root: __dirname, version, argv: yargs.argv }); }); } }) .command({ command: 'install', describe: 'Install the plugin.', builder: (yargs: Argv) => yargs .option('update', { type: 'boolean' }), handler({ update }) { setImmediate(async () => { if (update) { await asyncExec(`yarn global upgrade ${PACKAGE_NAME}`); } const script = path.join(__dirname, '../scripts/install.sh'); const output = await asyncExec(script); console.log(output); }) } }) .command(depsModule) .command(kbaseModule) .command(repoModule) .command(rushModule) .command(wikiModule) .command(workflowModule) .command({ command: '*', handler() { yargs.showHelp() } }) .example([ ['$0 repo list --pr', 'List open PRs for all repos.'], ['$0 rush exec --cmd "$0 deps stale"', "List stale deps for each package."], ['$0 repo exec react --cmd "rush lint"', 'Run lint in each react package.'] ]) .epilogue('For more information see http://github.com/dxos/x and https://github.com/dxos/eng/wiki/Getting-Started') .strict() .argv;