From e724970788577522f91558bb7432dc319b224642 Mon Sep 17 00:00:00 2001 From: lcxfs1991 Date: Thu, 23 Jun 2016 15:10:47 +0800 Subject: [PATCH] improve install pkg feature --- bin/steamer.js | 34 +++++++++++++++++++++++++++++++++- package.json | 9 ++++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/bin/steamer.js b/bin/steamer.js index f5073d1..0caa45e 100755 --- a/bin/steamer.js +++ b/bin/steamer.js @@ -6,7 +6,9 @@ const fs = require('fs'), argv = require('yargs').argv, exec = require('child_process').exec, execSync = require('child_process').execSync, - _ = require('lodash'); + _ = require('lodash'), + requireg = require('requireg'), + npm = requireg('npm'); const Warning = require('../libs/SteamerErrWarning'), Logger = require('../libs/SteamerLogger'), @@ -149,7 +151,36 @@ function installPkg(paths, projects) { // let cmd = "nvm use " + nodeVer; // console.log(execSync(cmd)); + + let pkgJsonPath = path.join(cwd, 'package.json'), + pgkJsonConfig = {}; + + if (fs.existsSync(pkgJsonPath)) { + pgkJsonConfig = JSON.parse(fs.readFileSync(pkgJsonPath)); + } + + console.log(pgkJsonConfig); + npm.load(pkgJsonPath, function (er) { + + if (er) { + Logger.error(currentProject + ": \n" + er); + return; + } + + npm.commands.install([], function (er, data) { + if (er){ + Logger.error(currentProject + ": \n" + er); + } + else { + Logger.log(currentProject + ": \n" + data); + } + + }); + }) + + return; + let cmd = "npm i"; let childProcess = exec(cmd, {cwd}, function (error, stdout, stderr) { @@ -175,6 +206,7 @@ function installPkg(paths, projects) { }); }; + // console.log(paths); runNpn(paths[0], 0); } diff --git a/package.json b/package.json index ad248d7..752bf6c 100755 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ }, "files": [ "bin", - "libs" + "libs", + "template" ], "repository": { "type": "git", @@ -27,12 +28,10 @@ }, "homepage": "https://github.com/lcxfs1991/steamer#readme", "dependencies": { - "gulp": "^3.9.1", - "merge-stream": "^1.0.0", "lodash": "^4.13.1", - "run-sequence": "^1.2.1", "yargs": "^4.7.1", - "colors": "^1.1.2" + "colors": "^1.1.2", + "requireg": "^0.1.5" }, "devDependencies": {