Skip to content

Commit

Permalink
Make build script printing small-terminals-friendly (jestjs#3892)
Browse files Browse the repository at this point in the history
* Make build script printing small-terminals-friendly

* Debug windows

* Fallback on undefined stdout.columns

* Bring back 'editor.formatOnSave'

* Update yarn.lock
  • Loading branch information
thymikee authored and cpojer committed Jun 26, 2017
1 parent 48af250 commit abbb75d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
14 changes: 8 additions & 6 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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');
}
23 changes: 11 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1304,13 +1304,13 @@ [email protected]:
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:
Expand Down Expand Up @@ -1941,7 +1941,7 @@ glob-parent@^2.0.0:
dependencies:
is-glob "^2.0.0"

[email protected], glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1:
[email protected], glob@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
dependencies:
Expand All @@ -1952,7 +1952,7 @@ [email protected], 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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit abbb75d

Please sign in to comment.