@samitouri / QOS-React-2 / commits / 670d1348f1

Chrome build+deploy script auto-increment a prerelease version

Brian Vaughn committed Apr 12, 2019 at 14:42 UTC 670d1348f15e6c24a702cb87c1d19e30255f4de8
5 files changed +72 -14
package.json
+3 -1
@@ -131,11 +131,13 @@
131 "react-is": "^16.9.0-alpha.0",
132 "react-virtualized-auto-sizer": "^1.0.2",
133 "react-window": "^1.8.0",
134 + "request-promise": "^4.2.4",
135 "scheduler": "^0.14.0-alpha.0",
136 "semver": "^5.5.1",
137 "style-loader": "^0.23.1",
138 "web-ext": "^3.0.0",
139 "webpack": "^4.26.0",
139 - "webpack-cli": "^3.1.2"
140 + "webpack-cli": "^3.1.2",
141 + "xml-js": "^1.6.11"
142 }
143 }
shells/browser/chrome/build.js
+18 -1
@@ -3,10 +3,27 @@
3 const chalk = require('chalk');
4 const { execSync } = require('child_process');
5 const { join } = require('path');
6 +const rp = require('request-promise');
7 +const convert = require('xml-js');
8 const build = require('../shared/build');
9
10 const main = async () => {
9 - await build('chrome');
11 + const manifestVersion = await rp(
12 + 'https://react-devtools-experimental-chrome.now.sh/updates.xml'
13 + )
14 + .then(xmlString => {
15 + const parsedXML = convert.xml2js(xmlString);
16 + const version =
17 + parsedXML.elements[0].elements[0].elements[0].attributes.version;
18 + const match = /(\d)\.(\d)\.(\d)\.*(\d)*/.exec(version);
19 + if (match !== null) {
20 + const prerelease = parseInt(match[4], 10) || 0;
21 + return `${match[1]}.${match[2]}.${match[3]}.${prerelease + 1}`;
22 + }
23 + })
24 + .catch(error => null);
25 +
26 + await build('chrome', manifestVersion);
27
28 const cwd = join(__dirname, 'build');
29 execSync('crx pack ./unpacked -o ReactDevTools.crx -p ../../../../key.pem', {
shells/browser/shared/build.js
+11 -5
@@ -17,7 +17,7 @@ const preProcess = async (destinationPath, tempPath) => {
17 await ensureDir(tempPath); // Create temp dir for this new build
18 };
19
20 -const build = async (tempPath, manifestPath) => {
20 +const build = async (tempPath, manifestPath, manifestVersion) => {
21 const binPath = join(tempPath, 'bin');
22 const zipPath = join(tempPath, 'zip');
23
@@ -63,8 +63,14 @@ const build = async (tempPath, manifestPath) => {
63 STATIC_FILES.map(file => copy(join(__dirname, file), join(zipPath, file)))
64 );
65
66 - let manifest = JSON.parse(readFileSync(copiedManifestPath).toString());
67 - manifest.description += `\n\nCreated from revision ${getGitCommit()}`;
66 + const commit = getGitCommit();
67 +
68 + const manifest = JSON.parse(readFileSync(copiedManifestPath).toString());
69 + manifest.description += `\n\nCreated from revision ${commit}`;
70 + if (manifestVersion) {
71 + manifest.version = manifestVersion;
72 + manifest.version_name = `${manifestVersion} ${commit}`;
73 + }
74 writeFileSync(copiedManifestPath, JSON.stringify(manifest, null, 2));
75
76 // Pack the extension
@@ -84,7 +90,7 @@ const postProcess = async (tempPath, destinationPath) => {
90 await remove(tempPath); // Clean up temp directory and files
91 };
92
87 -const main = async buildId => {
93 +const main = async (buildId, manifestVersion) => {
94 const root = join(__dirname, '..', buildId);
95 const manifestPath = join(root, 'manifest.json');
96 const destinationPath = join(root, 'build');
@@ -92,7 +98,7 @@ const main = async buildId => {
98 try {
99 const tempPath = join(__dirname, 'build', buildId);
100 await preProcess(destinationPath, tempPath);
95 - await build(tempPath, manifestPath);
101 + await build(tempPath, manifestPath, manifestVersion);
102
103 const builtUnpackedPath = join(destinationPath, 'unpacked');
104 await postProcess(tempPath, destinationPath);
shells/browser/shared/deploy.js
+10 -6
@@ -3,6 +3,7 @@
3 const { exec, execSync } = require('child_process');
4 const { readFileSync, writeFileSync } = require('fs');
5 const { join } = require('path');
6 +const convert = require('xml-js');
7
8 const main = async buildId => {
9 const root = join(__dirname, '..', buildId);
@@ -15,12 +16,15 @@ const main = async buildId => {
16 });
17
18 if (buildId === 'chrome') {
18 - await exec(
19 - `cp ${join(root, 'updates.xml')} ${join(buildPath, 'updates.xml')}`,
20 - {
21 - cwd: root,
22 - }
23 - );
19 + const file = readFileSync(join(buildPath, 'unpacked', 'manifest.json'));
20 + const json = JSON.parse(file);
21 + const { version } = json;
22 +
23 + const xmlString = readFileSync(join(root, 'updates.xml'), 'utf8');
24 + const parsedXML = convert.xml2js(xmlString);
25 + parsedXML.elements[0].elements[0].elements[0].attributes.version = version;
26 +
27 + writeFileSync(join(buildPath, 'updates.xml'), convert.js2xml(parsedXML));
28 }
29
30 const file = readFileSync(join(root, 'now.json'));
yarn.lock
+30 -1
@@ -2386,6 +2386,11 @@ bl@^1.0.0:
2386 readable-stream "^2.3.5"
2387 safe-buffer "^5.1.1"
2388
2389 +bluebird@^3.5.0:
2390 + version "3.5.4"
2391 + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.4.tgz#d6cc661595de30d5b3af5fcedd3c0b3ef6ec5714"
2392 + integrity sha512-FG+nFEZChJrbQ9tIccIfZJBz3J7mLrAhxakAbnrJWn8d7aKOC+LWifa0G+p4ZqKp4y13T7juYvdhq9NzKdsrjw==
2393 +
2394 bluebird@^3.5.3:
2395 version "3.5.3"
2396 resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
@@ -9538,6 +9543,13 @@ request-promise-core@1.1.1:
9543 dependencies:
9544 lodash "^4.13.1"
9545
9546 +request-promise-core@1.1.2:
9547 + version "1.1.2"
9548 + resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.2.tgz#339f6aababcafdb31c799ff158700336301d3346"
9549 + integrity sha512-UHYyq1MO8GsefGEt7EprS8UrXsm1TxEvFUX1IMTuSLU2Rh7fTIdFtl8xD7JiEYiWU2dl+NYAjCTksTehQUxPag==
9550 + dependencies:
9551 + lodash "^4.17.11"
9552 +
9553 request-promise-native@^1.0.5:
9554 version "1.0.5"
9555 resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.5.tgz#5281770f68e0c9719e5163fd3fab482215f4fda5"
@@ -9546,6 +9558,16 @@ request-promise-native@^1.0.5:
9558 stealthy-require "^1.1.0"
9559 tough-cookie ">=2.3.3"
9560
9561 +request-promise@^4.2.4:
9562 + version "4.2.4"
9563 + resolved "https://registry.yarnpkg.com/request-promise/-/request-promise-4.2.4.tgz#1c5ed0d71441e38ad58c7ce4ea4ea5b06d54b310"
9564 + integrity sha512-8wgMrvE546PzbR5WbYxUQogUnUDfM0S7QIFZMID+J73vdFARkFy+HElj4T+MWYhpXwlLp0EQ8Zoj8xUA0he4Vg==
9565 + dependencies:
9566 + bluebird "^3.5.0"
9567 + request-promise-core "1.1.2"
9568 + stealthy-require "^1.1.1"
9569 + tough-cookie "^2.3.3"
9570 +
9571 request@2.87.0:
9572 version "2.87.0"
9573 resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e"
@@ -10284,7 +10306,7 @@ static-extend@^0.1.1:
10306 define-property "^0.2.5"
10307 object-copy "^0.1.0"
10308
10287 -stealthy-require@^1.1.0:
10309 +stealthy-require@^1.1.0, stealthy-require@^1.1.1:
10310 version "1.1.1"
10311 resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
10312
@@ -11498,6 +11520,13 @@ xdg-basedir@^3.0.0:
11520 resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4"
11521 integrity sha1-SWsswQnsqNus/i3HK2A8F8WHCtQ=
11522
11523 +xml-js@^1.6.11:
11524 + version "1.6.11"
11525 + resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.6.11.tgz#927d2f6947f7f1c19a316dd8eea3614e8b18f8e9"
11526 + integrity sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==
11527 + dependencies:
11528 + sax "^1.2.4"
11529 +
11530 xml-name-validator@^3.0.0:
11531 version "3.0.0"
11532 resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"