From 410241061db6fc2721be18c8ede850800ec54af3 Mon Sep 17 00:00:00 2001 From: Nick Chen Date: Thu, 20 Jul 2017 20:05:36 -0700 Subject: [PATCH] Add scripts to help with packaging and publishing of .vsix @W-4162004@ --- package.json | 4 ++ .../salesforcedx-vscode-apex/package.json | 3 ++ .../salesforcedx-vscode-core/package.json | 5 +- .../package.json | 5 +- .../package.json | 5 +- packages/salesforcedx-vscode/package.json | 8 ++- scripts/clean-all-but-jar.js | 2 + scripts/generate-sha256.js | 19 +++++++ scripts/publish-vsix.js | 24 +++++++++ scripts/publish.js | 54 +++++++++++++++++++ 10 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 scripts/generate-sha256.js create mode 100644 scripts/publish-vsix.js create mode 100644 scripts/publish.js diff --git a/package.json b/package.json index 53c0707602..12b31aa9db 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,11 @@ "clean": "lerna run clean", "compile": "lerna run --stream compile", "lint": "lerna run lint", + "publish": "node scripts/publish.js", "test": "lerna run test --concurrency 1", + "vscode:package": "lerna run vscode:package --concurrency 1", + "vscode:sha256": "lerna run vscode:sha256 --concurrency 1", + "vscode:publish": "lerna run vscode:publish --concurrency 1", "watch": "lerna run --parallel watch" }, "repository": { diff --git a/packages/salesforcedx-vscode-apex/package.json b/packages/salesforcedx-vscode-apex/package.json index a77be3e9e7..3a45682e39 100644 --- a/packages/salesforcedx-vscode-apex/package.json +++ b/packages/salesforcedx-vscode-apex/package.json @@ -28,6 +28,9 @@ }, "scripts": { "vscode:prepublish": "npm prune --production", + "vscode:package": "vsce package", + "vscode:sha256": "node ../../scripts/generate-sha256.js >> ../../SHA256", + "vscode:publish": "node ../../scripts/publish-vsix.js", "compile": "tsc -p ./", "lint": "tslint --project .", "watch": "tsc -watch -p .", diff --git a/packages/salesforcedx-vscode-core/package.json b/packages/salesforcedx-vscode-core/package.json index a411828ebf..ff25feac92 100644 --- a/packages/salesforcedx-vscode-core/package.json +++ b/packages/salesforcedx-vscode-core/package.json @@ -33,7 +33,10 @@ "vscode": "1.1.2" }, "scripts": { - "vscode:prepublish": "tsc -p ./", + "vscode:prepublish": "npm prune --production", + "vscode:package": "vsce package", + "vscode:sha256": "node ../../scripts/generate-sha256.js >> ../../SHA256", + "vscode:publish": "node ../../scripts/publish-vsix.js", "compile": "tsc -p ./", "lint": "tslint --project .", "watch": "tsc -watch -p .", diff --git a/packages/salesforcedx-vscode-lightning/package.json b/packages/salesforcedx-vscode-lightning/package.json index f54dc41301..30f57f6fdf 100644 --- a/packages/salesforcedx-vscode-lightning/package.json +++ b/packages/salesforcedx-vscode-lightning/package.json @@ -27,7 +27,10 @@ "vscode": "1.1.2" }, "scripts": { - "vscode:prepublish": "tsc -p ./", + "vscode:prepublish": "npm prune --production", + "vscode:package": "vsce package", + "vscode:sha256": "node ../../scripts/generate-sha256.js >> ../../SHA256", + "vscode:publish": "node ../../scripts/publish-vsix.js", "compile": "tsc -p ./", "lint": "tslint --project .", "watch": "tsc -watch -p .", diff --git a/packages/salesforcedx-vscode-visualforce/package.json b/packages/salesforcedx-vscode-visualforce/package.json index 06d49b1d1f..317098edce 100644 --- a/packages/salesforcedx-vscode-visualforce/package.json +++ b/packages/salesforcedx-vscode-visualforce/package.json @@ -27,7 +27,10 @@ "vscode": "1.1.2" }, "scripts": { - "vscode:prepublish": "tsc -p ./", + "vscode:prepublish": "npm prune --production", + "vscode:package": "vsce package", + "vscode:sha256": "node ../../scripts/generate-sha256.js >> ../../SHA256", + "vscode:publish": "node ../../scripts/publish-vsix.js", "compile": "tsc -p ./", "lint": "tslint --project .", "watch": "tsc -watch -p .", diff --git a/packages/salesforcedx-vscode/package.json b/packages/salesforcedx-vscode/package.json index 85c497ca93..926fb5015b 100644 --- a/packages/salesforcedx-vscode/package.json +++ b/packages/salesforcedx-vscode/package.json @@ -2,7 +2,7 @@ "preview": true, "name": "salesforcedx-vscode", "displayName": "Visual Studio Code Extension Pack for Salesforce DX", - "description": "Collection of extension for Salesforce DX", + "description": "Collection of extensions for Salesforce DX", "icon": "images/icon.png", "galleryBanner": { "color": "#ECECEC", @@ -14,6 +14,12 @@ "engines": { "vscode": "^1.13.0" }, + "scripts": { + "vscode:prepublish": "npm prune --production", + "vscode:package": "vsce package", + "vscode:sha256": "node ../../scripts/generate-sha256.js >> ../../SHA256", + "vscode:publish": "node ../../scripts/publish-vsix.js" + }, "categories": ["Extension Packs"], "extensionDependencies": [ "salesforce.salesforcedx-vscode-apex", diff --git a/scripts/clean-all-but-jar.js b/scripts/clean-all-but-jar.js index c5b127a20d..d904ea23bb 100755 --- a/scripts/clean-all-but-jar.js +++ b/scripts/clean-all-but-jar.js @@ -2,4 +2,6 @@ const shell = require('shelljs'); +// Removes all files but .jar files at the top-level + shell.rm('-rf', shell.ls().filter(file => !file.match(/\.jar$/))); diff --git a/scripts/generate-sha256.js b/scripts/generate-sha256.js new file mode 100644 index 0000000000..532d2e0990 --- /dev/null +++ b/scripts/generate-sha256.js @@ -0,0 +1,19 @@ +#!/usr/bin/env node + +const shell = require('shelljs'); + +// Generate the SHA256 for the .vsix that matches the version in package.json + +const packageVersion = JSON.parse(shell.cat('package.json')).version; +const vsix = shell.ls().filter(file => file.match(`-${packageVersion}.vsix`)); + +if (!vsix.length) { + shell.error('No VSIX found matching the requested version in package.json'); + shell.exit(1); +} + +if (/win32/.test(process.platform)) { + shell.exec(`CertUtil -hashfile ${vsix} SHA256`); +} else { + shell.exec(`shasum -a 256 ${vsix}`); +} diff --git a/scripts/publish-vsix.js b/scripts/publish-vsix.js new file mode 100644 index 0000000000..fa44d22bf7 --- /dev/null +++ b/scripts/publish-vsix.js @@ -0,0 +1,24 @@ +#!/usr/bin/env node + +const shell = require('shelljs'); + +// Publishes the .vsix that matches the version in package.json + +const packageVersion = JSON.parse(shell.cat('package.json')).version; +const vsix = shell.ls().filter(file => file.match(`-${packageVersion}.vsix`)); + +if (!vsix.length) { + shell.error('No VSIX found matching the requested version in package.json'); + shell.exit(1); +} + +const vsce = '../../node_modules/.bin/vsce'; +const VSCE_PERSONAL_ACCESS_TOKEN = process.env['VSCE_PERSONAL_ACCESS_TOKEN']; +if (VSCE_PERSONAL_ACCESS_TOKEN) { + shell.exec( + `${vsce} publish --pat ${VSCE_PERSONAL_ACCESS_TOKEN} --packagePath ${vsix}` + ); +} else { + // Assume that one has already been configured + shell.exec(`${vsce} publish --packagePath ${vsix}`); +} diff --git a/scripts/publish.js b/scripts/publish.js new file mode 100644 index 0000000000..b84033e232 --- /dev/null +++ b/scripts/publish.js @@ -0,0 +1,54 @@ +#!/usr/bin/env node + +const shell = require('shelljs'); +shell.set('-e'); +shell.set('+v'); + +/* + * Assumptions: + * 0. The script is running locally - it's not optimized for Travis workflow + * yet. + * 1. The script is running in the right branch. + * 2. The script is running in a clean environment - all changes have been + * committed. + */ + +// Bootstrap +shell.exec('npm run bootstrap'); + +// Compile +shell.exec('npm run compile'); + +// Test +shell.exec('npm run test'); + +// lerna publish +// --skip-npm to increment the version number in all packages but not publish to npmjs +// This will still make a commit in Git with the tag of the version used +const nextVersion = process.env['VERSION_INCREMENT']; +if (nextVersion) { + shell.exec(`lerna publish --exact --repo-version ${nextVersion} --skip-npm`); +} else { + shell.exec('lerna publish --exact --cd-version minor --yes --skip-npm'); +} + +// Generate the .vsix files +shell.exec(`npm run vscode:package`); + +// Generate the SHA256 and append to the file +shell.exec(`npm run vscode:sha256`); + +// Publish to VS Code Marketplace +shell.exec(`npm run vscode:publish`); + +// Push the SHA256 to AWS +shell.exec('aws s3 cp SHA256 s3://dfc-data-production/media/vscode/SHA256'); + +// Add SHA256 to git +shell.exec(`git add SHA256`); + +// Perform these steps manually for now +// Git commit +// shell.exec(`git commit -m "Updated SHA256"`); +// Push back to GitHub +//shell.exec(`git push`);