diff --git a/.vscode/launch.json b/.vscode/launch.json index 50ef06713aca..daa7997bc064 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,6 +17,22 @@ "skipFiles": [ "/**" ] - }, + }, { + "type": "node", + "request": "launch", + "name": "cli html", + "cwd": "${workspaceFolder}/lib/cli/stories", + "runtimeArgs": [ + "--inspect-brk", + "${workspaceFolder}/lib/cli/bin/index.js", + "init", + "--type", + "html" + ], + "port": 9229, + "skipFiles": [ + "/**" + ] + } ] } \ No newline at end of file diff --git a/lib/cli/lib/helpers.js b/lib/cli/lib/helpers.js index 2ef52288bfbe..0051cf341498 100644 --- a/lib/cli/lib/helpers.js +++ b/lib/cli/lib/helpers.js @@ -65,8 +65,15 @@ export function getPackageJson() { export async function retrievePackageJson() { const existing = getPackageJson(); + if (existing) { + return existing; + } + + // npmInit will create a new package.json file + npmInit(); - return existing || npmInit(); + // read the newly created packafe,json file + return getPackageJson() || {}; } export function getBowerJson() { diff --git a/lib/cli/lib/npm_init.js b/lib/cli/lib/npm_init.js index 8843ae8699c1..d6526166eaa9 100644 --- a/lib/cli/lib/npm_init.js +++ b/lib/cli/lib/npm_init.js @@ -4,17 +4,12 @@ import hasYarn from './has_yarn'; const packageManager = hasYarn() ? 'yarn' : 'npm'; export default function npmInit() { - return new Promise((resolve, reject) => { - const command = spawn(packageManager, ['init', '-y'], { - cwd: process.cwd(), - env: process.env, - stdio: 'pipe', - encoding: 'utf-8', - silent: true, - }); - - command.stdout.on('data', resolve); - - command.stderr.on('data', reject); + const results = spawn.sync(packageManager, ['init', '-y'], { + cwd: process.cwd(), + env: process.env, + stdio: 'pipe', + encoding: 'utf-8', + silent: true, }); + return results.stdout; }