From b25120ee3cf9854b2775892d4f6ba9c0064e53e8 Mon Sep 17 00:00:00 2001 From: Danny McClanahan <1305167+cosmicexplorer@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:14:06 -0500 Subject: [PATCH] fix colors --- Cakefile | 20 ++++++++------------ build-support/caching.coffee | 31 ++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Cakefile b/Cakefile index 553fc1fde8..36af9433ce 100644 --- a/Cakefile +++ b/Cakefile @@ -3,7 +3,6 @@ fs = require 'fs' os = require 'os' path = require 'path' stream = require 'stream' -_ = require 'underscore' { spawn, exec, execSync } = require 'child_process' CoffeeScript = require './lib/coffeescript' helpers = require './lib/coffeescript/helpers' @@ -36,7 +35,8 @@ task = (name, description, action) -> # ANSI Terminal Colors. bold = red = green = yellow = reset = '' -if process.stdout.hasColors() and not process.env.NODE_DISABLE_COLORS +USE_COLORS = process.stdout.hasColors?() and not process.env.NODE_DISABLE_COLORS +if USE_COLORS bold = '\x1B[0;1m' red = '\x1B[0;31m' green = '\x1B[0;32m' @@ -80,18 +80,12 @@ class TopLevelError extends AggregateError if e instanceof AggregateError aggregateStack.push ...e.errors.reverse() else if e instanceof TaskFailed - title = e.title() - console.error "task failed: #{title}" - operation = e.operation() - console.info util.styleText ['yellow'], "operation: #{operation}" - reason = e.reason() - console.info util.styleText ['cyan'], "reason: #{reason}" - inner = e.inner() - if inner? - console.error util.styleText 'reset', inner + e.print console, {useColors: USE_COLORS} if (heading = e.heading?())? - console.error util.styleText ['underline', 'magenta', 'italic'], heading + if USE_COLORS + heading = util.styleText ['underline', 'magenta', 'italic'], heading + console.error heading process.exit 1 @@ -286,6 +280,8 @@ task 'build:watch:harmony', 'watch and continually rebuild the CoffeeScript comp buildDocs = (watch = no) -> + _ = require 'underscore' + # Constants indexFile = 'documentation/site/index.html' siteSourceFolder = "documentation/site" diff --git a/build-support/caching.coffee b/build-support/caching.coffee index 73c89cab65..9835a428a2 100644 --- a/build-support/caching.coffee +++ b/build-support/caching.coffee @@ -1,10 +1,11 @@ -assert = require 'assert' -{ createHash } = require 'crypto' -fs = require 'fs' -path = require 'path' -{ performance } = require 'perf_hooks' -stream = require 'stream' -helpers = require '../lib/coffeescript/helpers' +assert = require 'assert' +fs = require 'fs' +helpers = require '../lib/coffeescript/helpers' +path = require 'path' +stream = require 'stream' +util = require 'util' +{ createHash } = require 'crypto' +{ performance } = require 'perf_hooks' exports.Content = class Content @@ -135,6 +136,22 @@ exports.TaskFailed = class TaskFailed extends Error reason: -> @cause.reason?() inner: -> @cause.inner?() + print: (console, {useColors}) -> + console.error "task failed: #{@title()}" + + operation = "operation: #{@operation()}" + if useColors + operation = util.styleText 'yellow', operation + console.info operation + + reason = "reason: #{@reason()}" + if useColors + reason = util.styleText 'cyan', reason + console.info reason + + if (inner = @inner())? + console.error util.styleText 'reset', inner + exports.BuildTask = class BuildTask identifier: -> throw new TypeError "unimplemented: #{@constructor.name}"