Skip to content

Commit

Permalink
feat: Add --no-browser flag to 'start' command
Browse files Browse the repository at this point in the history
  • Loading branch information
francium committed Jun 29, 2019
1 parent e5ac3b6 commit b51722d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
57 changes: 44 additions & 13 deletions bin/elm-app-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,29 @@ if (commands.length === 0) {
}

const script = commands[0];
const scriptArgs = commands.splice(1);

switch (script) {
case 'create':
case 'build':
case 'eject':
case 'start':
spawnSyncNode(path.resolve(__dirname, '../scripts', script), scriptArgs);
if (argv['help']) {
help(version, 'start');
break;
}

let args = [];
Object.keys(argv || {}).forEach(key => {
if (key === 'browser') {
// `--no-browser` turns into `--browser false`
// See https://github.com/substack/minimist/issues/123
args = args.concat([
argv[key] ? '--browser' : '--no-browser'
]);
}
});

spawnSyncNode(path.resolve(__dirname, '../scripts', script), args);
break;

case 'test': {
Expand Down Expand Up @@ -76,19 +91,35 @@ switch (script) {
/**
*Prints help message
*
* @param {string} version [description]
* @param {string} version Package version
* @param {string} command Name of command for which to print help message
* @return {undefined}
*/
function help(version) {
console.log();
console.log('Usage: elm-app <command>');
console.log();
console.log('where <command> is one of:');
console.log(' build, start, test, eject, ' + elmCommands.join(', '));
console.log();
console.log();
console.log('Elm ' + elmVersion);
console.log();
function help(version, command='') {
switch (command) {
case 'start':
console.log();
console.log('Usage: elm-app start [options...]');
console.log();
console.log('where [options...] is any number of:');
console.log('--no-browser\tDo not open the browser automatically');
console.log();
break;
case 'test':
// NOTE: Current implementation calls through to `elm-test` for help message
break;
default:
console.log();
console.log('Usage: elm-app <command>');
console.log();
console.log('where <command> is one of:');
console.log(' build, start, test, eject, ' + elmCommands.join(', '));
console.log();
console.log();
console.log('Elm ' + elmVersion);
console.log();
}

console.log(
'create-elm-app@' + version + ' ' + path.resolve(__dirname, '..')
);
Expand Down
6 changes: 5 additions & 1 deletion scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const formatElmCompilerErrors = require('./utils/formatElmCompilerErrors');
const paths = require('../config/paths');
const warn = require('./utils/warn');

const openBrowserFlag = !process.argv.includes('--no-browser');

if (fs.existsSync('elm.json') === false) {
console.log('Please, run the build script from project root directory');
process.exit(0);
Expand Down Expand Up @@ -183,7 +185,9 @@ choosePort(HOST, DEFAULT_PORT)
clearConsole();
}
console.log(chalk.cyan('Starting the development server...\n'));
openBrowser(urls.localUrlForBrowser);
if (openBrowserFlag) {
openBrowser(urls.localUrlForBrowser);
}
});

['SIGINT', 'SIGTERM'].forEach(sig => {
Expand Down

0 comments on commit b51722d

Please sign in to comment.