Bladeren bron

fixato bug shelljs

Mirko Domenici 4 jaren geleden
bovenliggende
commit
d153e1a87f
3 gewijzigde bestanden met toevoegingen van 35 en 68 verwijderingen
  1. 0 0
      bin/cmd.js
  2. 34 66
      bin/commands/start.js
  3. 1 2
      package.json

+ 0 - 0
bin/cmd.js


+ 34 - 66
bin/commands/start.js

@@ -4,7 +4,6 @@ const hostile = require('hostile');
 const colors = require('colors');
 const docker = require('docker-compose');
 const log = require('../inc/log');
-const shell = require('shelljs');
 const ProjectEnvironment = require('../classes/ProjectEnvironment');
 
 const installHosts = (hosts) => {
@@ -20,64 +19,44 @@ const installHosts = (hosts) => {
   }
 };
 
-const runServiceHook = (hook, service, projectEnv) => {
+const runServiceStart = (service, projectEnv) => {
   const env = projectEnv.getEnv();
   const scripts = [
-    `${hook}.before`,
-    `${hook}.before.${env}`,
-    `${hook}`,
-    `${hook}.${env}`,
-    `${hook}.after`,
-    `${hook}.after.${env}`,
+    'start.before',
+    `start.before.${env}`,
+    'start',
+    `start.${env}`,
+    'start.after',
+    `start.after.${env}`,
   ];
 
-  let scriptArgument = {
-    service: service,
-    log: (message) => {
-      log.log('%s - %s', colors.bold(service), message);
-    },
-    env: projectEnv.getEnv(),
-    shell: (cmd) => {
-      shell.cd(path.join(projectEnv.getCwd(), service));
-      const ret = shell.exec(cmd, { fatal: true });
-      if (ret.code !== 0) {
-        throw ret.code;
-      }
-    }
-  };
-
-  switch (hook) {
-    case "start":
-      scriptArgument.exec = (command, options) => {
-        const opts = { ...projectEnv.getDockerOptions(), ...options };
-        return docker.exec(service, command, opts);
-      };
-      break;
-    default:
-      break;
-  }
-
   let chain = Promise.resolve();
 
   scripts.forEach(script => {
     chain = chain.then(() => {
-      return new Promise((resolve, reject) => {
+      return new Promise(resolve => {
         try {
-          const scriptFunction = require(path.join(projectEnv.getCwd(), service, script));
+          const start = require(path.join(projectEnv.getCwd(), service, script));
           log.log(`\nExecuting %s script for %s...`, colors.bold(script), colors.bold(service));
 
-          try {
-            Promise
-              .all([scriptFunction({ ...scriptArgument })])
-              .then(() => {
-                resolve();
-              })
-              .catch((e) => {
-                reject(e);
-              });
-          } catch (ex) {
-            reject(ex);
-          }
+          Promise
+            .all([start({
+              exec: (command, options) => {
+                const opts = { ...projectEnv.getDockerOptions(), ...options };
+                return docker.exec(service, command, opts);
+              },
+              log: (message) => {
+                log.log('%s - %s', colors.bold(service), message);
+              },
+              env: projectEnv.getEnv()
+            })])
+            .catch(() => {
+
+            })
+            .then(() => {
+              resolve();
+            });
+
         } catch (ex) {
           resolve();
         }
@@ -85,31 +64,20 @@ const runServiceHook = (hook, service, projectEnv) => {
     });
   });
 
-  return chain.then(() => { });
-};
-
-const runServices = async (projectEnv) => {
-  const services = await projectEnv.getServices();
+  return chain.then(() => {
 
-  let preparePromises = [];
-  services.forEach(service => {
-    preparePromises.push(runServiceHook("prepare", service, projectEnv));
   });
-  try {
-    await Promise.all(preparePromises);
-  } catch (e) {
-    log.error(e);
-    return;
-  }
+};
 
+const runServices = async (projectEnv) => {
   await docker.buildAll(projectEnv.getDockerOptions());
   await docker.upAll(projectEnv.getDockerOptions());
-
-  let startPromises = [];
+  const services = await projectEnv.getServices();
+  let promises = [];
   services.forEach(service => {
-    startPromises.push(runServiceHook("start", service, projectEnv));
+    promises.push(runServiceStart(service, projectEnv));
   });
-  await Promise.all(startPromises);
+  await Promise.all(promises);
 };
 
 module.exports = (env) => {

+ 1 - 2
package.json

@@ -33,8 +33,7 @@
     "commander": "^4.0.1",
     "docker-compose": "^0.23.1",
     "hostile": "^1.3.2",
-    "is-root": "^2.1.0",
-    "shelljs": "^0.8.3"
+    "is-root": "^2.1.0"
   },
   "deprecated": false,
   "description": "",