-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy.js
60 lines (53 loc) · 1.89 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 fs = require('fs-extra');
const zipper = require("zip-local");
const jsonfile = require('jsonfile');
const path = require('path');
const { execSync } = require('child_process');
let releaseLocation = path.join(__dirname, "releases");
let distFolder = path.join(__dirname, "dist");
let publicFolder = path.join(__dirname, "public");
let manifestFilePath = path.join(publicFolder, "manifest.json");
function buildPackage() {
return execSync("npm run build");
}
function getNewVersion(oldVersion) {
let splitedVer = oldVersion.split('.');
var ver = parseInt(splitedVer[2]);
ver++;
return `${splitedVer[0]}.${splitedVer[1]}.${ver}`;
}
function preparePackage() {
// read manifest file
var manifest = jsonfile.readFileSync(manifestFilePath);
var version = getNewVersion(manifest.version);
// replace version
manifest.version = version;
// save manifest file
jsonfile.writeFileSync(manifestFilePath, manifest);
// create zip
zipper.sync.zip(distFolder).compress().save(path.join(releaseLocation, "googlerankchecker.zip"));
}
async function buildAndPrepare() {
// Check if releaseLocation exists, create it if not
const res = await fs.exists(releaseLocation);
if (!res) {
await fs.mkdir(releaseLocation);
}
// Try to build the package, catch any errors
let isBuildSuccessful = false;
try {
buildPackage();
isBuildSuccessful = true;
} catch (error) {
console.log(error.message);
console.log("Use 'npm run build' to see the exact error.");
}
// If the build was successful, prepare the package
if (isBuildSuccessful) {
preparePackage();
}
}
// Invoke the buildAndPrepare
(async () => {
await buildAndPrepare();
})();