From abbb75d333d285b55c4908dbde56f08d73b56f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 27 Jun 2017 01:16:58 +0200 Subject: [PATCH] Make build script printing small-terminals-friendly (#3892) * Make build script printing small-terminals-friendly * Debug windows * Fallback on undefined stdout.columns * Bring back 'editor.formatOnSave' * Update yarn.lock --- package.json | 1 + scripts/build.js | 14 ++++++++------ yarn.lock | 23 +++++++++++------------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index af8e05804b56..1875062cfe58 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "regenerator-runtime": "^0.10.3", "rimraf": "^2.5.4", "slash": "^1.0.0", + "string-length": "^1.0.1", "strip-ansi": "^3.0.1", "typescript": "^2.2.2" }, diff --git a/scripts/build.js b/scripts/build.js index d3fdac401e85..45425f8d52e9 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -25,9 +25,10 @@ const mkdirp = require('mkdirp'); const babel = require('babel-core'); const chalk = require('chalk'); const micromatch = require('micromatch'); - +const stringLength = require('string-length'); const getPackages = require('./_getPackages'); +const OK = chalk.reset.inverse.bold.green(' DONE '); const SRC_DIR = 'src'; const BUILD_DIR = 'build'; const BUILD_ES5_DIR = 'build-es5'; @@ -46,8 +47,9 @@ const babelEs5Options = Object.assign( {plugins: [...babelNodeOptions.plugins, 'transform-runtime']} ); -const fixedWidth = str => { - const WIDTH = 80; +const adjustToTerminalWidth = str => { + const columns = process.stdout.columns || 80; + const WIDTH = columns - stringLength(OK) + 1; const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g')); let lastString = strs[strs.length - 1]; if (lastString.length < WIDTH) { @@ -73,10 +75,10 @@ function buildPackage(p) { const pattern = path.resolve(srcDir, '**/*'); const files = glob.sync(pattern, {nodir: true}); - process.stdout.write(fixedWidth(`${path.basename(p)}\n`)); + process.stdout.write(adjustToTerminalWidth(`${path.basename(p)}\n`)); files.forEach(file => buildFile(file, true)); - process.stdout.write(`[ ${chalk.green('OK')} ]\n`); + process.stdout.write(`${OK}\n`); } function buildFile(file, silent) { @@ -141,7 +143,7 @@ const files = process.argv.slice(2); if (files.length) { files.forEach(buildFile); } else { - process.stdout.write(chalk.bold.inverse('Building packages\n')); + process.stdout.write(chalk.inverse(' Building packages \n')); getPackages().forEach(buildPackage); process.stdout.write('\n'); } diff --git a/yarn.lock b/yarn.lock index 117a88344d03..eb910d6ee371 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1304,13 +1304,13 @@ debug@2.2.0: dependencies: ms "0.7.1" -debug@^2.1.1, debug@^2.2.0: +debug@^2.1.1: version "2.6.3" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d" dependencies: ms "0.7.2" -debug@^2.6.8: +debug@^2.2.0, debug@^2.6.8: version "2.6.8" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc" dependencies: @@ -1941,7 +1941,7 @@ glob-parent@^2.0.0: dependencies: is-glob "^2.0.0" -glob@7.1.1, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1: +glob@7.1.1, glob@^7.1.1: version "7.1.1" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" dependencies: @@ -1952,7 +1952,7 @@ glob@7.1.1, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.1.2: +glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.2: version "7.1.2" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" dependencies: @@ -2464,14 +2464,7 @@ js-tokens@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7" -js-yaml@^3.7.0: - version "3.8.3" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.3.tgz#33a05ec481c850c8875929166fe1beb61c728766" - dependencies: - argparse "^1.0.7" - esprima "^3.1.1" - -js-yaml@^3.8.4: +js-yaml@^3.7.0, js-yaml@^3.8.4: version "3.8.4" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.4.tgz#520b4564f86573ba96662af85a8cafa7b4b5a6f6" dependencies: @@ -3631,6 +3624,12 @@ state-toggle@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/state-toggle/-/state-toggle-1.0.0.tgz#d20f9a616bb4f0c3b98b91922d25b640aa2bc425" +string-length@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/string-length/-/string-length-1.0.1.tgz#56970fb1c38558e9e70b728bf3de269ac45adfac" + dependencies: + strip-ansi "^3.0.0" + string-width@^1.0.1, string-width@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"