Repository navigation
Expand file tree
/
Copy pathcleanup.js
More file actions
64 lines (57 loc) · 2.07 KB
/
Copy pathcleanup.js
File metadata and controls
64 lines (57 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
const BbPromise = require('bluebird');
const path = require('path');
const fse = require('fs-extra');
const _ = require('lodash');
module.exports = {
cleanup() {
const webpackOutputPath = this.webpackOutputPath;
const moveArtifact = new BbPromise((resolve, reject) => {
if (this.originalServicePath) {
this.serverless.config.servicePath = this.originalServicePath;
fse.copy(
path.join(webpackOutputPath, '.serverless'),
path.join(this.serverless.config.servicePath, '.serverless'),
(err) => {
if (err) {
reject(err);
} else {
if (this.serverless.service.package.individually) {
const functionNames = this.serverless.service.getAllFunctions();
_.forEach(functionNames, name => {
const func = this.serverless.service.getFunction(name);
// The location of the artifact property changed from Serverless
// 1.17 to 1.18 (damn, the guys should use SemVer!). We have to
// use the new one if available here.
const artifactParent = func.artifact ? func : func.package;
artifactParent.artifact = path.join(
this.serverless.config.servicePath,
'.serverless',
path.basename(artifactParent.artifact)
);
});
resolve();
return;
}
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());
},
};