Skip to content

Commit

Permalink
create-project: Display lint command output when using --debug (neutr…
Browse files Browse the repository at this point in the history
…inojs#1265)

Previously the stdout/stderr of the "initial lint" step was not shown as
expected when `--debug` had been passed to `create-project`. Now the full
console output is displayed inline, like was already the case for the
package install steps.

The yeoman `spawnCommandSync()` options have also been refactored to
reduce duplication, and the error handling adjusted so that:
- a user friendly message is still shown in the case of `result.error`
- the suggestion to use `--debug` is not shown if it was already passed
- there is no longer a verbose Neutrino stack trace shown

See:
https://yeoman.github.io/generator/Generator.html#spawnCommandSync
https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options

Fixes neutrinojs#1262.
  • Loading branch information
edmorley authored and Tim Kelty committed Dec 19, 2018
1 parent 818f7c9 commit fe43001
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
1 change: 1 addition & 0 deletions packages/create-project/bin/create-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ env.run('create-project', {
directory,
name,
registry: cli.registry,
debug: !!cli.debug,
stdio: cli.debug ? 'inherit' : 'ignore'
}, done);
57 changes: 23 additions & 34 deletions packages/create-project/commands/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,28 @@ module.exports = class Project extends Generator {
).sort();
}

_spawnSync(...args) {
const result = this.spawnCommandSync(...args);
_spawnSync(command, args) {
const result = this.spawnCommandSync(command, args, {
cwd: this.options.directory,
stdio: this.options.stdio,
env: process.env
});

if (result.error || result.status !== 0) {
const command = [args[0], ...args[1]].join(' ');
const commandString = [command, ...args].join(' ');

if (result.error) {
// The child process failed to start entirely, or timed out.
this.log.error(result.error);
}

this.log.error(`The command "${commandString}" exited unsuccessfully.`);

if (!this.options.debug) {
this.log.error('Try again with the --debug flag for more detailed information about the failure.');
}

removeSync(this.options.directory);
this.log.error(
result.error ||
new Error(
`The command "${command}" exited unsuccessfully. Try again with the --debug flag ` +
'for more detailed information about the failure.'
)
);
process.exit(result.status || 1);
}

Expand Down Expand Up @@ -131,10 +139,7 @@ module.exports = class Project extends Generator {
scripts.lint = `eslint --cache --format codeframe --ext ${lintExtensions} ${lintDirectories}`;
}

this._spawnSync(installer, ['init', '--yes'], {
cwd: this.options.directory,
stdio: this.options.stdio
});
this._spawnSync(installer, ['init', '--yes']);

const jsonPath = join(this.options.directory, 'package.json');
const json = readJsonSync(jsonPath);
Expand Down Expand Up @@ -211,12 +216,7 @@ module.exports = class Project extends Generator {
[]
),
...dependencies
],
{
cwd: this.options.directory,
stdio: this.options.stdio,
env: process.env
}
]
);
}

Expand All @@ -233,12 +233,7 @@ module.exports = class Project extends Generator {
[]
),
...devDependencies
],
{
cwd: this.options.directory,
stdio: this.options.stdio,
env: process.env
}
]
);
}

Expand All @@ -247,14 +242,8 @@ module.exports = class Project extends Generator {
this._spawnSync(packageManager,
isYarn
? ['lint', '--fix']
: ['run', 'lint', '--fix'],
{
stdio: this.options.stdio === 'inherit' || !this.options.stdio
? 'ignore' :
this.options.stdio,
env: process.env,
cwd: this.options.directory
});
: ['run', 'lint', '--fix']
);
}
}

Expand Down

0 comments on commit fe43001

Please sign in to comment.