Handle dependencies and lib templates for Python runtime

This commit is contained in:
Ryan S. Brown 2016-01-21 20:07:16 -05:00
parent 3e198c1d8d
commit d9ad1ecb74
3 changed files with 21 additions and 5 deletions

View File

@ -268,18 +268,27 @@ class ServerlessComponent {
return BbPromise.try(function() {
writeDeferred.push(
fs.mkdirSync(_this._config.fullPath),
fs.mkdirSync(path.join(_this._config.fullPath, 'lib'))
);
// Runtime: nodejs
if (_this.runtime === 'nodejs') {
let packageJsonTemplate = SUtils.readAndParseJsonSync(path.join(_this._S.config.serverlessPath, 'templates', 'nodejs', 'package.json')),
libJs = fs.readFileSync(path.join(_this._S.config.serverlessPath, 'templates', 'nodejs', 'index.js'));
writeDeferred.push(
fs.mkdirSync(_this._config.fullPath),
fs.mkdirSync(path.join(_this._config.fullPath, 'lib')),
SUtils.writeFile(path.join(_this._config.fullPath, 'lib', 'index.js'), libJs),
SUtils.writeFile(path.join(_this._config.fullPath, 'package.json'), JSON.stringify(packageJsonTemplate, null, 2))
);
} else if (_this.runtime === 'python2.7') {
let requirements = fs.readFileSync(path.join(_this._S.config.serverlessPath, 'templates', 'python2.7', 'requirements.txt')),
initPy = fs.readFileSync(path.join(_this._S.config.serverlessPath, 'templates', 'python2.7', '__init__.py'));
writeDeferred.push(
SUtils.writeFile(path.join(_this._config.fullPath, 'lib', '__init__.py'), initPy),
SUtils.writeFile(path.join(_this._config.fullPath, 'requirements.txt'), requirements)
);
}
return BbPromise.all(writeDeferred);

View File

@ -231,8 +231,13 @@ usage: serverless component create`,
*/
_installComponentDependencies() {
SCli.log('Installing "serverless-helpers" for this component via NPM...');
SUtils.npmInstall(path.join(this.S.config.projectPath, this.evt.options.component));
let _this = this;
if (_this.runtime === 'nodejs') {
SCli.log('Installing "serverless-helpers" for this component via NPM...');
SUtils.npmInstall(path.join(this.S.config.projectPath, this.evt.options.component));
} else if (_this.runtime === 'python2.7') {
SCli.log("Python functions don't install dependencies by default...");
}
return BbPromise.resolve();
}
}

View File

@ -0,0 +1,2 @@
# learn about this file here:
# https://pip.pypa.io/en/stable/user_guide/#requirements-files