From ae9f5d4e8e6b72e9e20995494b43d756c5b95d9a Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 20 Jun 2018 21:03:23 -0600 Subject: [PATCH] fixes #1691 --- bin/cli-plugins | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/bin/cli-plugins b/bin/cli-plugins index 85132c39d..4a778cd48 100755 --- a/bin/cli-plugins +++ b/bin/cli-plugins @@ -143,9 +143,9 @@ async function reconcileRemotePlugins({ dryRun, upgradeRemote }) { if (fetchable.length > 0) { console.log( - `$ yarn add --ignore-scripts --ignore-workspace-root-check ${fetchable.map( - ({ name, version }) => `${name}@${version}`.cyan - )}` + `$ yarn add --ignore-scripts --ignore-workspace-root-check ${fetchable + .map(({ name, version }) => `${name}@${version}`.cyan) + .join(' ')}` ); if (!dryRun) { @@ -162,7 +162,7 @@ async function reconcileRemotePlugins({ dryRun, upgradeRemote }) { if (output.status) { throw new Error( - 'Could not install external plugins, errors occured during install' + 'Could not install external plugins, errors occurred during install' ); } @@ -329,27 +329,28 @@ async function createSeedPlugin() { if (answers.addPluginsJson) { const pluginsJson = path.resolve(__dirname, '..', 'plugins.json'); - fs.readJson(pluginsJson) - .then(j => { - // This is a client-side plugin, let's push this. - if (answers.client) { - j.client.push(answers.pluginName); + let j; + try { + j = await fs.readJson(pluginsJson); + } catch (err) { + j = { client: [], server: [] }; + } - const output = JSON.stringify(j, null, 2); - fs.writeFileSync(pluginsJson, output); - } + // This is a client-side plugin, let's push this. + if (answers.client) { + j.client.push(answers.pluginName); - // This is a server-side plugin, let's push this. - if (answers.server) { - j.server.push(answers.pluginName); + const output = JSON.stringify(j, null, 2); + fs.writeFileSync(pluginsJson, output); + } - const output = JSON.stringify(j, null, 2); - fs.writeFileSync(pluginsJson, output); - } - }) - .catch(err => { - console.error(err); - }); + // This is a server-side plugin, let's push this. + if (answers.server) { + j.server.push(answers.pluginName); + + const output = JSON.stringify(j, null, 2); + fs.writeFileSync(pluginsJson, output); + } } console.log(