From 91f97dcd96fa243fd23cb4219f2c1e3d67bc99ee Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Tue, 26 Jan 2016 16:24:17 +0700 Subject: [PATCH] projectInstall: fixed errors --- lib/actions/ProjectInstall.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/actions/ProjectInstall.js b/lib/actions/ProjectInstall.js index d976fc35f..6aa7a2678 100644 --- a/lib/actions/ProjectInstall.js +++ b/lib/actions/ProjectInstall.js @@ -352,6 +352,10 @@ module.exports = function(SPlugin, serverlessPath) { return new BbPromise(function (resolve, reject) { + // create temp package.json for npm install + let packageJson = SUtils.readAndParseJsonSync(path.join(_this.S.config.serverlessPath, 'templates', 'nodejs', 'package.json')); + fs.writeFileSync(path.join(process.cwd(), 'package.json'), JSON.stringify(packageJson, null, 2)); + let exec = require('child_process').exec, child; @@ -361,13 +365,16 @@ module.exports = function(SPlugin, serverlessPath) { if (error !== null) return reject(new SError(error)); try { - fse.copySync(path.join(process.cwd(), 'node_modules'), process.cwd()) + fs.mkdirSync(path.join(process.cwd(), _this.evt.options.name)); + fse.copySync(path.join(process.cwd(), 'node_modules', _this.evt.options.project), path.join(process.cwd(), _this.evt.options.name)); + } catch (err) { return reject(new SError(err)) } - // Delete node_modules + // Delete node_modules & package.json fse.removeSync(path.join(process.cwd(), 'node_modules')); + fse.removeSync(path.join(process.cwd(), 'package.json')); return resolve(); }) @@ -419,12 +426,6 @@ module.exports = function(SPlugin, serverlessPath) { return BbPromise.try(function() { - // Rename project dir - fs.renameSync( - path.join(process.cwd(), _this.evt.options.project), - path.join(process.cwd(), _this.evt.options.name) - ); - // Rename .npmignore to .gitignore fs.renameSync( path.join(process.cwd(), _this.evt.options.name, '.npmignore'),