mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Handle dependencies and lib templates for Python runtime
This commit is contained in:
parent
3e198c1d8d
commit
d9ad1ecb74
@ -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);
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
2
lib/templates/python2.7/requirements.txt
Normal file
2
lib/templates/python2.7/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
# learn about this file here:
|
||||
# https://pip.pypa.io/en/stable/user_guide/#requirements-files
|
||||
Loading…
x
Reference in New Issue
Block a user