Skip to content

Commit 5577ece

Browse files
thymikeecpojer
authored andcommitted
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
1 parent 3d45888 commit 5577ece

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"regenerator-runtime": "^0.10.3",
4949
"rimraf": "^2.5.4",
5050
"slash": "^1.0.0",
51+
"string-length": "^1.0.1",
5152
"strip-ansi": "^3.0.1",
5253
"typescript": "^2.2.2"
5354
},

scripts/build.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ const mkdirp = require('mkdirp');
2525
const babel = require('babel-core');
2626
const chalk = require('chalk');
2727
const micromatch = require('micromatch');
28-
28+
const stringLength = require('string-length');
2929
const getPackages = require('./_getPackages');
3030

31+
const OK = chalk.reset.inverse.bold.green(' DONE ');
3132
const SRC_DIR = 'src';
3233
const BUILD_DIR = 'build';
3334
const BUILD_ES5_DIR = 'build-es5';
@@ -46,8 +47,9 @@ const babelEs5Options = Object.assign(
4647
{plugins: [...babelNodeOptions.plugins, 'transform-runtime']}
4748
);
4849

49-
const fixedWidth = str => {
50-
const WIDTH = 80;
50+
const adjustToTerminalWidth = str => {
51+
const columns = process.stdout.columns || 80;
52+
const WIDTH = columns - stringLength(OK) + 1;
5153
const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g'));
5254
let lastString = strs[strs.length - 1];
5355
if (lastString.length < WIDTH) {
@@ -73,10 +75,10 @@ function buildPackage(p) {
7375
const pattern = path.resolve(srcDir, '**/*');
7476
const files = glob.sync(pattern, {nodir: true});
7577

76-
process.stdout.write(fixedWidth(`${path.basename(p)}\n`));
78+
process.stdout.write(adjustToTerminalWidth(`${path.basename(p)}\n`));
7779

7880
files.forEach(file => buildFile(file, true));
79-
process.stdout.write(`[ ${chalk.green('OK')} ]\n`);
81+
process.stdout.write(`${OK}\n`);
8082
}
8183

8284
function buildFile(file, silent) {
@@ -141,7 +143,7 @@ const files = process.argv.slice(2);
141143
if (files.length) {
142144
files.forEach(buildFile);
143145
} else {
144-
process.stdout.write(chalk.bold.inverse('Building packages\n'));
146+
process.stdout.write(chalk.inverse(' Building packages \n'));
145147
getPackages().forEach(buildPackage);
146148
process.stdout.write('\n');
147149
}

yarn.lock

+11-12
Original file line numberDiff line numberDiff line change
@@ -1304,13 +1304,13 @@ [email protected]:
13041304
dependencies:
13051305
ms "0.7.1"
13061306

1307-
debug@^2.1.1, debug@^2.2.0:
1307+
debug@^2.1.1:
13081308
version "2.6.3"
13091309
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d"
13101310
dependencies:
13111311
ms "0.7.2"
13121312

1313-
debug@^2.6.8:
1313+
debug@^2.2.0, debug@^2.6.8:
13141314
version "2.6.8"
13151315
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
13161316
dependencies:
@@ -1941,7 +1941,7 @@ glob-parent@^2.0.0:
19411941
dependencies:
19421942
is-glob "^2.0.0"
19431943

1944-
[email protected], glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1:
1944+
[email protected], glob@^7.1.1:
19451945
version "7.1.1"
19461946
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
19471947
dependencies:
@@ -1952,7 +1952,7 @@ [email protected], glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1:
19521952
once "^1.3.0"
19531953
path-is-absolute "^1.0.0"
19541954

1955-
glob@^7.1.2:
1955+
glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.2:
19561956
version "7.1.2"
19571957
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
19581958
dependencies:
@@ -2464,14 +2464,7 @@ js-tokens@^3.0.0:
24642464
version "3.0.1"
24652465
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"
24662466

2467-
js-yaml@^3.7.0:
2468-
version "3.8.3"
2469-
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.3.tgz#33a05ec481c850c8875929166fe1beb61c728766"
2470-
dependencies:
2471-
argparse "^1.0.7"
2472-
esprima "^3.1.1"
2473-
2474-
js-yaml@^3.8.4:
2467+
js-yaml@^3.7.0, js-yaml@^3.8.4:
24752468
version "3.8.4"
24762469
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.4.tgz#520b4564f86573ba96662af85a8cafa7b4b5a6f6"
24772470
dependencies:
@@ -3631,6 +3624,12 @@ state-toggle@^1.0.0:
36313624
version "1.0.0"
36323625
resolved "https://registry.yarnpkg.com/state-toggle/-/state-toggle-1.0.0.tgz#d20f9a616bb4f0c3b98b91922d25b640aa2bc425"
36333626

3627+
string-length@^1.0.1:
3628+
version "1.0.1"
3629+
resolved "https://registry.yarnpkg.com/string-length/-/string-length-1.0.1.tgz#56970fb1c38558e9e70b728bf3de269ac45adfac"
3630+
dependencies:
3631+
strip-ansi "^3.0.0"
3632+
36343633
string-width@^1.0.1, string-width@^1.0.2:
36353634
version "1.0.2"
36363635
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"

0 commit comments

Comments
 (0)