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.validate)
.then(this.compile), .then(this.compile),
'after:deploy:deploy': () => BbPromise.bind(this) 'after:deploy:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(this.cleanup), .then(this.cleanup),
'webpack:validate': () => BbPromise.bind(this) 'webpack:validate': () => BbPromise.bind(this)

36
lib/cleanup.js

@ -1,15 +1,43 @@
'use strict'; 'use strict';
const BbPromise = require('bluebird'); const BbPromise = require('bluebird');
const path = require('path');
const fse = require('fs-extra'); const fse = require('fs-extra');
module.exports = { module.exports = {
cleanup() { cleanup() {
const webpackOutputPath = this.webpackOutputPath; const webpackOutputPath = this.webpackOutputPath;
if (this.serverless.utils.dirExistsSync(webpackOutputPath)) { const moveArtifact = new BbPromise((resolve, reject) => {
fse.removeSync(webpackOutputPath); if (this.originalServicePath) {
} this.serverless.config.servicePath = this.originalServicePath;
return BbPromise.resolve(); 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; const outputPath = stats.compilation.compiler.outputPath;
this.webpackOutputPath = outputPath; this.webpackOutputPath = outputPath;
this.originalServicePath = this.serverless.config.servicePath;
this.serverless.config.servicePath = outputPath; this.serverless.config.servicePath = outputPath;
return stats; return stats;
}); });

Loading…
Cancel
Save