Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
expose cli options correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
lhorie committed Dec 8, 2017
1 parent 226a660 commit 3580298
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 40 deletions.
18 changes: 12 additions & 6 deletions commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
const winston = require('winston');
const {Compiler} = require('../build/compiler.js');

exports.command = 'build [dir]';
exports.command =
'build [--dir] [--test] [--cover] [--production] [--log-level]';
exports.desc = 'Build your app';
exports.builder = {
cover: {
dir: {
type: 'string',
default: '.',
describe: 'Root path for the application relative to CLI CWD',
},
test: {
type: 'boolean',
default: false,
describe: 'Build tests (with coverage) as well as application',
describe: 'Build test assets as well as development assets',
},
test: {
cover: {
type: 'boolean',
default: false,
describe: 'Build tests as well as application',
describe: 'Build tests (with coverage) as well as development assets',
},
production: {
type: 'boolean',
Expand All @@ -37,8 +43,8 @@ exports.run = async function({dir = '.', production, test, cover, logLevel}) {

const envs = [];
if (production) envs.push('production');
if (test) envs.push('test');
if (envs.length === 0) envs.push('development');
if (test) envs.push('test');
const compiler = new Compiler({envs, dir, cover, logger});

await compiler.clean();
Expand Down
54 changes: 23 additions & 31 deletions commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,20 @@ const {Compiler} = require('../build/compiler');
const {DevelopmentRuntime} = require('../build/dev-runtime');
const {TestRuntime} = require('../build/test-runtime');

exports.command = 'dev [dir]';
exports.command =
'dev [--dir] [--debug] [--test] [--cover] [--port] [--no-open] [--no-hmr] [--log-level]';
exports.describe = 'Run your app in development';
exports.builder = {
cover: {
type: 'boolean',
default: false,
describe: 'Run tests (with coverage) as well as your application',
dir: {
type: 'string',
default: '.',
describe: 'Root path for the application relative to CLI CWD',
},
debug: {
type: 'boolean',
default: false,
describe: 'Debug application',
},
'no-open': {
type: 'boolean',
default: false,
describe: 'Run without opening the url in your browser',
},
'no-hmr': {
type: 'boolean',
default: false,
describe: 'Run without hot module replacement',
},
test: {
type: 'boolean',
default: false,
describe: 'Run tests as well as your application',
},
// TODO(#18): support watch-mode `dev --profile`
// profile: {
// type: 'boolean',
// default: false,
// describe: 'Run profiling as well as your application',
// },
// TODO(#19): support dev with production assets
// production: {
// type: 'boolean',
Expand All @@ -49,6 +29,18 @@ exports.builder = {
default: 3000,
describe: 'The port at which the app runs',
},
open: {
// yargs generates no-open option
type: 'boolean',
default: true,
describe: 'Run without opening the url in your browser',
},
hmr: {
// yargs generates no-hmr option
type: 'boolean',
default: true,
describe: 'Run without hot module replacement',
},
'log-level': {
type: 'string',
default: 'info',
Expand All @@ -62,8 +54,8 @@ exports.run = async function({
debug,
port,
cover,
noHmr,
noOpen,
hmr,
open,
logLevel,
}) {
const logger = new winston.Logger({
Expand All @@ -75,7 +67,7 @@ exports.run = async function({
const compiler = new Compiler({
envs: test ? ['development', 'test'] : ['development'],
dir,
watch: !noHmr,
watch: hmr,
cover,
logger,
});
Expand All @@ -86,9 +78,9 @@ exports.run = async function({
dir,
port,
debug,
noOpen,
noOpen: !open,
},
!noHmr ? {middleware: compiler.getMiddleware()} : {}
hmr ? {middleware: compiler.getMiddleware()} : {}
)
);

Expand Down
7 changes: 6 additions & 1 deletion commands/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs');
const profile = require('../lib/profiler');
const launchSourceMapExplorer = require('../launch-source-map-explorer.js');

exports.command = 'profile [dir]';
exports.command = 'profile [--dir] [--environment] [--watch] [--file-count]';
exports.desc = 'Profile your application';
exports.builder = {
// TODO(#18): support fusion profile --watch
Expand All @@ -13,6 +13,11 @@ exports.builder = {
// default: false,
// describe: 'Use existing built assets',
// },
dir: {
type: 'string',
default: '.',
describe: 'Root path for the application relative to CLI CWD',
},
environment: {
type: 'string',
default: 'production',
Expand Down
7 changes: 6 additions & 1 deletion commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const fs = require('fs');
const path = require('path');

exports.command = 'start [dir]';
exports.command = 'start [--dir] [--environment]';
exports.desc = 'Run your app';
exports.builder = {
// TODO: https://github.com/uber-web/framework/issues/882
Expand All @@ -11,6 +11,11 @@ exports.builder = {
// default: false,
// describe: 'Debug application',
// },
dir: {
type: 'string',
default: '.',
describe: 'Root path for the application relative to CLI CWD',
},
environment: {
type: 'string',
describe:
Expand Down
6 changes: 5 additions & 1 deletion commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
const {Compiler} = require('../build/compiler');
const {TestRuntime} = require('../build/test-runtime');

exports.command = 'test [dir]';
exports.desc = 'Run tests';
exports.builder = {
dir: {
type: 'string',
default: '.',
describe: 'Root path for the application relative to CLI CWD',
},
cover: {
type: 'boolean',
default: false,
Expand Down

0 comments on commit 3580298

Please sign in to comment.