Skip to content

Instantly share code, notes, and snippets.

@gokatz gokatz/deploy.js
Last active May 1, 2019

Embed
What would you like to do?
script to automate chrome extension deployment
const zipFolder = require('zip-folder');
let folder = 'dist';
let zipName = 'extension.zip';
// credentials and IDs from gitlab-ci.yml file (your appropriate config file)
let REFRESH_TOKEN = process.env.REFRESH_TOKEN;
let EXTENSION_ID = process.env.EXTENSION_ID;
let CLIENT_SECRET = process.env.CLIENT_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);
});
}
@juanlugm

This comment has been minimized.

Copy link

commented Feb 17, 2019

I had to add
var fs =var fs = require('fs');
Please see my fork. I couldn't find a way to do a merge request in gist.
https://gist.github.com/juanlugm/3ee2aa2a73a3f3a1e27778615a46e241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.