mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
implement postinstall
This commit is contained in:
parent
c84388cc46
commit
8a09f4df02
4
bin/jaws
4
bin/jaws
@ -88,7 +88,7 @@ program
|
||||
)
|
||||
.option('-l, --lambda', '[create]: create lambda. Default is create lambda and endpoint.')
|
||||
.option('-e, --endpoint', '[create]: create API Gateway endpoint. Default is create lambda and endpoint.')
|
||||
.option('-n, --npm', '[create]: creates a node_module along with your aws_module')
|
||||
.option('-p, --package-manager', '[create]: creates pkg manager scaffolding along with your aws_module. Valid: npm')
|
||||
.action(function(cmd, params, options) {
|
||||
|
||||
var theParams = process.argv.slice(3);
|
||||
@ -110,7 +110,7 @@ program
|
||||
name: theParams[1],
|
||||
action: theParams[2],
|
||||
runtime: options.runtime || 'nodejs',
|
||||
npm: options.npm || false,
|
||||
packageManager: options.packageManager || false,
|
||||
};
|
||||
|
||||
if (options.lambda) {
|
||||
|
||||
@ -26,9 +26,13 @@ module.exports.run = function(JAWS, moduleName, packageManager) {
|
||||
};
|
||||
|
||||
function CMD(JAWS, moduleName, packageManager) {
|
||||
if (['npm'].indexOf(packageManager) == -1) {
|
||||
return Promise.reject(new JawsError('Unsupported package manager', JawsError.errorCodes.UNKNOWN));
|
||||
}
|
||||
this._JAWS = JAWS;
|
||||
this._module = moduleName;
|
||||
this._packageManager = packageManager;
|
||||
this._rootAwsmJson;
|
||||
}
|
||||
|
||||
CMD.prototype.constructor = CMD;
|
||||
@ -41,26 +45,26 @@ CMD.prototype.run = Promise.method(function() {
|
||||
.bind(_this)
|
||||
.then(_this._installFiles)
|
||||
.then(function(module) {
|
||||
if (_this._saveCf) {
|
||||
return _this._saveCfTemplate(module.path).then(function() {
|
||||
return module;
|
||||
});
|
||||
} else {
|
||||
return module;
|
||||
}
|
||||
return Promise.all([module, _this._saveCfTemplate(module.path)]);
|
||||
})
|
||||
.then(function(module) {
|
||||
.spread(function(module) {
|
||||
JawsCLI.log('Successfully installed ' + module.name);
|
||||
|
||||
var deferredDepInstalls = [];
|
||||
|
||||
if (utils.fileExistsSync(path.join(module.path, 'package.json'))) {
|
||||
if (_this._dontInstallDep) {
|
||||
JawsCLI.log('Make sure to run "npm install" from the module\'s dir');
|
||||
} else {
|
||||
JawsCLI.log('Installing node dependencies...');
|
||||
deferredDepInstalls.push(utils.npmInstall(module.path));
|
||||
}
|
||||
switch (_this._packageManager) {
|
||||
case 'npm':
|
||||
if (utils.fileExistsSync(path.join(module.path, 'package.json'))) {
|
||||
deferredDepInstalls.push(utils.npmInstall(module.path));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new JawsError('Unsupported package manager', JawsError.errorCodes.UNKNOWN);
|
||||
break;
|
||||
}
|
||||
|
||||
if (deferredDepInstalls.length > 0) {
|
||||
JawsCLI.log('Installing ' + _this._packageManager + ' dependencies...');
|
||||
}
|
||||
|
||||
return Promise.all(deferredDepInstalls);
|
||||
@ -76,8 +80,14 @@ CMD.prototype.run = Promise.method(function() {
|
||||
CMD.prototype._installFiles = Promise.method(function() {
|
||||
|
||||
var _this = this,
|
||||
srcAwsmPath = path.join(_this._JAWS._meta.projectRootPath, 'node_modules', _this._module, 'awsm'),
|
||||
srcAwsmJsonPath = path.join(_this._JAWS._meta.projectRootPath, 'node_modules', _this._module, 'awsm.json'),
|
||||
pkgMgrDir;
|
||||
|
||||
if (_this._packageManager == 'npm') {
|
||||
pkgMgrDir = 'node_modules';
|
||||
}
|
||||
|
||||
var srcAwsmPath = path.join(_this._JAWS._meta.projectRootPath, pkgMgrDir, _this._module, 'awsm'),
|
||||
srcAwsmJsonPath = path.join(_this._JAWS._meta.projectRootPath, pkgMgrDir, _this._module, 'awsm.json'),
|
||||
awsModsPath = path.join(_this._JAWS._meta.projectRootPath, 'aws_modules');
|
||||
|
||||
if (!utils.fileExistsSync(srcAwsmJsonPath)) {
|
||||
@ -85,6 +95,7 @@ CMD.prototype._installFiles = Promise.method(function() {
|
||||
}
|
||||
|
||||
var awsmJson = utils.readAndParseJsonSync(srcAwsmJsonPath);
|
||||
_this._rootAwsmJson = awsmJson;
|
||||
|
||||
if (!awsmJson.name) {
|
||||
throw new JawsError('awsm.json for module missing name attr', JawsError.errorCodes.UNKNOWN);
|
||||
@ -104,13 +115,14 @@ CMD.prototype._installFiles = Promise.method(function() {
|
||||
throw new JawsError('Module does not have required cloudFormation attributes', JawsError.errorCodes.UNKNOWN);
|
||||
}
|
||||
|
||||
// Things look good, copy over to proj
|
||||
//Copy over jaws awsm scaffolding
|
||||
JawsCLI.log('Copying ' + srcAwsmPath + ' to ' + targetModPath);
|
||||
wrench.copyDirSyncRecursive(
|
||||
srcAwsmPath,
|
||||
targetModPath, {
|
||||
forceDelete: _this._delExisting,
|
||||
excludeHiddenUnix: false,
|
||||
});
|
||||
forceDelete: true,
|
||||
excludeHiddenUnix: false,
|
||||
});
|
||||
|
||||
return {name: awsmJson.name, path: targetModPath};
|
||||
});
|
||||
@ -118,12 +130,12 @@ CMD.prototype._installFiles = Promise.method(function() {
|
||||
/**
|
||||
* Save CloudFormation attrs
|
||||
*
|
||||
* @param modPath path to the newly installed module
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
CMD.prototype._saveCfTemplate = Promise.method(function(modPath) {
|
||||
var awsmJson = utils.readAndParseJsonSync(path.join(modPath, 'awsm.json')),
|
||||
CMD.prototype._saveCfTemplate = Promise.method(function() {
|
||||
var _this = this,
|
||||
awsmJson = _this._rootAwsmJson,
|
||||
projectCfPath = path.join(this._JAWS._meta.projectRootPath, 'cloudformation');
|
||||
|
||||
var cfExtensionPoints = awsmJson.resources.cloudFormation;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user