Skip to content

Instantly share code, notes, and snippets.

@gokatz
Last active June 16, 2022 14:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gokatz/b99c36c74a0b0f219f3c3e4096e7d26d to your computer and use it in GitHub Desktop.
Save gokatz/b99c36c74a0b0f219f3c3e4096e7d26d to your computer and use it in GitHub Desktop.
script to automate chrome extension deployment
const zipFolder = require('zip-folder');
const fs = require('fs');
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);
});
}
@gokatz
Copy link
Author

gokatz commented Jul 18, 2019

Thanks @cawa-93. I haven't tried anything personally. But this package looks cool. Will try to hack this during the weekend.

@cawa-93
Copy link

cawa-93 commented Sep 10, 2019

The zip-folder package is legacy. There are many forks with the updated version. One of them is my realization with latest archiver package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment