Skip to content

Instantly share code, notes, and snippets.

@gokatz gokatz/deploy.js
Last active Sep 10, 2019

Embed
What would you like to do?
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);
});
}
@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

@cawa-93

This comment has been minimized.

Copy link

commented Jul 18, 2019

It is incredibly. Is there an analog for publication in addons.mozilla.org?

@gokatz

This comment has been minimized.

Copy link
Owner Author

commented Jul 18, 2019

Thanks @juanlugm. Updated the gist

@gokatz

This comment has been minimized.

Copy link
Owner Author

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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.