Files
serverless-webpack/lib/copyFunctionArtifact.js
Francisco GuimarĂ£es 22a460d8b1 Integration with deploy package function (#130)
* Deploy  package function

* Listen pipe and reject pipe errors

* using once instead of on

* Fix babel example

* - Adding babel-multiple-statically-entries example
- Renaming multiple-entries-example to multiple-statically-entries

* Exposing entries to lib

*  Adding babel-dynamically-entries examples

* - Updating examples dependencies
- Adding yarn to examples
- Fix typescript example

*  Adding tests

* Removed yarn lock file. yarn should use package-lock.json

* Allow handlers in arbitrary paths. Use lodash and SLS functions.

* Adapted unit tests

* Mention new entry resolution in README

* Bundle names now contain the js ending. Fixed output in examples.
2017-07-26 22:42:15 +02:00

34 lines
1.0 KiB
JavaScript

'use strict';
const BbPromise = require('bluebird');
const webpack = require('webpack');
const fs = require('fs');
const path = require('path');
module.exports = {
copyFunctionArtifact() {
const packagePath = this.options.package ||
this.serverless.service.package.path ||
path.join(this.servicePath || '.', '.serverless');
const provider = this.serverless.getProvider('aws');
const artifactFileName = provider.naming.getFunctionArtifactName(this.options.function);
const artifactFilePath = path.join(packagePath, artifactFileName);
const webpackPackageFunctionPath = path.join(this.webpackOutputPath, artifactFilePath);
return new BbPromise((resolve, reject) => {
const readStream = fs.createReadStream(webpackPackageFunctionPath);
readStream.once('error', (err) => {
reject(err);
});
readStream.once('end', () => {
resolve();
});
readStream.pipe(fs.createWriteStream(artifactFilePath)).once('error', (err) => {
reject(err);
});
});
},
};