mirror of
https://github.com/serverless/serverless.git
synced 2026-02-01 16:07:28 +00:00
replaced wrench with fs extra
This commit is contained in:
parent
72b129068c
commit
a50e9361b7
@ -176,6 +176,7 @@ module.exports = function(S) {
|
||||
stage = stage ? stage.toUpperCase() : null;
|
||||
|
||||
// implicitly already in the config...
|
||||
|
||||
this.addConfigurationCredentials(credentials, S.config); // use the given configuration credentials if they are the only available credentials.
|
||||
// first from environment
|
||||
this.addEnvironmentCredentials(credentials, 'AWS'); // allow for Amazon standard credential environment variable prefix.
|
||||
@ -188,6 +189,7 @@ module.exports = function(S) {
|
||||
this.addProfileCredentials(credentials, 'AWS_' + stage); // allow for *stage specific* Amazon standard prefix based profile declaration
|
||||
this.addProfileCredentials(credentials, 'SERVERLESS_ADMIN_AWS_' + stage); // allow for *stage specific* Serverless standard prefix based profile declaration
|
||||
// if they aren't loaded now, the credentials weren't provided by a valid means
|
||||
|
||||
if (!credentials.accessKeyId || !credentials.secretAccessKey) {
|
||||
throw new SError('Cant find AWS credentials', SError.errorCodes.MISSING_AWS_CREDS);
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ const SError = require('./Error'),
|
||||
fs = require('fs'),
|
||||
fse = BbPromise.promisifyAll(require('fs-extra')),
|
||||
path = require('path'),
|
||||
wrench = require('wrench'),
|
||||
_ = require('lodash');
|
||||
|
||||
module.exports = function(S) {
|
||||
@ -107,9 +106,8 @@ module.exports = function(S) {
|
||||
|
||||
let packageRoot = handlerFullPath.replace(func.handler, '');
|
||||
|
||||
return wrench.copyDirSyncRecursive(packageRoot, pathDist, {
|
||||
exclude: this._processExcludePatterns(func, pathDist, stage, region),
|
||||
inflateSymlinks: true
|
||||
return fse.copySync(packageRoot, pathDist, {
|
||||
filter: this._processExcludePatterns(func, pathDist, stage, region)
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -134,23 +132,21 @@ module.exports = function(S) {
|
||||
|
||||
excludePatterns = excludePatterns.concat([pathToMeta, path.sep + 'admin\.env$', path.sep + '\.env$']);
|
||||
|
||||
return function (name, prefix) {
|
||||
return function (filePath) {
|
||||
|
||||
if (!excludePatterns.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let relPath = path.join(prefix.replace(pathDist, ''), name);
|
||||
|
||||
relPath = (relPath.charAt(0) == path.sep) ? relPath.substr(1) : relPath;
|
||||
filePath = (filePath.charAt(0) == path.sep) ? filePath.substr(1) : filePath;
|
||||
|
||||
return excludePatterns.some(sRegex => {
|
||||
let re = new RegExp(sRegex),
|
||||
matches = re.exec(relPath),
|
||||
matches = re.exec(filePath),
|
||||
willExclude = (matches && matches.length > 0);
|
||||
|
||||
if (willExclude) {
|
||||
S.utils.sDebug(`"${stage} - ${region} - ${func.name}": Excluding - ${relPath}`);
|
||||
S.utils.sDebug(`"${stage} - ${region} - ${func.name}": Excluding - ${filePath}`);
|
||||
}
|
||||
|
||||
return willExclude;
|
||||
|
||||
@ -1,206 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Action: ModuleInstall
|
||||
* - downloads module from github url
|
||||
* - validate downloaded module
|
||||
* - copy downloaded module into project module dir and install deps
|
||||
* - update project CF template
|
||||
*
|
||||
* Event Properties:
|
||||
* - github-url: (String) github url of the module in this format:
|
||||
* https://github.com/serverless/serverless
|
||||
*/
|
||||
|
||||
module.exports = function(S) {
|
||||
|
||||
const path = require('path'),
|
||||
BbPromise = require('bluebird'),
|
||||
fs = BbPromise.promisifyAll(require('fs')),
|
||||
wrench = BbPromise.promisifyAll(require('wrench')),
|
||||
temp = BbPromise.promisifyAll(require('temp')),
|
||||
SUtils = S.utils,
|
||||
SError = require(S.getServerlessPath('Error')),
|
||||
SCli = require(S.getServerlessPath('utils/cli')),
|
||||
URL = require('url'),
|
||||
Download = require('download');
|
||||
|
||||
temp.track();
|
||||
|
||||
|
||||
/**
|
||||
* ModuleInstall Class
|
||||
*/
|
||||
|
||||
class ModuleInstall extends S.classes.Plugin {
|
||||
|
||||
static getName() {
|
||||
return 'serverless.core.' + this.name;
|
||||
}
|
||||
|
||||
registerActions() {
|
||||
S.addAction(this.moduleInstall.bind(this), {
|
||||
handler: 'moduleInstall',
|
||||
description: `Downloads and installs a new module from github.
|
||||
usage: serverless module install <github-url>`,
|
||||
context: 'module',
|
||||
contextAction: 'install',
|
||||
options: [],
|
||||
parameters: [
|
||||
{
|
||||
parameter: 'url',
|
||||
description: 'Github repo url of the Serverless Module you want to install',
|
||||
position: '0'
|
||||
}
|
||||
]
|
||||
});
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Action
|
||||
*/
|
||||
|
||||
moduleInstall(evt) {
|
||||
|
||||
let _this = this;
|
||||
_this.evt = evt;
|
||||
|
||||
return _this._downloadModule()
|
||||
.bind(_this)
|
||||
.then(_this._validateAndPrepare)
|
||||
.then(_this._installModule)
|
||||
.then(function() {
|
||||
SCli.log('Successfully installed "' + _this.evt.data.module + '" module.');
|
||||
|
||||
/**
|
||||
* Return EVT
|
||||
*/
|
||||
|
||||
return _this.evt;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads the module from github
|
||||
*/
|
||||
|
||||
_downloadModule() {
|
||||
|
||||
// If URL is not provided, throw error.
|
||||
if(!this.evt.options.url) {
|
||||
return BbPromise.reject(new SError('Github URL is required. (eg. serverless module install <github-url>)', SError.errorCodes.UNKNOWN));
|
||||
}
|
||||
|
||||
let _this = this,
|
||||
spinner = SCli.spinner(),
|
||||
url = URL.parse(_this.evt.options.url),
|
||||
parts = url.pathname.split('/'),
|
||||
repo = {
|
||||
owner: parts[1],
|
||||
repo: parts[2],
|
||||
branch: 'master'
|
||||
};
|
||||
|
||||
//TODO: support github tree URLS (branch): https://github.com/serverless/serverless/tree/cf-deploy
|
||||
if (~repo.repo.indexOf('#')) {
|
||||
url[2].split('#');
|
||||
repo.repo = url[2].split('#')[0];
|
||||
repo.branch = url[2].split('#')[1];
|
||||
}
|
||||
|
||||
if (url.hostname !== 'github.com' || !repo.owner || !repo.repo) {
|
||||
spinner.stop(true);
|
||||
return BbPromise.reject(new SError('Must be a github url in this format: https://github.com/serverless/serverless', SError.errorCodes.UNKNOWN));
|
||||
}
|
||||
|
||||
let downloadUrl = 'https://github.com/' + repo.owner + '/' + repo.repo + '/archive/' + repo.branch + '.zip';
|
||||
|
||||
return temp.mkdirAsync('module')
|
||||
.then(function(tempModulePath) {
|
||||
return new BbPromise(function(resolve, reject) {
|
||||
SCli.log('Downloading module ...');
|
||||
spinner.start();
|
||||
|
||||
new Download({
|
||||
timeout: 30000,
|
||||
extract: true,
|
||||
strip: 1,
|
||||
mode: '755',
|
||||
}).get(downloadUrl)
|
||||
.dest(tempModulePath)
|
||||
.run(function(error) {
|
||||
spinner.stop(true);
|
||||
if (error) {
|
||||
return BbPromise.reject(new SError('Module Download and installation failed: ' + error, SError.errorCodes.UNKNOWN));
|
||||
}
|
||||
_this.pathTempModule = tempModulePath;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Validate and prepare data before installing the downloaded module
|
||||
*/
|
||||
|
||||
_validateAndPrepare() {
|
||||
let _this = this,
|
||||
srcModuleJsonPath = path.join(_this.pathTempModule, 's-module.json');
|
||||
|
||||
// if s-module.json doesn't exist in downloaded module, throw error
|
||||
if (!SUtils.fileExistsSync(srcModuleJsonPath)) {
|
||||
return BbPromise.reject(new SError('Missing s-module.json file in module root', SError.errorCodes.UNKNOWN));
|
||||
}
|
||||
|
||||
let srcModuleJson = SUtils.readFileSync(srcModuleJsonPath);
|
||||
|
||||
// if name is missing from s-module.json, throw error
|
||||
if (!srcModuleJson.name) {
|
||||
return BbPromise.reject(new SError('s-module.json for downloaded module missing name attr', SError.errorCodes.UNKNOWN));
|
||||
}
|
||||
|
||||
_this.evt.data.module = srcModuleJson.name;
|
||||
_this.pathModule = S.getProject().getRootPath('back', 'modules', _this.evt.data.module);
|
||||
|
||||
// if same module name exists, throw error
|
||||
if (SUtils.doesModuleExist(srcModuleJson.name, S.getProject().getRootPath())) {
|
||||
return BbPromise.reject(new SError(
|
||||
'Module ' + _this.evt.data.module + ' already exists',
|
||||
SError.errorCodes.INVALID_PROJECT_SERVERLESS
|
||||
));
|
||||
}
|
||||
|
||||
// if required cloudformation attrs are missing, throw error
|
||||
if (
|
||||
(!srcModuleJson.cloudFormation) ||
|
||||
(!srcModuleJson.cloudFormation.lambdaIamPolicyDocumentStatements)
|
||||
) {
|
||||
return BbPromise.reject(new SError('Module does not have required cloudFormation attributes', SError.errorCodes.UNKNOWN));
|
||||
}
|
||||
|
||||
return BbPromise.resolve();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Installs the downloaded module
|
||||
*/
|
||||
|
||||
_installModule() {
|
||||
let _this = this;
|
||||
|
||||
// all good! copy/install module
|
||||
wrench.copyDirSyncRecursive(_this.pathTempModule, _this.pathModule, {
|
||||
forceDelete: true,
|
||||
excludeHiddenUnix: false
|
||||
});
|
||||
|
||||
return BbPromise.resolve();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return( ModuleInstall );
|
||||
};
|
||||
@ -66,7 +66,6 @@
|
||||
"shelljs": "^0.6.0",
|
||||
"shortid": "^2.2.2",
|
||||
"temp": "^0.8.3",
|
||||
"traverse": "^0.6.6",
|
||||
"wrench": "^1.5.8"
|
||||
"traverse": "^0.6.6"
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ describe('All Tests', function() {
|
||||
require('./tests/actions/EndpointDeploy');
|
||||
require('./tests/actions/EventDeploy');
|
||||
require('./tests/actions/ProjectInit');
|
||||
// require('./tests/actions/ProjectInstall'); // Broken until Serverless-Starter is fixed
|
||||
require('./tests/actions/ProjectInstall'); // Broken until Serverless-Starter is fixed
|
||||
require('./tests/actions/ResourcesDiff');
|
||||
require('./tests/actions/PluginCreate');
|
||||
require('./tests/actions/FunctionRollback');
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
let fs = require('fs'),
|
||||
fse = require('fs-extra'),
|
||||
os = require('os'),
|
||||
wrench = require('wrench'),
|
||||
path = require('path'),
|
||||
rimraf = require('rimraf'),
|
||||
Promise = require('bluebird'),
|
||||
@ -37,8 +37,8 @@ module.exports.createTestProject = function(config, npmInstallDirs) {
|
||||
|
||||
// Copy test private to temp directory
|
||||
fs.mkdirSync(tmpProjectPath);
|
||||
wrench.copyDirSyncRecursive(path.join(__dirname, './test-prj'), tmpProjectPath, {
|
||||
forceDelete: true
|
||||
fse.copySync(path.join(__dirname, './test-prj'), tmpProjectPath, {
|
||||
clobber: true
|
||||
});
|
||||
|
||||
let projectJSON = SUtils.readFileSync(path.join(tmpProjectPath, 's-project.json'));
|
||||
|
||||
@ -18,7 +18,7 @@ let Serverless = require('../../../lib/Serverless'),
|
||||
config = require('../../config');
|
||||
|
||||
// Instantiate
|
||||
let serverless = new Serverless( undefined, {
|
||||
let serverless = new Serverless({
|
||||
interactive: false,
|
||||
awsAdminKeyId: config.awsAdminKeyId,
|
||||
awsAdminSecretKey: config.awsAdminSecretKey
|
||||
|
||||
@ -70,7 +70,9 @@ describe('Test Action: Stage Create', function() {
|
||||
|
||||
serverless = new Serverless({
|
||||
projectPath,
|
||||
interactive: false
|
||||
interactive: false,
|
||||
awsAdminKeyId: config.awsAdminKeyId,
|
||||
awsAdminSecretKey: config.awsAdminSecretKey
|
||||
});
|
||||
|
||||
return serverless.init().then(function() {
|
||||
|
||||
@ -27,7 +27,7 @@ let Serverless = require('../../../lib/Serverless'),
|
||||
config = require('../../config');
|
||||
|
||||
|
||||
let serverless = new Serverless( undefined, {
|
||||
let serverless = new Serverless({
|
||||
interactive: false,
|
||||
awsAdminKeyId: config.awsAdminKeyId,
|
||||
awsAdminSecretKey: config.awsAdminSecretKey
|
||||
@ -157,6 +157,7 @@ describe('Test: Project Live Cycle', function() {
|
||||
assert.equal(true, typeof evt.data !== 'undefined');
|
||||
};
|
||||
|
||||
|
||||
return serverless.actions.regionCreate(evt)
|
||||
.then(function(evt) {
|
||||
assert.equal(true, typeof serverless.getProject().getRegion(config.stage2, config.region2).getVariables().region != 'undefined');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user