1- oldConsole = require ' console'
21fs = require ' fs'
32os = require ' os'
43path = require ' path'
@@ -7,10 +6,12 @@ _ = require 'underscore'
76{ spawn , exec , execSync } = require ' child_process'
87CoffeeScript = require ' ./lib/coffeescript'
98helpers = require ' ./lib/coffeescript/helpers'
9+ { setupConsole } = require ' ./build-support/console'
1010
1111# ANSI Terminal Colors.
1212bold = 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
1415 bold = ' \x1B [0;1m'
1516 red = ' \x1B [0;31m'
1617 green = ' \x1B [0;32m'
@@ -31,59 +32,11 @@ header = """
3132# Used in folder names like `docs/v1`.
3233majorVersion = parseInt CoffeeScript .VERSION .split (' .' )[0 ], 10
3334
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-
7735option ' -l' , ' --level [LEVEL]' , ' log level [debug < info < log(default) < warn < error]'
7836
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 ) ->
8538 global .task name, description, ({level = ' log' , ... opts} = {}) ->
86- setupConsole {level}
39+ setupConsole {level, useColors : USE_COLORS }
8740 action {... opts}
8841
8942# Log a message with a color.
@@ -196,7 +149,7 @@ watchAndBuildAndTest = (harmony = no) ->
196149 buildAndTest no , harmony
197150
198151
199- consoleTask ' build' , ' build the CoffeeScript compiler from source' , build
152+ task ' build' , ' build the CoffeeScript compiler from source' , build
200153
201154task ' build:parser' , ' build the Jison parser only' , buildParser
202155
@@ -265,7 +218,7 @@ task 'build:browser:full', 'merge the built scripts into a single file for use i
265218 console .log " built ... running browser tests:"
266219 invoke ' test:browser'
267220
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' , ->
269222 watchAndBuildAndTest ()
270223
271224task ' 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'
622575option ' -d' , ' --desc [REGEXP*]' , ' test description patterns to positively match'
623576option null , ' --negDesc [REGEXP*]' , ' test description patterns to negatively match'
624577
625- consoleTask ' test' , ' run the CoffeeScript language test suite' , ({
578+ task ' test' , ' run the CoffeeScript language test suite' , ({
626579 file = [],
627580 negFile = [' sourcemap' ],
628581 desc = [],
0 commit comments