From 034b6107f5be4360deb60e3a197f71f4577dbb27 Mon Sep 17 00:00:00 2001 From: gokatz Date: Tue, 2 Oct 2018 20:38:51 +0530 Subject: [PATCH] adds default deploy script --- default_files/deploy.js | 51 +++++++++++++++++++++++++++++++++++++++++ index.js | 3 ++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 default_files/deploy.js diff --git a/default_files/deploy.js b/default_files/deploy.js new file mode 100644 index 0000000..8cde09d --- /dev/null +++ b/default_files/deploy.js @@ -0,0 +1,51 @@ + +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); + }); +} diff --git a/index.js b/index.js index 80f838a..60151a7 100755 --- a/index.js +++ b/index.js @@ -32,7 +32,8 @@ inquirer.prompt( 'Has background activity', 'Need to manipulate other website with your chrome extension', 'Need jQuery for DOM maniuplation', - 'Need Bootstrap for basic styling'], + 'Need Bootstrap for basic styling', + 'Need Deploy script that helps automating extension deployment (CI environment)'], default: ['Need a popup page when clicking on extension icon', 'Need jQuery for DOM maniuplation', 'Need Bootstrap for basic styling'] } ]