1
- oldConsole = require ' console'
2
1
fs = require ' fs'
3
2
os = require ' os'
4
3
path = require ' path'
@@ -7,10 +6,12 @@ _ = require 'underscore'
7
6
{ spawn , exec , execSync } = require ' child_process'
8
7
CoffeeScript = require ' ./lib/coffeescript'
9
8
helpers = require ' ./lib/coffeescript/helpers'
9
+ { setupConsole } = require ' ./build-support/console'
10
10
11
11
# ANSI Terminal Colors.
12
12
bold = red = green = yellow = reset = ' '
13
- unless process .env .NODE_DISABLE_COLORS
13
+ USE_COLORS = process .stdout .hasColors ? () and not process .env .NODE_DISABLE_COLORS
14
+ if USE_COLORS
14
15
bold = ' \x1B [0;1m'
15
16
red = ' \x1B [0;31m'
16
17
green = ' \x1B [0;32m'
@@ -31,59 +32,11 @@ header = """
31
32
# Used in folder names like `docs/v1`.
32
33
majorVersion = parseInt CoffeeScript .VERSION .split (' .' )[0 ], 10
33
34
34
-
35
- class CakeConsole extends oldConsole.Console
36
- @LEVELS : [' debug' , ' info' , ' log' , ' warn' , ' error' , ' trace' ]
37
- @levelNumsMap : do =>
38
- ret = {}
39
- ret[k] = i for k, i in @LEVELS
40
- ret
41
- @ validLevels: => " [#{ (@LEVELS .map (l) -> " '#{ l} '" ).join ' , ' } ]"
42
-
43
- constructor : ({@level = ' log' , ... opts} = {}) ->
44
- super opts
45
- unless @level in @constructor .LEVELS
46
- throw new TypeError " argument '#{ @level } ' was not a valid log level
47
- (should be: #{ @constructor .validLevels ()} )"
48
-
49
- @ getLevelNum: (l ) => @levelNumsMap [l] ? throw new TypeError " invalid level #{ l} "
50
- curLevelNum : -> @constructor .getLevelNum @level
51
- doesThisLevelApply : (l ) -> @ curLevelNum () <= @constructor .getLevelNum l
52
-
53
- # TODO: for some reason this is done lazily in buildParser, so let's do the same here.
54
- helpers .extend global , require ' util'
55
- for l in @LEVELS
56
- do (l ) => @ :: [l] = (... args ) ->
57
- if @ doesThisLevelApply l
58
- # NB: it's literally impossible to extend Console and propagate to the parent class because
59
- # of some horrific unexplained initialization code used for the singleton console
60
- # object, which employs a very complex prototype chain that makes it impossible to do
61
- # the simple thing: https://github.com/nodejs/node/blob/17fae65c72321659390c4cbcd9ddaf248accb953/lib/internal/console/global.js#L29-L33.
62
- # Undo the prototype chain nonsense and bind the method back to our subclass.
63
- (oldConsole[l].bind @ ) ... args
64
- else global .format ... args
65
-
66
- @stdio : ({
67
- stdout = process .stdout ,
68
- stderr = process .stderr ,
69
- ... opts,
70
- } = {}) => new @ {
71
- stdout,
72
- stderr,
73
- ... opts
74
- }
75
-
76
-
77
35
option ' -l' , ' --level [LEVEL]' , ' log level [debug < info < log(default) < warn < error]'
78
36
79
- setupConsole = ({level} = {}) ->
80
- global .cakeConsole = CakeConsole .stdio {level}
81
- global .console = global .cakeConsole
82
- console .info " log level = #{ level} "
83
-
84
- consoleTask = (name , description , action ) ->
37
+ task = (name , description , action ) ->
85
38
global .task name, description, ({level = ' log' , ... opts} = {}) ->
86
- setupConsole {level}
39
+ setupConsole {level, useColors : USE_COLORS }
87
40
action {... opts}
88
41
89
42
# Log a message with a color.
@@ -196,7 +149,7 @@ watchAndBuildAndTest = (harmony = no) ->
196
149
buildAndTest no , harmony
197
150
198
151
199
- consoleTask ' build' , ' build the CoffeeScript compiler from source' , build
152
+ task ' build' , ' build the CoffeeScript compiler from source' , build
200
153
201
154
task ' build:parser' , ' build the Jison parser only' , buildParser
202
155
@@ -265,7 +218,7 @@ task 'build:browser:full', 'merge the built scripts into a single file for use i
265
218
console .log " built ... running browser tests:"
266
219
invoke ' test:browser'
267
220
268
- consoleTask ' build:watch' , ' watch and continually rebuild the CoffeeScript compiler, running tests on each build' , ->
221
+ task ' build:watch' , ' watch and continually rebuild the CoffeeScript compiler, running tests on each build' , ->
269
222
watchAndBuildAndTest ()
270
223
271
224
task ' build:watch:harmony' , ' watch and continually rebuild the CoffeeScript compiler, running harmony tests on each build' , ->
@@ -622,7 +575,7 @@ option null, '--negFile [REGEXP*]', 'test file patterns to negatively match'
622
575
option ' -d' , ' --desc [REGEXP*]' , ' test description patterns to positively match'
623
576
option null , ' --negDesc [REGEXP*]' , ' test description patterns to negatively match'
624
577
625
- consoleTask ' test' , ' run the CoffeeScript language test suite' , ({
578
+ task ' test' , ' run the CoffeeScript language test suite' , ({
626
579
file = [],
627
580
negFile = [' sourcemap' ],
628
581
desc = [],
0 commit comments