From 7e08fd7b8d801fff9fd2d532c60c56bd6cb62a86 Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 27 Nov 2018 13:15:36 -0800 Subject: [PATCH 1/5] [kbn/i18n] remove npm-run-all --- packages/kbn-i18n/package.json | 14 +-- packages/kbn-i18n/scripts/build.js | 20 +++++ packages/kbn-i18n/tasks/build_cli.js | 127 +++++++++++++++++++++++++++ yarn.lock | 70 --------------- 4 files changed, 154 insertions(+), 77 deletions(-) create mode 100644 packages/kbn-i18n/scripts/build.js create mode 100644 packages/kbn-i18n/tasks/build_cli.js diff --git a/packages/kbn-i18n/package.json b/packages/kbn-i18n/package.json index d46f2423d40b8..63d4204831e9a 100644 --- a/packages/kbn-i18n/package.json +++ b/packages/kbn-i18n/package.json @@ -7,12 +7,9 @@ "license": "Apache-2.0", "private": true, "scripts": { - "build": "run-p build:**", - "kbn:bootstrap": "run-p \"build:babel:** --quiet\" build:tsc", - "kbn:watch": "run-p \"build:** --watch\"", - "build:tsc": "tsc --emitDeclarationOnly", - "build:babel:web": "cross-env BABEL_ENV=web babel src --config-file ./babel.config.js --out-dir target/web --extensions \".ts,.js,.tsx\"", - "build:babel:node": "cross-env BABEL_ENV=node babel src --config-file ./babel.config.js --out-dir target/node --extensions \".ts,.js,.tsx\"" + "build": "node scripts/build", + "kbn:bootstrap": "node scripts/build", + "kbn:watch": "node scripts/build --watch" }, "devDependencies": { "@babel/cli": "^7.1.0", @@ -22,11 +19,14 @@ "@babel/preset-env": "^7.1.0", "@babel/preset-react": "^7.0.0", "@babel/preset-typescript": "^7.1.0", + "@kbn/dev-utils": "1.0.0", "@types/intl-relativeformat": "^2.1.0", "@types/json5": "^0.0.30", "@types/react-intl": "^2.3.11", "cross-env": "^5.2.0", - "npm-run-all": "^4.1.5", + "del": "^3.0.0", + "getopts": "^2.2.3", + "supports-color": "^5.5.0", "typescript": "^3.0.3" }, "dependencies": { diff --git a/packages/kbn-i18n/scripts/build.js b/packages/kbn-i18n/scripts/build.js new file mode 100644 index 0000000000000..6d53a8469b0e0 --- /dev/null +++ b/packages/kbn-i18n/scripts/build.js @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +require('../tasks/build_cli'); diff --git a/packages/kbn-i18n/tasks/build_cli.js b/packages/kbn-i18n/tasks/build_cli.js new file mode 100644 index 0000000000000..04d85cce8474f --- /dev/null +++ b/packages/kbn-i18n/tasks/build_cli.js @@ -0,0 +1,127 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +const { resolve } = require('path'); + +const getopts = require('getopts'); +const del = require('del'); +const supportsColor = require('supports-color'); +const { ToolingLog, withProcRunner, pickLevelFromFlags } = require('@kbn/dev-utils'); + +const ROOT_DIR = resolve(__dirname, '..'); +const BUILD_DIR = resolve(ROOT_DIR, 'target'); + +const unknownFlags = []; +const flags = getopts(process.argv, { + boolean: ['watch', 'help'], + unknown(name) { + unknownFlags.push(name); + }, +}); + +const log = new ToolingLog({ + level: pickLevelFromFlags(flags), + writeTo: process.stdout, +}); + +if (unknownFlags.length) { + log.error(`Unknown flag(s): ${unknownFlags.join(', ')}`); + flags.help = true; + process.exitCode = 1; +} + +if (flags.help) { + log.info(` + Simple build tool for @kbn/i18n package + + --watch Run in watch mode + --help Show this message + `); + process.exit(); +} + +withProcRunner(log, async proc => { + log.info('Deleting old output'); + await del(BUILD_DIR); + + const cwd = ROOT_DIR; + const env = { ...process.env }; + if (supportsColor.stdout) { + env.FORCE_COLOR = 'true'; + } + + log.info(`Starting babel and typescript${flags.watch ? ' in watch mode' : ''}`); + await Promise.all([ + proc.run('babel:web ', { + cmd: 'babel', + args: [ + 'src', + '--config-file', + require.resolve('../babel.config.js'), + '--out-dir', + resolve(BUILD_DIR, 'web'), + '--extensions', + '.ts,.js,.tsx', + ...(flags.watch ? ['--watch'] : ['--quiet']), + ], + wait: true, + env: { + ...env, + BABEL_ENV: 'web', + }, + cwd, + }), + + proc.run('babel:node', { + cmd: 'babel', + args: [ + 'src', + '--config-file', + require.resolve('../babel.config.js'), + '--out-dir', + resolve(BUILD_DIR, 'node'), + '--extensions', + '.ts,.js,.tsx', + ...(flags.watch ? ['--watch'] : ['--quiet']), + ], + wait: true, + env: { + ...env, + BABEL_ENV: 'node', + }, + cwd, + }), + + proc.run('tsc ', { + cmd: 'tsc', + args: [ + '--emitDeclarationOnly', + ...(flags.watch ? ['--watch', '--preserveWatchOutput', 'true'] : []), + ], + wait: true, + env, + cwd, + }), + ]); + + log.success('Complete'); +}).catch(error => { + log.error(error); + process.exit(1); +}); diff --git a/yarn.lock b/yarn.lock index b921e9e93bccf..d613aa748adae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2415,11 +2415,6 @@ array-equal@^1.0.0: resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93" integrity sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM= -array-filter@~0.0.0: - version "0.0.1" - resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-0.0.1.tgz#7da8cf2e26628ed732803581fd21f67cacd2eeec" - integrity sha1-fajPLiZijtcygDWB/SH2fKzS7uw= - array-find-index@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/array-find-index/-/array-find-index-1.0.2.tgz#df010aa1287e164bbda6f9723b0a96a1ec4187a1" @@ -2448,21 +2443,11 @@ array-includes@^3.0.3: define-properties "^1.1.2" es-abstract "^1.7.0" -array-map@~0.0.0: - version "0.0.0" - resolved "https://registry.yarnpkg.com/array-map/-/array-map-0.0.0.tgz#88a2bab73d1cf7bcd5c1b118a003f66f665fa662" - integrity sha1-iKK6tz0c97zVwbEYoAP2b2ZfpmI= - array-parallel@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/array-parallel/-/array-parallel-0.1.3.tgz#8f785308926ed5aa478c47e64d1b334b6c0c947d" integrity sha1-j3hTCJJu1apHjEfmTRszS2wMlH0= -array-reduce@~0.0.0: - version "0.0.0" - resolved "https://registry.yarnpkg.com/array-reduce/-/array-reduce-0.0.0.tgz#173899d3ffd1c7d9383e4479525dbe278cab5f2b" - integrity sha1-FziZ0//Rx9k4PkR5Ul2+J4yrXys= - array-series@~0.1.5: version "0.1.5" resolved "https://registry.yarnpkg.com/array-series/-/array-series-0.1.5.tgz#df5d37bfc5c2ef0755e2aa4f92feae7d4b5a972f" @@ -7427,17 +7412,6 @@ error@^7.0.0, error@^7.0.2: string-template "~0.2.1" xtend "~4.0.0" -es-abstract@^1.4.3: - version "1.12.0" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.12.0.tgz#9dbbdd27c6856f0001421ca18782d786bf8a6165" - integrity sha512-C8Fx/0jFmV5IPoMOFPA9P9G5NtqW+4cOPit3MIuvR2t7Ag2K15EJTpxnHAYTzL+aYQJIESYeXZmDBfOBE1HcpA== - dependencies: - es-to-primitive "^1.1.1" - function-bind "^1.1.1" - has "^1.0.1" - is-callable "^1.1.3" - is-regex "^1.0.4" - es-abstract@^1.5.1, es-abstract@^1.6.1, es-abstract@^1.7.0: version "1.10.0" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.10.0.tgz#1ecb36c197842a00d8ee4c2dfd8646bb97d60864" @@ -13935,11 +13909,6 @@ memory-fs@^0.4.0, memory-fs@~0.4.1: errno "^0.1.3" readable-stream "^2.0.1" -memorystream@^0.3.1: - version "0.3.1" - resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2" - integrity sha1-htcJCzDORV1j+64S3aUaR93K+bI= - meow@^3.0.0, meow@^3.3.0, meow@^3.7.0: version "3.7.0" resolved "https://registry.yarnpkg.com/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb" @@ -14951,21 +14920,6 @@ npm-packlist@^1.1.6: ignore-walk "^3.0.1" npm-bundled "^1.0.1" -npm-run-all@^4.1.5: - version "4.1.5" - resolved "https://registry.yarnpkg.com/npm-run-all/-/npm-run-all-4.1.5.tgz#04476202a15ee0e2e214080861bff12a51d98fba" - integrity sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ== - dependencies: - ansi-styles "^3.2.1" - chalk "^2.4.1" - cross-spawn "^6.0.5" - memorystream "^0.3.1" - minimatch "^3.0.4" - pidtree "^0.3.0" - read-pkg "^3.0.0" - shell-quote "^1.6.1" - string.prototype.padend "^3.0.0" - npm-run-path@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-1.0.0.tgz#f5c32bf595fe81ae927daec52e82f8b000ac3c8f" @@ -15954,11 +15908,6 @@ pez@4.x.x: hoek "5.x.x" nigel "3.x.x" -pidtree@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/pidtree/-/pidtree-0.3.0.tgz#f6fada10fccc9f99bf50e90d0b23d72c9ebc2e6b" - integrity sha512-9CT4NFlDcosssyg8KVFltgokyKZIFjoBxw8CTGy+5F38Y1eQWrt8tRayiUOXE+zVKQnYu5BR8JjCtvK3BcnBhg== - pify@^2.0.0, pify@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" @@ -19038,16 +18987,6 @@ shebang-regex@^1.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= -shell-quote@^1.6.1: - version "1.6.1" - resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767" - integrity sha1-9HgZSczkAmlxJ0MOo7PFR29IF2c= - dependencies: - array-filter "~0.0.0" - array-map "~0.0.0" - array-reduce "~0.0.0" - jsonify "~0.0.0" - shelljs@^0.7.0: version "0.7.8" resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.8.tgz#decbcf874b0d1e5fb72e14b164a9683048e9acb3" @@ -19802,15 +19741,6 @@ string-width@^2.0.0, string-width@^2.1.0, string-width@^2.1.1: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" -string.prototype.padend@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.0.0.tgz#f3aaef7c1719f170c5eab1c32bf780d96e21f2f0" - integrity sha1-86rvfBcZ8XDF6rHDK/eA2W4h8vA= - dependencies: - define-properties "^1.1.2" - es-abstract "^1.4.3" - function-bind "^1.0.2" - string_decoder@0.10, string_decoder@~0.10.x: version "0.10.31" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" From 2bff63a66560c3e488cc1a670c5dbdfff5fb2035 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 28 Nov 2018 06:49:33 -0800 Subject: [PATCH 2/5] remove unnecessary package --- packages/kbn-i18n/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/kbn-i18n/package.json b/packages/kbn-i18n/package.json index 63d4204831e9a..01f7c57963425 100644 --- a/packages/kbn-i18n/package.json +++ b/packages/kbn-i18n/package.json @@ -23,7 +23,6 @@ "@types/intl-relativeformat": "^2.1.0", "@types/json5": "^0.0.30", "@types/react-intl": "^2.3.11", - "cross-env": "^5.2.0", "del": "^3.0.0", "getopts": "^2.2.3", "supports-color": "^5.5.0", From a26d56e21a8fc418cb7307042ecb7c95dee0c727 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 28 Nov 2018 06:50:41 -0800 Subject: [PATCH 3/5] loop through babel sub tasks and use helper for task name padding --- packages/kbn-i18n/tasks/build_cli.js | 65 +++++++++++----------------- 1 file changed, 25 insertions(+), 40 deletions(-) diff --git a/packages/kbn-i18n/tasks/build_cli.js b/packages/kbn-i18n/tasks/build_cli.js index 04d85cce8474f..b628068badd91 100644 --- a/packages/kbn-i18n/tasks/build_cli.js +++ b/packages/kbn-i18n/tasks/build_cli.js @@ -27,6 +27,9 @@ const { ToolingLog, withProcRunner, pickLevelFromFlags } = require('@kbn/dev-uti const ROOT_DIR = resolve(__dirname, '..'); const BUILD_DIR = resolve(ROOT_DIR, 'target'); +const padRight = (width, str) => + str.length >= width ? str : `${str}${' '.repeat(width - str.length)}`; + const unknownFlags = []; const flags = getopts(process.argv, { boolean: ['watch', 'help'], @@ -68,47 +71,29 @@ withProcRunner(log, async proc => { log.info(`Starting babel and typescript${flags.watch ? ' in watch mode' : ''}`); await Promise.all([ - proc.run('babel:web ', { - cmd: 'babel', - args: [ - 'src', - '--config-file', - require.resolve('../babel.config.js'), - '--out-dir', - resolve(BUILD_DIR, 'web'), - '--extensions', - '.ts,.js,.tsx', - ...(flags.watch ? ['--watch'] : ['--quiet']), - ], - wait: true, - env: { - ...env, - BABEL_ENV: 'web', - }, - cwd, - }), - - proc.run('babel:node', { - cmd: 'babel', - args: [ - 'src', - '--config-file', - require.resolve('../babel.config.js'), - '--out-dir', - resolve(BUILD_DIR, 'node'), - '--extensions', - '.ts,.js,.tsx', - ...(flags.watch ? ['--watch'] : ['--quiet']), - ], - wait: true, - env: { - ...env, - BABEL_ENV: 'node', - }, - cwd, - }), + ...['web', 'node'].map(subTask => + proc.run(padRight(10, `babel:${subTask}`), { + cmd: 'babel', + args: [ + 'src', + '--config-file', + require.resolve('../babel.config.js'), + '--out-dir', + resolve(BUILD_DIR, subTask), + '--extensions', + '.ts,.js,.tsx', + ...(flags.watch ? ['--watch'] : ['--quiet']), + ], + wait: true, + env: { + ...env, + BABEL_ENV: subTask, + }, + cwd, + }) + ), - proc.run('tsc ', { + proc.run(padRight(10, 'tsc'), { cmd: 'tsc', args: [ '--emitDeclarationOnly', From 018074931c1743155da05e3f7c521e544540b518 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 28 Nov 2018 06:54:03 -0800 Subject: [PATCH 4/5] add --source-maps flag --- packages/kbn-i18n/package.json | 4 ++-- packages/kbn-i18n/tasks/build_cli.js | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/kbn-i18n/package.json b/packages/kbn-i18n/package.json index 01f7c57963425..0897df5f56f97 100644 --- a/packages/kbn-i18n/package.json +++ b/packages/kbn-i18n/package.json @@ -8,8 +8,8 @@ "private": true, "scripts": { "build": "node scripts/build", - "kbn:bootstrap": "node scripts/build", - "kbn:watch": "node scripts/build --watch" + "kbn:bootstrap": "node scripts/build --source-maps", + "kbn:watch": "node scripts/build --watch --source-maps" }, "devDependencies": { "@babel/cli": "^7.1.0", diff --git a/packages/kbn-i18n/tasks/build_cli.js b/packages/kbn-i18n/tasks/build_cli.js index b628068badd91..28f6b5adcc8b8 100644 --- a/packages/kbn-i18n/tasks/build_cli.js +++ b/packages/kbn-i18n/tasks/build_cli.js @@ -32,7 +32,7 @@ const padRight = (width, str) => const unknownFlags = []; const flags = getopts(process.argv, { - boolean: ['watch', 'help'], + boolean: ['watch', 'help', 'source-maps'], unknown(name) { unknownFlags.push(name); }, @@ -53,8 +53,9 @@ if (flags.help) { log.info(` Simple build tool for @kbn/i18n package - --watch Run in watch mode - --help Show this message + --watch Run in watch mode + --source-maps Include sourcemaps + --help Show this message `); process.exit(); } @@ -83,6 +84,7 @@ withProcRunner(log, async proc => { '--extensions', '.ts,.js,.tsx', ...(flags.watch ? ['--watch'] : ['--quiet']), + ...(flags['source-maps'] ? ['--source-map', 'inline'] : []), ], wait: true, env: { @@ -98,6 +100,7 @@ withProcRunner(log, async proc => { args: [ '--emitDeclarationOnly', ...(flags.watch ? ['--watch', '--preserveWatchOutput', 'true'] : []), + ...(flags['source-maps'] ? ['--declarationMap', 'true'] : []), ], wait: true, env, From fa0be20186631d1c3710f38092d3fcf5c9acd27b Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 28 Nov 2018 10:20:09 -0800 Subject: [PATCH 5/5] update yarn.lock --- yarn.lock | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/yarn.lock b/yarn.lock index 8d23b0a9aae64..d32ed9fb91917 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5866,14 +5866,6 @@ cronstrue@^1.51.0: resolved "https://registry.yarnpkg.com/cronstrue/-/cronstrue-1.51.0.tgz#7a63153d61d940344049037628da38a60784c8e2" integrity sha512-fSRAz/MV0TRjeNZKAsovmH/MSsly7+8np4XsfsrjOOz7sjxLrE9SmedRYAs3nPAtLLC5UsMpvenjXYRz463bMA== -cross-env@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.2.0.tgz#6ecd4c015d5773e614039ee529076669b9d126f2" - integrity sha512-jtdNFfFW1hB7sMhr/H6rW1Z45LFqyI431m3qU6bFXcQ3Eh7LtBuG3h74o7ohHZ3crrRkkqHlo4jYHFPcjroANg== - dependencies: - cross-spawn "^6.0.5" - is-windows "^1.0.0" - cross-spawn-async@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cross-spawn-async/-/cross-spawn-async-1.0.1.tgz#bb525c1e420d9942552e04791a3eb2d9887a105f" @@ -11628,16 +11620,16 @@ is-whitespace-character@^1.0.0: resolved "https://registry.yarnpkg.com/is-whitespace-character/-/is-whitespace-character-1.0.1.tgz#9ae0176f3282b65457a1992cdb084f8a5f833e3b" integrity sha1-muAXbzKCtlRXoZks2whPil+DPjs= -is-windows@^1.0.0, is-windows@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" - integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== - is-windows@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.1.tgz#310db70f742d259a16a369202b51af84233310d9" integrity sha1-MQ23D3QtJZoWo2kgK1GvhCMzENk= +is-windows@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" + integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== + is-word-character@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/is-word-character/-/is-word-character-1.0.1.tgz#5a03fa1ea91ace8a6eb0c7cd770eb86d65c8befb"