Last active
May 3, 2024 14:09
-
-
Save gokatz/b99c36c74a0b0f219f3c3e4096e7d26d to your computer and use it in GitHub Desktop.
script to automate chrome extension deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
It is incredibly. Is there an analog for publication in addons.mozilla.org?
Thanks @juanlugm. Updated the gist
Thanks @cawa-93. I haven't tried anything personally. But this package looks cool. Will try to hack this during the weekend.
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
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