This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
72 lines (63 loc) · 2.21 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
var fs = require("fs");
var path = require("path");
var CWS = require("chrome-webstore-manager");
var zipFolder = require("zip-folder");
var variablesLink = "https://gitlab.com/iPlug/iplug/variables";
function checkVariable(variable) {
if (typeof process.env[variable] != "string") {
console.log("Please visit:\n\n%s\n\nthen add missing %s variable", variablesLink, variable);
process.exit(1);
}
}
checkVariable("EXTENSION_ID")
checkVariable("CLIENT_SECRET");
checkVariable("CLIENT_ID");
var chromeWebStore = new CWS(process.env["CLIENT_ID"], process.env["CLIENT_SECRET"]);
if (typeof process.env["TOKEN"] != "string") {
if (typeof process.env["CODE"] != "string") {
console.log("Please visit:\n\n%s\n\nthen set CODE variable on %s", chromeWebStore.getCodeUrl(), variablesLink);
process.exit(1);
} else {
var tokenPR = chromeWebStore.getAccessToken(process.env["CODE"]);
tokenPR.then(function(a) {
a = JSON.parse(a);
var token = a["access_token"];
if (token == null) {
console.log("Error getting access_token...");
console.log(a);
process.exit(1);
}
console.log("Please visit:\n\n%s\n\nthen remove CODE variable and add TOKEN variable = %s", variablesLink, token);
console.log("AFTER YOU COPY TOKEN ERASE LOGS!");
uploadChromeFolder(token);
}, function(b) {
console.log("Error getting access token using CODE variable");
console.log(b);
console.log("Please visit:\n\n%s\n\nthen set CODE variable on %s", chromeWebStore.getCodeUrl(), variablesLink);
process.exit(1);
});
}
} else {
uploadChromeFolder(process.env["TOKEN"]);
}
function uploadChromeFolder(token){
var filepath = path.resolve(__dirname, "package.zip");
var dirpath = path.resolve(__dirname, "Chrome");
console.log("Zipping %s\ninto: %s", dirpath, filepath);
zipFolder(dirpath, filepath, function(err) {
if (err) {
console.log(err);
process.exit(1);
}
console.log("Zipped!");
console.log("Updating extension %s", process.env["EXTENSION_ID"]);
var zip = fs.readFileSync(filepath);
chromeWebStore.updateItem(token, zip, process.env["EXTENSION_ID"]).then(function(data) {
console.log("Success");
console.log(data);
}, function(err) {
console.log("Error");
console.log(err);
});
});
}