import * as child_process from "child_process"

import jsonDatabase from "../db/json"
import { DATABASE_JSON_FILE } from "../globals"

const log = console.log

const go = async () => {
  // Download settings
  const db = jsonDatabase(DATABASE_JSON_FILE)
  await db.setup()

  const installation = await db.getInstallation(0)
  if (!installation) {
    return
  }
  // Look for plugins
  if (installation.settings.plugins && installation.settings.plugins.length !== 0) {
    const plugins = installation.settings.plugins.join(" ")
    log("Installing: " + plugins)

    const ls = child_process.spawn("yarn", ["add", ...plugins])

    ls.stdout.on("data", data => log(`stdout: ${data}`))
    ls.stderr.on("data", data => log(`stderr: ${data}`))
    ls.on("close", code => log(`child process exited with code ${code}`))
  } else {
    log("Not adding any plugins")
  }
}

go()

import * as child_process from "child_process"

import jsonDatabase from "../db/json"
import { DATABASE_JSON_FILE } from "../globals"

const go = async () => {
  // Download settings
  const db = jsonDatabase(DATABASE_JSON_FILE)
  await db.setup()

  const installation = await db.getInstallation(0)
  if (!installation) {
    return
  }
  // Look for plugins
  if (installation.settings.plugins && installation.settings.plugins.length !== 0) {
    const plugins = installation.settings.plugins.join(" ")
    console.log("Installing: " + plugins) // tslint:disable-line
    // Install them with yarn
    child_process.execSync("yarn add " + plugins)
  } else {
    console.log("Not adding any plugins") // tslint:disable-line
  }
}

go()

--- 
+++ 
@@ -2,6 +2,8 @@
 
 import jsonDatabase from "../db/json"
 import { DATABASE_JSON_FILE } from "../globals"
+
+const log = console.log
 
 const go = async () => {
   // Download settings
@@ -15,11 +17,15 @@
   // Look for plugins
   if (installation.settings.plugins && installation.settings.plugins.length !== 0) {
     const plugins = installation.settings.plugins.join(" ")
-    console.log("Installing: " + plugins) // tslint:disable-line
-    // Install them with yarn
-    child_process.execSync("yarn add " + plugins)
+    log("Installing: " + plugins)
+
+    const ls = child_process.spawn("yarn", ["add", ...plugins])
+
+    ls.stdout.on("data", data => log(`stdout: ${data}`))
+    ls.stderr.on("data", data => log(`stderr: ${data}`))
+    ls.on("close", code => log(`child process exited with code ${code}`))
   } else {
-    console.log("Not adding any plugins") // tslint:disable-line
+    log("Not adding any plugins")
   }
 }
 
Add some stdout logs for plugin deploys
