Skip to content

Commit

Permalink
Reversing options and command order (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekbh authored Dec 7, 2020
1 parent 30fb1fc commit 41fedbd
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 92 deletions.
58 changes: 29 additions & 29 deletions packages/cli/lib/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,6 @@ const { validateArgs } = require('./validate-args');

const toBool = val => val === void 0 || (val === 'false' ? false : val);

async function command(src, argv) {
validateArgs(argv, options, 'build');
argv.src = src || argv.src;
// add `default:true`s, `--no-*` disables
argv.prerender = toBool(argv.prerender);
argv.production = toBool(argv.production);

let cwd = resolve(argv.cwd);
let modules = resolve(cwd, 'node_modules');

if (!isDir(modules)) {
return error(
'No `node_modules` found! Please run `npm install` before continuing.',
1
);
}

if (argv.clean === void 0) {
let dest = resolve(cwd, argv.dest);
await promisify(rimraf)(dest);
}

let stats = await runWebpack(argv, false);

if (argv.json) {
await runWebpack.writeJsonStats(stats);
}
}

const options = [
{
name: '--src',
Expand Down Expand Up @@ -110,6 +81,35 @@ const options = [
},
];

async function command(src, argv) {
validateArgs(argv, options, 'build');
argv.src = src || argv.src;
// add `default:true`s, `--no-*` disables
argv.prerender = toBool(argv.prerender);
argv.production = toBool(argv.production);

let cwd = resolve(argv.cwd);
let modules = resolve(cwd, 'node_modules');

if (!isDir(modules)) {
return error(
'No `node_modules` found! Please run `npm install` before continuing.',
1
);
}

if (argv.clean === void 0) {
let dest = resolve(cwd, argv.dest);
await promisify(rimraf)(dest);
}

let stats = await runWebpack(argv, false);

if (argv.json) {
await runWebpack.writeJsonStats(stats);
}
}

module.exports = {
command,
options,
Expand Down
84 changes: 42 additions & 42 deletions packages/cli/lib/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,48 @@ const RGX = /\.(woff2?|ttf|eot|jpe?g|ico|png|gif|webp|mp4|mov|ogg|webm)(\?.*)?$/
const isMedia = str => RGX.test(str);
const capitalize = str => str.charAt(0).toUpperCase() + str.substring(1);

const options = [
{
name: '--name',
description: 'The application name',
},
{
name: '--cwd',
description: 'A directory to use instead of $PWD',
default: '.',
},
{
name: '--force',
description: 'Force destination output; will override!',
default: false,
},
{
name: '--install',
description: 'Install dependencies',
default: true,
},
{
name: '--yarn',
description: 'Use `yarn` instead of `npm`',
default: false,
},
{
name: '--git',
description: 'Initialize git repository',
default: false,
},
{
name: '--license',
description: 'License type',
default: 'MIT',
},
{
name: '-v, --verbose',
description: 'Verbose output',
default: false,
},
];

// Formulate Questions if `create` args are missing
function requestParams(argv, templates) {
const cwd = resolve(argv.cwd);
Expand Down Expand Up @@ -385,48 +427,6 @@ async function command(repo, dest, argv) {
);
}

const options = [
{
name: '--name',
description: 'The application name',
},
{
name: '--cwd',
description: 'A directory to use instead of $PWD',
default: '.',
},
{
name: '--force',
description: 'Force destination output; will override!',
default: false,
},
{
name: '--install',
description: 'Install dependencies',
default: true,
},
{
name: '--yarn',
description: 'Use `yarn` instead of `npm`',
default: false,
},
{
name: '--git',
description: 'Initialize git repository',
default: false,
},
{
name: '--license',
description: 'License type',
default: 'MIT',
},
{
name: '-v, --verbose',
description: 'Verbose output',
default: false,
},
];

module.exports = {
command,
options,
Expand Down
42 changes: 21 additions & 21 deletions packages/cli/lib/commands/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@ const runWebpack = require('../lib/webpack/run-webpack');
const { warn } = require('../util');
const { validateArgs } = require('./validate-args');

async function command(src, argv) {
validateArgs(argv, options, 'watch');
if (argv.rhl) {
delete argv.rhl;
argv.refresh = argv.rhl;
}
argv.src = src || argv.src;
argv.production = false;

if (argv.https || process.env.HTTPS) {
let { key, cert, cacert } = argv;
if (key && cert) {
argv.https = { key, cert, ca: cacert };
} else {
warn('Reverting to `webpack-dev-server` internal certificate.');
}
}

return runWebpack(argv, true);
}

const options = [
{
name: '--src',
Expand Down Expand Up @@ -114,6 +93,27 @@ const options = [
},
];

async function command(src, argv) {
validateArgs(argv, options, 'watch');
if (argv.rhl) {
delete argv.rhl;
argv.refresh = argv.rhl;
}
argv.src = src || argv.src;
argv.production = false;

if (argv.https || process.env.HTTPS) {
let { key, cert, cacert } = argv;
if (key && cert) {
argv.https = { key, cert, ca: cacert };
} else {
warn('Reverting to `webpack-dev-server` internal certificate.');
}
}

return runWebpack(argv, true);
}

module.exports = {
command,
options,
Expand Down

0 comments on commit 41fedbd

Please sign in to comment.