Skip to content

Commit

Permalink
fix: print error on init when cannot find a package.json (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypercubed authored and Kent C. Dodds committed Jun 22, 2018
1 parent 8f8c25c commit e52b136
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/bin-utils/initialize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const CORE_SCRIPTS = [
function initialize(configType = 'js') {
/* eslint global-require:0,import/no-dynamic-require:0 */
const packageJsonPath = findUpSync('package.json')
if (packageJsonPath === null) {
return
}
const packageJson = require(packageJsonPath)
const {scripts = {}} = packageJson
packageJson.scripts = getCoreScripts(packageJson.scripts)
Expand Down
7 changes: 6 additions & 1 deletion src/bin-utils/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ function parse(rawArgv) {
return
}
}
const {packageScriptsPath} = initialize(initArgv.type)
const init = initialize(initArgv.type)
if (!packageScriptsPath) {
log.error(chalk.red('Unable to to find an existing package.json'))
return
}
const packageScriptsPath = init.packageScriptsPath
log.info(
`Your scripts have been saved at ${chalk.green(packageScriptsPath)}`,
)
Expand Down

0 comments on commit e52b136

Please sign in to comment.