Browse Source

Move artifact in default position after zipping

master
Nicola Peduzzi 8 years ago
parent
commit
1483a000c8
  1. 2
      index.js
  2. 36
      lib/cleanup.js
  3. 1
      lib/compile.js

2
index.js

@ -77,7 +77,7 @@ class ServerlessWebpack {
.then(this.validate)
.then(this.compile),
'after:deploy:deploy': () => BbPromise.bind(this)
'after:deploy:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(this.cleanup),
'webpack:validate': () => BbPromise.bind(this)

36
lib/cleanup.js

@ -1,15 +1,43 @@
'use strict';
const BbPromise = require('bluebird');
const path = require('path');
const fse = require('fs-extra');
module.exports = {
cleanup() {
const webpackOutputPath = this.webpackOutputPath;
if (this.serverless.utils.dirExistsSync(webpackOutputPath)) {
fse.removeSync(webpackOutputPath);
}
return BbPromise.resolve();
const moveArtifact = new BbPromise((resolve, reject) => {
if (this.originalServicePath) {
this.serverless.config.servicePath = this.originalServicePath;
fse.move(
path.join(webpackOutputPath, '.serverless'),
path.join(this.serverless.config.servicePath, '.serverless'),
(err) => {
if (err) {
reject(err);
} else {
this.serverless.service.package.artifact = path.join(
this.serverless.config.servicePath,
'.serverless',
path.basename(this.serverless.service.package.artifact)
);
resolve();
}
}
);
} else {
resolve();
}
});
return moveArtifact
.then(() => {
if (this.serverless.utils.dirExistsSync(webpackOutputPath)) {
fse.removeSync(webpackOutputPath);
}
})
.then(() => BbPromise.resolve());
},
};

1
lib/compile.js

@ -24,6 +24,7 @@ module.exports = {
}
const outputPath = stats.compilation.compiler.outputPath;
this.webpackOutputPath = outputPath;
this.originalServicePath = this.serverless.config.servicePath;
this.serverless.config.servicePath = outputPath;
return stats;
});

Loading…
Cancel
Save