-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.js
51 lines (43 loc) · 1.5 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
const zipFolder = require('zip-folder');
var fs = require('fs');
let folder = 'build';
let zipName = 'build.zip';
// getting all the credentials and IDs from `gitlab-ci.yml` file
let REFRESH_TOKEN = process.env.REFRESH_TOKEN;
let EXTENSION_ID = process.env.EXTENSION_ID;
let CLIENT_SECRET = process.env.SECRET;
let CLIENT_ID = process.env.CLIENT_ID;
const webStore = require('chrome-webstore-upload')({
extensionId: EXTENSION_ID,
clientId: CLIENT_ID,
clientSecret: CLIENT_SECRET,
refreshToken: REFRESH_TOKEN
});
// zipping the output folder
zipFolder(folder, zipName, function (err) {
if (err) {
console.log('oh no!', err);
process.exit(1);
} else {
console.log(`Successfully Zipped ${folder} and saved as ${zipName}`);
uploadZip(); // on successful zipping, call upload
}
});
function uploadZip() {
// creating file stream to upload
const extensionSource = fs.createReadStream(`./${zipName}`);
// upload the zip to webstore
webStore.uploadExisting(extensionSource).then(res => {
console.log('Successfully uploaded the ZIP');
// publish the uploaded zip
webStore.publish().then(res => {
console.log('Successfully published the newer version');
}).catch((error) => {
console.log(`Error while publishing uploaded extension: ${error}`);
process.exit(1);
});
}).catch((error) => {
console.log(`Error while uploading ZIP: ${error}`);
process.exit(1);
});
}