Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 82a6970

Browse files
committed
fix ansi styles build
1 parent c8a1409 commit 82a6970

7 files changed

Lines changed: 2167 additions & 742 deletions

File tree

build-babel/ansi-styles.js

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
'use strict';
2+
const colorConvert = require('color-convert');
3+
4+
const wrapAnsi16 = (fn, offset) => function () {
5+
const code = fn.apply(colorConvert, arguments);
6+
return `\u001B[${code + offset}m`;
7+
};
8+
9+
const wrapAnsi256 = (fn, offset) => function () {
10+
const code = fn.apply(colorConvert, arguments);
11+
return `\u001B[${38 + offset};5;${code}m`;
12+
};
13+
14+
const wrapAnsi16m = (fn, offset) => function () {
15+
const rgb = fn.apply(colorConvert, arguments);
16+
return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
17+
};
18+
19+
function assembleStyles() {
20+
const styles = {
21+
modifier: {
22+
reset: [0, 0],
23+
// 21 isn't widely supported and 22 does the same thing
24+
bold: [1, 22],
25+
dim: [2, 22],
26+
italic: [3, 23],
27+
underline: [4, 24],
28+
inverse: [7, 27],
29+
hidden: [8, 28],
30+
strikethrough: [9, 29]
31+
},
32+
color: {
33+
black: [30, 39],
34+
red: [31, 39],
35+
green: [32, 39],
36+
yellow: [33, 39],
37+
blue: [34, 39],
38+
magenta: [35, 39],
39+
cyan: [36, 39],
40+
white: [37, 39],
41+
gray: [90, 39],
42+
43+
// Bright color
44+
redBright: [91, 39],
45+
greenBright: [92, 39],
46+
yellowBright: [93, 39],
47+
blueBright: [94, 39],
48+
magentaBright: [95, 39],
49+
cyanBright: [96, 39],
50+
whiteBright: [97, 39]
51+
},
52+
bgColor: {
53+
bgBlack: [40, 49],
54+
bgRed: [41, 49],
55+
bgGreen: [42, 49],
56+
bgYellow: [43, 49],
57+
bgBlue: [44, 49],
58+
bgMagenta: [45, 49],
59+
bgCyan: [46, 49],
60+
bgWhite: [47, 49],
61+
62+
// Bright color
63+
bgBlackBright: [100, 49],
64+
bgRedBright: [101, 49],
65+
bgGreenBright: [102, 49],
66+
bgYellowBright: [103, 49],
67+
bgBlueBright: [104, 49],
68+
bgMagentaBright: [105, 49],
69+
bgCyanBright: [106, 49],
70+
bgWhiteBright: [107, 49]
71+
}
72+
};
73+
74+
// Fix humans
75+
styles.color.grey = styles.color.gray;
76+
77+
Object.keys(styles).forEach(groupName => {
78+
const group = styles[groupName];
79+
80+
Object.keys(group).forEach(styleName => {
81+
const style = group[styleName];
82+
83+
styles[styleName] = {
84+
open: `\u001B[${style[0]}m`,
85+
close: `\u001B[${style[1]}m`
86+
};
87+
88+
group[styleName] = styles[styleName];
89+
});
90+
91+
Object.defineProperty(styles, groupName, {
92+
value: group,
93+
enumerable: false
94+
});
95+
});
96+
97+
const rgb2rgb = (r, g, b) => [r, g, b];
98+
99+
styles.color.close = '\u001B[39m';
100+
styles.bgColor.close = '\u001B[49m';
101+
102+
styles.color.ansi = {};
103+
styles.color.ansi256 = {};
104+
styles.color.ansi16m = {
105+
rgb: wrapAnsi16m(rgb2rgb, 0)
106+
};
107+
108+
styles.bgColor.ansi = {};
109+
styles.bgColor.ansi256 = {};
110+
styles.bgColor.ansi16m = {
111+
rgb: wrapAnsi16m(rgb2rgb, 10)
112+
};
113+
114+
for (const key of Object.keys(colorConvert)) {
115+
if (typeof colorConvert[key] !== 'object') {
116+
continue;
117+
}
118+
119+
const suite = colorConvert[key];
120+
121+
if ('ansi16' in suite) {
122+
styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
123+
styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
124+
}
125+
126+
if ('ansi256' in suite) {
127+
styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
128+
styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
129+
}
130+
131+
if ('rgb' in suite) {
132+
styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
133+
styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
134+
}
135+
}
136+
137+
return styles;
138+
}
139+
140+
//Object.defineProperty(module, 'exports', {
141+
// enumerable: true,
142+
// get: assembleStyles
143+
//});
144+
module.exports = assembleStyles();

build-babel/jspm.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SystemJS.config({
1717
"babel-runtime": "npm:babel-runtime@6.23.0",
1818
"babel-preset-react": "npm:babel-preset-react@6.24.1",
1919
"babel-plugin-syntax-dynamic-import": "npm:babel-plugin-syntax-dynamic-import@6.18.0",
20+
"color-convert": "npm:color-convert@1.9.0",
2021
"debug": "npm:debug@2.6.8",
2122
"babel-core": "npm:babel-core@6.25.0",
2223
"constants": "npm:jspm-nodelibs-constants@0.2.1",
@@ -866,6 +867,11 @@ SystemJS.config({
866867
"minimalistic-assert": "npm:minimalistic-assert@1.0.0",
867868
"minimalistic-crypto-utils": "npm:minimalistic-crypto-utils@1.0.1"
868869
}
870+
},
871+
"npm:color-convert@1.9.0": {
872+
"map": {
873+
"color-name": "npm:color-name@1.1.2"
874+
}
869875
}
870876
}
871877
});

build-babel/node-build.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"map": {
3+
"npm:chalk@1.1.3": {
4+
"ansi-styles": "ansi-styles.js",
5+
"escape-string-regexp": "npm:escape-string-regexp@1.0.5",
6+
"has-ansi": "npm:has-ansi@2.0.0",
7+
"strip-ansi": "npm:strip-ansi@3.0.1",
8+
"supports-color": "npm:supports-color@2.0.0"
9+
}
10+
}
11+
}

build-babel/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"babel-preset-stage-2": "npm:babel-preset-stage-2@^6.5.0",
3333
"babel-preset-stage-3": "npm:babel-preset-stage-3@^6.3.13",
3434
"babel-runtime": "npm:babel-runtime@^6.23.0",
35+
"color-convert": "npm:color-convert@^1.9.0",
3536
"core-js": "npm:core-js@^2.4.0",
3637
"debug": "npm:debug@^2.6.0",
3738
"regenerator-runtime": "npm:regenerator-runtime@^0.10.1"

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cd $BUILD_DIR
1111
cp -r jspm_packages_override/* jspm_packages
1212

1313
jspm build systemjs-babel.js ../systemjs-babel-browser.js --format amd --skip-source-maps --skip-rollup --minify --log ok
14-
jspm build systemjs-babel.js ../systemjs-babel-node.js --format amd --node --skip-source-maps --skip-rollup --log ok
14+
jspm build systemjs-babel.js ../systemjs-babel-node.js --format amd --node --skip-source-maps --skip-rollup --log ok --config node-build.json
1515
jspm run systemjs-build-babel-helpers.js > ../babel-helpers.js
1616
jspm run systemjs-build-modular-babel-helpers.js
1717
# (

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "systemjs-plugin-babel",
3-
"version": "0.0.23",
3+
"version": "0.0.24",
44
"registry": "npm",
55
"jspmPackage": true,
66
"repository": {

0 commit comments

Comments
 (0)