-
Notifications
You must be signed in to change notification settings - Fork 83
/
deploy.js
60 lines (55 loc) · 1.87 KB
/
deploy.js
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
const path = require('path');
const exec = require('@actions/exec');
let deploy = function (params) {
return new Promise((resolve, reject) => {
const {
folder,
bucket,
bucketRegion,
distId,
invalidation,
deleteRemoved,
noCache,
private,
cache,
immutable,
cacheControl,
filesToInclude,
} = params;
const distIdArg = distId ? `--distId ${distId}` : '';
const invalidationArg = distId ? `--invalidate "${invalidation}"` : '';
const deleteRemovedArg =
deleteRemoved && !/false/i.test(deleteRemoved)
? /true/i.test(deleteRemoved)
? `--deleteRemoved`
: `--deleteRemoved ${deleteRemoved}`
: '';
const noCacheArg = noCache ? '--noCache' : '';
const immutableArg = immutable ? '--immutable' : '';
const cacheControlArg = cacheControl ? `--cacheControl ${cacheControl}` : '';
const privateArg = private ? '--private' : '';
const cacheFlag = cache ? `--cache ${cache}` : '';
const filesRegex = filesToInclude ? filesToInclude : '**';
try {
const command = `npx [email protected] ./${filesRegex} \
--bucket ${bucket} \
--region ${bucketRegion} \
--cwd ./ \
${distIdArg} \
--etag \
--gzip xml,html,htm,js,css,ttf,otf,svg,txt \
${cacheFlag} \
${invalidationArg} \
${deleteRemovedArg} \
${noCacheArg} \
${immutableArg} \
${cacheControlArg} \
${privateArg} `;
const cwd = path.resolve(folder);
exec.exec(command, [], { cwd }).then(resolve).catch(reject);
} catch (e) {
reject(e);
}
});
};
module.exports = deploy;