Skip to content

Commit

Permalink
add cli options support
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 10, 2021
1 parent e8652bc commit 4135ce3
Show file tree
Hide file tree
Showing 10 changed files with 1,215 additions and 1,191 deletions.
2 changes: 1 addition & 1 deletion packages/vest/types/vest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,6 @@ declare const _default: typeof testBase & {
};
};
declare const test: typeof _default;
declare const VERSION = '1.0.31';
declare const VERSION = '3.2.3';
export { test, create, only, skip, warn, group, optional, enforce, VERSION };
//# sourceMappingURL=vest.d.ts.map
2 changes: 1 addition & 1 deletion packages/vest/types/vest.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 27 additions & 8 deletions vx/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ const glob = require('glob');
const { hideBin } = require('yargs/helpers');
const yargs = require('yargs/yargs');

const packageNames = require('./util/packageNames');
const packageNames = require('vx/packageNames');
const vxPath = require('vx/vxPath');

require('./scripts/genTsConfig');

const { _: args, ...options } = yargs(hideBin(process.argv)).argv;

const [command, target = insidePackageDir()] = args;

const commands = glob
.sync(`./commands/*.js`, {
cwd: vxPath.VX_ROOT_PATH,
Expand All @@ -27,11 +21,36 @@ const commands = glob
{}
);

require('./scripts/genTsConfig');

const argv = hideBin(process.argv);

const cli = yargs(argv)
.command('$0 <command> [options..]', 'Run vx monorepo utility', yargs => {
yargs.positional('command', {
describe: 'Command to run',
choices: Object.keys(commands),
demandOption: true,
});
})
.option('packageName', {
alias: 'p',
choices: packageNames.list,
demandOption: false,
describe: 'Optional. Package to run the command on.',
})
.help().argv;

// is there a better way of doing this?
const options = argv.slice(cli.packageName ? 3 : 1).join(' ');

const { packageName = insidePackageDir(), command } = cli;

if (!commands[command]) {
throw new Error(`Command ${command} not found.`);
}

commands[command](target, options);
commands[command](packageName, options);

function insidePackageDir() {
if (!process.cwd().includes(vxPath.PACKAGES_PATH)) {
Expand Down
6 changes: 3 additions & 3 deletions vx/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const exec = require('vx/exec');

function build(packageName, { watch } = {}) {
function build(packageName, options) {
if (!packageName) {
exec([`yarn workspaces run vx buildPackage`, watch && '--watch']);
exec([`yarn workspaces run vx buildPackage`, options]);
} else {
exec([`yarn workspace ${packageName} vx buildPackage`, watch && '--watch']);
exec([`yarn workspace ${packageName} vx buildPackage`, options]);
}
}

Expand Down
6 changes: 3 additions & 3 deletions vx/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const configOpt = `--config ${path.resolve(
'jest.config.js'
)}`;

function test(packageName, { watch }) {
function test(packageName, options) {
if (!packageName) {
exec([`jest ./packages/*`, configOpt, watch && '--watch']);
exec([`jest ./packages/*`, configOpt, options]);
} else {
exec([`yarn workspace ${packageName} jest`, configOpt, watch && '--watch']);
exec([`yarn workspace ${packageName} jest`, configOpt, options]);
}
}

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions vx/scripts/build/buildPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const logger = require('vx/logger');
const packageName = require('vx/packageName');
const vxPath = require('vx/vxPath');

function buildPackage(name = packageName(), { watch } = {}) {
function buildPackage(name = packageName(), options) {
logger.info(`🛠 Building package: ${name}`);

fse.removeSync(vxPath.packageDist());

exec([`rollup -c`, vxPath.ROLLUP_CONFIG_PATH, watch && '--watch']);
exec([`rollup -c`, vxPath.ROLLUP_CONFIG_PATH, options]);

writeMainTemplate(packageName(), vxPath.packageDist(packageName()));
}
Expand Down
9 changes: 5 additions & 4 deletions vx/scripts/release/steps/pushToLatestBranch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ const path = require('path');

const { sample } = require('lodash');

const exec = require('vx/exec');
const logger = require('vx/logger');
const packageJson = require('../../../util/packageJson');
const packageNames = require('../../../util/packageNames');
const vxPath = require('vx/vxPath');
const listAllChangesSinceStableBranch = require('../github/listAllChangesSinceStableBranch');
const matchPackageNameInCommit = require('../github/matchPackageNameInCommit');

const exec = require('vx/exec');
const logger = require('vx/logger');
const packageNames = require('vx/packageNames');
const vxPath = require('vx/vxPath');

const SCRIPT_PATH = path.resolve(
vxPath.ROOT_PATH,
'scripts',
Expand Down
3 changes: 1 addition & 2 deletions vx/scripts/release/steps/updateDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ const path = require('path');

const fse = require('fs-extra');

const packageNames = require('../../../util/packageNames');

const logger = require('vx/logger');
const packageNames = require('vx/packageNames');
const vxPath = require('vx/vxPath');

const DOCS = 'docs';
Expand Down
Loading

0 comments on commit 4135ce3

Please sign in to comment.