diff --git a/lib/ServerlessComponent.js b/lib/ServerlessComponent.js index 4ef5f78d6..0f410a855 100644 --- a/lib/ServerlessComponent.js +++ b/lib/ServerlessComponent.js @@ -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); diff --git a/lib/actions/ComponentCreate.js b/lib/actions/ComponentCreate.js index 7dc3597d0..1c08d790b 100644 --- a/lib/actions/ComponentCreate.js +++ b/lib/actions/ComponentCreate.js @@ -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(); } } diff --git a/lib/templates/python2.7/requirements.txt b/lib/templates/python2.7/requirements.txt new file mode 100644 index 000000000..8c157a865 --- /dev/null +++ b/lib/templates/python2.7/requirements.txt @@ -0,0 +1,2 @@ +# learn about this file here: +# https://pip.pypa.io/en/stable/user_guide/#requirements-files