-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeploy.js
87 lines (74 loc) · 2.61 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const shell = require('shelljs');
const cv = require('compare-version');
const fs = require('fs');
const path = require('path');
const rmrf = require('rimraf');
const {
TRAVIS_BRANCH,
AWS_BUCKET,
AWS_ACCESS_KEY_ID,
AWS_SECRET_KEY,
AWS_SUBFOLDER
} = process.env;
const projectDir = process.cwd();
const pjson = require(path.join(projectDir, 'package.json'));
const oldPjson = JSON.parse(shell.exec("git show HEAD~1:package.json").stdout);
const lastPublishedVersion = shell.exec("npm show " + pjson.name + " version").stdout.trim();
const versionBump = cv(oldPjson.version, pjson.version) < 0;
const bump = () => {
if (TRAVIS_BRANCH !== "develop") {
return console.log("--- Not publishing.");
}
const FLAGFILE = "/tmp/deployment.flag";
fs.writeFileSync(FLAGFILE);
console.log("--- Latest published version: ", lastPublishedVersion);
console.log("--- Previous package.json version: ", oldPjson.version);
console.log("--- Current package.json version: ", pjson.version);
console.log("===== Bumped version:", versionBump);
if (!versionBump) {
console.log("--- Publishing...");
pjson.version = lastPublishedVersion;
fs.writeFileSync(path.join(projectDir, 'package.json'), JSON.stringify(pjson, null, 2));
shell.exec("git add package.json");
shell.exec("git config --global user.name travis");
shell.exec("git config --global user.email [email protected]");
shell.exec("git commit --amend -C $(git rev-parse --verify HEAD)");
shell.exec("npm version --no-git-tag-version prerelease");
shell.exec("git status");
shell.exec("git add package.json");
shell.exec("git commit --amend -C $(git rev-parse --verify HEAD)");
// need rebuild after version bump so that the published vizabi is self-aware of its version
shell.exec("npm run build");
}
};
const upload = (path) => {
shell.exec(
`s3cmd -v --config=/tmp/.${AWS_BUCKET}-s3.s3cfg` +
` --acl-public` +
` --recursive` +
` --no-mime-magic` +
` --guess-mime-type` +
` sync dist/reader-ddfcsv.js "${path}"`
);
shell.exec(
`s3cmd -v --config=/tmp/.${AWS_BUCKET}-s3.s3cfg` +
` --acl-public` +
` --recursive` +
` --no-mime-magic` +
` --guess-mime-type` +
` sync dist/reader-ddfcsv.js.map "${path}"`
);
};
const deploy = () => {
shell.ShellString([
'[default]',
`access_key = ${AWS_ACCESS_KEY_ID}`,
`secret_key = ${AWS_SECRET_KEY}`,
`acl_public = True`
].join('\n')).to(`/tmp/.${AWS_BUCKET}-s3.s3cfg`);
upload(`s3://${AWS_BUCKET}/${AWS_SUBFOLDER}/${TRAVIS_BRANCH}/`);
versionBump && upload(`s3://${AWS_BUCKET}/`);
rmrf.sync('/.tmp');
};
deploy();
bump();