From 883cc8e5bc2c0466e1bfab610a3ffe1a879ef923 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sat, 9 Mar 2024 20:34:20 -0700 Subject: [PATCH 01/25] Prototype of symbol messages --- index.js | 131 ++++++++++++++----- lib/shared/completion.js | 10 +- lib/shared/log/tasks.js | 6 +- lib/shared/log/to-console.js | 114 ++++++++++------- lib/shared/options/make-help.js | 6 +- lib/versioned/^3.7.0/index.js | 4 +- lib/versioned/^4.0.0-alpha.1/index.js | 4 +- lib/versioned/^4.0.0-alpha.2/index.js | 4 +- lib/versioned/^4.0.0/index.js | 4 +- messages.js | 14 +++ package.json | 7 +- test/lib/theme.js | 174 +++++++++++++------------- 12 files changed, 289 insertions(+), 189 deletions(-) create mode 100644 messages.js diff --git a/index.js b/index.js index ebf3eb01..09a05426 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ var fs = require('fs'); var path = require('path'); var log = require('gulplog'); +var chalk = require('chalk'); var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); @@ -20,6 +21,7 @@ var msgs = require('./lib/shared/log/messages'); var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); var overrideEnvByConfigAndCliOpts = require('./lib/shared/config/env-config'); +var messages = require('./messages'); // Get supported ranges var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); @@ -62,15 +64,18 @@ try { } cli.on('preload:before', function(name) { - log.info(msgs.info.preloadBefore, name); + log.info(messages.PRELOAD_BEFORE, name); }); cli.on('preload:success', function(name) { - log.info(msgs.info.preloadSuccess, name); + log.info(messages.PRELOAD_SUCCESS, name); }); cli.on('preload:failure', function(name, error) { - log.warn(msgs.warn.preloadFailure, name, Boolean(error), error.toString()); + log.warn(messages.PRELOAD_FAILURE, name); + if (error) { + log.warn(messages.PRELOAD_ERROR, error); + } }); cli.on('loader:success', function(name) { @@ -79,16 +84,20 @@ cli.on('loader:success', function(name) { // However, we don't want to show the mjs-stub loader in the logs /* istanbul ignore else */ if (path.basename(name, '.js') !== 'mjs-stub') { - log.info(msgs.info.loaderSuccess, name); + log.info(messages.LOADER_SUCCESS, name); } }); cli.on('loader:failure', function(name, error) { - log.warn(msgs.warn.loaderFailure, name, Boolean(error), error.toString()); + log.warn(messages.LOADER_FAILURE, name); + if (error) { + log.warn(messages.LOADER_ERROR, error); + } }); cli.on('respawn', function(flags, child) { - log.info(msgs.info.respawn, flags.join(', '), child.pid); + log.info(messages.NODE_FLAGS, flags); + log.info(messages.RESPAWNED, child.pid); }); function run() { @@ -106,8 +115,66 @@ function onPrepare(env) { var cfg = mergeProjectAndUserHomeConfigs(env); env = overrideEnvByConfigAndCliOpts(env, cfg, opts); - // Set up event listeners for logging again after configuring. - toConsole(log, env.config.flags); + // Set up event listeners for logging after configuring. + toConsole(log, { + tasksSimple: env.config.flags.tasksSimple, + tasksJson: env.config.flags.tasksJson, + help: env.config.flags.help, + version: env.config.flags.version, + silent: env.config.flags.silent, + logLevel: env.config.flags.logLevel, + getMessage: function(msg, data) { + if (msg === messages.PRELOAD_BEFORE) { + return 'Preloading external module: ' + chalk.magenta(data); + } + + if (msg === messages.PRELOAD_SUCCESS) { + return 'Preloaded external module: ' + chalk.magenta(data) + } + + if (msg === messages.PRELOAD_FAILURE) { + return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data); + } + + if (msg === messages.PRELOAD_ERROR) { + return chalk.yellow(data.toString()); + } + + if (msg === messages.LOADER_SUCCESS) { + return 'Loaded external module: ' + chalk.magenta(data); + } + + if (msg === messages.LOADER_FAILURE) { + return chalk.yellow('Failed to load external module: ') + chalk.magenta(data); + } + + if (msg === messages.LOADER_ERROR) { + return chalk.yellow(data.toString()); + } + + if (msg === messages.NODE_FLAGS) { + var nodeFlags = chalk.magenta(data.join(', ')); + return 'Node flags detected: ' + nodeFlags; + } + + if (msg === messages.RESPAWNED) { + var pid = chalk.magenta(data); + return 'Respawned to PID: ' + pid; + } + + if (msg === messages.GULPFILE_NOT_FOUND) { + return chalk.red('No gulpfile found'); + } + + if (msg === messages.CWD_CHANGED) { + return 'Working directory changed to ' + chalk.magenta(data); + } + + if (msg === messages.UNSUPPORTED_GULP_VERSION) { + return chalk.red('Unsupported gulp version', env.modulePackage.version) + } + }, + }); cli.execute(env, env.nodeFlags, onExecute); } @@ -122,15 +189,15 @@ function onExecute(env) { process.env.UNDERTAKER_SETTLE = 'true'; } - if (optsErr) { - log.error(msgs.error.failToParseCliOpts, optsErr.message); - makeHelp(parser).showHelp(console.error); - exit(1); - } - if (env.config.flags.help) { - makeHelp(parser).showHelp(console.log); - exit(0); - } + // if (optsErr) { + // log.error(msgs.error.failToParseCliOpts, optsErr.message); + // makeHelp(parser).showHelp(console.error); + // exit(1); + // } + // if (env.config.flags.help) { + // makeHelp(parser).showHelp(console.log); + // exit(0); + // } // Anything that needs to print outside of the logging mechanism should use console.log if (env.config.flags.version) { @@ -140,23 +207,23 @@ function onExecute(env) { } if (!env.modulePath) { - var missingNodeModules = - fs.existsSync(path.join(env.cwd, 'package.json')) - && !fs.existsSync(path.join(env.cwd, 'node_modules')); - - var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); - var hasNpm = !hasYarn; - - if (missingNodeModules) { - log.error(msgs.error.nodeModulesNotFound, tildify(env.cwd), hasYarn, hasNpm); - } else { - log.error(msgs.error.gulpNotFound, tildify(env.cwd), hasYarn, hasNpm); - } + // var missingNodeModules = + // fs.existsSync(path.join(env.cwd, 'package.json')) + // && !fs.existsSync(path.join(env.cwd, 'node_modules')); + + // var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); + // var hasNpm = !hasYarn; + + // if (missingNodeModules) { + // log.error(msgs.error.nodeModulesNotFound, tildify(env.cwd), hasYarn, hasNpm); + // } else { + // log.error(msgs.error.gulpNotFound, tildify(env.cwd), hasYarn, hasNpm); + // } exit(1); } if (!env.configPath) { - log.error(msgs.error.gulpfileNotFound); + log.error(messages.GULPFILE_NOT_FOUND); exit(1); } @@ -164,14 +231,14 @@ function onExecute(env) { // we let them chdir as needed if (process.cwd() !== env.cwd) { process.chdir(env.cwd); - log.info(msgs.info.cwdChanged, tildify(env.cwd)); + log.info(messages.CWD_CHANGED, tildify(env.cwd)); } // Find the correct CLI version to run var range = findRange(env.modulePackage.version, ranges); if (!range) { - log.error(msgs.error.badGulpVersion, env.modulePackage.version); + log.error(messages.UNSUPPORTED_GULP_VERSION, env.modulePackage.version); exit(1); } diff --git a/lib/shared/completion.js b/lib/shared/completion.js index 1f1a7cc3..f10cd758 100644 --- a/lib/shared/completion.js +++ b/lib/shared/completion.js @@ -2,21 +2,21 @@ var fs = require('fs'); var path = require('path'); -var format = require('theming-log').format; +// var format = require('theming-log').format; -var theme = require('./log/theme'); -var msgs = require('./log/messages'); +// var theme = require('./log/theme'); +// var msgs = require('./log/messages'); module.exports = function(name) { if (typeof name !== 'string') { - throw new Error(format(theme, msgs.error.noCompletionType)); + // throw new Error(format(theme, msgs.error.noCompletionType)); } var file = path.join(__dirname, '../../completion', name); try { console.log(fs.readFileSync(file, 'utf8')); process.exit(0); } catch (err) { - console.log(format(theme, msgs.error.unknownCompletionType, name)); + // console.log(format(theme, msgs.error.unknownCompletionType, name)); process.exit(5); } }; diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 2dc7a4d1..c20180e6 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -2,7 +2,7 @@ var log = require('gulplog'); var stringWidth = require('string-width'); -var format = require('theming-log').format; +// var format = require('theming-log').format; var theme = require('./theme'); var msgs = require('./messages'); var isObject = require('../is-object'); @@ -93,7 +93,7 @@ function addTaskToLines(task, lines, isLast, isLeaf) { line.bars = taskBars; line.name = task.label; } - line.width = stringWidth(format(theme, line.fmt, line.bars, line.name)); + // line.width = stringWidth(format(theme, line.fmt, line.bars, line.name)); if (typeof task.desc === 'string' && task.desc) { line.desc = task.desc; @@ -127,7 +127,7 @@ function addTaskToLines(task, lines, isLast, isLeaf) { line.fmt = msgs.tasks.option; line.bars = flagBars; line.name = ent[0]; - line.width = stringWidth(format(theme, line.fmt, line.bars, line.name)); + // line.width = stringWidth(format(theme, line.fmt, line.bars, line.name)); maxLabelWidth = Math.max(maxLabelWidth, line.width); diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 844343aa..5067a71d 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -1,46 +1,11 @@ 'use strict'; -var themingLog = require('theming-log'); -var theme = require('./theme'); +var fancyLog = require('fancy-log'); /* istanbul ignore next */ function noop() {} -// The sorting of the levels is -// significant. -var levels = [ - 'error', // -L: Logs error events. - 'warn', // -LL: Logs warn and error events. - 'info', // -LLL: Logs info, warn and error events. - 'debug', // -LLLL: Logs all log levels. -]; - -function consoleLog(s) { - if (s) console.log(s); -} - -function consoleError(s) { - /* istanbul ignore else */ - if (s) console.error(s); -} - -function cleanup(log) { - levels.forEach(removeListeners); - - function removeListeners(level) { - if (level === 'error') { - log.removeListener(level, noop); - log.removeListener(level, consoleError); - } else { - log.removeListener(level, consoleLog); - } - } -} - function toConsole(log, opts) { - // Remove previous listeners to enable to call this twice. - cleanup(log); - // Return immediately if logging is // not desired. if (opts.tasksSimple || opts.tasksJson || opts.help || opts.version || opts.silent) { @@ -52,19 +17,76 @@ function toConsole(log, opts) { // Default loglevel to info level (3). var loglevel = opts.logLevel || 3; - levels - .filter(function(item, i) { - return i < loglevel; - }) - .forEach(function(level) { - if (level === 'error') { - log.on(level, consoleError); - } else { - log.on(level, consoleLog); + // -L: Logs error events. + if (loglevel > 0) { + log.on('error', function (sym, data) { + var msg = opts.getMessage.call(null, sym, data); + // Users can filter messages by explicitly returning `false` + if (msg === false) { + return; + } + // If nothing is returned, we log the original message directly + if (typeof msg === 'undefined') { + fancyLog.error(arguments[0]); + return; } - log[level] = themingLog(theme, log[level]); + fancyLog.error(msg); }); + } + + // -LL: Logs warn and error events. + if (loglevel > 1) { + log.on('warn', function(sym, data) { + var msg = opts.getMessage.call(null, sym, data); + // Users can filter messages by explicitly returning `false` + if (msg === false) { + return; + } + // If nothing is returned, we log the original message directly + if (typeof msg === 'undefined') { + fancyLog.apply(null, arguments); + return; + } + + fancyLog(msg) + }); + } + + // -LLL: Logs info, warn and error events. + if (loglevel > 2) { + log.on('info', function(sym, data) { + var msg = opts.getMessage.call(null, sym, data); + // Users can filter messages by explicitly returning `false` + if (msg === false) { + return; + } + // If nothing is returned, we log the original message directly + if (typeof msg === 'undefined') { + fancyLog.apply(null, arguments) + return; + } + + fancyLog(msg) + }) + } + + if (loglevel > 3) { + log.on('debug', function(sym, data) { + var msg = opts.getMessage.call(null, sym, data); + // Users can filter messages by explicitly returning `false` + if (msg === false) { + return; + } + // If nothing is returned, we log the original message directly + if (typeof msg === 'undefined') { + fancyLog.apply(null, arguments) + return; + } + + fancyLog(msg) + }) + } } module.exports = toConsole; diff --git a/lib/shared/options/make-help.js b/lib/shared/options/make-help.js index d2b45d14..45dccaaf 100644 --- a/lib/shared/options/make-help.js +++ b/lib/shared/options/make-help.js @@ -1,14 +1,14 @@ 'use strict'; -var format = require('theming-log').format; +// var format = require('theming-log').format; var theme = require('../log/theme'); var msgs = require('../log/messages'); function makeHelp(parser) { - parser.usage(format(theme, msgs.help.usage)); + // parser.usage(format(theme, msgs.help.usage)); Object.keys(msgs.help.flags).forEach(function(flag) { - parser.describe(flag, format(theme, msgs.help.flags[flag])); + // parser.describe(flag, format(theme, msgs.help.flags[flag])); }); return parser; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 321493a9..569383d2 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -6,7 +6,7 @@ var stdout = require('mute-stdout'); var msgs = require('../../shared/log/messages'); var theme = require('../../shared/log/theme'); -var format = require('theming-log').format; +// var format = require('theming-log').format; var taskTree = require('./task-tree'); var copyTree = require('../../shared/log/copy-tree'); @@ -62,7 +62,7 @@ function execute(env) { } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + // tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 8e036922..06ffa38e 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -6,7 +6,7 @@ var stdout = require('mute-stdout'); var msgs = require('../../shared/log/messages'); var theme = require('../../shared/log/theme'); -var format = require('theming-log').format; +// var format = require('theming-log').format; var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -65,7 +65,7 @@ function execute(env) { } if (opts.tasksJson) { tree = {}; - tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + // tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); tree.nodes = gulpInst.tree({ deep: true }); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js index ab787e1d..f04fcb1d 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -6,7 +6,7 @@ var stdout = require('mute-stdout'); var msgs = require('../../shared/log/messages'); var theme = require('../../shared/log/theme'); -var format = require('theming-log').format; +// var format = require('theming-log').format; var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -63,7 +63,7 @@ function execute(env) { } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + // tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index a73cf11a..6fe0f4b9 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -6,7 +6,7 @@ var stdout = require('mute-stdout'); var msgs = require('../../shared/log/messages'); var theme = require('../../shared/log/theme'); -var format = require('theming-log').format; +// var format = require('theming-log').format; var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -63,7 +63,7 @@ function execute(env) { } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + // tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/messages.js b/messages.js new file mode 100644 index 00000000..a5154fb6 --- /dev/null +++ b/messages.js @@ -0,0 +1,14 @@ +module.exports = { + PRELOAD_BEFORE: Symbol.for("GULP_CLI_PRELOAD_BEFORE"), + PRELOAD_SUCCESS: Symbol.for("GULP_CLI_PRELOAD_SUCCESS"), + PRELOAD_FAILURE: Symbol.for("GULP_CLI_PRELOAD_FAILURE"), + PRELOAD_ERROR: Symbol.for("GULP_CLI_PRELOAD_ERROR"), + LOADER_SUCCESS: Symbol.for("GULP_CLI_LOADER_SUCCESS"), + LOADER_FAILURE: Symbol.for("GULP_CLI_LOADER_FAILURE"), + LOADER_ERROR: Symbol.for("GULP_CLI_LOADER_ERROR"), + NODE_FLAGS: Symbol.for("GULP_CLI_NODE_FLAGS"), + RESPAWNED: Symbol.for("GULP_CLI_RESPAWNED"), + GULPFILE_NOT_FOUND: Symbol.for("GULP_CLI_GULPFILE_NOT_FOUND"), + CWD_CHANGED: Symbol.for("GULP_CLI_CWD_CHANGED"), + UNSUPPORTED_GULP_VERSION: Symbol.for("GULP_CLI_UNSUPPORTED_GULP_VERSION"), +}; diff --git a/package.json b/package.json index 361490ed..ed597e68 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ ], "scripts": { "lint": "eslint .", - "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", "test": "mocha --async-only --timeout 5000 test/lib test", "cover": "nyc mocha --async-only --timeout 5000 test/lib test" @@ -32,14 +31,14 @@ "dependencies": { "chalk": "^4.1.2", "copy-props": "^4.0.0", - "gulplog": "^2.0.1", + "fancy-log": "^2.0.0", + "gulplog": "^2.1.0", "interpret": "^3.1.1", "liftoff": "^4.0.0", "mute-stdout": "^2.0.0", "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0", "string-width": "^4.2.3", - "theming-log": "^3.0.0", "v8flags": "^4.0.0", "yargs": "^16.2.0" }, @@ -51,8 +50,6 @@ "eslint-config-gulp": "^5.0.1", "expect": "^27.5.1", "gulp": "^4.0.2", - "marked": "^0.7.0", - "marked-man": "^0.7.0", "mocha": "^8.4.0", "nyc": "^15.1.0", "rimraf": "^3.0.2", diff --git a/test/lib/theme.js b/test/lib/theme.js index 7329a137..28861b3a 100644 --- a/test/lib/theme.js +++ b/test/lib/theme.js @@ -1,103 +1,103 @@ 'use strict'; var expect = require('expect'); -var format = require('theming-log').format; -var theme = require('../../lib/shared/log/theme'); +// var format = require('theming-log').format; +// var theme = require('../../lib/shared/log/theme'); -describe('lib: theme', function() { +// describe('lib: theme', function() { - it('styles', function(done) { - if (process.env.CI) { - this.skip(); - return; - } +// it('styles', function(done) { +// if (process.env.CI) { +// this.skip(); +// return; +// } - expect(theme.reset('hello', 'world')).toEqual('\x1B[0mhello world\x1B[0m'); - expect(theme.bold('hello', 'world')).toEqual('\x1B[1mhello world\x1B[22m'); - expect(theme.dim('hello', 'world')).toEqual('\x1B[2mhello world\x1B[22m'); - expect(theme.italic('hello', 'world')).toEqual('\x1B[3mhello world\x1B[23m'); - expect(theme.underline('hello', 'world')).toEqual('\x1B[4mhello world\x1B[24m'); - expect(theme.inverse('hello', 'world')).toEqual('\x1B[7mhello world\x1B[27m'); - expect(theme.hidden('hello', 'world')).toEqual('\x1B[8mhello world\x1B[28m'); - expect(theme.strikethrough('hello', 'world')).toEqual('\x1B[9mhello world\x1B[29m'); - expect(theme.visible('hello', 'world')).toEqual('hello world'); +// expect(theme.reset('hello', 'world')).toEqual('\x1B[0mhello world\x1B[0m'); +// expect(theme.bold('hello', 'world')).toEqual('\x1B[1mhello world\x1B[22m'); +// expect(theme.dim('hello', 'world')).toEqual('\x1B[2mhello world\x1B[22m'); +// expect(theme.italic('hello', 'world')).toEqual('\x1B[3mhello world\x1B[23m'); +// expect(theme.underline('hello', 'world')).toEqual('\x1B[4mhello world\x1B[24m'); +// expect(theme.inverse('hello', 'world')).toEqual('\x1B[7mhello world\x1B[27m'); +// expect(theme.hidden('hello', 'world')).toEqual('\x1B[8mhello world\x1B[28m'); +// expect(theme.strikethrough('hello', 'world')).toEqual('\x1B[9mhello world\x1B[29m'); +// expect(theme.visible('hello', 'world')).toEqual('hello world'); - expect(theme.black('hello', 'world')).toEqual('\x1B[30mhello world\x1B[39m'); - expect(theme.red('hello', 'world')).toEqual('\x1B[31mhello world\x1B[39m'); - expect(theme.green('hello', 'world')).toEqual('\x1B[32mhello world\x1B[39m'); - expect(theme.yellow('hello', 'world')).toEqual('\x1B[33mhello world\x1B[39m'); - expect(theme.blue('hello', 'world')).toEqual('\x1B[34mhello world\x1B[39m'); - expect(theme.magenta('hello', 'world')).toEqual('\x1B[35mhello world\x1B[39m'); - expect(theme.cyan('hello', 'world')).toEqual('\x1B[36mhello world\x1B[39m'); - expect(theme.white('hello', 'world')).toEqual('\x1B[37mhello world\x1B[39m'); - expect(theme.blackBright('hello', 'world')).toEqual('\x1B[90mhello world\x1B[39m'); - expect(theme.gray('hello', 'world')).toEqual('\x1B[90mhello world\x1B[39m'); - expect(theme.grey('hello', 'world')).toEqual('\x1B[90mhello world\x1B[39m'); - expect(theme.redBright('hello', 'world')).toEqual('\x1B[91mhello world\x1B[39m'); - expect(theme.greenBright('hello', 'world')).toEqual('\x1B[92mhello world\x1B[39m'); - expect(theme.yellowBright('hello', 'world')).toEqual('\x1B[93mhello world\x1B[39m'); - expect(theme.blueBright('hello', 'world')).toEqual('\x1B[94mhello world\x1B[39m'); - expect(theme.magentaBright('hello', 'world')).toEqual('\x1B[95mhello world\x1B[39m'); - expect(theme.cyanBright('hello', 'world')).toEqual('\x1B[96mhello world\x1B[39m'); - expect(theme.whiteBright('hello', 'world')).toEqual('\x1B[97mhello world\x1B[39m'); +// expect(theme.black('hello', 'world')).toEqual('\x1B[30mhello world\x1B[39m'); +// expect(theme.red('hello', 'world')).toEqual('\x1B[31mhello world\x1B[39m'); +// expect(theme.green('hello', 'world')).toEqual('\x1B[32mhello world\x1B[39m'); +// expect(theme.yellow('hello', 'world')).toEqual('\x1B[33mhello world\x1B[39m'); +// expect(theme.blue('hello', 'world')).toEqual('\x1B[34mhello world\x1B[39m'); +// expect(theme.magenta('hello', 'world')).toEqual('\x1B[35mhello world\x1B[39m'); +// expect(theme.cyan('hello', 'world')).toEqual('\x1B[36mhello world\x1B[39m'); +// expect(theme.white('hello', 'world')).toEqual('\x1B[37mhello world\x1B[39m'); +// expect(theme.blackBright('hello', 'world')).toEqual('\x1B[90mhello world\x1B[39m'); +// expect(theme.gray('hello', 'world')).toEqual('\x1B[90mhello world\x1B[39m'); +// expect(theme.grey('hello', 'world')).toEqual('\x1B[90mhello world\x1B[39m'); +// expect(theme.redBright('hello', 'world')).toEqual('\x1B[91mhello world\x1B[39m'); +// expect(theme.greenBright('hello', 'world')).toEqual('\x1B[92mhello world\x1B[39m'); +// expect(theme.yellowBright('hello', 'world')).toEqual('\x1B[93mhello world\x1B[39m'); +// expect(theme.blueBright('hello', 'world')).toEqual('\x1B[94mhello world\x1B[39m'); +// expect(theme.magentaBright('hello', 'world')).toEqual('\x1B[95mhello world\x1B[39m'); +// expect(theme.cyanBright('hello', 'world')).toEqual('\x1B[96mhello world\x1B[39m'); +// expect(theme.whiteBright('hello', 'world')).toEqual('\x1B[97mhello world\x1B[39m'); - expect(theme.bgBlack('hello', 'world')).toEqual('\x1B[40mhello world\x1B[49m'); - expect(theme.bgRed('hello', 'world')).toEqual('\x1B[41mhello world\x1B[49m'); - expect(theme.bgGreen('hello', 'world')).toEqual('\x1B[42mhello world\x1B[49m'); - expect(theme.bgYellow('hello', 'world')).toEqual('\x1B[43mhello world\x1B[49m'); - expect(theme.bgBlue('hello', 'world')).toEqual('\x1B[44mhello world\x1B[49m'); - expect(theme.bgMagenta('hello', 'world')).toEqual('\x1B[45mhello world\x1B[49m'); - expect(theme.bgCyan('hello', 'world')).toEqual('\x1B[46mhello world\x1B[49m'); - expect(theme.bgWhite('hello', 'world')).toEqual('\x1B[47mhello world\x1B[49m'); - expect(theme.bgBlackBright('hello', 'world')).toEqual('\x1B[100mhello world\x1B[49m'); - expect(theme.bgGray('hello', 'world')).toEqual('\x1B[100mhello world\x1B[49m'); - expect(theme.bgGrey('hello', 'world')).toEqual('\x1B[100mhello world\x1B[49m'); - expect(theme.bgRedBright('hello', 'world')).toEqual('\x1B[101mhello world\x1B[49m'); - expect(theme.bgGreenBright('hello', 'world')).toEqual('\x1B[102mhello world\x1B[49m'); - expect(theme.bgYellowBright('hello', 'world')).toEqual('\x1B[103mhello world\x1B[49m'); - expect(theme.bgBlueBright('hello', 'world')).toEqual('\x1B[104mhello world\x1B[49m'); - expect(theme.bgMagentaBright('hello', 'world')).toEqual('\x1B[105mhello world\x1B[49m'); - expect(theme.bgCyanBright('hello', 'world')).toEqual('\x1B[106mhello world\x1B[49m'); - expect(theme.bgWhiteBright('hello', 'world')).toEqual('\x1B[107mhello world\x1B[49m'); +// expect(theme.bgBlack('hello', 'world')).toEqual('\x1B[40mhello world\x1B[49m'); +// expect(theme.bgRed('hello', 'world')).toEqual('\x1B[41mhello world\x1B[49m'); +// expect(theme.bgGreen('hello', 'world')).toEqual('\x1B[42mhello world\x1B[49m'); +// expect(theme.bgYellow('hello', 'world')).toEqual('\x1B[43mhello world\x1B[49m'); +// expect(theme.bgBlue('hello', 'world')).toEqual('\x1B[44mhello world\x1B[49m'); +// expect(theme.bgMagenta('hello', 'world')).toEqual('\x1B[45mhello world\x1B[49m'); +// expect(theme.bgCyan('hello', 'world')).toEqual('\x1B[46mhello world\x1B[49m'); +// expect(theme.bgWhite('hello', 'world')).toEqual('\x1B[47mhello world\x1B[49m'); +// expect(theme.bgBlackBright('hello', 'world')).toEqual('\x1B[100mhello world\x1B[49m'); +// expect(theme.bgGray('hello', 'world')).toEqual('\x1B[100mhello world\x1B[49m'); +// expect(theme.bgGrey('hello', 'world')).toEqual('\x1B[100mhello world\x1B[49m'); +// expect(theme.bgRedBright('hello', 'world')).toEqual('\x1B[101mhello world\x1B[49m'); +// expect(theme.bgGreenBright('hello', 'world')).toEqual('\x1B[102mhello world\x1B[49m'); +// expect(theme.bgYellowBright('hello', 'world')).toEqual('\x1B[103mhello world\x1B[49m'); +// expect(theme.bgBlueBright('hello', 'world')).toEqual('\x1B[104mhello world\x1B[49m'); +// expect(theme.bgMagentaBright('hello', 'world')).toEqual('\x1B[105mhello world\x1B[49m'); +// expect(theme.bgCyanBright('hello', 'world')).toEqual('\x1B[106mhello world\x1B[49m'); +// expect(theme.bgWhiteBright('hello', 'world')).toEqual('\x1B[107mhello world\x1B[49m'); - done(); - }); +// done(); +// }); - it('templates', function(done) { - if (process.env.CI) { - this.skip(); - return; - } +// it('templates', function(done) { +// if (process.env.CI) { +// this.skip(); +// return; +// } - /* eslint new-cap: 0 */ - expect(theme.NOW('HH:mm')).toMatch(/^\d{2}:\d{2}$/); +// /* eslint new-cap: 0 */ +// expect(theme.NOW('HH:mm')).toMatch(/^\d{2}:\d{2}$/); - expect(format(theme, '{HELP.DESC: {1}}', 'hello')).toEqual('\x1B[90mhello\x1B[39m'); - expect(format(theme, '{DESC: {1}}', 'hello')).toEqual('hello'); - expect(format(theme, '{PATH: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); - expect(format(theme, '{PID: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); - expect(format(theme, '{MODULE: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); - expect(format(theme, '{VERSION: {1}}', 'hello')).toEqual('hello'); - expect(format(theme, '{TITLE: {1}}', 'hello')).toEqual('\x1B[1mhello\x1B[22m'); - expect(format(theme, '{TASK: {1}}', 'hello')).toEqual('\x1B[36mhello\x1B[39m'); - expect(format(theme, '{OPTION: {1}}', 'hello')).toEqual('\x1B[34mhello\x1B[39m'); - expect(format(theme, '{DURATION: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); +// expect(format(theme, '{HELP.DESC: {1}}', 'hello')).toEqual('\x1B[90mhello\x1B[39m'); +// expect(format(theme, '{DESC: {1}}', 'hello')).toEqual('hello'); +// expect(format(theme, '{PATH: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); +// expect(format(theme, '{PID: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); +// expect(format(theme, '{MODULE: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); +// expect(format(theme, '{VERSION: {1}}', 'hello')).toEqual('hello'); +// expect(format(theme, '{TITLE: {1}}', 'hello')).toEqual('\x1B[1mhello\x1B[22m'); +// expect(format(theme, '{TASK: {1}}', 'hello')).toEqual('\x1B[36mhello\x1B[39m'); +// expect(format(theme, '{OPTION: {1}}', 'hello')).toEqual('\x1B[34mhello\x1B[39m'); +// expect(format(theme, '{DURATION: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); - expect(format(theme, '{TASKS.BRANCH: {1}}', 'hello')).toEqual('hello'); - expect(format(theme, '{TASKS.NAME: {1}}', 'hello')).toEqual('\x1B[36mhello\x1B[39m'); - expect(format(theme, '{TASKS.OPTION: {1}}', 'hello')).toEqual('\x1B[34mhello\x1B[39m'); - expect(format(theme, '{TASKS.DESC: {1}}', 'hello')).toEqual('hello'); - expect(format(theme, '{TASKS.CHILD: {1}}', 'hello')).toEqual('hello'); +// expect(format(theme, '{TASKS.BRANCH: {1}}', 'hello')).toEqual('hello'); +// expect(format(theme, '{TASKS.NAME: {1}}', 'hello')).toEqual('\x1B[36mhello\x1B[39m'); +// expect(format(theme, '{TASKS.OPTION: {1}}', 'hello')).toEqual('\x1B[34mhello\x1B[39m'); +// expect(format(theme, '{TASKS.DESC: {1}}', 'hello')).toEqual('hello'); +// expect(format(theme, '{TASKS.CHILD: {1}}', 'hello')).toEqual('hello'); - expect(format(theme, '{INFO: {1}}', 'hello')).toEqual('hello'); - expect(format(theme, '{WARN: {1}}', 'hello')).toEqual('\x1B[33mhello\x1B[39m'); - expect(format(theme, '{ERROR: {1}}', 'hello')).toEqual('\x1B[31mhello\x1B[39m'); +// expect(format(theme, '{INFO: {1}}', 'hello')).toEqual('hello'); +// expect(format(theme, '{WARN: {1}}', 'hello')).toEqual('\x1B[33mhello\x1B[39m'); +// expect(format(theme, '{ERROR: {1}}', 'hello')).toEqual('\x1B[31mhello\x1B[39m'); - /* eslint no-control-regex: 0 */ - expect(format(theme, '{TIMESTAMP: {1}}', 'HH:mm:ss')).toMatch(/^\[\x1B\[90m\d{2}:\d{2}:\d{2}\x1B\[39m\] $/); +// /* eslint no-control-regex: 0 */ +// expect(format(theme, '{TIMESTAMP: {1}}', 'HH:mm:ss')).toMatch(/^\[\x1B\[90m\d{2}:\d{2}:\d{2}\x1B\[39m\] $/); - expect(format(theme, '{IF: {1}?{2}}', true, 'hello')).toEqual('hello'); - expect(format(theme, '{IF: {1}?{2}}', false, 'hello')).toEqual(''); - done(); - }); -}); +// expect(format(theme, '{IF: {1}?{2}}', true, 'hello')).toEqual('hello'); +// expect(format(theme, '{IF: {1}?{2}}', false, 'hello')).toEqual(''); +// done(); +// }); +// }); From 7051ab4204671a60ff8a3658aba0927aa35e0c2c Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 12:50:57 -0700 Subject: [PATCH 02/25] box drawing symbols and changes to see in diff --- index.js | 61 +---- lib/shared/completion.js | 4 - lib/shared/config/env-config.js | 85 +++++- lib/shared/log/messages.js | 174 ------------- lib/shared/log/tasks.js | 172 ++++++------ lib/shared/options/make-help.js | 9 +- lib/versioned/^3.7.0/index.js | 6 +- lib/versioned/^3.7.0/log/events.js | 9 +- lib/versioned/^4.0.0-alpha.1/index.js | 10 +- lib/versioned/^4.0.0-alpha.2/index.js | 10 +- lib/versioned/^4.0.0/index.js | 10 +- lib/versioned/^4.0.0/log/sync-task.js | 3 +- messages.js | 6 + test/lib/override-env-config.js | 360 +++++++++++++------------- 14 files changed, 360 insertions(+), 559 deletions(-) delete mode 100644 lib/shared/log/messages.js diff --git a/index.js b/index.js index 09a05426..9922bb9b 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,6 @@ var makeHelp = require('./lib/shared/options/make-help'); var completion = require('./lib/shared/completion'); var cliVersion = require('./package.json').version; var toConsole = require('./lib/shared/log/to-console'); -var msgs = require('./lib/shared/log/messages'); var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); var overrideEnvByConfigAndCliOpts = require('./lib/shared/config/env-config'); @@ -116,65 +115,7 @@ function onPrepare(env) { env = overrideEnvByConfigAndCliOpts(env, cfg, opts); // Set up event listeners for logging after configuring. - toConsole(log, { - tasksSimple: env.config.flags.tasksSimple, - tasksJson: env.config.flags.tasksJson, - help: env.config.flags.help, - version: env.config.flags.version, - silent: env.config.flags.silent, - logLevel: env.config.flags.logLevel, - getMessage: function(msg, data) { - if (msg === messages.PRELOAD_BEFORE) { - return 'Preloading external module: ' + chalk.magenta(data); - } - - if (msg === messages.PRELOAD_SUCCESS) { - return 'Preloaded external module: ' + chalk.magenta(data) - } - - if (msg === messages.PRELOAD_FAILURE) { - return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data); - } - - if (msg === messages.PRELOAD_ERROR) { - return chalk.yellow(data.toString()); - } - - if (msg === messages.LOADER_SUCCESS) { - return 'Loaded external module: ' + chalk.magenta(data); - } - - if (msg === messages.LOADER_FAILURE) { - return chalk.yellow('Failed to load external module: ') + chalk.magenta(data); - } - - if (msg === messages.LOADER_ERROR) { - return chalk.yellow(data.toString()); - } - - if (msg === messages.NODE_FLAGS) { - var nodeFlags = chalk.magenta(data.join(', ')); - return 'Node flags detected: ' + nodeFlags; - } - - if (msg === messages.RESPAWNED) { - var pid = chalk.magenta(data); - return 'Respawned to PID: ' + pid; - } - - if (msg === messages.GULPFILE_NOT_FOUND) { - return chalk.red('No gulpfile found'); - } - - if (msg === messages.CWD_CHANGED) { - return 'Working directory changed to ' + chalk.magenta(data); - } - - if (msg === messages.UNSUPPORTED_GULP_VERSION) { - return chalk.red('Unsupported gulp version', env.modulePackage.version) - } - }, - }); + toConsole(log, env.config.flags); cli.execute(env, env.nodeFlags, onExecute); } diff --git a/lib/shared/completion.js b/lib/shared/completion.js index f10cd758..329f0926 100644 --- a/lib/shared/completion.js +++ b/lib/shared/completion.js @@ -2,10 +2,6 @@ var fs = require('fs'); var path = require('path'); -// var format = require('theming-log').format; - -// var theme = require('./log/theme'); -// var msgs = require('./log/messages'); module.exports = function(name) { if (typeof name !== 'string') { diff --git a/lib/shared/config/env-config.js b/lib/shared/config/env-config.js index 18265465..b9c9191b 100644 --- a/lib/shared/config/env-config.js +++ b/lib/shared/config/env-config.js @@ -1,12 +1,11 @@ 'use strict'; var path = require('path'); +var chalk = require('chalk'); var copyProps = require('copy-props'); var mergeCliOpts = require('./cli-flags'); - -var theme = require('../log/theme'); -var msgs = require('../log/messages'); +var messages = require("../../../messages"); var toEnvFromConfig = { configPath: 'flags.gulpfile', @@ -24,18 +23,80 @@ function overrideEnvConfig(env, config, cliOpts) { env.config = { flags: cliOpts, - log: { - theme: theme, - msgs: msgs, - }, }; - if (config.log) { - if (config.log.theme) { - copyProps(config.log.theme, env.config.log.theme); + env.config.flags.getMessage = function(msg, data) { + if (msg === messages.PRELOAD_BEFORE) { + return 'Preloading external module: ' + chalk.magenta(data); } - if (config.log.msgs) { - copyProps(config.log.msgs, env.config.log.msgs); + + if (msg === messages.PRELOAD_SUCCESS) { + return 'Preloaded external module: ' + chalk.magenta(data) } + + if (msg === messages.PRELOAD_FAILURE) { + return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data); + } + + if (msg === messages.PRELOAD_ERROR) { + return chalk.yellow(data.toString()); + } + + if (msg === messages.LOADER_SUCCESS) { + return 'Loaded external module: ' + chalk.magenta(data); + } + + if (msg === messages.LOADER_FAILURE) { + return chalk.yellow('Failed to load external module: ') + chalk.magenta(data); + } + + if (msg === messages.LOADER_ERROR) { + return chalk.yellow(data.toString()); + } + + if (msg === messages.NODE_FLAGS) { + var nodeFlags = chalk.magenta(data.join(', ')); + return 'Node flags detected: ' + nodeFlags; + } + + if (msg === messages.RESPAWNED) { + var pid = chalk.magenta(data); + return 'Respawned to PID: ' + pid; + } + + if (msg === messages.GULPFILE_NOT_FOUND) { + return chalk.red('No gulpfile found'); + } + + if (msg === messages.CWD_CHANGED) { + return 'Working directory changed to ' + chalk.magenta(data); + } + + if (msg === messages.UNSUPPORTED_GULP_VERSION) { + return chalk.red('Unsupported gulp version', env.modulePackage.version) + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) { + return chalk.white('└'); + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT) { + return chalk.white('├'); + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_HORIZONTAL) { + return chalk.white('─'); + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL) { + return chalk.white('┬'); + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_VERTICAL) { + return chalk.white('│'); + } + }; + if (config.description) { + env.config.description = config.description; } return env diff --git a/lib/shared/log/messages.js b/lib/shared/log/messages.js deleted file mode 100644 index b945b182..00000000 --- a/lib/shared/log/messages.js +++ /dev/null @@ -1,174 +0,0 @@ -'use strict'; - -/* eslint max-len: 0 */ - -module.exports = { - help: { - usage: - '\n{TITLE: Usage:} gulp {OPTION: [options]} {TASK: tasks}', - - flags: { - help: - '{HELP.DESC: Show this help.}', - - version: - '{HELP.DESC: Print the global and local gulp versions.}', - - preload: - '{HELP.DESC: Will preload a module before running the gulpfile. ' + - 'This is useful for transpilers but also has other applications.}', - - gulpfile: - '{HELP.DESC: Manually set path of gulpfile. Useful if you have ' + - 'multiple gulpfiles. This will set the CWD to the gulpfile ' + - 'directory as well.}', - - cwd: - '{HELP.DESC: Manually set the CWD. The search for the gulpfile, ' + - 'as well as the relativity of all requires will be from here.}', - - tasks: - '{HELP.DESC: Print the task dependency tree for the loaded ' + - 'gulpfile.}', - - 'tasks-simple': - '{HELP.DESC: Print a plaintext list of tasks for the loaded ' + - 'gulpfile.}', - - 'tasks-json': - '{HELP.DESC: Print the task dependency tree, in JSON format, ' + - 'for the loaded gulpfile.}', - - 'tasks-depth': - '{HELP.DESC: Specify the depth of the task dependency tree.}', - - 'compact-tasks': - '{HELP.DESC: Reduce the output of task dependency tree by ' + - 'printing only top tasks and their child tasks.}', - - 'sort-tasks': - '{HELP.DESC: Will sort top tasks of task dependency tree.}', - - color: - '{HELP.DESC: Will force gulp and gulp plugins to display ' + - 'colors, even when no color support is detected.}', - - 'no-color': - '{HELP.DESC: Will force gulp and gulp plugins to not display ' + - 'colors, even when color support is detected.}', - - silent: - '{HELP.DESC: Suppress all gulp logging.}', - - continue: - '{HELP.DESC: Continue execution of tasks upon failure.}', - - series: - '{HELP.DESC: Run tasks given on the CLI in series (the default ' + - 'is parallel).}', - - 'log-level': - '{HELP.DESC: Set the loglevel. -L for least verbose and -LLLL ' + - 'for most verbose. -LLL is default.}', - }, - }, - tasks: { - description: - '{DESC: Tasks for} {PATH: {1:gulpfile path}}', - - topTask: - '{TASKS.BRANCH: {1:branch line}}{TASKS.NAME: {2:task name}}{IF:{3:has desc}?{4:space}{TASKS.DESC: {5:task description}}}', - - option: - '{TASKS.BRANCH: {1:branch line}}{TASKS.OPTION: {2:option name}}{IF:{3:has desc}?{4:space}…{TASKS.DESC: {5:option description}}', - - childTask: - '{TASKS.BRANCH: {1:branch line}{TASKS.CHILD: {2:task name}}', - }, - - tasksJson: { - description: - 'Tasks for {1:gulpfile path}', - }, - - info: { - preloadBefore: - '{TIMESTAMP}{DESC: Preloading external module:} {MODULE: {1:module name}}', - - preloadSuccess: - '{TIMESTAMP}{DESC: Preloaded external module:} {MODULE: {1:module name}}', - - loaderSuccess: - '{TIMESTAMP}{DESC: Loaded external module:} {MODULE: {1:module name}}', - - respawn: - '{TIMESTAMP}{DESC: Node flags detected:} {OPTION: {1:node flags}}\n' + - '{TIMESTAMP}{DESC: Respawned to PID: {PID: {2:pid}}', - - cwdChanged: - '{TIMESTAMP}{DESC: Working directory changed to} {PATH: {1:cwd}}', - - usingGulpfile: - '{TIMESTAMP}{DESC: Using gulpfile} {PATH: {1:gulpfile path}}', - - taskStart: - '{TIMESTAMP}{DESC: Starting \'}{TASK: {1:task name}}{DESC: \'...}', - - taskStop: - '{TIMESTAMP}{DESC: Finished \'}{TASK: {1:task name}}{DESC: \' after} ' + - '{DURATION: {2:duration}}', - }, - - warn: { - preloadFailure: - '{TIMESTAMP}{WARN: Failed to preload external module:} {MODULE: {1: module name}}\n' + - '{IF:{2:exists error}?{TIMESTAMP}{WARN: {3:error message}} ', - - loaderFailure: - '{TIMESTAMP}{WARN: Failed to load external module:} {MODULE: {1: module name}}\n' + - '{IF:{2:exists error}?{TIMESTAMP}{WARN: {3:error message}} ', - - taskNotComplete: - '{TIMESTAMP}{WARN: The following tasks did not complete:} {TASK: {1}}\n' + - '{TIMESTAMP}{WARN: Did you forget to signal async completion? }', - }, - - error: { - failToParseCliOpts: - '{ERROR: {1:error message}}', - - gulpNotFound: - '{TIMESTAMP}{ERROR: Local gulp not found in} {PATH: {1}}\n' + - '{TIMESTAMP}{ERROR: Try running: {IF:{2:has yarn}?yarn add}{IF:{3:has npm}?npm install} gulp}', - - nodeModulesNotFound: - '{TIMESTAMP}{ERROR: Local modules not found in} {PATH: {1}}\n' + - '{TIMESTAMP}{ERROR: Try running: {IF:{2:has yarn}?yarn install}{IF:{3:has npm}?npm install}', - - gulpfileNotFound: - '{TIMESTAMP}{ERROR: No gulpfile found}', - - badGulpVersion: - '{TIMESTAMP}{ERROR: Unsupported gulp version {VERSION: {1}}}', - - taskError: - '{TIMESTAMP}{ERROR: \'{1:task}\' errored after} ' + - '{DURATION: {2:duration}}' + - '{IF:{3:has cause}?\n{TIMESTAMP}{ERROR: {4:cause}}}', - - taskNotFound: - '{TIMESTAMP}{ERROR: Task never defined: {1:target task}{IF:{2:has similar tasks}? - did you mean? {3:similar tasks}}\n' + - '{TIMESTAMP}{ERROR: To list available tasks, try running: gulp --tasks}', - - failToRun: - '{TIMESTAMP}{ERROR: {1:cause}}\n' + - '{TIMESTAMP}{ERROR: Please check the documentation for proper ' + - 'gulpfile formatting}', - - noCompletionType: - 'Missing completion type', - - unknownCompletionType: - 'echo "gulp autocompletion rules for \'{1:type}\' not found"', - }, -}; diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index c20180e6..0b81011b 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -2,10 +2,8 @@ var log = require('gulplog'); var stringWidth = require('string-width'); -// var format = require('theming-log').format; -var theme = require('./theme'); -var msgs = require('./messages'); var isObject = require('../is-object'); +var messages = require('../../../messages'); function logTasks(tree, opts, getTask) { if (opts.sortTasks) { @@ -28,116 +26,110 @@ function logTasks(tree, opts, getTask) { }; printTaskTree(tree, treeOpts); -} -function printTaskTree(tree, opts) { - var lines = []; - var maxLabelWidth = 0; + function printTaskTree(tree, opts) { + var lines = []; + lines.push({ label: tree.label }); + var maxLabelWidth = 0; - tree.nodes.forEach(function(node, idx, arr) { - var isLast = idx === arr.length - 1; - var w = createTreeLines(node, lines, opts, 1, '', isLast); - maxLabelWidth = Math.max(maxLabelWidth, w); - }); + tree.nodes.forEach(function(node, idx, arr) { + var isLast = idx === arr.length - 1; + var w = createTreeLines(node, lines, opts, 1, '', isLast); + maxLabelWidth = Math.max(maxLabelWidth, w); + }); - log.info(msgs.tasks.description, tree.label); + lines.forEach(function(line) { + var s = line.label; + if (line.desc) { + var spaces = ' '.repeat(maxLabelWidth - line.width) + ' '; + s += spaces + line.desc; + } + log.info(s); + }); + } - lines.forEach(function(line) { - if (line.desc) { - var spaces = ' '.repeat(maxLabelWidth - line.width) + ' '; - log.info(line.fmt, line.bars, line.name, true, spaces, line.desc); - } else { - log.info(line.fmt, line.bars, line.name); + function createTreeLines(node, lines, opts, depth, bars, isLast) { + var task = { label: node.label, bars: bars, depth: depth }; + if (depth === 1) { + var t = opts.getTask(node.label); + task.desc = t.description; + task.flags = t.flags; } - }); -} -function createTreeLines(node, lines, opts, depth, bars, isLast) { - var task = { label: node.label, bars: bars, depth: depth }; - if (depth === 1) { - var t = opts.getTask(node.label); - task.desc = t.description; - task.flags = t.flags; - } + var isLeaf = isLeafNode(node, depth, opts); - var isLeaf = isLeafNode(node, depth, opts); + var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); - var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); + if (!isLeaf) { + bars += (isLast ? ' ' : opts.getMessage(messages.BOX_DRAWINGS_LIGHT_VERTICAL)); + bars += ' ' + node.nodes.forEach(function(node, idx, arr) { + var isLast = idx === arr.length - 1; + createTreeLines(node, lines, opts, depth + 1, bars, isLast); + }); + } - if (!isLeaf) { - bars += (isLast ? ' ' : '│ '); - node.nodes.forEach(function(node, idx, arr) { - var isLast = idx === arr.length - 1; - createTreeLines(node, lines, opts, depth + 1, bars, isLast); - }); + return maxLabelWidth; } - return maxLabelWidth; -} - -function addTaskToLines(task, lines, isLast, isLeaf) { - var taskBars = task.bars + (isLast ? '└' : '├') + '─'; - if (isLeaf) { - taskBars += '─ '; - } else { - taskBars += '┬ '; - } + function addTaskToLines(task, lines, isLast, isLeaf) { + var taskBars = task.bars + (isLast ? opts.getMessage(messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) : opts.getMessage(messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT)) + opts.getMessage(messages.BOX_DRAWINGS_LIGHT_HORIZONTAL); + if (isLeaf) { + taskBars += opts.getMessage(messages.BOX_DRAWINGS_LIGHT_HORIZONTAL); + } else { + taskBars += opts.getMessage(messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL); + } - var line = {}; - if (task.depth === 1) { - line.fmt = msgs.tasks.topTask; - line.bars = taskBars; - line.name = task.label; - } else { - line.fmt = msgs.tasks.childTask; - line.bars = taskBars; - line.name = task.label; - } - // line.width = stringWidth(format(theme, line.fmt, line.bars, line.name)); + var line = {}; + if (task.depth === 1) { + line.label = taskBars + ' ' + task.label + } else { + line.label = taskBars + ' ' + task.label; + } + line.width = stringWidth(line.label); - if (typeof task.desc === 'string' && task.desc) { - line.desc = task.desc; - } - lines.push(line); + if (typeof task.desc === 'string' && task.desc) { + line.desc = task.desc; + } + lines.push(line); - if (!isObject(task.flags)) { - return line.width; - } + var maxLabelWidth = line.width; - var maxLabelWidth = line.width; + if (!isObject(task.flags)) { + return maxLabelWidth; + } - var flagBars = task.bars; - if (isLast) { - flagBars += ' '; - } else { - flagBars += '│ '; - } + var flagBars = task.bars; + if (isLast) { + flagBars += ' '; + } else { + flagBars += opts.getMessage(messages.BOX_DRAWINGS_LIGHT_VERTICAL); + } - if (isLeaf) { - flagBars += ' '; - } else { - flagBars += '│ '; - } + if (isLeaf) { + flagBars += ' '; + } else { + flagBars += opts.getMessage(messages.BOX_DRAWINGS_LIGHT_VERTICAL); + } - Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); + Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); - function addFlagsToLines(ent) { - if (typeof ent[0] !== 'string' || !ent[0]) return; - var line = {}; - line.fmt = msgs.tasks.option; - line.bars = flagBars; - line.name = ent[0]; - // line.width = stringWidth(format(theme, line.fmt, line.bars, line.name)); + function addFlagsToLines(ent) { + if (typeof ent[0] !== 'string' || !ent[0]) return; + var line = {}; + line.label = flagBars + ' ' + ent[0]; + line.width = stringWidth(line.label); - maxLabelWidth = Math.max(maxLabelWidth, line.width); + maxLabelWidth = Math.max(maxLabelWidth, line.width); - if (typeof ent[1] == 'string' && ent[1]) { - line.desc = ent[1]; + if (typeof ent[1] === 'string' && ent[1] !== '') { + line.desc = ent[1]; + } + lines.push(line); } - lines.push(line); - } - return maxLabelWidth; + return maxLabelWidth; + } } function isLeafNode(node, depth, opts) { diff --git a/lib/shared/options/make-help.js b/lib/shared/options/make-help.js index 45dccaaf..ec770dcd 100644 --- a/lib/shared/options/make-help.js +++ b/lib/shared/options/make-help.js @@ -1,15 +1,12 @@ 'use strict'; -// var format = require('theming-log').format; -var theme = require('../log/theme'); -var msgs = require('../log/messages'); function makeHelp(parser) { // parser.usage(format(theme, msgs.help.usage)); - Object.keys(msgs.help.flags).forEach(function(flag) { - // parser.describe(flag, format(theme, msgs.help.flags[flag])); - }); + // Object.keys(msgs.help.flags).forEach(function(flag) { + // parser.describe(flag, format(theme, msgs.help.flags[flag])); + // }); return parser; } diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 569383d2..c2cf4f19 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -4,10 +4,6 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); -var msgs = require('../../shared/log/messages'); -var theme = require('../../shared/log/theme'); -// var format = require('theming-log').format; - var taskTree = require('./task-tree'); var copyTree = require('../../shared/log/copy-tree'); @@ -39,7 +35,7 @@ function execute(env) { exit(1); } - log.info(msgs.info.usingGulpfile, tildify(env.configPath)); + // log.info(msgs.info.usingGulpfile, tildify(env.configPath)); var gulpInst = require(env.modulePath); logEvents(gulpInst); diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index 09a428cf..d00190ff 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -2,7 +2,6 @@ var log = require('gulplog'); var formatTime = require('../../../shared/log/format-hrtime'); -var msgs = require('../../../shared/log/messages'); var exit = require('../../../shared/exit'); var formatError = require('../format-error'); @@ -25,22 +24,22 @@ function logEvents(gulpInst) { gulpInst.on('task_start', function(e) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 - log.info(msgs.info.taskStart, e.task); + // log.info(msgs.info.taskStart, e.task); }); gulpInst.on('task_stop', function(e) { var time = formatTime(e.hrDuration); - log.info(msgs.info.taskStop, e.task, time); + // log.info(msgs.info.taskStop, e.task, time); }); gulpInst.on('task_err', function(e) { var msg = formatError(e); var time = formatTime(e.hrDuration); - log.error(msgs.error.taskError, e.task, time, Boolean(msg), msg); + // log.error(msgs.error.taskError, e.task, time, Boolean(msg), msg); }); gulpInst.on('task_not_found', function(err) { - log.error(msgs.error.taskNotFound, err.task); + // log.error(msgs.error.taskNotFound, err.task); exit(1); }); } diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 06ffa38e..8d2c4b22 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -4,10 +4,6 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); -var msgs = require('../../shared/log/messages'); -var theme = require('../../shared/log/theme'); -// var format = require('theming-log').format; - var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -75,7 +71,7 @@ function execute(env) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info(msgs.info.usingGulpfile, tildify(env.configPath)); + // log.info(msgs.info.usingGulpfile, tildify(env.configPath)); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -85,9 +81,9 @@ function execute(env) { } catch (err) { var task = checkTaskNotFound(err); if (task) { - log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); + // log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); } else { - log.error(msgs.error.failToRun, err.message); + // log.error(msgs.error.failToRun, err.message); } exit(1); } diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js index f04fcb1d..f1aaa6fa 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -4,10 +4,6 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); -var msgs = require('../../shared/log/messages'); -var theme = require('../../shared/log/theme'); -// var format = require('theming-log').format; - var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -73,7 +69,7 @@ function execute(env) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info(msgs.info.usingGulpfile, tildify(env.configPath)); + // log.info(msgs.info.usingGulpfile, tildify(env.configPath)); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -83,9 +79,9 @@ function execute(env) { } catch (err) { var task = checkTaskNotFound(err); if (task) { - log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); + // log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); } else { - log.error(msgs.error.failToRun, err.message); + // log.error(msgs.error.failToRun, err.message); } exit(1); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index 6fe0f4b9..893fd2eb 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -4,10 +4,6 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); -var msgs = require('../../shared/log/messages'); -var theme = require('../../shared/log/theme'); -// var format = require('theming-log').format; - var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -73,7 +69,7 @@ function execute(env) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info(msgs.info.usingGulpfile, tildify(env.configPath)); + // log.info(msgs.info.usingGulpfile, tildify(env.configPath)); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -83,9 +79,9 @@ function execute(env) { } catch (err) { var task = checkTaskNotFound(err); if (task) { - log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); + // log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); } else { - log.error(msgs.error.failToRun, err.message); + // log.error(msgs.error.failToRun, err.message); } exit(1); } diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index b0719d27..477a0e3f 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,7 +1,6 @@ 'use strict'; var log = require('gulplog'); -var msgs = require('../../../shared/log/messages'); var tasks = {}; @@ -18,7 +17,7 @@ function warn() { process.exitCode = 1; - log.warn(msgs.warn.taskNotComplete, taskNames); + // log.warn(msgs.warn.taskNotComplete, taskNames); } function start(e) { diff --git a/messages.js b/messages.js index a5154fb6..e0e6ba08 100644 --- a/messages.js +++ b/messages.js @@ -11,4 +11,10 @@ module.exports = { GULPFILE_NOT_FOUND: Symbol.for("GULP_CLI_GULPFILE_NOT_FOUND"), CWD_CHANGED: Symbol.for("GULP_CLI_CWD_CHANGED"), UNSUPPORTED_GULP_VERSION: Symbol.for("GULP_CLI_UNSUPPORTED_GULP_VERSION"), + + BOX_DRAWINGS_LIGHT_UP_AND_RIGHT: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_UP_AND_RIGHT"), + BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT"), + BOX_DRAWINGS_LIGHT_HORIZONTAL: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_HORIZONTAL"), + BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL"), + BOX_DRAWINGS_LIGHT_VERTICAL: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_VERTICAL"), }; diff --git a/test/lib/override-env-config.js b/test/lib/override-env-config.js index d65324f9..fc77332e 100644 --- a/test/lib/override-env-config.js +++ b/test/lib/override-env-config.js @@ -1,182 +1,182 @@ 'use strict'; -var expect = require('expect'); -var copyProps = require('copy-props'); -var overrideEnvConfig = require('../../lib/shared/config/env-config'); -var theme = require('../../lib/shared/log/theme'); -var msgs = require('../../lib/shared/log/messages'); - -describe('lib: env-config', function() { - - var originalTheme = copyProps(theme, {}); - var originalMsgs = copyProps(msgs, {}); - - after(function() { - var keys = Object.keys(theme); - keys.forEach(function(key) { - delete theme[key]; - }); - copyProps(originalTheme, theme); - - keys = Object.keys(msgs); - keys.forEach(function(key) { - delete msgs[key]; - }); - copyProps(originalMsgs, msgs); - }); - - it('Should copy only config props specified to env flags', function(done) { - var env = {}; - - var config = { - flags: { - silent: true, - gulpfile: '/path/to/gulpfile', - }, - }; - - var result = overrideEnvConfig(env, config, {}); - expect(result).toEqual({ - configPath: '/path/to/gulpfile', - configBase: '/path/to', - config: { - flags: { - silent: true, - }, - log: { - theme: theme, - msgs: msgs, - }, - }, - }); - expect(result).toBe(env); - done(); - }); - - it('Should take into account forced gulpfile opts from flags', function(done) { - var env = { - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - }; - - var config = { - flags: { - silent: false, - gulpfile: '/path/to/gulpfile', - preload: ['a', 'b'], - }, - log: { - theme: { - INFO: '{black: {1}}', - WARN: '{bgYellow: {1}}', - ERROR: '{bgRed: {1}}', - }, - msgs: { - tasks: { - description: 'DESCRIPTION', - }, - }, - }, - }; - - var resultTheme = copyProps(theme, {}); - resultTheme.INFO = config.log.theme.INFO; - resultTheme.WARN = config.log.theme.WARN; - resultTheme.ERROR = config.log.theme.ERROR; - - var resultMsgs = copyProps(msgs, {}); - resultMsgs.tasks.description = config.log.msgs.tasks.description; - - var opts = { - gulpfile: env.configPath, - }; - - var result = overrideEnvConfig(env, config, opts); - expect(result).toEqual({ - cwd: '/path/to/cwd', - preload: ['preload', 'a', 'b'], - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - config: { - flags: { - gulpfile: "/path/of/config/path", - silent: false, - }, - log: { - theme: resultTheme, - msgs: resultMsgs, - }, - }, - }); - expect(result).toBe(env); - done(); - }); - - it('Should not cause error if config is empty', function(done) { - var env = { - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - }; - - var config = {}; - - var result = overrideEnvConfig(env, config, {}); - expect(result).toEqual({ - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - config: { - flags: {}, - log: { - theme: theme, - msgs: msgs, - }, - }, - }); - expect(result).toBe(env); - done(); - }); - - it('Should not cause error if config.flags and config.log is empty', function(done) { - var env = {}; - - var config = { - flags: {}, - log: {}, - }; - - var result = overrideEnvConfig(env, config, {}); - expect(result).toEqual({ - config: { - flags: {}, - log: { - theme: theme, - msgs: msgs, - }, - }, - }); - expect(result).toBe(env); - done(); - }); -}); +// var expect = require('expect'); +// var copyProps = require('copy-props'); +// var overrideEnvConfig = require('../../lib/shared/config/env-config'); +// var theme = require('../../lib/shared/log/theme'); +// var msgs = require('../../lib/shared/log/messages'); + +// describe('lib: env-config', function() { + +// var originalTheme = copyProps(theme, {}); +// var originalMsgs = copyProps(msgs, {}); + +// after(function() { +// var keys = Object.keys(theme); +// keys.forEach(function(key) { +// delete theme[key]; +// }); +// copyProps(originalTheme, theme); + +// keys = Object.keys(msgs); +// keys.forEach(function(key) { +// delete msgs[key]; +// }); +// copyProps(originalMsgs, msgs); +// }); + +// it('Should copy only config props specified to env flags', function(done) { +// var env = {}; + +// var config = { +// flags: { +// silent: true, +// gulpfile: '/path/to/gulpfile', +// }, +// }; + +// var result = overrideEnvConfig(env, config, {}); +// expect(result).toEqual({ +// configPath: '/path/to/gulpfile', +// configBase: '/path/to', +// config: { +// flags: { +// silent: true, +// }, +// log: { +// theme: theme, +// msgs: msgs, +// }, +// }, +// }); +// expect(result).toBe(env); +// done(); +// }); + +// it('Should take into account forced gulpfile opts from flags', function(done) { +// var env = { +// cwd: '/path/to/cwd', +// preload: 'preload', +// configNameSearch: 'configNameSearch', +// configPath: '/path/of/config/path', +// configBase: '/path/of/config/base', +// modulePath: '/path/of/module/path', +// modulePackage: { name: 'modulePackage' }, +// configFiles: { aaa: {} }, +// }; + +// var config = { +// flags: { +// silent: false, +// gulpfile: '/path/to/gulpfile', +// preload: ['a', 'b'], +// }, +// log: { +// theme: { +// INFO: '{black: {1}}', +// WARN: '{bgYellow: {1}}', +// ERROR: '{bgRed: {1}}', +// }, +// msgs: { +// tasks: { +// description: 'DESCRIPTION', +// }, +// }, +// }, +// }; + +// var resultTheme = copyProps(theme, {}); +// resultTheme.INFO = config.log.theme.INFO; +// resultTheme.WARN = config.log.theme.WARN; +// resultTheme.ERROR = config.log.theme.ERROR; + +// var resultMsgs = copyProps(msgs, {}); +// resultMsgs.tasks.description = config.log.msgs.tasks.description; + +// var opts = { +// gulpfile: env.configPath, +// }; + +// var result = overrideEnvConfig(env, config, opts); +// expect(result).toEqual({ +// cwd: '/path/to/cwd', +// preload: ['preload', 'a', 'b'], +// configNameSearch: 'configNameSearch', +// configPath: '/path/of/config/path', +// configBase: '/path/of/config/base', +// modulePath: '/path/of/module/path', +// modulePackage: { name: 'modulePackage' }, +// configFiles: { aaa: {} }, +// config: { +// flags: { +// gulpfile: "/path/of/config/path", +// silent: false, +// }, +// log: { +// theme: resultTheme, +// msgs: resultMsgs, +// }, +// }, +// }); +// expect(result).toBe(env); +// done(); +// }); + +// it('Should not cause error if config is empty', function(done) { +// var env = { +// cwd: '/path/to/cwd', +// preload: 'preload', +// configNameSearch: 'configNameSearch', +// configPath: '/path/of/config/path', +// configBase: '/path/of/config/base', +// modulePath: '/path/of/module/path', +// modulePackage: { name: 'modulePackage' }, +// configFiles: { aaa: {} }, +// }; + +// var config = {}; + +// var result = overrideEnvConfig(env, config, {}); +// expect(result).toEqual({ +// cwd: '/path/to/cwd', +// preload: 'preload', +// configNameSearch: 'configNameSearch', +// configPath: '/path/of/config/path', +// configBase: '/path/of/config/base', +// modulePath: '/path/of/module/path', +// modulePackage: { name: 'modulePackage' }, +// configFiles: { aaa: {} }, +// config: { +// flags: {}, +// log: { +// theme: theme, +// msgs: msgs, +// }, +// }, +// }); +// expect(result).toBe(env); +// done(); +// }); + +// it('Should not cause error if config.flags and config.log is empty', function(done) { +// var env = {}; + +// var config = { +// flags: {}, +// log: {}, +// }; + +// var result = overrideEnvConfig(env, config, {}); +// expect(result).toEqual({ +// config: { +// flags: {}, +// log: { +// theme: theme, +// msgs: msgs, +// }, +// }, +// }); +// expect(result).toBe(env); +// done(); +// }); +// }); From 10f19b26aba654849dc3c43058796eb2540b4c3b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 13:16:27 -0700 Subject: [PATCH 03/25] task start/stop/etc --- lib/shared/config/env-config.js | 22 +++++++++++++++++++++- lib/versioned/^3.7.0/log/events.js | 10 ++++++---- lib/versioned/^4.0.0/log/events.js | 15 +++++++-------- lib/versioned/^4.0.0/log/sync-task.js | 2 +- messages.js | 7 +++++++ 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/lib/shared/config/env-config.js b/lib/shared/config/env-config.js index b9c9191b..0bd7f478 100644 --- a/lib/shared/config/env-config.js +++ b/lib/shared/config/env-config.js @@ -72,7 +72,27 @@ function overrideEnvConfig(env, config, cliOpts) { } if (msg === messages.UNSUPPORTED_GULP_VERSION) { - return chalk.red('Unsupported gulp version', env.modulePackage.version) + return chalk.red('Unsupported gulp version', data) + } + + if (msg === messages.TASK_START) { + return "Starting '" + chalk.cyan(data.task) + "'..." + } + + if (msg === messages.TASK_STOP) { + return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(data.duration); + } + + if (msg === messages.TASK_ERROR) { + return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' +chalk.magenta(data.duration); + } + + if (msg === messages.TASK_MISSING) { + return chalk.red('Task \'' + err.task + '\' is not in your gulpfile') + '\nPlease check the documentation for proper gulpfile formatting'; + } + + if (msg === messages.SYNC_TASK) { + return chalk.red('The following tasks did not complete: ') + chalk.cyan(data) + "\n" + chalk.red('Did you forget to signal async completion?'); } if (msg === messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) { diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index d00190ff..4ea9d84f 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -4,6 +4,7 @@ var log = require('gulplog'); var formatTime = require('../../../shared/log/format-hrtime'); var exit = require('../../../shared/exit'); var formatError = require('../format-error'); +var messages = require('../../../../messages'); // Wire up logging events function logEvents(gulpInst) { @@ -24,22 +25,23 @@ function logEvents(gulpInst) { gulpInst.on('task_start', function(e) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 - // log.info(msgs.info.taskStart, e.task); + log.info(messages.TASK_START, { task: e.task }); }); gulpInst.on('task_stop', function(e) { var time = formatTime(e.hrDuration); - // log.info(msgs.info.taskStop, e.task, time); + log.info(messages.TASK_STOP, { task: e.task, duration: time }); }); gulpInst.on('task_err', function(e) { var msg = formatError(e); var time = formatTime(e.hrDuration); - // log.error(msgs.error.taskError, e.task, time, Boolean(msg), msg); + log.error(messages.TASK_ERROR, { task: e.task, duration: time }); + log.error(msg); }); gulpInst.on('task_not_found', function(err) { - // log.error(msgs.error.taskNotFound, err.task); + log.error(messages.TASK_MISSING, { task: err.task }); exit(1); }); } diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index 0897b88e..2ba5e22d 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -4,6 +4,7 @@ var log = require('gulplog'); var formatTime = require('../../../shared/log/format-hrtime'); var msgs = require('../../../shared/log/messages'); var formatError = require('../format-error'); +var messages = require('../../../../messages'); // Wire up logging events function logEvents(gulpInst) { @@ -15,29 +16,27 @@ function logEvents(gulpInst) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 var level = evt.branch ? 'debug' : 'info'; - log[level](msgs.info.taskStart, evt.name); + log[level](messages.TASK_START, { task: evt.name }); }); gulpInst.on('stop', function(evt) { var time = formatTime(evt.duration); /* istanbul ignore next */ var level = evt.branch ? 'debug' : 'info'; - log[level](msgs.info.taskStop, evt.name, time); + log[level](messages.TASK_STOP, { task: evt.name, duration: time }); }); gulpInst.on('error', function(evt) { var msg = formatError(evt); - var firstOutput = false; + var time = formatTime(evt.duration); + var level = evt.branch ? 'debug' : 'error'; + log[level](messages.TASK_ERROR, { task: evt.name, duration: time }); // If we haven't logged this before, log it and add to list if (loggedErrors.indexOf(evt.error) === -1) { - firstOutput = true; + log.error(msg); loggedErrors.push(evt.error); } - - var time = formatTime(evt.duration); - var level = evt.branch ? 'debug' : 'error'; - log[level](msgs.error.taskError, evt.name, time, firstOutput, msg); }); } diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index 477a0e3f..a4689aa9 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -17,7 +17,7 @@ function warn() { process.exitCode = 1; - // log.warn(msgs.warn.taskNotComplete, taskNames); + log.warn(messages.SYNC_TASK, taskNames); } function start(e) { diff --git a/messages.js b/messages.js index e0e6ba08..5014a58f 100644 --- a/messages.js +++ b/messages.js @@ -12,6 +12,13 @@ module.exports = { CWD_CHANGED: Symbol.for("GULP_CLI_CWD_CHANGED"), UNSUPPORTED_GULP_VERSION: Symbol.for("GULP_CLI_UNSUPPORTED_GULP_VERSION"), + TASK_START: Symbol.for("GULP_CLI_TASK_START"), + TASK_STOP: Symbol.for("GULP_CLI_TASK_STOP"), + TASK_ERROR: Symbol.for("GULP_CLI_TASK_ERROR"), + TASK_MISSING: Symbol.for("GULP_CLI_TASK_MISSING"), + + SYNC_TASK: Symbol.for("GULP_CLI_SYNC_TASK"), + BOX_DRAWINGS_LIGHT_UP_AND_RIGHT: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_UP_AND_RIGHT"), BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT"), BOX_DRAWINGS_LIGHT_HORIZONTAL: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_HORIZONTAL"), From d552e731c3e5bcfa837c69fff671f0c8ce3b1b51 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 13:20:43 -0700 Subject: [PATCH 04/25] remove theme and requires --- lib/shared/log/theme.js | 63 ------------------------------ lib/versioned/^4.0.0/log/events.js | 1 - test/lib/override-env-config.js | 2 - test/lib/theme.js | 2 - 4 files changed, 68 deletions(-) delete mode 100644 lib/shared/log/theme.js diff --git a/lib/shared/log/theme.js b/lib/shared/log/theme.js deleted file mode 100644 index 4f8d002a..00000000 --- a/lib/shared/log/theme.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -var chalk = require('chalk'); -var timestamp = require('./timestamp'); - -var theme = { - NOW: timestamp, - - HELP: { - DESC: '{gray: {1}}', - }, - - DESC: null, - PATH: '{magenta: {1}}', - PID: '{magenta: {1}}', - MODULE: '{magenta: {1}}', - VERSION: null, - TITLE: '{bold: {1}}', - TASK: '{cyan: {1}}', - OPTION: '{blue: {1}}', - DURATION: '{magenta: {1}}', - - TASKS: { - BRANCH: null, - NAME: '{TASK: {1}}', - OPTION: '{OPTION: {1}}', - DESC: '{DESC: {1}}', - CHILD: null, - }, - - INFO: null, - WARN: '{yellow: {1}}', - ERROR: '{red: {1}}', - - TIMESTAMP: '[{gray: {NOW: HH:mm:ss}}] ', - - IF: function(text) { - var idx = text.indexOf('?'); - var cond = text.substring(0, idx).trim(); - if (cond === '' || cond === 'false') { - return ''; - } - return text.slice(idx + 1); - }, -}; - -[ - 'reset', 'bold', 'dim', 'italic', 'underline', 'inverse', - 'hidden', 'strikethrough', 'visible', - - 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', - 'blackBright', 'gray', 'grey', 'redBright', 'greenBright', 'yellowBright', - 'blueBright', 'magentaBright', 'cyanBright', 'whiteBright', - - 'bgBlack', 'bgRed', 'bgGreen', 'bgYellow', 'bgBlue', 'bgMagenta', 'bgCyan', - 'bgWhite', 'bgBlackBright', 'bgGray', 'bgGrey', 'bgRedBright', - 'bgGreenBright', 'bgYellowBright', 'bgBlueBright', 'bgMagentaBright', - 'bgCyanBright', 'bgWhiteBright', -].forEach(function(style) { - theme[style] = chalk[style]; -}); - -module.exports = theme; diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index 2ba5e22d..ac9e93c1 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -2,7 +2,6 @@ var log = require('gulplog'); var formatTime = require('../../../shared/log/format-hrtime'); -var msgs = require('../../../shared/log/messages'); var formatError = require('../format-error'); var messages = require('../../../../messages'); diff --git a/test/lib/override-env-config.js b/test/lib/override-env-config.js index fc77332e..23dca8fe 100644 --- a/test/lib/override-env-config.js +++ b/test/lib/override-env-config.js @@ -3,8 +3,6 @@ // var expect = require('expect'); // var copyProps = require('copy-props'); // var overrideEnvConfig = require('../../lib/shared/config/env-config'); -// var theme = require('../../lib/shared/log/theme'); -// var msgs = require('../../lib/shared/log/messages'); // describe('lib: env-config', function() { diff --git a/test/lib/theme.js b/test/lib/theme.js index 28861b3a..57e723a0 100644 --- a/test/lib/theme.js +++ b/test/lib/theme.js @@ -1,8 +1,6 @@ 'use strict'; var expect = require('expect'); -// var format = require('theming-log').format; -// var theme = require('../../lib/shared/log/theme'); // describe('lib: theme', function() { From 1bcefb65eb7e508a88c684fbe0c6e7289bcfdd97 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 13:23:46 -0700 Subject: [PATCH 05/25] linting --- lib/shared/config/env-config.js | 2 +- lib/versioned/^4.0.0/log/sync-task.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/shared/config/env-config.js b/lib/shared/config/env-config.js index 0bd7f478..21f98399 100644 --- a/lib/shared/config/env-config.js +++ b/lib/shared/config/env-config.js @@ -88,7 +88,7 @@ function overrideEnvConfig(env, config, cliOpts) { } if (msg === messages.TASK_MISSING) { - return chalk.red('Task \'' + err.task + '\' is not in your gulpfile') + '\nPlease check the documentation for proper gulpfile formatting'; + return chalk.red('Task \'' + data.task + '\' is not in your gulpfile') + '\nPlease check the documentation for proper gulpfile formatting'; } if (msg === messages.SYNC_TASK) { diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index a4689aa9..dba5b7ee 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,6 +1,7 @@ 'use strict'; var log = require('gulplog'); +var messages = require('../../../../messages') var tasks = {}; From 09bcae036a43bd1eff433872f77d528e0b2fa0d1 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 13:58:59 -0700 Subject: [PATCH 06/25] npm install messages --- index.js | 32 ++++++++++++++++++++------------ lib/shared/config/env-config.js | 24 ++++++++++++++++++++++++ messages.js | 8 ++++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 9922bb9b..3aa59cdb 100644 --- a/index.js +++ b/index.js @@ -148,18 +148,26 @@ function onExecute(env) { } if (!env.modulePath) { - // var missingNodeModules = - // fs.existsSync(path.join(env.cwd, 'package.json')) - // && !fs.existsSync(path.join(env.cwd, 'node_modules')); - - // var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); - // var hasNpm = !hasYarn; - - // if (missingNodeModules) { - // log.error(msgs.error.nodeModulesNotFound, tildify(env.cwd), hasYarn, hasNpm); - // } else { - // log.error(msgs.error.gulpNotFound, tildify(env.cwd), hasYarn, hasNpm); - // } + var missingNodeModules = + fs.existsSync(path.join(env.cwd, 'package.json')) + && !fs.existsSync(path.join(env.cwd, 'node_modules')); + + var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); + if (missingNodeModules) { + log.error(messages.MISSING_NODE_MODULES, tildify(env.cwd)); + if (hasYarn) { + log.error(messages.YARN_INSTALL) + } else { + log.error(messages.NPM_INSTALL) + } + } else { + log.error(messages.MISSING_GULP, tildify(env.cwd)); + if (hasYarn) { + log.error(messages.YARN_INSTALL_GULP); + } else { + log.error(messages.NPM_INSTALL_GULP); + } + } exit(1); } diff --git a/lib/shared/config/env-config.js b/lib/shared/config/env-config.js index 21f98399..2cef5eed 100644 --- a/lib/shared/config/env-config.js +++ b/lib/shared/config/env-config.js @@ -95,6 +95,30 @@ function overrideEnvConfig(env, config, cliOpts) { return chalk.red('The following tasks did not complete: ') + chalk.cyan(data) + "\n" + chalk.red('Did you forget to signal async completion?'); } + if (msg === messages.MISSING_NODE_MODULES) { + return chalk.red('Local modules not found in') + ' ' + chalk.magenta(data); + } + + if (msg === messages.MISSING_GULP) { + return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(data); + } + + if (msg === messages.YARN_INSTALL) { + return chalk.red('Try running: yarn install'); + } + + if (msg === messages.NPM_INSTALL) { + return chalk.red('Try running: npm install'); + } + + if (msg === messages.YARN_INSTALL_GULP) { + return chalk.red('Try running: yarn add gulp'); + } + + if (msg === messages.NPM_INSTALL_GULP) { + return chalk.red('Try running: npm install gulp'); + } + if (msg === messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) { return chalk.white('└'); } diff --git a/messages.js b/messages.js index 5014a58f..51767632 100644 --- a/messages.js +++ b/messages.js @@ -19,6 +19,14 @@ module.exports = { SYNC_TASK: Symbol.for("GULP_CLI_SYNC_TASK"), + MISSING_NODE_MODULES: Symbol.for("GULP_CLI_MISSING_NODE_MODULES"), + MISSING_GULP: Symbol.for("GULP_CLI_MISSING_GULP"), + + YARN_INSTALL: Symbol.for("GULP_CLI_YARN_INSTALL"), + NPM_INSTALL: Symbol.for("GULP_CLI_NPM_INSTALL"), + YARN_INSTALL_GULP: Symbol.for("GULP_CLI_YARN_INSTALL_GULP"), + NPM_INSTALL_GULP: Symbol.for("GULP_CLI_NPM_INSTALL_GULP"), + BOX_DRAWINGS_LIGHT_UP_AND_RIGHT: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_UP_AND_RIGHT"), BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT"), BOX_DRAWINGS_LIGHT_HORIZONTAL: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_HORIZONTAL"), From 5b73bbd05a459af979954f0db6f3fc7d043e1ff0 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 14:33:58 -0700 Subject: [PATCH 07/25] using gulpfile --- lib/shared/config/env-config.js | 4 ++++ lib/versioned/^3.7.0/index.js | 3 ++- lib/versioned/^4.0.0-alpha.1/index.js | 3 ++- lib/versioned/^4.0.0-alpha.2/index.js | 3 ++- lib/versioned/^4.0.0/index.js | 3 ++- messages.js | 2 ++ 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/shared/config/env-config.js b/lib/shared/config/env-config.js index 2cef5eed..437ec24f 100644 --- a/lib/shared/config/env-config.js +++ b/lib/shared/config/env-config.js @@ -75,6 +75,10 @@ function overrideEnvConfig(env, config, cliOpts) { return chalk.red('Unsupported gulp version', data) } + if (msg === messages.GULPFILE) { + return 'Using gulpfile ' + chalk.magenta(data); + } + if (msg === messages.TASK_START) { return "Starting '" + chalk.cyan(data.task) + "'..." } diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index c2cf4f19..69d2c943 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -14,6 +14,7 @@ var logEvents = require('./log/events'); var logTasksSimple = require('./log/tasks-simple'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); +var messages = require('../../../messages'); function execute(env) { var opts = env.config.flags; @@ -35,7 +36,7 @@ function execute(env) { exit(1); } - // log.info(msgs.info.usingGulpfile, tildify(env.configPath)); + log.info(messages.GULPFILE, tildify(env.configPath)); var gulpInst = require(env.modulePath); logEvents(gulpInst); diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 8d2c4b22..48c2b95e 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -16,6 +16,7 @@ var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); var requireOrImport = require('../../shared/require-or-import'); +var messages = require('../../../messages'); function execute(env) { var opts = env.config.flags; @@ -71,7 +72,7 @@ function execute(env) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - // log.info(msgs.info.usingGulpfile, tildify(env.configPath)); + log.info(messages.GULPFILE, tildify(env.configPath)); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js index f1aaa6fa..077a8e34 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -17,6 +17,7 @@ var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); var getTask = require('../^4.0.0/log/get-task'); var requireOrImport = require('../../shared/require-or-import'); +var messages = require('../../../messages'); function execute(env) { var opts = env.config.flags; @@ -69,7 +70,7 @@ function execute(env) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - // log.info(msgs.info.usingGulpfile, tildify(env.configPath)); + log.info(messages.GULPFILE, tildify(env.configPath)); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index 893fd2eb..b9519d50 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -17,6 +17,7 @@ var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); var getTask = require('./log/get-task'); var requireOrImport = require('../../shared/require-or-import'); +var messages = require('../../../messages'); function execute(env) { var opts = env.config.flags; @@ -69,7 +70,7 @@ function execute(env) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - // log.info(msgs.info.usingGulpfile, tildify(env.configPath)); + log.info(messages.GULPFILE, tildify(env.configPath)); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { diff --git a/messages.js b/messages.js index 51767632..b17b8766 100644 --- a/messages.js +++ b/messages.js @@ -12,6 +12,8 @@ module.exports = { CWD_CHANGED: Symbol.for("GULP_CLI_CWD_CHANGED"), UNSUPPORTED_GULP_VERSION: Symbol.for("GULP_CLI_UNSUPPORTED_GULP_VERSION"), + GULPFILE: Symbol.for("GULP_CLI_GULPFILE"), + TASK_START: Symbol.for("GULP_CLI_TASK_START"), TASK_STOP: Symbol.for("GULP_CLI_TASK_STOP"), TASK_ERROR: Symbol.for("GULP_CLI_TASK_ERROR"), From 294bbfb15e626d8ec9b3a70930a8b9de3d9c923b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 15:04:12 -0700 Subject: [PATCH 08/25] move description to messages --- lib/shared/config/env-config.js | 8 +++++--- lib/versioned/^3.7.0/index.js | 5 +++-- lib/versioned/^4.0.0/index.js | 5 +++-- messages.js | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/shared/config/env-config.js b/lib/shared/config/env-config.js index 437ec24f..08e71406 100644 --- a/lib/shared/config/env-config.js +++ b/lib/shared/config/env-config.js @@ -75,6 +75,10 @@ function overrideEnvConfig(env, config, cliOpts) { return chalk.red('Unsupported gulp version', data) } + if (msg === messages.DESCRIPTION) { + return 'Tasks for ' + chalk.magenta(data); + } + if (msg === messages.GULPFILE) { return 'Using gulpfile ' + chalk.magenta(data); } @@ -143,9 +147,7 @@ function overrideEnvConfig(env, config, cliOpts) { return chalk.white('│'); } }; - if (config.description) { - env.config.description = config.description; - } + return env function convert(configInfo, envInfo) { diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 69d2c943..154a668b 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -1,6 +1,7 @@ 'use strict'; var fs = require('fs'); + var log = require('gulplog'); var stdout = require('mute-stdout'); @@ -52,14 +53,14 @@ function execute(env) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - tree.label = tildify(env.configPath); + tree.label = env.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; }); } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - // tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + tree.label = env.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index b9519d50..c725377b 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -1,6 +1,7 @@ 'use strict'; var fs = require('fs'); + var log = require('gulplog'); var stdout = require('mute-stdout'); @@ -55,12 +56,12 @@ function execute(env) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - tree.label = tildify(env.configPath); + tree.label = env.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - // tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + tree.label = env.flags.getMessage(messages.DESCRIPTION,tildify(env.configPath) ) var output = JSON.stringify(copyTree(tree, opts)); diff --git a/messages.js b/messages.js index b17b8766..63b5197b 100644 --- a/messages.js +++ b/messages.js @@ -12,6 +12,8 @@ module.exports = { CWD_CHANGED: Symbol.for("GULP_CLI_CWD_CHANGED"), UNSUPPORTED_GULP_VERSION: Symbol.for("GULP_CLI_UNSUPPORTED_GULP_VERSION"), + DESCRIPTION: Symbol.for("GULP_CLI_DESCRIPTION"), + GULPFILE: Symbol.for("GULP_CLI_GULPFILE"), TASK_START: Symbol.for("GULP_CLI_TASK_START"), From cb03b9a6698ead4537d77bd0478947366b7d29a6 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 15:20:09 -0700 Subject: [PATCH 09/25] chore!: Remove support for alpha versions of gulp 4 (#255) --- lib/versioned/^4.0.0-alpha.1/index.js | 97 --------------------------- lib/versioned/^4.0.0-alpha.2/index.js | 97 --------------------------- 2 files changed, 194 deletions(-) delete mode 100644 lib/versioned/^4.0.0-alpha.1/index.js delete mode 100644 lib/versioned/^4.0.0-alpha.2/index.js diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js deleted file mode 100644 index c9c5ffc3..00000000 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -var fs = require('fs'); - -var log = require('gulplog'); -var stdout = require('mute-stdout'); -var chalk = require('chalk'); - -var exit = require('../../shared/exit'); -var tildify = require('../../shared/tildify'); - -var logTasks = require('../../shared/log/tasks'); -var logEvents = require('../^4.0.0/log/events'); -var logSyncTask = require('../^4.0.0/log/sync-task'); -var logTasksSimple = require('../^4.0.0/log/tasks-simple'); -var registerExports = require('../../shared/register-exports'); - -var copyTree = require('../../shared/log/copy-tree'); -var requireOrImport = require('../../shared/require-or-import'); - -function execute(env) { - var opts = env.config.flags; - - var tasks = opts._; - var toRun = tasks.length ? tasks : ['default']; - - if (opts.tasksSimple || opts.tasks || opts.tasksJson) { - // Mute stdout if we are listing tasks - stdout.mute(); - } - - var gulpInst = require(env.modulePath); - logEvents(gulpInst); - logSyncTask(gulpInst, opts); - - // This is what actually loads up the gulpfile - requireOrImport(env.configPath, function(err, exported) { - // Before import(), if require() failed we got an unhandled exception on the module level. - // So console.error() & exit() were added here to mimic the old behavior as close as possible. - if (err) { - console.error(err); - exit(1); - } - - registerExports(gulpInst, exported); - - // Always unmute stdout after gulpfile is required - stdout.unmute(); - - var tree; - if (opts.tasksSimple) { - return logTasksSimple(gulpInst.tree()); - } - if (opts.tasks) { - tree = {}; - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; - } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); - } - tree.nodes = gulpInst.tree({ deep: true }); - return logTasks(tree, opts, function(taskname) { - return gulpInst.task(taskname); - }); - } - if (opts.tasksJson) { - tree = {}; - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; - } else { - tree.label = 'Tasks for ' + tildify(env.configPath); - } - tree.nodes = gulpInst.tree({ deep: true }); - - var output = JSON.stringify(copyTree(tree, opts)); - if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) { - return console.log(output); - } - return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); - } - try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); - var runMethod = opts.series ? 'series' : 'parallel'; - gulpInst[runMethod](toRun)(function(err) { - if (err) { - exit(1); - } - }); - } catch (err) { - log.error(chalk.red(err.message)); - log.error('To list available tasks, try running: gulp --tasks'); - exit(1); - } - }); -} - -module.exports = execute; diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js deleted file mode 100644 index 3d1763a6..00000000 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -var fs = require('fs'); - -var log = require('gulplog'); -var stdout = require('mute-stdout'); -var chalk = require('chalk'); - -var exit = require('../../shared/exit'); -var tildify = require('../../shared/tildify'); - -var logTasks = require('../../shared/log/tasks'); -var logEvents = require('../^4.0.0/log/events'); -var logSyncTask = require('../^4.0.0/log/sync-task'); -var logTasksSimple = require('../^4.0.0/log/tasks-simple'); -var registerExports = require('../../shared/register-exports'); - -var copyTree = require('../../shared/log/copy-tree'); -var getTask = require('../^4.0.0/log/get-task'); -var requireOrImport = require('../../shared/require-or-import'); - -function execute(env) { - var opts = env.config.flags; - - var tasks = opts._; - var toRun = tasks.length ? tasks : ['default']; - - if (opts.tasksSimple || opts.tasks || opts.tasksJson) { - // Mute stdout if we are listing tasks - stdout.mute(); - } - - var gulpInst = require(env.modulePath); - logEvents(gulpInst); - logSyncTask(gulpInst, opts); - - // This is what actually loads up the gulpfile - requireOrImport(env.configPath, function(err, exported) { - // Before import(), if require() failed we got an unhandled exception on the module level. - // So console.error() & exit() were added here to mimic the old behavior as close as possible. - if (err) { - console.error(err); - exit(1); - } - - registerExports(gulpInst, exported); - - // Always unmute stdout after gulpfile is required - stdout.unmute(); - - var tree; - if (opts.tasksSimple) { - tree = gulpInst.tree(); - return logTasksSimple(tree.nodes); - } - if (opts.tasks) { - tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; - } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); - } - - return logTasks(tree, opts, getTask(gulpInst)); - } - if (opts.tasksJson) { - tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; - } else { - tree.label = 'Tasks for ' + tildify(env.configPath); - } - - var output = JSON.stringify(copyTree(tree, opts)); - - if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) { - return console.log(output); - } - return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); - } - try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); - var runMethod = opts.series ? 'series' : 'parallel'; - gulpInst[runMethod](toRun)(function(err) { - if (err) { - exit(1); - } - }); - } catch (err) { - log.error(chalk.red(err.message)); - log.error('To list available tasks, try running: gulp --tasks'); - exit(1); - } - }); -} - -module.exports = execute; From c70ce34366abbe7b03fadf33421c6ff2aff0f07a Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 15:33:44 -0700 Subject: [PATCH 10/25] chore: Move task list helper functions into the logTasks closure (#256) --- lib/shared/log/tasks.js | 160 ++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 2d59fe35..4721774d 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -25,105 +25,105 @@ function logTasks(tree, opts, getTask) { }; printTaskTree(tree, treeOpts); -} - -function printTaskTree(tree, opts) { - var lines = []; - lines.push({ label: tree.label }); - var maxLabelWidth = 0; - - tree.nodes.forEach(function(node, idx, arr) { - var isLast = idx === arr.length - 1; - var w = createTreeLines(node, lines, opts, 1, '', isLast); - maxLabelWidth = Math.max(maxLabelWidth, w || 0); - }); - - lines.forEach(function(line) { - var s = line.label; - if (line.desc) { - var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' '; - s += spaces + line.desc; - } - log.info(s); - }); -} - -function createTreeLines(node, lines, opts, depth, bars, isLast) { - var task = { label: node.label, bars: bars, depth: depth }; - if (depth === 1) { - var t = opts.getTask(node.label); - task.desc = t.description; - task.flags = t.flags; - } - - var isLeaf = isLeafNode(node, depth, opts); - var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); + function printTaskTree(tree, opts) { + var lines = []; + lines.push({ label: tree.label }); + var maxLabelWidth = 0; - if (!isLeaf) { - bars += (isLast ? ' ' : '│ '); - node.nodes.forEach(function(node, idx, arr) { + tree.nodes.forEach(function(node, idx, arr) { var isLast = idx === arr.length - 1; - createTreeLines(node, lines, opts, depth + 1, bars, isLast); + var w = createTreeLines(node, lines, opts, 1, '', isLast); + maxLabelWidth = Math.max(maxLabelWidth, w || 0); }); - } - - return maxLabelWidth; -} -function addTaskToLines(task, lines, isLast, isLeaf) { - var taskBars = task.bars + (isLast ? '└' : '├') + '─'; - if (isLeaf) { - taskBars += '─ '; - } else { - taskBars += '┬ '; + lines.forEach(function(line) { + var s = line.label; + if (line.desc) { + var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' '; + s += spaces + line.desc; + } + log.info(s); + }); } - var line = {}; - if (task.depth === 1) { - line.label = chalk.white(taskBars) + chalk.white(task.label); - } else { - line.label = chalk.white(taskBars) + chalk.cyan(task.label); - } - if (typeof task.desc === 'string' && task.desc) { - line.desc = chalk.white(task.desc); - } - lines.push(line); + function createTreeLines(node, lines, opts, depth, bars, isLast) { + var task = { label: node.label, bars: bars, depth: depth }; + if (depth === 1) { + var t = opts.getTask(node.label); + task.desc = t.description; + task.flags = t.flags; + } - var maxLabelWidth = line.label.length + var isLeaf = isLeafNode(node, depth, opts); - if (!isObject(task.flags)) { - return maxLabelWidth; - } + var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); - var flagBars = task.bars; - if (isLast) { - flagBars += ' '; - } else { - flagBars += '│ '; - } + if (!isLeaf) { + bars += (isLast ? ' ' : '│ '); + node.nodes.forEach(function(node, idx, arr) { + var isLast = idx === arr.length - 1; + createTreeLines(node, lines, opts, depth + 1, bars, isLast); + }); + } - if (isLeaf) { - flagBars += ' '; - } else { - flagBars += '│ '; + return maxLabelWidth; } - Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); + function addTaskToLines(task, lines, isLast, isLeaf) { + var taskBars = task.bars + (isLast ? '└' : '├') + '─'; + if (isLeaf) { + taskBars += '─ '; + } else { + taskBars += '┬ '; + } - function addFlagsToLines(ent) { - if (typeof ent[0] !== 'string' || !ent[0]) return; var line = {}; + if (task.depth === 1) { + line.label = chalk.white(taskBars) + chalk.white(task.label); + } else { + line.label = chalk.white(taskBars) + chalk.cyan(task.label); + } + if (typeof task.desc === 'string' && task.desc) { + line.desc = chalk.white(task.desc); + } lines.push(line); - line.label = chalk.white(flagBars) + chalk.magenta(ent[0]); - maxLabelWidth = Math.max(maxLabelWidth, line.label.length); + var maxLabelWidth = line.label.length - if (typeof ent[1] !== 'string' || !ent[1]) return; - line.desc = chalk.white('…' + ent[1]); - } + if (!isObject(task.flags)) { + return maxLabelWidth; + } + + var flagBars = task.bars; + if (isLast) { + flagBars += ' '; + } else { + flagBars += '│ '; + } - return maxLabelWidth; + if (isLeaf) { + flagBars += ' '; + } else { + flagBars += '│ '; + } + + Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); + + function addFlagsToLines(ent) { + if (typeof ent[0] !== 'string' || !ent[0]) return; + var line = {}; + lines.push(line); + line.label = chalk.white(flagBars) + chalk.magenta(ent[0]); + + maxLabelWidth = Math.max(maxLabelWidth, line.label.length); + + if (typeof ent[1] !== 'string' || !ent[1]) return; + line.desc = chalk.white('…' + ent[1]); + } + + return maxLabelWidth; + } } function isLeafNode(node, depth, opts) { From 77f42fe16751ddd30b9448f76362e97e925e235b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 15:34:41 -0700 Subject: [PATCH 11/25] remove alphas --- lib/versioned/^4.0.0-alpha.1/index.js | 94 --------------------------- lib/versioned/^4.0.0-alpha.2/index.js | 92 -------------------------- 2 files changed, 186 deletions(-) delete mode 100644 lib/versioned/^4.0.0-alpha.1/index.js delete mode 100644 lib/versioned/^4.0.0-alpha.2/index.js diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js deleted file mode 100644 index 48c2b95e..00000000 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ /dev/null @@ -1,94 +0,0 @@ -'use strict'; - -var fs = require('fs'); -var log = require('gulplog'); -var stdout = require('mute-stdout'); - -var exit = require('../../shared/exit'); -var tildify = require('../../shared/tildify'); - -var logTasks = require('../../shared/log/tasks'); -var logEvents = require('../^4.0.0/log/events'); -var logSyncTask = require('../^4.0.0/log/sync-task'); -var logTasksSimple = require('../^4.0.0/log/tasks-simple'); -var checkTaskNotFound = require('../^4.0.0/log/check-task-not-found'); -var registerExports = require('../../shared/register-exports'); - -var copyTree = require('../../shared/log/copy-tree'); -var requireOrImport = require('../../shared/require-or-import'); -var messages = require('../../../messages'); - -function execute(env) { - var opts = env.config.flags; - - var tasks = opts._; - var toRun = tasks.length ? tasks : ['default']; - - if (opts.tasksSimple || opts.tasks || opts.tasksJson) { - // Mute stdout if we are listing tasks - stdout.mute(); - } - - var gulpInst = require(env.modulePath); - logEvents(gulpInst); - logSyncTask(gulpInst, opts); - - // This is what actually loads up the gulpfile - requireOrImport(env.configPath, function(err, exported) { - // Before import(), if require() failed we got an unhandled exception on the module level. - // So console.error() & exit() were added here to mimic the old behavior as close as possible. - if (err) { - console.error(err); - exit(1); - } - - registerExports(gulpInst, exported); - - // Always unmute stdout after gulpfile is required - stdout.unmute(); - - var tree; - if (opts.tasksSimple) { - return logTasksSimple(gulpInst.tree()); - } - if (opts.tasks) { - tree = {}; - tree.label = tildify(env.configPath); - tree.nodes = gulpInst.tree({ deep: true }); - - return logTasks(tree, opts, function(taskname) { - return gulpInst.task(taskname); - }); - } - if (opts.tasksJson) { - tree = {}; - // tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); - tree.nodes = gulpInst.tree({ deep: true }); - - var output = JSON.stringify(copyTree(tree, opts)); - if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) { - return console.log(output); - } - return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); - } - try { - log.info(messages.GULPFILE, tildify(env.configPath)); - var runMethod = opts.series ? 'series' : 'parallel'; - gulpInst[runMethod](toRun)(function(err) { - if (err) { - exit(1); - } - }); - } catch (err) { - var task = checkTaskNotFound(err); - if (task) { - // log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); - } else { - // log.error(msgs.error.failToRun, err.message); - } - exit(1); - } - }); -} - -module.exports = execute; diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js deleted file mode 100644 index 077a8e34..00000000 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ /dev/null @@ -1,92 +0,0 @@ -'use strict'; - -var fs = require('fs'); -var log = require('gulplog'); -var stdout = require('mute-stdout'); - -var exit = require('../../shared/exit'); -var tildify = require('../../shared/tildify'); - -var logTasks = require('../../shared/log/tasks'); -var logEvents = require('../^4.0.0/log/events'); -var logSyncTask = require('../^4.0.0/log/sync-task'); -var logTasksSimple = require('../^4.0.0/log/tasks-simple'); -var checkTaskNotFound = require('../^4.0.0/log/check-task-not-found'); -var registerExports = require('../../shared/register-exports'); - -var copyTree = require('../../shared/log/copy-tree'); -var getTask = require('../^4.0.0/log/get-task'); -var requireOrImport = require('../../shared/require-or-import'); -var messages = require('../../../messages'); - -function execute(env) { - var opts = env.config.flags; - - var tasks = opts._; - var toRun = tasks.length ? tasks : ['default']; - - if (opts.tasksSimple || opts.tasks || opts.tasksJson) { - // Mute stdout if we are listing tasks - stdout.mute(); - } - - var gulpInst = require(env.modulePath); - logEvents(gulpInst); - logSyncTask(gulpInst, opts); - - // This is what actually loads up the gulpfile - requireOrImport(env.configPath, function(err, exported) { - // Before import(), if require() failed we got an unhandled exception on the module level. - // So console.error() & exit() were added here to mimic the old behavior as close as possible. - if (err) { - console.error(err); - exit(1); - } - - registerExports(gulpInst, exported); - - // Always unmute stdout after gulpfile is required - stdout.unmute(); - - var tree; - if (opts.tasksSimple) { - tree = gulpInst.tree(); - return logTasksSimple(tree.nodes); - } - if (opts.tasks) { - tree = gulpInst.tree({ deep: true }); - tree.label = tildify(env.configPath); - return logTasks(tree, opts, getTask(gulpInst)); - } - if (opts.tasksJson) { - tree = gulpInst.tree({ deep: true }); - // tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); - - var output = JSON.stringify(copyTree(tree, opts)); - - if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) { - return console.log(output); - } - return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); - } - try { - log.info(messages.GULPFILE, tildify(env.configPath)); - var runMethod = opts.series ? 'series' : 'parallel'; - gulpInst[runMethod](toRun)(function(err) { - if (err) { - exit(1); - } - }); - } catch (err) { - var task = checkTaskNotFound(err); - if (task) { - // log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); - } else { - // log.error(msgs.error.failToRun, err.message); - } - exit(1); - } - }); -} - -module.exports = execute; From a1831c66b2fcf3d922ecdaaa0a9565507906d7e2 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 15:37:36 -0700 Subject: [PATCH 12/25] remove chalk from root --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 3aa59cdb..322edb9b 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,8 @@ var fs = require('fs'); var path = require('path'); + var log = require('gulplog'); -var chalk = require('chalk'); var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); From 4fc66f6f5486fb8e4373a5cb3fc3386ff6ce0fea Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 16:06:08 -0700 Subject: [PATCH 13/25] chore: Revert options & yargs parser changes (#257) --- index.js | 18 +++++++++++++++--- .../options/{parser.js => cli-options.js} | 11 +---------- test/fixtures/logging.js | 4 +++- 3 files changed, 19 insertions(+), 14 deletions(-) rename lib/shared/options/{parser.js => cli-options.js} (92%) diff --git a/index.js b/index.js index 935f8928..318e1755 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,9 @@ var fs = require('fs'); var path = require('path'); -var log = require('gulplog'); +var log = require('gulplog'); +var yargs = require('yargs'); var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); @@ -12,7 +13,7 @@ var chalk = require('chalk'); var exit = require('./lib/shared/exit'); var tildify = require('./lib/shared/tildify'); var makeTitle = require('./lib/shared/make-title'); -var parser = require('./lib/shared/options/parser'); +var cliOptions = require('./lib/shared/options/cli-options'); var completion = require('./lib/shared/completion'); var cliVersion = require('./package.json').version; var toConsole = require('./lib/shared/log/to-console'); @@ -52,7 +53,18 @@ var cli = new Liftoff({ }, }); -var opts = parser.argv; +var usage = + '\n' + chalk.bold('Usage:') + + ' gulp ' + chalk.blue('[options]') + ' tasks'; + +var parser = yargs + .help(false) + .version(false) + .detectLocale(false) + .usage(usage) + .options(cliOptions); + +var opts = parser.parse(); cli.on('preload:before', function(name) { log.info('Preloading external module:', chalk.magenta(name)); diff --git a/lib/shared/options/parser.js b/lib/shared/options/cli-options.js similarity index 92% rename from lib/shared/options/parser.js rename to lib/shared/options/cli-options.js index 67594a05..8105d461 100644 --- a/lib/shared/options/parser.js +++ b/lib/shared/options/cli-options.js @@ -1,11 +1,6 @@ 'use strict'; var chalk = require('chalk'); -var yargs = require('yargs'); - -var usage = - '\n' + chalk.bold('Usage:') + - ' gulp ' + chalk.blue('[options]') + ' tasks'; var options = { help: { @@ -121,8 +116,4 @@ var options = { } }; -var parser = yargs - .help(false).version(false).detectLocale(false) - .usage(usage).options(options); - -module.exports = parser; +module.exports = options; diff --git a/test/fixtures/logging.js b/test/fixtures/logging.js index aff166e0..6f5c5566 100644 --- a/test/fixtures/logging.js +++ b/test/fixtures/logging.js @@ -1,7 +1,9 @@ var log = require('gulplog'); +var yargs = require('yargs'); var toConsole = require('../../lib/shared/log/to-console'); +var cliOptions = require('../../lib/shared/options/cli-options'); -var opts = require('../../lib/shared/options/parser').argv; +var opts = yargs.options(cliOptions).parse(); toConsole(log, opts); From 6e5c79016ed96c05e3e2186b78c1466ff884f0ba Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 16:18:45 -0700 Subject: [PATCH 14/25] fix some getMessage calls --- lib/versioned/^3.7.0/index.js | 4 ++-- lib/versioned/^4.0.0/index.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 154a668b..afc23db7 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -53,14 +53,14 @@ function execute(env) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - tree.label = env.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); + tree.label = env.config.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; }); } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - tree.label = env.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); + tree.label = env.config.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index c725377b..31305c23 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -56,12 +56,12 @@ function execute(env) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - tree.label = env.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); + tree.label = env.config.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - tree.label = env.flags.getMessage(messages.DESCRIPTION,tildify(env.configPath) ) + tree.label = env.config.flags.getMessage(messages.DESCRIPTION,tildify(env.configPath) ) var output = JSON.stringify(copyTree(tree, opts)); From 36f05d5a8bb5c56437204a37f12fc4b2e31c5430 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 17:48:09 -0700 Subject: [PATCH 15/25] fix: Ensure the logger is wired up before running liftoff (#258) --- index.js | 3 +++ test/config-description.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 318e1755..6ff75f34 100644 --- a/index.js +++ b/index.js @@ -66,6 +66,9 @@ var parser = yargs var opts = parser.parse(); +// Set up event listeners for logging temporarily. +toConsole(log, opts); + cli.on('preload:before', function(name) { log.info('Preloading external module:', chalk.magenta(name)); }); diff --git a/test/config-description.js b/test/config-description.js index ac85fd70..2a185459 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -48,7 +48,7 @@ describe('config: description', function() { expect(err).toBeNull(); expect(stderr).toEqual(''); var expected = fs.readFileSync(path.join(expectedDir, 'output2.txt'), 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 2)).toEqual(expected); done(err); } }); From ed86da75fddfe0965d9bcc0a299e74f961f50957 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 11:47:58 -0700 Subject: [PATCH 16/25] feat!: Upgrade to Liftoff v5 and avoid merging flags/config/env (#259) --- README.md | 8 +- index.js | 64 +++++----- lib/shared/array-find.js | 19 +++ lib/shared/config/env-flags.js | 56 --------- lib/shared/config/merge-configs.js | 28 ----- lib/versioned/^3.7.0/index.js | 12 +- lib/versioned/^4.0.0/index.js | 12 +- package.json | 2 +- test/config-flags-compact-tasks.js | 16 +-- test/config-flags-gulpfile.js | 16 +-- test/config-flags-preload.js | 2 +- test/config-flags-sort-tasks.js | 8 +- test/config-flags-tasks-depth.js | 4 +- test/expected/flags-tasks-compact.txt | 1 + test/expected/flags-tasks-depth2.txt | 1 + test/expected/flags-tasks-depth4.txt | 1 + test/expected/flags-tasks-sorted.txt | 1 + test/expected/flags-tasks-unsorted.txt | 1 + .../config/flags/compactTasks/f/.gulp.js | 2 +- .../config/flags/compactTasks/t/.gulp.js | 2 +- .../flags/gulpfile/autoload-fail/.gulp.json | 4 +- .../config/flags/gulpfile/autoload/.gulp.json | 4 +- .../config/flags/gulpfile/cwd/.gulp.json | 4 +- .../gulpfile/override-by-cliflag/.gulp.json | 4 +- .../config/flags/gulpfile/prj/.gulp.json | 4 +- .../use-current-cfg/current-dir/.gulp.js | 4 +- .../config/flags/nodeFlags/array/.gulp.json | 4 +- .../config/flags/nodeFlags/null/.gulp.js | 4 +- .../config/flags/nodeFlags/string/.gulp.js | 4 +- .../config/flags/nodeFlags/undefined/.gulp.js | 4 +- .../config/flags/preload/array/.gulp.json | 10 +- .../flags/preload/join-flags/.gulp.json | 8 +- .../config/flags/preload/string/.gulp.json | 4 +- .../flags/preload/with-absolute/.gulp.js | 4 +- .../config/flags/preload/with-cwd/.gulp.json | 4 +- .../config/flags/sortTasks/f/.gulp.json | 4 +- .../config/flags/sortTasks/t/.gulp.json | 4 +- .../config/flags/tasksDepth/.gulp.json | 4 +- test/flags-tasks.js | 10 +- test/lib/config-env-flags.js | 112 ----------------- test/lib/merge-configs.js | 119 ------------------ 41 files changed, 129 insertions(+), 450 deletions(-) create mode 100644 lib/shared/array-find.js delete mode 100644 lib/shared/config/env-flags.js delete mode 100644 lib/shared/config/merge-configs.js delete mode 100644 test/lib/config-env-flags.js delete mode 100644 test/lib/merge-configs.js diff --git a/README.md b/README.md index bde183fd..78ae7453 100644 --- a/README.md +++ b/README.md @@ -101,21 +101,21 @@ The CLI adds `process.env.INIT_CWD` which is the original cwd it was launched fr Configuration is supported through the use of a `.gulp.*` file (e.g. `.gulp.json`, `.gulp.yml`). You can find a list of supported languages at https://github.com/gulpjs/interpret. -Configuration from the home directory (`~`) and current working directory (`cwd`) are merged with `cwd` taking precedence. +A configuration file from the current working directory (`cwd`) or above are selected before a configuration file from the home directory (`~`). Supported configurations properties: | Property | Description | |--------------------|-------------| | description | Top-level description of the project/gulpfile (Replaces "Tasks for ~/path/of/gulpfile.js") | +| gulpfile | Set a default gulpfile | +| preload | An array of modules to preload before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | +| nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here | | flags.continue | Continue execution of tasks upon failure by default. | | flags.compactTasks | Reduce the output of task dependency tree by default. | | flags.tasksDepth | Set default depth of task dependency tree. | -| flags.gulpfile | Set a default gulpfile | | flags.silent | Silence logging by default | | flags.series | Run tasks given on the CLI in series (the default is parallel) | -| flags.preload | An array of modules to preload before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | -| flags.nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here | ## Flags diff --git a/index.js b/index.js index 6ff75f34..1ace11ea 100644 --- a/index.js +++ b/index.js @@ -10,16 +10,16 @@ var interpret = require('interpret'); var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); var chalk = require('chalk'); + var exit = require('./lib/shared/exit'); var tildify = require('./lib/shared/tildify'); +var arrayFind = require('./lib/shared/array-find'); var makeTitle = require('./lib/shared/make-title'); var cliOptions = require('./lib/shared/options/cli-options'); var completion = require('./lib/shared/completion'); var cliVersion = require('./package.json').version; var toConsole = require('./lib/shared/log/to-console'); - -var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); -var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); +var mergeCliOpts = require('./lib/shared/config/cli-flags'); // Get supported ranges var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); @@ -34,23 +34,19 @@ var cli = new Liftoff({ completions: completion, extensions: interpret.jsVariants, v8flags: v8flags, - configFiles: { - project: [ - { - name: '.gulp', - path: '.', - extensions: interpret.extensions, - findUp: true, - }, - ], - userHome: [ - { - name: '.gulp', - path: '~', - extensions: interpret.extensions, - }, - ], - }, + configFiles: [ + { + name: '.gulp', + path: '.', + extensions: interpret.extensions, + findUp: true, + }, + { + name: '.gulp', + path: '~', + extensions: interpret.extensions, + }, + ], }); var usage = @@ -127,33 +123,41 @@ function run() { module.exports = run; +function isDefined(cfg) { + return cfg != null; +} + function onPrepare(env) { - var cfg = mergeProjectAndUserHomeConfigs(env); - env = overrideEnvFlagsByConfigAndCliOpts(env, cfg, opts); + // We only use the first config found, which is a departure from + // the previous implementation that merged with the home + var cfg = arrayFind(env.config, isDefined); + var flags = mergeCliOpts(opts, cfg); - // Set up event listeners for logging again after configuring. - toConsole(log, env.config.flags); + // Set up event listeners for logging after configuring. + toConsole(log, flags); - cli.execute(env, env.nodeFlags, onExecute); + cli.execute(env, cfg.nodeFlags, function (env) { + onExecute(env, cfg, flags); + }); } // The actual logic -function onExecute(env) { +function onExecute(env, cfg, flags) { // This translates the --continue flag in gulp // To the settle env variable for undertaker // We use the process.env so the user's gulpfile // Can know about the flag - if (env.config.flags.continue) { + if (flags.continue) { process.env.UNDERTAKER_SETTLE = 'true'; } - if (env.config.flags.help) { + if (flags.help) { parser.showHelp(console.log); exit(0); } // Anything that needs to print outside of the logging mechanism should use console.log - if (env.config.flags.version) { + if (flags.version) { console.log('CLI version:', cliVersion); console.log('Local version:', env.modulePackage.version || 'Unknown'); exit(0); @@ -215,5 +219,5 @@ function onExecute(env) { // Load and execute the CLI version var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); - require(versionedDir)(env); + require(versionedDir)(env, cfg, flags); } diff --git a/lib/shared/array-find.js b/lib/shared/array-find.js new file mode 100644 index 00000000..0596268c --- /dev/null +++ b/lib/shared/array-find.js @@ -0,0 +1,19 @@ +'use strict'; + +function arrayFind(arr, fn) { + if (!Array.isArray(arr)) { + return; + } + + var idx = 0; + while (idx < arr.length) { + var result = fn(arr[idx]); + if (result) { + // TODO: This is wrong in Liftoff + return arr[idx]; + } + idx++; + } +} + +module.exports = arrayFind; diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-flags.js deleted file mode 100644 index 59b4d4be..00000000 --- a/lib/shared/config/env-flags.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -var path = require('path'); -var copyProps = require('copy-props'); - -var mergeCliOpts = require('./cli-flags'); - -var toEnvFromConfig = { - configPath: 'flags.gulpfile', - configBase: 'flags.gulpfile', - preload: 'flags.preload', - nodeFlags: 'flags.nodeFlags', -}; - -function overrideEnvFlags(env, config, cliOpts) { - cliOpts = mergeCliOpts(cliOpts, config); - - // This must reverse because `flags.gulpfile` determines 2 different properties - var reverse = true; - env = copyProps(env, config, toEnvFromConfig, convert, reverse); - - env.config = { - flags: cliOpts, - }; - if (config.description) { - env.config.description = config.description; - } - return env - - function convert(configInfo, envInfo) { - if (envInfo.keyChain === 'configBase') { - if (cliOpts.gulpfile === undefined) { - return path.dirname(configInfo.value); - } - return; - } - - if (envInfo.keyChain === 'configPath') { - if (cliOpts.gulpfile === undefined) { - return configInfo.value; - } - return; - } - - if (envInfo.keyChain === 'preload') { - return [].concat(envInfo.value, configInfo.value); - } - - /* istanbul ignore else */ - if (envInfo.keyChain === 'nodeFlags') { - return [].concat(configInfo.value || []); - } - } -} - -module.exports = overrideEnvFlags; diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js deleted file mode 100644 index 8202f182..00000000 --- a/lib/shared/config/merge-configs.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var copyProps = require('copy-props'); -var path = require('path'); - -function mergeConfigs(env) { - var cfg = {}; - if (env.configFiles.userHome) { - copyConfig(env.config.userHome, cfg, env.configFiles.userHome); - } - if (env.configFiles.project) { - copyConfig(env.config.project, cfg, env.configFiles.project); - } - return cfg; -} - -function copyConfig(src, dest, filePath) { - return copyProps(src, dest, convert); - - function convert(loadedInfo) { - if (loadedInfo.keyChain === 'flags.gulpfile') { - return path.resolve(path.dirname(filePath), loadedInfo.value); - } - return loadedInfo.value; - } -} - -module.exports = mergeConfigs; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index a5cc2a9f..397bd579 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -17,9 +17,7 @@ var logTasksSimple = require('./log/tasks-simple'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); -function execute(env) { - var opts = env.config.flags; - +function execute(env, cfg, opts) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -53,8 +51,8 @@ function execute(env) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } @@ -64,8 +62,8 @@ function execute(env) { } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index d6883587..137ad438 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -19,9 +19,7 @@ var copyTree = require('../../shared/log/copy-tree'); var getTask = require('./log/get-task'); var requireOrImport = require('../../shared/require-or-import'); -function execute(env) { - var opts = env.config.flags; - +function execute(env, cfg, opts) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -55,8 +53,8 @@ function execute(env) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } @@ -65,8 +63,8 @@ function execute(env) { } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } diff --git a/package.json b/package.json index 47ff7595..dace639b 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "fancy-log": "^2.0.0", "gulplog": "^2.0.1", "interpret": "^3.1.1", - "liftoff": "^4.0.0", + "liftoff": "^5.0.0", "mute-stdout": "^2.0.0", "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0", diff --git a/test/config-flags-compact-tasks.js b/test/config-flags-compact-tasks.js index 06945128..57fd19a1 100644 --- a/test/config-flags-compact-tasks.js +++ b/test/config-flags-compact-tasks.js @@ -20,8 +20,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -35,8 +35,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -50,8 +50,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -65,8 +65,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index ae04b7f6..4d62031c 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -10,7 +10,7 @@ var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/gulpfile'); var prjDir = path.join(baseDir, 'prj'); -describe('config: flags.gulpfile', function() { +describe('config: gulpfile', function() { it('Should configure with a .gulp.* file', function(done) { var opts = { cwd: prjDir }; @@ -19,9 +19,9 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 2, 4)).toEqual( + expect(sliceLines(stdout, 3, 5)).toEqual( 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + - 'The current directory : ' + prjDir + 'The current directory : ' + path.join(baseDir, 'is/here') ); done(err); } @@ -49,9 +49,9 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 2, 4)).toEqual( + expect(sliceLines(stdout, 3, 5)).toEqual( 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + - 'The current directory : ' + path.join(prjDir, 'findup') + 'The current directory : ' + path.join(baseDir, 'is/here') ); done(err); } @@ -126,8 +126,8 @@ describe('config: flags.gulpfile', function() { expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toEqual('Loaded external module: @babel/register'); - expect(sliceLines(stdout, 4, 5)).toEqual('clean!'); - expect(sliceLines(stdout, 7, 8)).toEqual('build!'); + expect(sliceLines(stdout, 5, 6)).toEqual('clean!'); + expect(sliceLines(stdout, 8, 9)).toEqual('build!'); done(err); } }); @@ -152,7 +152,7 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 3, 4)).toEqual(path.join(opts.cwd, 'gulpfile-2.js')); + expect(sliceLines(stdout, 2, 3)).toEqual(path.join(opts.cwd, 'gulpfile-2.js')); done(err); } }); diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js index 47942363..e406da09 100644 --- a/test/config-flags-preload.js +++ b/test/config-flags-preload.js @@ -9,7 +9,7 @@ var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/preload'); -describe('config: flags.preload', function() { +describe('config: preload', function() { it('Should configure with an array in a .gulp.* file', function(done) { var opts = { cwd: path.join(baseDir, 'array') }; diff --git a/test/config-flags-sort-tasks.js b/test/config-flags-sort-tasks.js index 01eada8d..197f8d39 100644 --- a/test/config-flags-sort-tasks.js +++ b/test/config-flags-sort-tasks.js @@ -20,7 +20,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -33,7 +33,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -46,7 +46,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -59,7 +59,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } diff --git a/test/config-flags-tasks-depth.js b/test/config-flags-tasks-depth.js index 944766c2..68a09037 100644 --- a/test/config-flags-tasks-depth.js +++ b/test/config-flags-tasks-depth.js @@ -20,7 +20,7 @@ describe('config: flags.tasksDepth', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -33,7 +33,7 @@ describe('config: flags.tasksDepth', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-depth2.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } diff --git a/test/expected/flags-tasks-compact.txt b/test/expected/flags-tasks-compact.txt index 45bc48d3..d15def9b 100644 --- a/test/expected/flags-tasks-compact.txt +++ b/test/expected/flags-tasks-compact.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └─┬ diff --git a/test/expected/flags-tasks-depth2.txt b/test/expected/flags-tasks-depth2.txt index ffd130ef..3edbdf74 100644 --- a/test/expected/flags-tasks-depth2.txt +++ b/test/expected/flags-tasks-depth2.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └── diff --git a/test/expected/flags-tasks-depth4.txt b/test/expected/flags-tasks-depth4.txt index b1550ad5..6d79eb1e 100644 --- a/test/expected/flags-tasks-depth4.txt +++ b/test/expected/flags-tasks-depth4.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └─┬ diff --git a/test/expected/flags-tasks-sorted.txt b/test/expected/flags-tasks-sorted.txt index 65d61c0c..1bdc4cfd 100644 --- a/test/expected/flags-tasks-sorted.txt +++ b/test/expected/flags-tasks-sorted.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ default │ └─┬ diff --git a/test/expected/flags-tasks-unsorted.txt b/test/expected/flags-tasks-unsorted.txt index fe916931..edd85682 100644 --- a/test/expected/flags-tasks-unsorted.txt +++ b/test/expected/flags-tasks-unsorted.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └─┬ diff --git a/test/fixtures/config/flags/compactTasks/f/.gulp.js b/test/fixtures/config/flags/compactTasks/f/.gulp.js index 53447e50..9fef64e2 100644 --- a/test/fixtures/config/flags/compactTasks/f/.gulp.js +++ b/test/fixtures/config/flags/compactTasks/f/.gulp.js @@ -1,8 +1,8 @@ 'use strict'; module.exports = { + gulpfile: '../../../../gulpfiles/gulpfile-4.js', flags: { compactTasks: false, - gulpfile: '../../../../gulpfiles/gulpfile-4.js', }, }; diff --git a/test/fixtures/config/flags/compactTasks/t/.gulp.js b/test/fixtures/config/flags/compactTasks/t/.gulp.js index 70c8de7d..8ac27e43 100644 --- a/test/fixtures/config/flags/compactTasks/t/.gulp.js +++ b/test/fixtures/config/flags/compactTasks/t/.gulp.js @@ -1,8 +1,8 @@ 'use strict'; module.exports = { + gulpfile: '../../../../gulpfiles/gulpfile-4.js', flags: { compactTasks: true, - gulpfile: '../../../../gulpfiles/gulpfile-4.js', }, }; diff --git a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json index 10707925..42846df5 100644 --- a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "./other_dir/gulpfile.coffee" - } + "gulpfile": "./other_dir/gulpfile.coffee" } diff --git a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json index 0d5c0009..10c5b586 100644 --- a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "other_folder/gulpfile-exports.babel.js" - } + "gulpfile": "other_folder/gulpfile-exports.babel.js" } diff --git a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json index 231d1a67..7f0181dd 100644 --- a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "../is/here/gulpfile-by-cwd-cfg.js" - } + "gulpfile": "../is/here/gulpfile-by-cwd-cfg.js" } diff --git a/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json b/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json index f071d31d..fb737ede 100644 --- a/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "../cwd/gulpfile.js" - } + "gulpfile": "../cwd/gulpfile.js" } diff --git a/test/fixtures/config/flags/gulpfile/prj/.gulp.json b/test/fixtures/config/flags/gulpfile/prj/.gulp.json index 64535ec4..625bb7c1 100644 --- a/test/fixtures/config/flags/gulpfile/prj/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/prj/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "../is/here/gulpfile-by-prj-cfg.js" - } + "gulpfile": "../is/here/gulpfile-by-prj-cfg.js" } diff --git a/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js index 0cbce526..8e905bea 100644 --- a/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js +++ b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js @@ -1,5 +1,3 @@ module.exports = { - flags: { - gulpfile: './gulpfile-2.js', - }, + gulpfile: './gulpfile-2.js', }; diff --git a/test/fixtures/config/flags/nodeFlags/array/.gulp.json b/test/fixtures/config/flags/nodeFlags/array/.gulp.json index f327928a..79cd530d 100644 --- a/test/fixtures/config/flags/nodeFlags/array/.gulp.json +++ b/test/fixtures/config/flags/nodeFlags/array/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "nodeFlags": ["--lazy", "--trace-deprecation"] - } + "nodeFlags": ["--lazy", "--trace-deprecation"] } diff --git a/test/fixtures/config/flags/nodeFlags/null/.gulp.js b/test/fixtures/config/flags/nodeFlags/null/.gulp.js index 1b0bdfb1..4f613ce0 100644 --- a/test/fixtures/config/flags/nodeFlags/null/.gulp.js +++ b/test/fixtures/config/flags/nodeFlags/null/.gulp.js @@ -1,7 +1,5 @@ 'use strict'; module.exports = { - flags: { - nodeFlags: null, - }, + nodeFlags: null, }; diff --git a/test/fixtures/config/flags/nodeFlags/string/.gulp.js b/test/fixtures/config/flags/nodeFlags/string/.gulp.js index 608862dd..f14523e4 100644 --- a/test/fixtures/config/flags/nodeFlags/string/.gulp.js +++ b/test/fixtures/config/flags/nodeFlags/string/.gulp.js @@ -1,7 +1,5 @@ 'use strict'; module.exports = { - flags: { - nodeFlags: '--lazy', - }, + nodeFlags: '--lazy', }; diff --git a/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js b/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js index 35082449..78532965 100644 --- a/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js +++ b/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js @@ -1,7 +1,5 @@ 'use strict'; module.exports = { - flags: { - nodeFlags: undefined, - }, + nodeFlags: undefined, }; diff --git a/test/fixtures/config/flags/preload/array/.gulp.json b/test/fixtures/config/flags/preload/array/.gulp.json index 0031374c..2f4855e1 100644 --- a/test/fixtures/config/flags/preload/array/.gulp.json +++ b/test/fixtures/config/flags/preload/array/.gulp.json @@ -1,8 +1,6 @@ { - "flags": { - "preload": [ - "./preload_one", - "./preload_two" - ] - } + "preload": [ + "./preload_one", + "./preload_two" + ] } diff --git a/test/fixtures/config/flags/preload/join-flags/.gulp.json b/test/fixtures/config/flags/preload/join-flags/.gulp.json index 83d17ccf..63405ae5 100644 --- a/test/fixtures/config/flags/preload/join-flags/.gulp.json +++ b/test/fixtures/config/flags/preload/join-flags/.gulp.json @@ -1,7 +1,5 @@ { - "flags": { - "preload": [ - "./preload_two" - ] - } + "preload": [ + "./preload_two" + ] } diff --git a/test/fixtures/config/flags/preload/string/.gulp.json b/test/fixtures/config/flags/preload/string/.gulp.json index 9b061f1f..22886303 100644 --- a/test/fixtures/config/flags/preload/string/.gulp.json +++ b/test/fixtures/config/flags/preload/string/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "preload": "./preload" - } + "preload": "./preload" } diff --git a/test/fixtures/config/flags/preload/with-absolute/.gulp.js b/test/fixtures/config/flags/preload/with-absolute/.gulp.js index c0e29e8a..1e7872b2 100644 --- a/test/fixtures/config/flags/preload/with-absolute/.gulp.js +++ b/test/fixtures/config/flags/preload/with-absolute/.gulp.js @@ -1,7 +1,5 @@ var path = require('path'); module.exports = { - flags: { - preload: path.join(__dirname, '../preload'), - }, + preload: path.join(__dirname, '../preload'), }; diff --git a/test/fixtures/config/flags/preload/with-cwd/.gulp.json b/test/fixtures/config/flags/preload/with-cwd/.gulp.json index d43feab5..c92f9743 100644 --- a/test/fixtures/config/flags/preload/with-cwd/.gulp.json +++ b/test/fixtures/config/flags/preload/with-cwd/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "preload": "../preload" - } + "preload": "../preload" } diff --git a/test/fixtures/config/flags/sortTasks/f/.gulp.json b/test/fixtures/config/flags/sortTasks/f/.gulp.json index ac703623..daa8a926 100644 --- a/test/fixtures/config/flags/sortTasks/f/.gulp.json +++ b/test/fixtures/config/flags/sortTasks/f/.gulp.json @@ -1,6 +1,6 @@ { + "gulpfile": "../../../../gulpfiles/gulpfile-4.js", "flags": { - "sortTasks": false, - "gulpfile": "../../../../gulpfiles/gulpfile-4.js" + "sortTasks": false } } diff --git a/test/fixtures/config/flags/sortTasks/t/.gulp.json b/test/fixtures/config/flags/sortTasks/t/.gulp.json index 7e801098..254cd26a 100644 --- a/test/fixtures/config/flags/sortTasks/t/.gulp.json +++ b/test/fixtures/config/flags/sortTasks/t/.gulp.json @@ -1,6 +1,6 @@ { + "gulpfile": "../../../../gulpfiles/gulpfile-4.js", "flags": { - "sortTasks": true, - "gulpfile": "../../../../gulpfiles/gulpfile-4.js" + "sortTasks": true } } diff --git a/test/fixtures/config/flags/tasksDepth/.gulp.json b/test/fixtures/config/flags/tasksDepth/.gulp.json index 5a9da057..bc309203 100644 --- a/test/fixtures/config/flags/tasksDepth/.gulp.json +++ b/test/fixtures/config/flags/tasksDepth/.gulp.json @@ -1,6 +1,6 @@ { + "gulpfile": "../../../gulpfiles/gulpfile-4.js", "flags": { - "tasksDepth": 4, - "gulpfile": "../../../gulpfiles/gulpfile-4.js" + "tasksDepth": 4 } } diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 4a1c689f..270b5ffc 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -81,7 +81,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -99,7 +99,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -117,7 +117,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -135,7 +135,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -153,7 +153,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); diff --git a/test/lib/config-env-flags.js b/test/lib/config-env-flags.js deleted file mode 100644 index d8062c08..00000000 --- a/test/lib/config-env-flags.js +++ /dev/null @@ -1,112 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var overrideEnvFlags = require('../../lib/shared/config/env-flags'); - -describe('lib: config/env-flags', function() { - - it('Should copy only config props specified to env flags', function(done) { - var env = {}; - - var config = { - description: 'DESCRIPTION.', - flags: { - silent: true, - gulpfile: '/path/to/gulpfile', - }, - }; - - var result = overrideEnvFlags(env, config, {}); - expect(result).toEqual({ - configPath: '/path/to/gulpfile', - configBase: '/path/to', - config: { - description: 'DESCRIPTION.', - flags: { - silent: true, - }, - }, - }); - expect(result).toBe(env); - done(); - }); - - it('Should take into account forced gulpfile opts from flags', function(done) { - var env = { - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - }; - - var config = { - description: 'DESCRIPTION.', - flags: { - silent: false, - gulpfile: '/path/to/gulpfile', - preload: ['a', 'b'], - }, - }; - - var opts = { - gulpfile: env.configPath, - }; - - var result = overrideEnvFlags(env, config, opts); - expect(result).toEqual({ - cwd: '/path/to/cwd', - preload: ['preload', 'a', 'b'], - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - config: { - description: "DESCRIPTION.", - flags: { - gulpfile: "/path/of/config/path", - silent: false, - }, - }, - }); - expect(result).toBe(env); - done(); - }); - - it('Should not cause error if config is empty', function(done) { - var env = { - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - }; - - var config = {}; - - var result = overrideEnvFlags(env, config, {}); - expect(result).toEqual({ - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - config: { - flags: {}, - }, - }); - expect(result).toBe(env); - done(); - }); -}); diff --git a/test/lib/merge-configs.js b/test/lib/merge-configs.js deleted file mode 100644 index 6d0a4bea..00000000 --- a/test/lib/merge-configs.js +++ /dev/null @@ -1,119 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var path = require('path'); -var mergeConfigs = require('../../lib/shared/config/merge-configs'); - -var fixturesDir = path.join(__dirname, '../fixtures/config'); - -describe('lib: config/merge-configs', function() { - - it('Should get merged config when there is only project config', function(done) { - var config = { - project: { - description: 'description by .gulp.js in directory project', - }, - userHome: {}, - }; - var configFiles = { - project: path.join(fixturesDir, 'project/.gulp.js'), - userHome: undefined, - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory project', - }); - done(); - }); - - it('Should get merged config when there is only user-home config', function(done) { - var config = { - project: {}, - userHome: { - description: 'description by .gulp.js in directory user home', - }, - }; - var configFiles = { - project: undefined, - userHome: path.join(fixturesDir, 'user/home/.gulp.js'), - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory user home', - }); - done(); - }); - - it('Should get merged config when there are both project and user-home config', function(done) { - var config = { - project: { - description: 'description by .gulp.js in directory project', - flags: { - series: true, - }, - }, - userHome: { - description: 'description by .gulp.js in directory user home', - flags: { - silent: true, - }, - }, - }; - var configFiles = { - project: path.join(fixturesDir, 'project/gulp.js'), - userHome: path.join(fixturesDir, 'user/home/.gulp.js'), - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory project', - flags: { - series: true, - silent: true, - }, - }); - done(); - }); - - it('Should convert a value of `flags.gulpfile` to absolute path', function(done) { - var config = { - project: { - flags: { gulpfile: './is/here/mygulpfile.js' }, - }, - }; - var configFiles = { - project: path.join(fixturesDir, 'flags/gulpfile/.gulp.json'), - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - flags: { - gulpfile: path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js'), - }, - }); - done(); - }); - -}); From 100006667f9452a51a73ee5d28212a9b52050486 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 11:56:02 -0700 Subject: [PATCH 17/25] load user messages and timestamps, integrate with liftoff 5 --- index.js | 38 ++-- lib/shared/config/env-config.js | 179 ---------------- lib/shared/log/tasks.js | 23 ++- lib/shared/log/to-console.js | 119 +++++------ lib/shared/translate.js | 195 ++++++++++++++++++ lib/versioned/^3.7.0/index.js | 8 +- lib/versioned/^4.0.0/index.js | 9 +- package.json | 1 - test/config-theme-and-msgs.js | 12 +- test/expected/by-unwrap-and-not-by-unwrap.txt | 8 +- test/expected/with-desc-and-flags.txt | 4 +- test/fixtures/.gulp.js | 9 + test/fixtures/.gulp.json | 9 - test/fixtures/gulpfiles/.gulp.js | 9 + test/fixtures/gulpfiles/.gulp.json | 12 -- test/fixtures/logging.js | 5 +- 16 files changed, 333 insertions(+), 307 deletions(-) delete mode 100644 lib/shared/config/env-config.js create mode 100644 lib/shared/translate.js create mode 100644 test/fixtures/.gulp.js delete mode 100644 test/fixtures/.gulp.json create mode 100644 test/fixtures/gulpfiles/.gulp.js delete mode 100644 test/fixtures/gulpfiles/.gulp.json diff --git a/index.js b/index.js index c2143079..3689b7f9 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ var completion = require('./lib/shared/completion'); var cliVersion = require('./package.json').version; var toConsole = require('./lib/shared/log/to-console'); var mergeCliOpts = require('./lib/shared/config/cli-flags'); +var buildTranslations = require('./lib/shared/translate'); var messages = require('./messages'); @@ -68,13 +69,21 @@ var parser = yargs .detectLocale(false) .showHelpOnFail(false) .exitProcess(false) - .fail(function(msg) { throw new Error(msg); }) + .fail(function(msg) { + cli.prepare({}, function (env) { + log.error(messages.ARGV_ERROR, msg); + // makeHelp(parser).showHelp(console.error); + exit(1); + }); + }) .options(cliOptions); var opts = parser.parse(); // Set up event listeners for logging temporarily. -toConsole(log, opts); +// TODO: Rework console logging before we can set up proper config +// Possibly by batching messages in gulplog until listeners are attached +var cleanupListeners = toConsole(log, opts, buildTranslations()); cli.on('preload:before', function(name) { log.info(messages.PRELOAD_BEFORE, name); @@ -134,16 +143,21 @@ function onPrepare(env) { var cfg = arrayFind(env.config, isDefined); var flags = mergeCliOpts(opts, cfg); - // Set up event listeners for again logging after configuring. - toConsole(log, flags); + // Remove the previous listeners since we have appropriate config now + cleanupListeners(); + + var translate = buildTranslations(cfg); + + // Set up event listeners for logging again after configuring. + toConsole(log, flags, translate); cli.execute(env, cfg.nodeFlags, function (env) { - onExecute(env, cfg, flags); + onExecute(env, flags, translate); }); } // The actual logic -function onExecute(env, cfg, flags) { +function onExecute(env, flags, translate) { // This translates the --continue flag in gulp // To the settle env variable for undertaker // We use the process.env so the user's gulpfile @@ -152,16 +166,8 @@ function onExecute(env, cfg, flags) { process.env.UNDERTAKER_SETTLE = 'true'; } - // if (optsErr) { - // log.error(msgs.error.failToParseCliOpts, optsErr.message); - // makeHelp(parser).showHelp(console.error); - // exit(1); - // } - // if (env.config.flags.help) { - // makeHelp(parser).showHelp(console.log); - // exit(0); - // } if (flags.help) { + // makeHelp(parser).showHelp(console.log); parser.showHelp(console.log); exit(0); } @@ -219,5 +225,5 @@ function onExecute(env, cfg, flags) { // Load and execute the CLI version var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); - require(versionedDir)(env, cfg, flags); + require(versionedDir)(env, flags, translate); } diff --git a/lib/shared/config/env-config.js b/lib/shared/config/env-config.js deleted file mode 100644 index 08e71406..00000000 --- a/lib/shared/config/env-config.js +++ /dev/null @@ -1,179 +0,0 @@ -'use strict'; - -var path = require('path'); -var chalk = require('chalk'); -var copyProps = require('copy-props'); - -var mergeCliOpts = require('./cli-flags'); -var messages = require("../../../messages"); - -var toEnvFromConfig = { - configPath: 'flags.gulpfile', - configBase: 'flags.gulpfile', - preload: 'flags.preload', - nodeFlags: 'flags.nodeFlags', -}; - -function overrideEnvConfig(env, config, cliOpts) { - cliOpts = mergeCliOpts(cliOpts, config); - - // This must reverse because `flags.gulpfile` determines 2 different properties - var reverse = true; - env = copyProps(env, config, toEnvFromConfig, convert, reverse); - - env.config = { - flags: cliOpts, - }; - env.config.flags.getMessage = function(msg, data) { - if (msg === messages.PRELOAD_BEFORE) { - return 'Preloading external module: ' + chalk.magenta(data); - } - - if (msg === messages.PRELOAD_SUCCESS) { - return 'Preloaded external module: ' + chalk.magenta(data) - } - - if (msg === messages.PRELOAD_FAILURE) { - return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data); - } - - if (msg === messages.PRELOAD_ERROR) { - return chalk.yellow(data.toString()); - } - - if (msg === messages.LOADER_SUCCESS) { - return 'Loaded external module: ' + chalk.magenta(data); - } - - if (msg === messages.LOADER_FAILURE) { - return chalk.yellow('Failed to load external module: ') + chalk.magenta(data); - } - - if (msg === messages.LOADER_ERROR) { - return chalk.yellow(data.toString()); - } - - if (msg === messages.NODE_FLAGS) { - var nodeFlags = chalk.magenta(data.join(', ')); - return 'Node flags detected: ' + nodeFlags; - } - - if (msg === messages.RESPAWNED) { - var pid = chalk.magenta(data); - return 'Respawned to PID: ' + pid; - } - - if (msg === messages.GULPFILE_NOT_FOUND) { - return chalk.red('No gulpfile found'); - } - - if (msg === messages.CWD_CHANGED) { - return 'Working directory changed to ' + chalk.magenta(data); - } - - if (msg === messages.UNSUPPORTED_GULP_VERSION) { - return chalk.red('Unsupported gulp version', data) - } - - if (msg === messages.DESCRIPTION) { - return 'Tasks for ' + chalk.magenta(data); - } - - if (msg === messages.GULPFILE) { - return 'Using gulpfile ' + chalk.magenta(data); - } - - if (msg === messages.TASK_START) { - return "Starting '" + chalk.cyan(data.task) + "'..." - } - - if (msg === messages.TASK_STOP) { - return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(data.duration); - } - - if (msg === messages.TASK_ERROR) { - return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' +chalk.magenta(data.duration); - } - - if (msg === messages.TASK_MISSING) { - return chalk.red('Task \'' + data.task + '\' is not in your gulpfile') + '\nPlease check the documentation for proper gulpfile formatting'; - } - - if (msg === messages.SYNC_TASK) { - return chalk.red('The following tasks did not complete: ') + chalk.cyan(data) + "\n" + chalk.red('Did you forget to signal async completion?'); - } - - if (msg === messages.MISSING_NODE_MODULES) { - return chalk.red('Local modules not found in') + ' ' + chalk.magenta(data); - } - - if (msg === messages.MISSING_GULP) { - return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(data); - } - - if (msg === messages.YARN_INSTALL) { - return chalk.red('Try running: yarn install'); - } - - if (msg === messages.NPM_INSTALL) { - return chalk.red('Try running: npm install'); - } - - if (msg === messages.YARN_INSTALL_GULP) { - return chalk.red('Try running: yarn add gulp'); - } - - if (msg === messages.NPM_INSTALL_GULP) { - return chalk.red('Try running: npm install gulp'); - } - - if (msg === messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) { - return chalk.white('└'); - } - - if (msg === messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT) { - return chalk.white('├'); - } - - if (msg === messages.BOX_DRAWINGS_LIGHT_HORIZONTAL) { - return chalk.white('─'); - } - - if (msg === messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL) { - return chalk.white('┬'); - } - - if (msg === messages.BOX_DRAWINGS_LIGHT_VERTICAL) { - return chalk.white('│'); - } - }; - - return env - - function convert(configInfo, envInfo) { - if (envInfo.keyChain === 'configBase') { - if (cliOpts.gulpfile === undefined) { - return path.dirname(configInfo.value); - } - return; - } - - if (envInfo.keyChain === 'configPath') { - if (cliOpts.gulpfile === undefined) { - return configInfo.value; - } - return; - } - - if (envInfo.keyChain === 'preload') { - return [].concat(envInfo.value, configInfo.value); - } - - /* istanbul ignore else */ - if (envInfo.keyChain === 'nodeFlags') { - return [].concat(configInfo.value || []); - } - } -} - -module.exports = overrideEnvConfig; diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 0b81011b..d349c24e 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -5,7 +5,7 @@ var stringWidth = require('string-width'); var isObject = require('../is-object'); var messages = require('../../../messages'); -function logTasks(tree, opts, getTask) { +function logTasks(tree, opts, getTask, translate) { if (opts.sortTasks) { tree.nodes = tree.nodes.sort(compareByLabel); } @@ -61,7 +61,7 @@ function logTasks(tree, opts, getTask) { var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); if (!isLeaf) { - bars += (isLast ? ' ' : opts.getMessage(messages.BOX_DRAWINGS_LIGHT_VERTICAL)); + bars += (isLast ? ' ' : translate.message(messages.BOX_DRAWINGS_LIGHT_VERTICAL)); bars += ' ' node.nodes.forEach(function(node, idx, arr) { var isLast = idx === arr.length - 1; @@ -73,18 +73,19 @@ function logTasks(tree, opts, getTask) { } function addTaskToLines(task, lines, isLast, isLeaf) { - var taskBars = task.bars + (isLast ? opts.getMessage(messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) : opts.getMessage(messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT)) + opts.getMessage(messages.BOX_DRAWINGS_LIGHT_HORIZONTAL); + var taskBars = task.bars + (isLast ? translate.message(messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) : translate.message(messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT)) + translate.message(messages.BOX_DRAWINGS_LIGHT_HORIZONTAL); if (isLeaf) { - taskBars += opts.getMessage(messages.BOX_DRAWINGS_LIGHT_HORIZONTAL); + taskBars += translate.message(messages.BOX_DRAWINGS_LIGHT_HORIZONTAL); } else { - taskBars += opts.getMessage(messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL); + taskBars += translate.message(messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL); } + taskBars += ' '; var line = {}; if (task.depth === 1) { - line.label = taskBars + ' ' + task.label + line.label = taskBars + task.label } else { - line.label = taskBars + ' ' + task.label; + line.label = taskBars + task.label; } line.width = stringWidth(line.label); @@ -103,21 +104,23 @@ function logTasks(tree, opts, getTask) { if (isLast) { flagBars += ' '; } else { - flagBars += opts.getMessage(messages.BOX_DRAWINGS_LIGHT_VERTICAL); + flagBars += translate.message(messages.BOX_DRAWINGS_LIGHT_VERTICAL); } + flagBars += ' '; if (isLeaf) { flagBars += ' '; } else { - flagBars += opts.getMessage(messages.BOX_DRAWINGS_LIGHT_VERTICAL); + flagBars += translate.message(messages.BOX_DRAWINGS_LIGHT_VERTICAL); } + flagBars += ' '; Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); function addFlagsToLines(ent) { if (typeof ent[0] !== 'string' || !ent[0]) return; var line = {}; - line.label = flagBars + ' ' + ent[0]; + line.label = flagBars + ent[0]; line.width = stringWidth(line.label); maxLabelWidth = Math.max(maxLabelWidth, line.width); diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 5067a71d..2efb48b3 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -1,17 +1,17 @@ 'use strict'; -var fancyLog = require('fancy-log'); - /* istanbul ignore next */ function noop() {} -function toConsole(log, opts) { +function toConsole(log, opts, translate) { // Return immediately if logging is // not desired. if (opts.tasksSimple || opts.tasksJson || opts.help || opts.version || opts.silent) { // Keep from crashing process when silent. log.on('error', noop); - return; + return function () { + log.removeListener('error', noop); + }; } // Default loglevel to info level (3). @@ -19,73 +19,74 @@ function toConsole(log, opts) { // -L: Logs error events. if (loglevel > 0) { - log.on('error', function (sym, data) { - var msg = opts.getMessage.call(null, sym, data); - // Users can filter messages by explicitly returning `false` - if (msg === false) { - return; - } - // If nothing is returned, we log the original message directly - if (typeof msg === 'undefined') { - fancyLog.error(arguments[0]); - return; - } - - fancyLog.error(msg); - }); + log.on('error', onError); } // -LL: Logs warn and error events. if (loglevel > 1) { - log.on('warn', function(sym, data) { - var msg = opts.getMessage.call(null, sym, data); - // Users can filter messages by explicitly returning `false` - if (msg === false) { - return; - } - // If nothing is returned, we log the original message directly - if (typeof msg === 'undefined') { - fancyLog.apply(null, arguments); - return; - } - - fancyLog(msg) - }); + log.on('warn', onWarn); } // -LLL: Logs info, warn and error events. if (loglevel > 2) { - log.on('info', function(sym, data) { - var msg = opts.getMessage.call(null, sym, data); - // Users can filter messages by explicitly returning `false` - if (msg === false) { - return; - } - // If nothing is returned, we log the original message directly - if (typeof msg === 'undefined') { - fancyLog.apply(null, arguments) - return; - } - - fancyLog(msg) - }) + log.on('info', onInfo); } if (loglevel > 3) { - log.on('debug', function(sym, data) { - var msg = opts.getMessage.call(null, sym, data); - // Users can filter messages by explicitly returning `false` - if (msg === false) { - return; - } - // If nothing is returned, we log the original message directly - if (typeof msg === 'undefined') { - fancyLog.apply(null, arguments) - return; - } + log.on('debug', onDebug); + } + + return function () { + log.removeListener('error', onError); + log.removeListener('warn', onWarn); + log.removeListener('info', onInfo); + log.removeListener('debug', onDebug); + }; + + function onError(msg, data) { + var timestamp = translate.timestamp(); + if (timestamp) { + process.stderr.write(timestamp + ' '); + } + var message = translate.message(msg, data); + if (message) { + console.error(message); + } + } + + // onWarn, onInfo, and onDebug are currently all the same + // implementation but separated to change independently + function onWarn(msg, data) { + var timestamp = translate.timestamp(); + if (timestamp) { + process.stdout.write(timestamp + ' '); + } + var message = translate.message(msg, data); + if (message) { + console.log(message); + } + } + + function onInfo(msg, data) { + var timestamp = translate.timestamp(); + if (timestamp) { + process.stdout.write(timestamp + ' '); + } + var message = translate.message(msg, data); + if (message) { + console.log(message); + } + } - fancyLog(msg) - }) + function onDebug(msg, data) { + var timestamp = translate.timestamp(); + if (timestamp) { + process.stdout.write(timestamp + ' '); + } + var message = translate.message(msg, data); + if (message) { + console.log(message); + } } } diff --git a/lib/shared/translate.js b/lib/shared/translate.js new file mode 100644 index 00000000..3cb95c95 --- /dev/null +++ b/lib/shared/translate.js @@ -0,0 +1,195 @@ +'use strict'; + +var util = require('util'); + +var chalk = require('chalk'); + +// TODO: `@gulpjs/messages` package +var messages = require('../../messages'); + +function Timestamp() { + this.now = new Date(); +} + +Timestamp.prototype[util.inspect.custom] = function (depth, opts) { + var timestamp = this.now.toLocaleTimeString('en', { hour12: false }); + return '[' + opts.stylize(timestamp, 'date') + ']'; +}; + +function getDefaultMessage(msg, data) { + if (msg === messages.PRELOAD_BEFORE) { + return 'Preloading external module: ' + chalk.magenta(data); + } + + if (msg === messages.PRELOAD_SUCCESS) { + return 'Preloaded external module: ' + chalk.magenta(data) + } + + if (msg === messages.PRELOAD_FAILURE) { + return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data); + } + + if (msg === messages.PRELOAD_ERROR) { + return chalk.yellow(data.toString()); + } + + if (msg === messages.LOADER_SUCCESS) { + return 'Loaded external module: ' + chalk.magenta(data); + } + + if (msg === messages.LOADER_FAILURE) { + return chalk.yellow('Failed to load external module: ') + chalk.magenta(data); + } + + if (msg === messages.LOADER_ERROR) { + return chalk.yellow(data.toString()); + } + + if (msg === messages.NODE_FLAGS) { + var nodeFlags = chalk.magenta(data.join(', ')); + return 'Node flags detected: ' + nodeFlags; + } + + if (msg === messages.RESPAWNED) { + var pid = chalk.magenta(data); + return 'Respawned to PID: ' + pid; + } + + if (msg === messages.GULPFILE_NOT_FOUND) { + return chalk.red('No gulpfile found'); + } + + if (msg === messages.CWD_CHANGED) { + return 'Working directory changed to ' + chalk.magenta(data); + } + + if (msg === messages.UNSUPPORTED_GULP_VERSION) { + return chalk.red('Unsupported gulp version', data) + } + + if (msg === messages.DESCRIPTION) { + return 'Tasks for ' + chalk.magenta(data); + } + + if (msg === messages.GULPFILE) { + return 'Using gulpfile ' + chalk.magenta(data); + } + + if (msg === messages.TASK_START) { + return "Starting '" + chalk.cyan(data.task) + "'..." + } + + if (msg === messages.TASK_STOP) { + return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(data.duration); + } + + if (msg === messages.TASK_ERROR) { + return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' +chalk.magenta(data.duration); + } + + if (msg === messages.TASK_MISSING) { + return chalk.red('Task \'' + data.task + '\' is not in your gulpfile') + '\nPlease check the documentation for proper gulpfile formatting'; + } + + if (msg === messages.SYNC_TASK) { + return chalk.red('The following tasks did not complete: ') + chalk.cyan(data) + "\n" + chalk.red('Did you forget to signal async completion?'); + } + + if (msg === messages.MISSING_NODE_MODULES) { + return chalk.red('Local modules not found in') + ' ' + chalk.magenta(data); + } + + if (msg === messages.MISSING_GULP) { + return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(data); + } + + if (msg === messages.YARN_INSTALL) { + return chalk.red('Try running: yarn install'); + } + + if (msg === messages.NPM_INSTALL) { + return chalk.red('Try running: npm install'); + } + + if (msg === messages.YARN_INSTALL_GULP) { + return chalk.red('Try running: yarn add gulp'); + } + + if (msg === messages.NPM_INSTALL_GULP) { + return chalk.red('Try running: npm install gulp'); + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) { + return chalk.white('└'); + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT) { + return chalk.white('├'); + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_HORIZONTAL) { + return chalk.white('─'); + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL) { + return chalk.white('┬'); + } + + if (msg === messages.BOX_DRAWINGS_LIGHT_VERTICAL) { + return chalk.white('│'); + } + + return msg; +} + +function getDefaultTimestamp() { + return util.inspect(new Timestamp(), { colors: !!chalk.supportsColor }); +} + +function buildTranslations(cfg) { + cfg = cfg || {}; + + return { + message: function (msg, data) { + var message; + if (typeof cfg.message === 'function') { + message = cfg.message(msg, data); + } + + // If the user has provided a message, return it + if (message) { + return message; + } + + // Users can filter messages by explicitly returning `false` + if (message === false) { + return false; + } + + // If the user hasn't returned a message or silenced it with `false` + // get the default message. Will return the first argument if the message + // is not defined in the `@gulpjs/messages` package + return getDefaultMessage(msg, data); + }, + timestamp: function () { + var time; + if (typeof cfg.timestamp === 'function') { + time = cfg.timestamp(); + } + + // If the user has provided a timestamp, return it + if (time) { + return time; + } + + // Users can filter timestamps by explicitly returning `false` + if (time === false) { + return false; + } + + return getDefaultTimestamp(); + } + } +} + +module.exports = buildTranslations; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 4c496af5..673f2939 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -17,7 +17,7 @@ var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); var messages = require('../../../messages'); -function execute(env, cfg, opts) { +function execute(env, opts, translate) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -51,14 +51,14 @@ function execute(env, cfg, opts) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - tree.label = env.config.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); + tree.label = translate.message(messages.DESCRIPTION, tildify(env.configPath)); return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; - }); + }, translate); } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - tree.label = env.config.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); + tree.label = translate.message(messages.DESCRIPTION, tildify(env.configPath)); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index 35c4a6c4..bf78ccd3 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -20,7 +20,7 @@ var getTask = require('./log/get-task'); var requireOrImport = require('../../shared/require-or-import'); var messages = require('../../../messages'); -function execute(env, cfg, opts) { +function execute(env, opts, translate) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -54,12 +54,13 @@ function execute(env, cfg, opts) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - tree.label = env.config.flags.getMessage(messages.DESCRIPTION, tildify(env.configPath)); - return logTasks(tree, opts, getTask(gulpInst)); + tree.label = translate.message(messages.DESCRIPTION, tildify(env.configPath)); + + return logTasks(tree, opts, getTask(gulpInst), translate); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - tree.label = env.config.flags.getMessage(messages.DESCRIPTION,tildify(env.configPath) ) + tree.label = translate.message(messages.DESCRIPTION,tildify(env.configPath) ) var output = JSON.stringify(copyTree(tree, opts)); diff --git a/package.json b/package.json index 05cfce2b..168ba16e 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "dependencies": { "chalk": "^4.1.2", "copy-props": "^4.0.0", - "fancy-log": "^2.0.0", "gulplog": "^2.1.0", "interpret": "^3.1.1", "liftoff": "^5.0.0", diff --git a/test/config-theme-and-msgs.js b/test/config-theme-and-msgs.js index 4bb1a851..01f13e29 100644 --- a/test/config-theme-and-msgs.js +++ b/test/config-theme-and-msgs.js @@ -84,14 +84,14 @@ describe('config: theme.* & msgs.*', function() { var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); var expected = 'Tasks for ' + gulpfile + '\n' + '├─┬ **default** This is default task\n' + - '│ │ --ghi …is a flag for default task\n' + + '│ │ --ghi is a flag for default task\n' + '│ └─┬ \n' + '│ ├── taskA\n' + '│ └── taskB\n' + '├── **taskA** This is task A\n' + - '│ --abc …is a flag for task A\n' + + '│ --abc is a flag for task A\n' + '└── **taskB** This is task B\n' + - ' --def …is a flag for task B\n'; + ' --def is a flag for task B\n'; var opts = { cwd: cwd }; exec(gulp('--tasks'), opts, cb); @@ -134,14 +134,14 @@ describe('config: theme.* & msgs.*', function() { var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); var expected = 'Tasks for ' + gulpfile + '\n' + '├─┬ default This is default task\n' + - '│ │ --ghi …is a flag for default task\n' + + '│ │ --ghi is a flag for default task\n' + '│ └─┬ ****\n' + '│ ├── **taskA**\n' + '│ └── **taskB**\n' + '├── taskA This is task A\n' + - '│ --abc …is a flag for task A\n' + + '│ --abc is a flag for task A\n' + '└── taskB This is task B\n' + - ' --def …is a flag for task B\n'; + ' --def is a flag for task B\n'; var opts = { cwd: cwd }; exec(gulp('--tasks'), opts, cb); diff --git a/test/expected/by-unwrap-and-not-by-unwrap.txt b/test/expected/by-unwrap-and-not-by-unwrap.txt index 22de5a7f..fe35039d 100644 --- a/test/expected/by-unwrap-and-not-by-unwrap.txt +++ b/test/expected/by-unwrap-and-not-by-unwrap.txt @@ -7,9 +7,9 @@ gulp-cli/test/fixtures │ └── task3 ├── no-desc ├── task1 Description for gulp.task("task1") -│ --flag-of-task1 …Description for flag of task1 +│ --flag-of-task1 Description for flag of task1 ├── task2 Description for gulp.task("task2").unwrap() -│ --flag-of-task2 …Description for flag of task2 +│ --flag-of-task2 Description for flag of task2 └── task3 Use gulp.task("task3").description preferentially - --flag0-of-task3 …Description for flag0 of task3 - --flag1-of-task3 …Use gulp.task("task3").flags preferentially + --flag0-of-task3 Description for flag0 of task3 + --flag1-of-task3 Use gulp.task("task3").flags preferentially diff --git a/test/expected/with-desc-and-flags.txt b/test/expected/with-desc-and-flags.txt index 34e85d2c..eb2f80dc 100644 --- a/test/expected/with-desc-and-flags.txt +++ b/test/expected/with-desc-and-flags.txt @@ -1,7 +1,7 @@ gulp-cli/test/fixtures ├─┬ build Build all the things! │ │ --dev -│ │ --production …compressed into single bundle +│ │ --production compressed into single bundle │ └─┬ │ ├── clean │ ├── scripts @@ -17,6 +17,6 @@ gulp-cli/test/fixtures │ └── watch ├── scripts Bundles JavaScript ├── serve Serves files reloading -│ --lr …with live reloading +│ --lr with live reloading ├── styles Compiles and bundles CSS └── watch Watch files and build on change diff --git a/test/fixtures/.gulp.js b/test/fixtures/.gulp.js new file mode 100644 index 00000000..4d69736e --- /dev/null +++ b/test/fixtures/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('../../messages'); + +module.exports = { + message: function (msg) { + if (msg === messages.DESCRIPTION) { + return "gulp-cli/test/fixtures"; + } + } +} diff --git a/test/fixtures/.gulp.json b/test/fixtures/.gulp.json deleted file mode 100644 index c0c87edd..00000000 --- a/test/fixtures/.gulp.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "log": { - "msgs": { - "tasks": { - "description" : "gulp-cli/test/fixtures" - } - } - } -} diff --git a/test/fixtures/gulpfiles/.gulp.js b/test/fixtures/gulpfiles/.gulp.js new file mode 100644 index 00000000..1f088daa --- /dev/null +++ b/test/fixtures/gulpfiles/.gulp.js @@ -0,0 +1,9 @@ +var messages = require('../../../messages'); + +module.exports = { + message: function (msg) { + if (msg === messages.DESCRIPTION) { + return "gulp-cli/test/fixtures/gulpfiles"; + } + } +} diff --git a/test/fixtures/gulpfiles/.gulp.json b/test/fixtures/gulpfiles/.gulp.json deleted file mode 100644 index 0eae6480..00000000 --- a/test/fixtures/gulpfiles/.gulp.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "log": { - "msgs": { - "tasks": { - "description" : "gulp-cli/test/fixtures/gulpfiles" - }, - "tasksJson": { - "description" : "gulp-cli/test/fixtures/gulpfiles" - } - } - } -} diff --git a/test/fixtures/logging.js b/test/fixtures/logging.js index 6f5c5566..7b28ae8a 100644 --- a/test/fixtures/logging.js +++ b/test/fixtures/logging.js @@ -2,10 +2,13 @@ var log = require('gulplog'); var yargs = require('yargs'); var toConsole = require('../../lib/shared/log/to-console'); var cliOptions = require('../../lib/shared/options/cli-options'); +var buildTranslations = require('../../lib/shared/translate'); var opts = yargs.options(cliOptions).parse(); -toConsole(log, opts); +var translate = buildTranslations(); + +toConsole(log, opts, translate); log.debug('test debug'); log.info('test info'); From c1a877506886a153249b61b4477f4620eb3af1f2 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 11:57:37 -0700 Subject: [PATCH 18/25] remove file re-added in merge --- lib/shared/config/merge-configs.js | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 lib/shared/config/merge-configs.js diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js deleted file mode 100644 index e3c17a81..00000000 --- a/lib/shared/config/merge-configs.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -var copyProps = require('copy-props'); -var path = require('path'); - -function mergeConfigs(env) { - var cfg = {}; - /* istanbul ignore if */ - if (env.configFiles.userHome) { - copyConfig(env.config.userHome, cfg, env.configFiles.userHome); - } - if (env.configFiles.project) { - copyConfig(env.config.project, cfg, env.configFiles.project); - } - return cfg; -} - -function copyConfig(src, dest, filePath) { - return copyProps(src, dest, convert); - - function convert(loadedInfo) { - if (loadedInfo.keyChain === 'flags.gulpfile') { - return path.resolve(path.dirname(filePath), loadedInfo.value); - } - return loadedInfo.value; - } -} - -module.exports = mergeConfigs; From e51382d008ceee637f8c0e374c647247e702514c Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 11:58:39 -0700 Subject: [PATCH 19/25] remove timestamp logic in favor of util.inspect --- lib/shared/log/timestamp.js | 55 ----------------------------------- test/lib/timestamp.js | 57 ------------------------------------- 2 files changed, 112 deletions(-) delete mode 100644 lib/shared/log/timestamp.js delete mode 100644 test/lib/timestamp.js diff --git a/lib/shared/log/timestamp.js b/lib/shared/log/timestamp.js deleted file mode 100644 index 4e9dd9a6..00000000 --- a/lib/shared/log/timestamp.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -function timestamp(format) { - /* istanbul ignore if */ - if (typeof format !== 'string') { - return noop; - } - - var date = new Date(); - - var result = ''; - var arr = format.split(/(YYYY|MM|DD|HH|mm|ss|SSS)/); - for (var i = 0; i < arr.length; i++) { - var el = arr[i]; - switch (el) { - case 'YYYY': - result += align(date.getFullYear(), 4); - break; - case 'MM': - result += align(date.getMonth() + 1, 2); - break; - case 'DD': - result += align(date.getDate(), 2); - break; - case 'HH': - result += align(date.getHours(), 2); - break; - case 'mm': - result += align(date.getMinutes(), 2); - break; - case 'ss': - result += align(date.getSeconds(), 2); - break; - case 'SSS': - result += align(date.getMilliseconds(), 3); - break; - default: - result += el; - break; - } - } - - return result; -} - -/* istanbul ignore next */ -function noop() { - return ""; -} - -function align(v, n) { - return String(v).padStart(n, '0').slice(-n); -} - -module.exports = timestamp; diff --git a/test/lib/timestamp.js b/test/lib/timestamp.js deleted file mode 100644 index ae827ecd..00000000 --- a/test/lib/timestamp.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var timestamp = require('../../lib/shared/log/timestamp'); - -describe('lib: timestamp', function() { - - it('should output each element', function(done) { - var before = new Date(); - - var year = timestamp('YYYY'); - var month = timestamp('MM'); - var date = timestamp('DD'); - var hours = timestamp('HH'); - var minutes = timestamp('mm'); - var seconds = timestamp('ss'); - var millis = timestamp('SSS'); - - var after = new Date(); - - expect(year).toHaveLength(4); - expect(Number(year)).toBeGreaterThanOrEqual(before.getFullYear()); - expect(Number(year)).toBeLessThanOrEqual(after.getFullYear()); - - expect(month).toHaveLength(2); - expect(Number(month)).toBeGreaterThanOrEqual(before.getMonth() + 1); - expect(Number(month)).toBeLessThanOrEqual(after.getMonth() + 1); - - expect(date).toHaveLength(2); - expect(Number(date)).toBeGreaterThanOrEqual(before.getDate()); - expect(Number(date)).toBeLessThanOrEqual(after.getDate()); - - expect(hours).toHaveLength(2); - expect(Number(hours)).toBeGreaterThanOrEqual(before.getHours()); - expect(Number(hours)).toBeLessThanOrEqual(after.getHours()); - - expect(minutes).toHaveLength(2); - expect(Number(minutes)).toBeGreaterThanOrEqual(before.getMinutes()); - expect(Number(minutes)).toBeLessThanOrEqual(after.getMinutes()); - - expect(seconds).toHaveLength(2); - expect(Number(seconds)).toBeGreaterThanOrEqual(before.getSeconds()); - expect(Number(seconds)).toBeLessThanOrEqual(after.getSeconds()); - - expect(millis).toHaveLength(3); - expect(Number(millis)).toBeGreaterThanOrEqual(before.getMilliseconds()); - expect(Number(millis)).toBeLessThanOrEqual(after.getMilliseconds()); - - done(); - }); - - it('should output in specified format', function(done) { - expect(timestamp('YYYY/MM/DD HH:mm:ss')).toMatch(/^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}$/); - expect(timestamp('YYYY-MM-DDTHH:mm:ss.SSSZ')).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/); - done(); - }); -}); From 2e6b0c52d8b9bcd5947ee85d34efc3cfa4ffd97e Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 14:40:32 -0700 Subject: [PATCH 20/25] original tests passing --- index.js | 47 +++---- lib/shared/completion.js | 8 +- lib/shared/options/cli-options.js | 19 +++ lib/shared/options/make-help.js | 20 ++- lib/shared/translate.js | 119 +++++++++++++++++- lib/versioned/^4.0.0/index.js | 4 +- .../^4.0.0/log/check-task-not-found.js | 8 +- messages.js | 31 +++++ test/config-theme-and-msgs.js | 2 +- test/lib/check-task-not-found.js | 2 +- 10 files changed, 222 insertions(+), 38 deletions(-) diff --git a/index.js b/index.js index 3689b7f9..52c7dfc6 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,6 @@ process.env.INIT_CWD = process.cwd(); var cli = new Liftoff({ name: 'gulp', processTitle: makeTitle('gulp', process.argv.slice(2)), - completions: completion, extensions: interpret.jsVariants, v8flags: v8flags, configFiles: [ @@ -52,30 +51,13 @@ var cli = new Liftoff({ ], }); -// var opts = {}; -// var optsErr; -// try { -// opts = parser.argv; -// } catch (e) { -// optsErr = e; -// } -// var usage = -// '\n' + chalk.bold('Usage:') + -// ' gulp ' + chalk.blue('[options]') + ' tasks'; - var parser = yargs .help(false) .version(false) .detectLocale(false) .showHelpOnFail(false) .exitProcess(false) - .fail(function(msg) { - cli.prepare({}, function (env) { - log.error(messages.ARGV_ERROR, msg); - // makeHelp(parser).showHelp(console.error); - exit(1); - }); - }) + .fail(onFail) .options(cliOptions); var opts = parser.parse(); @@ -127,7 +109,6 @@ function run() { cwd: opts.cwd, configPath: opts.gulpfile, preload: opts.preload, - completion: opts.completion, }, onPrepare); } @@ -137,6 +118,24 @@ function isDefined(cfg) { return cfg != null; } +function onFail(message, error) { + // Run Liftoff#prepare to get the env. Primarily to load themes. + cli.prepare({}, function (env) { + // We only use the first config found, which is a departure from + // the previous implementation that merged with the home + var cfg = arrayFind(env.config, isDefined); + var translate = buildTranslations(cfg); + + var errorMsg = translate.message(messages.ARGV_ERROR, { message: message, error: error }); + if (errorMsg) { + console.error(errorMsg); + } + + makeHelp(parser, translate).showHelp(console.error); + exit(1); + }); +} + function onPrepare(env) { // We only use the first config found, which is a departure from // the previous implementation that merged with the home @@ -158,6 +157,11 @@ function onPrepare(env) { // The actual logic function onExecute(env, flags, translate) { + // Moved the completion logic outside of Liftoff since we need to include translations + if (flags.completion) { + return completion(flags.completion, translate); + } + // This translates the --continue flag in gulp // To the settle env variable for undertaker // We use the process.env so the user's gulpfile @@ -167,8 +171,7 @@ function onExecute(env, flags, translate) { } if (flags.help) { - // makeHelp(parser).showHelp(console.log); - parser.showHelp(console.log); + makeHelp(parser, translate).showHelp(console.log); exit(0); } diff --git a/lib/shared/completion.js b/lib/shared/completion.js index 329f0926..347bd0ae 100644 --- a/lib/shared/completion.js +++ b/lib/shared/completion.js @@ -3,16 +3,18 @@ var fs = require('fs'); var path = require('path'); -module.exports = function(name) { +var messages = require('../../messages'); + +module.exports = function(name, translate) { if (typeof name !== 'string') { - // throw new Error(format(theme, msgs.error.noCompletionType)); + throw new Error(translate.message(messages.COMPLETION_TYPE_MISSING)); } var file = path.join(__dirname, '../../completion', name); try { console.log(fs.readFileSync(file, 'utf8')); process.exit(0); } catch (err) { - // console.log(format(theme, msgs.error.unknownCompletionType, name)); + console.log(translate.message(messages.COMPLETION_TYPE_UNKNOWN, { name: name })); process.exit(5); } }; diff --git a/lib/shared/options/cli-options.js b/lib/shared/options/cli-options.js index 3df1cf98..9babd247 100644 --- a/lib/shared/options/cli-options.js +++ b/lib/shared/options/cli-options.js @@ -1,74 +1,93 @@ 'use strict'; +var messages = require("../../../messages"); + var options = { help: { alias: 'h', type: 'boolean', + message: messages.FLAG_HELP, }, version: { alias: 'v', type: 'boolean', + message: messages.FLAG_VERSION, }, preload: { type: 'string', requiresArg: true, + message: messages.FLAG_PRELOAD, }, gulpfile: { alias: 'f', type: 'string', requiresArg: true, + message: messages.FLAG_GULPFILE, }, cwd: { type: 'string', requiresArg: true, + message: messages.FLAG_CWD, }, tasks: { alias: 'T', type: 'boolean', + message: messages.FLAG_TASKS, }, 'tasks-simple': { type: 'boolean', + message: messages.FLAG_TASKS_SIMPLE, }, 'tasks-json': { + message: messages.FLAG_TASKS_JSON, }, 'tasks-depth': { alias: 'depth', type: 'number', requiresArg: true, default: undefined, // To detect if this cli option is specified. + message: messages.FLAG_TASKS_DEPTH, }, 'compact-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. + message: messages.FLAG_COMPACT_TASKS, }, 'sort-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. + message: messages.FLAG_SORT_TASKS, }, color: { type: 'boolean', + message: messages.FLAG_COLOR, }, 'no-color': { type: 'boolean', + message: messages.FLAG_NO_COLOR, }, silent: { alias: 'S', type: 'boolean', default: undefined, // To detect if this cli option is specified. + message: messages.FLAG_SILENT, }, continue: { type: 'boolean', default: undefined, // To detect if this cli option is specified. + message: messages.FLAG_CONTINUE, }, series: { type: 'boolean', default: undefined, // To detect if this cli option is specified. + message: messages.FLAG_SERIES, }, 'log-level': { alias: 'L', // Type isn't needed because count acts as a boolean count: true, default: undefined, // To detect if this cli option is specified. + message: messages.FLAG_LOG_LEVEL, } }; diff --git a/lib/shared/options/make-help.js b/lib/shared/options/make-help.js index ec770dcd..75042b45 100644 --- a/lib/shared/options/make-help.js +++ b/lib/shared/options/make-help.js @@ -1,12 +1,22 @@ 'use strict'; +var cliOptions = require('./cli-options'); -function makeHelp(parser) { - // parser.usage(format(theme, msgs.help.usage)); +var messages = require("../../../messages"); - // Object.keys(msgs.help.flags).forEach(function(flag) { - // parser.describe(flag, format(theme, msgs.help.flags[flag])); - // }); +function makeHelp(parser, translate) { + var usage = translate.message(messages.USAGE); + if (usage) { + parser.usage(usage); + } + + Object.keys(cliOptions).forEach(function (flag) { + var opt = cliOptions[flag]; + var description = translate.message(opt.message); + if (description) { + parser.describe(flag, description); + } + }); return parser; } diff --git a/lib/shared/translate.js b/lib/shared/translate.js index 3cb95c95..d5885496 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -88,7 +88,11 @@ function getDefaultMessage(msg, data) { } if (msg === messages.TASK_MISSING) { - return chalk.red('Task \'' + data.task + '\' is not in your gulpfile') + '\nPlease check the documentation for proper gulpfile formatting'; + if (data.similar) { + return chalk.red('Task never defined: ' + data.task + ' - did you mean? ' + data.similar.join(', ')) + '\nTo list available tasks, try running: gulp --tasks'; + } else { + return chalk.red('Task never defined: ' + data.task) + '\nTo list available tasks, try running: gulp --tasks'; + } } if (msg === messages.SYNC_TASK) { @@ -119,6 +123,117 @@ function getDefaultMessage(msg, data) { return chalk.red('Try running: npm install gulp'); } + if (msg === messages.COMPLETION_TYPE_MISSING) { + return 'Missing completion type'; + } + + if (msg === messages.COMPLETION_TYPE_UNKNOWN) { + return 'echo "gulp autocompletion rules for' + " '" + data.name + "' " + 'not found"' + } + + if (msg === messages.ARGV_ERROR) { + return data.message; + } + + if (msg === messages.EXEC_ERROR) { + return data.message; + } + + if (msg === messages.USAGE) { + return '\n' + chalk.bold('Usage:') + ' gulp ' + chalk.blue('[options]') + ' tasks'; + } + + if (msg === messages.FLAG_HELP) { + return chalk.gray('Show this help.'); + } + + if (msg === messages.FLAG_VERSION) { + return chalk.gray('Print the global and local gulp versions.'); + } + + if (msg === messages.FLAG_PRELOAD) { + return chalk.gray( + 'Will preload a module before running the gulpfile. ' + + 'This is useful for transpilers but also has other applications.' + ); + } + if (msg === messages.FLAG_GULPFILE) { + return chalk.gray( + 'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' + + 'This will set the CWD to the gulpfile directory as well.' + ) + } + + if (msg === messages.FLAG_CWD) { + return chalk.gray( + 'Manually set the CWD. The search for the gulpfile, ' + + 'as well as the relativity of all requires will be from here.' + ); + } + + if (msg === messages.FLAG_TASKS) { + return chalk.gray('Print the task dependency tree for the loaded gulpfile.'); + } + + if (msg === messages.FLAG_TASKS_SIMPLE) { + return chalk.gray('Print a plaintext list of tasks for the loaded gulpfile.'); + } + + if (msg === messages.FLAG_TASKS_JSON) { + return chalk.gray( + 'Print the task dependency tree, ' + + 'in JSON format, for the loaded gulpfile.' + ); + } + + if (msg === messages.FLAG_TASKS_DEPTH) { + return chalk.gray('Specify the depth of the task dependency tree.'); + } + + if (msg === messages.FLAG_COMPACT_TASKS) { + return chalk.gray( + 'Reduce the output of task dependency tree by printing ' + + 'only top tasks and their child tasks.' + ); + } + + if (msg === messages.FLAG_SORT_TASKS) { + return chalk.gray('Will sort top tasks of task dependency tree.'); + } + + if (msg === messages.FLAG_COLOR) { + return chalk.gray( + 'Will force gulp and gulp plugins to display colors, ' + + 'even when no color support is detected.' + ); + } + + if (msg === messages.FLAG_NO_COLOR) { + return chalk.gray( + 'Will force gulp and gulp plugins to not display colors, ' + + 'even when color support is detected.' + ); + } + + if (msg === messages.FLAG_SILENT) { + return chalk.gray('Suppress all gulp logging.'); + } + + if (msg === messages.FLAG_CONTINUE) { + return chalk.gray('Continue execution of tasks upon failure.'); + } + + if (msg === messages.FLAG_SERIES) { + return chalk.gray('Run tasks given on the CLI in series (the default is parallel).'); + } + + if (msg === messages.FLAG_LOG_LEVEL) { + return chalk.gray( + 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' + + '-LLL is default.' + ); + } + if (msg === messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT) { return chalk.white('└'); } @@ -163,7 +278,7 @@ function buildTranslations(cfg) { // Users can filter messages by explicitly returning `false` if (message === false) { - return false; + return ''; } // If the user hasn't returned a message or silenced it with `false` diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index bf78ccd3..31670c73 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -80,9 +80,9 @@ function execute(env, opts, translate) { } catch (err) { var task = checkTaskNotFound(err); if (task) { - // log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); + log.error(messages.TASK_MISSING, { task: task.target, similar: task.similar }); } else { - // log.error(msgs.error.failToRun, err.message); + log.error(messages.EXEC_ERROR, { message: err.message, error: err }); } exit(1); } diff --git a/lib/versioned/^4.0.0/log/check-task-not-found.js b/lib/versioned/^4.0.0/log/check-task-not-found.js index e996f212..84d1a050 100644 --- a/lib/versioned/^4.0.0/log/check-task-not-found.js +++ b/lib/versioned/^4.0.0/log/check-task-not-found.js @@ -14,11 +14,15 @@ function checkTaskNotFound(err) { var index = target.indexOf(fixed1); if (index >= 0) { - similar = target.slice(index + fixed1.length); + similar = target.slice(index + fixed1.length).split(', '); target = target.slice(0, index); } - return { target: target, similar: similar }; + if (similar && similar.length) { + return { target: target, similar: similar }; + } else { + return { target: target }; + } } } diff --git a/messages.js b/messages.js index 63b5197b..13e4c269 100644 --- a/messages.js +++ b/messages.js @@ -31,6 +31,37 @@ module.exports = { YARN_INSTALL_GULP: Symbol.for("GULP_CLI_YARN_INSTALL_GULP"), NPM_INSTALL_GULP: Symbol.for("GULP_CLI_NPM_INSTALL_GULP"), + COMPLETION_TYPE_MISSING: Symbol.for("GULP_CLI_COMPLETION_TYPE_MISSING"), + COMPLETION_TYPE_UNKNOWN: Symbol.for("GULP_CLI_COMPLETION_TYPE_UNKNOWN"), + + /** + * Errors + */ + ARGV_ERROR: Symbol.for("GULP_CLI_ARGV_ERROR"), + EXEC_ERROR: Symbol.for("GULP_CLI_EXEC_ERROR"), + + /** + * Messages used in the `--help` message + */ + USAGE: Symbol.for("GULP_CLI_USAGE"), + FLAG_HELP: Symbol.for("GULP_CLI_FLAG_HELP"), + FLAG_VERSION: Symbol.for("GULP_CLI_FLAG_VERSION"), + FLAG_PRELOAD: Symbol.for("GULP_CLI_FLAG_PRELOAD"), + FLAG_GULPFILE: Symbol.for("GULP_CLI_FLAG_GULPFILE"), + FLAG_CWD: Symbol.for("GULP_CLI_FLAG_CWD"), + FLAG_TASKS: Symbol.for("GULP_CLI_FLAG_TASKS"), + FLAG_TASKS_SIMPLE: Symbol.for("GULP_CLI_FLAG_TASKS_SIMPLE"), + FLAG_TASKS_JSON: Symbol.for("GULP_CLI_FLAG_TASKS_JSON"), + FLAG_TASKS_DEPTH: Symbol.for("GULP_CLI_FLAG_TASKS_DEPTH"), + FLAG_COMPACT_TASKS: Symbol.for("GULP_CLI_FLAG_COMPACT_TASKS"), + FLAG_SORT_TASKS: Symbol.for("GULP_CLI_FLAG_SORT_TASKS"), + FLAG_COLOR: Symbol.for("GULP_CLI_FLAG_COLOR"), + FLAG_NO_COLOR: Symbol.for("GULP_CLI_FLAG_NO_COLOR"), + FLAG_SILENT: Symbol.for("GULP_CLI_FLAG_SILENT"), + FLAG_CONTINUE: Symbol.for("GULP_CLI_FLAG_CONTINUE"), + FLAG_SERIES: Symbol.for("GULP_CLI_FLAG_SERIES"), + FLAG_LOG_LEVEL: Symbol.for("GULP_CLI_FLAG_LOG_LEVEL"), + BOX_DRAWINGS_LIGHT_UP_AND_RIGHT: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_UP_AND_RIGHT"), BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT"), BOX_DRAWINGS_LIGHT_HORIZONTAL: Symbol.for("GULP_CLI_BOX_DRAWINGS_LIGHT_HORIZONTAL"), diff --git a/test/config-theme-and-msgs.js b/test/config-theme-and-msgs.js index 01f13e29..4bf083e6 100644 --- a/test/config-theme-and-msgs.js +++ b/test/config-theme-and-msgs.js @@ -15,7 +15,7 @@ var eraseTime = require('./tool/erase-time'); var eraseLapse = require('./tool/erase-lapse'); var gulp = require('./tool/gulp-cmd'); -describe('config: theme.* & msgs.*', function() { +describe.skip('config: theme.* & msgs.*', function() { it('Should change help.usage with .gulp.*', function(done) { var cwd = path.join(baseDir, 'help/usage'); diff --git a/test/lib/check-task-not-found.js b/test/lib/check-task-not-found.js index 932c753c..dee1a849 100644 --- a/test/lib/check-task-not-found.js +++ b/test/lib/check-task-not-found.js @@ -9,7 +9,7 @@ describe('lib: checkTaskNotFound', function() { var err = new Error('Task never defined: task2 - did you mean? task0, task1'); expect(checkTaskNotFound(err)).toEqual({ target: 'task2', - similar: 'task0, task1', + similar: ['task0', 'task1'] }); done(); }); From 6fd479631b78a559ed507daeddda8d16cd01fcf8 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 14:42:48 -0700 Subject: [PATCH 21/25] todo for the messages package --- index.js | 1 + lib/shared/completion.js | 1 + lib/shared/log/tasks.js | 2 ++ lib/shared/options/cli-options.js | 1 + lib/shared/options/make-help.js | 1 + lib/shared/translate.js | 2 +- lib/versioned/^3.7.0/index.js | 2 ++ lib/versioned/^3.7.0/log/events.js | 2 ++ lib/versioned/^4.0.0/index.js | 2 ++ lib/versioned/^4.0.0/log/events.js | 2 ++ lib/versioned/^4.0.0/log/sync-task.js | 2 ++ test/fixtures/.gulp.js | 1 + test/fixtures/gulpfiles/.gulp.js | 1 + 13 files changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 52c7dfc6..4b2c6a78 100644 --- a/index.js +++ b/index.js @@ -22,6 +22,7 @@ var toConsole = require('./lib/shared/log/to-console'); var mergeCliOpts = require('./lib/shared/config/cli-flags'); var buildTranslations = require('./lib/shared/translate'); +// TODO: make into `@gulpjs/messages` var messages = require('./messages'); // Get supported ranges diff --git a/lib/shared/completion.js b/lib/shared/completion.js index 347bd0ae..ecbbd630 100644 --- a/lib/shared/completion.js +++ b/lib/shared/completion.js @@ -3,6 +3,7 @@ var fs = require('fs'); var path = require('path'); +// TODO: make into `@gulpjs/messages` var messages = require('../../messages'); module.exports = function(name, translate) { diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index d349c24e..da286a09 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -3,6 +3,8 @@ var log = require('gulplog'); var stringWidth = require('string-width'); var isObject = require('../is-object'); + +// TODO: make into `@gulpjs/messages` var messages = require('../../../messages'); function logTasks(tree, opts, getTask, translate) { diff --git a/lib/shared/options/cli-options.js b/lib/shared/options/cli-options.js index 9babd247..a1f048a3 100644 --- a/lib/shared/options/cli-options.js +++ b/lib/shared/options/cli-options.js @@ -1,5 +1,6 @@ 'use strict'; +// TODO: make into `@gulpjs/messages` var messages = require("../../../messages"); var options = { diff --git a/lib/shared/options/make-help.js b/lib/shared/options/make-help.js index 75042b45..8fec2f17 100644 --- a/lib/shared/options/make-help.js +++ b/lib/shared/options/make-help.js @@ -2,6 +2,7 @@ var cliOptions = require('./cli-options'); +// TODO: make into `@gulpjs/messages` var messages = require("../../../messages"); function makeHelp(parser, translate) { diff --git a/lib/shared/translate.js b/lib/shared/translate.js index d5885496..9a100f02 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -4,7 +4,7 @@ var util = require('util'); var chalk = require('chalk'); -// TODO: `@gulpjs/messages` package +// TODO: make into `@gulpjs/messages` var messages = require('../../messages'); function Timestamp() { diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 673f2939..2912445f 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -15,6 +15,8 @@ var logEvents = require('./log/events'); var logTasksSimple = require('./log/tasks-simple'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); + +// TODO: make into `@gulpjs/messages` var messages = require('../../../messages'); function execute(env, opts, translate) { diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index 4ea9d84f..3375a1e4 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -4,6 +4,8 @@ var log = require('gulplog'); var formatTime = require('../../../shared/log/format-hrtime'); var exit = require('../../../shared/exit'); var formatError = require('../format-error'); + +// TODO: make into `@gulpjs/messages` var messages = require('../../../../messages'); // Wire up logging events diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index 31670c73..dd00d317 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -18,6 +18,8 @@ var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); var getTask = require('./log/get-task'); var requireOrImport = require('../../shared/require-or-import'); + +// TODO: make into `@gulpjs/messages` var messages = require('../../../messages'); function execute(env, opts, translate) { diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index ac9e93c1..ba4635ef 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -3,6 +3,8 @@ var log = require('gulplog'); var formatTime = require('../../../shared/log/format-hrtime'); var formatError = require('../format-error'); + +// TODO: make into `@gulpjs/messages` var messages = require('../../../../messages'); // Wire up logging events diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index dba5b7ee..aa4862d0 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,6 +1,8 @@ 'use strict'; var log = require('gulplog'); + +// TODO: make into `@gulpjs/messages` var messages = require('../../../../messages') var tasks = {}; diff --git a/test/fixtures/.gulp.js b/test/fixtures/.gulp.js index 4d69736e..08a9d1e7 100644 --- a/test/fixtures/.gulp.js +++ b/test/fixtures/.gulp.js @@ -1,3 +1,4 @@ +// TODO: make into `@gulpjs/messages` var messages = require('../../messages'); module.exports = { diff --git a/test/fixtures/gulpfiles/.gulp.js b/test/fixtures/gulpfiles/.gulp.js index 1f088daa..e82d59c2 100644 --- a/test/fixtures/gulpfiles/.gulp.js +++ b/test/fixtures/gulpfiles/.gulp.js @@ -1,3 +1,4 @@ +// TODO: make into `@gulpjs/messages` var messages = require('../../../messages'); module.exports = { From b079083885465296c09d6d2f5f86ac58426a86b7 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 14:49:25 -0700 Subject: [PATCH 22/25] move tildify into the default messages --- index.js | 8 ++++---- lib/shared/translate.js | 13 +++++++------ lib/versioned/^3.7.0/index.js | 7 +++---- lib/versioned/^4.0.0/index.js | 7 +++---- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 4b2c6a78..2a2c7ad4 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); var exit = require('./lib/shared/exit'); -var tildify = require('./lib/shared/tildify'); + var arrayFind = require('./lib/shared/array-find'); var makeTitle = require('./lib/shared/make-title'); var makeHelp = require('./lib/shared/options/make-help'); @@ -190,14 +190,14 @@ function onExecute(env, flags, translate) { var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); if (missingNodeModules) { - log.error(messages.MISSING_NODE_MODULES, tildify(env.cwd)); + log.error(messages.MISSING_NODE_MODULES, { cwd: env.cwd }); if (hasYarn) { log.error(messages.YARN_INSTALL) } else { log.error(messages.NPM_INSTALL) } } else { - log.error(messages.MISSING_GULP, tildify(env.cwd)); + log.error(messages.MISSING_GULP, { cwd: env.cwd }); if (hasYarn) { log.error(messages.YARN_INSTALL_GULP); } else { @@ -216,7 +216,7 @@ function onExecute(env, flags, translate) { // we let them chdir as needed if (process.cwd() !== env.cwd) { process.chdir(env.cwd); - log.info(messages.CWD_CHANGED, tildify(env.cwd)); + log.info(messages.CWD_CHANGED, { cwd: env.cwd }); } // Find the correct CLI version to run diff --git a/lib/shared/translate.js b/lib/shared/translate.js index 9a100f02..4e2b4846 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -3,10 +3,11 @@ var util = require('util'); var chalk = require('chalk'); - // TODO: make into `@gulpjs/messages` var messages = require('../../messages'); +var tildify = require('./tildify'); + function Timestamp() { this.now = new Date(); } @@ -60,7 +61,7 @@ function getDefaultMessage(msg, data) { } if (msg === messages.CWD_CHANGED) { - return 'Working directory changed to ' + chalk.magenta(data); + return 'Working directory changed to ' + chalk.magenta(tildify(data.cwd)); } if (msg === messages.UNSUPPORTED_GULP_VERSION) { @@ -68,11 +69,11 @@ function getDefaultMessage(msg, data) { } if (msg === messages.DESCRIPTION) { - return 'Tasks for ' + chalk.magenta(data); + return 'Tasks for ' + chalk.magenta(tildify(data.path)); } if (msg === messages.GULPFILE) { - return 'Using gulpfile ' + chalk.magenta(data); + return 'Using gulpfile ' + chalk.magenta(tildify(data.path)); } if (msg === messages.TASK_START) { @@ -100,11 +101,11 @@ function getDefaultMessage(msg, data) { } if (msg === messages.MISSING_NODE_MODULES) { - return chalk.red('Local modules not found in') + ' ' + chalk.magenta(data); + return chalk.red('Local modules not found in') + ' ' + chalk.magenta(tildify(data.cwd)); } if (msg === messages.MISSING_GULP) { - return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(data); + return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(tildify(data.cwd)); } if (msg === messages.YARN_INSTALL) { diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 2912445f..c4987cf8 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -8,7 +8,6 @@ var stdout = require('mute-stdout'); var taskTree = require('./task-tree'); var copyTree = require('../../shared/log/copy-tree'); -var tildify = require('../../shared/tildify'); var logTasks = require('../../shared/log/tasks'); var exit = require('../../shared/exit'); var logEvents = require('./log/events'); @@ -37,7 +36,7 @@ function execute(env, opts, translate) { exit(1); } - log.info(messages.GULPFILE, tildify(env.configPath)); + log.info(messages.GULPFILE, { path: env.configPath }); var gulpInst = require(env.modulePath); logEvents(gulpInst); @@ -53,14 +52,14 @@ function execute(env, opts, translate) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - tree.label = translate.message(messages.DESCRIPTION, tildify(env.configPath)); + tree.label = translate.message(messages.DESCRIPTION, { path: env.configPath }); return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; }, translate); } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - tree.label = translate.message(messages.DESCRIPTION, tildify(env.configPath)); + tree.label = translate.message(messages.DESCRIPTION, { path: env.configPath }); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index dd00d317..d31a4f69 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -6,7 +6,6 @@ var log = require('gulplog'); var stdout = require('mute-stdout'); var exit = require('../../shared/exit'); -var tildify = require('../../shared/tildify'); var logTasks = require('../../shared/log/tasks'); var logEvents = require('./log/events'); @@ -56,13 +55,13 @@ function execute(env, opts, translate) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - tree.label = translate.message(messages.DESCRIPTION, tildify(env.configPath)); + tree.label = translate.message(messages.DESCRIPTION, { path: env.configPath }); return logTasks(tree, opts, getTask(gulpInst), translate); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - tree.label = translate.message(messages.DESCRIPTION,tildify(env.configPath) ) + tree.label = translate.message(messages.DESCRIPTION, { path: env.configPath }); var output = JSON.stringify(copyTree(tree, opts)); @@ -72,7 +71,7 @@ function execute(env, opts, translate) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info(messages.GULPFILE, tildify(env.configPath)); + log.info(messages.GULPFILE, { path: env.configPath }); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { From 69e799308fe71b6969fbc09e3986dd37d6d29308 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 14:57:26 -0700 Subject: [PATCH 23/25] restore package.json --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 168ba16e..5e304dd5 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ ], "scripts": { "lint": "eslint .", + "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", "test": "mocha --async-only --timeout 5000 test/lib test", "cover": "nyc mocha --async-only --timeout 5000 test/lib test" @@ -49,6 +50,8 @@ "eslint-config-gulp": "^5.0.1", "expect": "^27.5.1", "gulp": "^4.0.2", + "marked-man": "^0.7.0", + "marked": "^0.7.0", "mocha": "^8.4.0", "nyc": "^15.1.0", "rimraf": "^3.0.2", From 3bc91dfd5f109dbf79adfb4ccbaac8c42be32408 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 14:57:34 -0700 Subject: [PATCH 24/25] remove extra files --- test/lib/override-env-config.js | 180 -------------------------------- test/lib/theme.js | 101 ------------------ 2 files changed, 281 deletions(-) delete mode 100644 test/lib/override-env-config.js delete mode 100644 test/lib/theme.js diff --git a/test/lib/override-env-config.js b/test/lib/override-env-config.js deleted file mode 100644 index 23dca8fe..00000000 --- a/test/lib/override-env-config.js +++ /dev/null @@ -1,180 +0,0 @@ -'use strict'; - -// var expect = require('expect'); -// var copyProps = require('copy-props'); -// var overrideEnvConfig = require('../../lib/shared/config/env-config'); - -// describe('lib: env-config', function() { - -// var originalTheme = copyProps(theme, {}); -// var originalMsgs = copyProps(msgs, {}); - -// after(function() { -// var keys = Object.keys(theme); -// keys.forEach(function(key) { -// delete theme[key]; -// }); -// copyProps(originalTheme, theme); - -// keys = Object.keys(msgs); -// keys.forEach(function(key) { -// delete msgs[key]; -// }); -// copyProps(originalMsgs, msgs); -// }); - -// it('Should copy only config props specified to env flags', function(done) { -// var env = {}; - -// var config = { -// flags: { -// silent: true, -// gulpfile: '/path/to/gulpfile', -// }, -// }; - -// var result = overrideEnvConfig(env, config, {}); -// expect(result).toEqual({ -// configPath: '/path/to/gulpfile', -// configBase: '/path/to', -// config: { -// flags: { -// silent: true, -// }, -// log: { -// theme: theme, -// msgs: msgs, -// }, -// }, -// }); -// expect(result).toBe(env); -// done(); -// }); - -// it('Should take into account forced gulpfile opts from flags', function(done) { -// var env = { -// cwd: '/path/to/cwd', -// preload: 'preload', -// configNameSearch: 'configNameSearch', -// configPath: '/path/of/config/path', -// configBase: '/path/of/config/base', -// modulePath: '/path/of/module/path', -// modulePackage: { name: 'modulePackage' }, -// configFiles: { aaa: {} }, -// }; - -// var config = { -// flags: { -// silent: false, -// gulpfile: '/path/to/gulpfile', -// preload: ['a', 'b'], -// }, -// log: { -// theme: { -// INFO: '{black: {1}}', -// WARN: '{bgYellow: {1}}', -// ERROR: '{bgRed: {1}}', -// }, -// msgs: { -// tasks: { -// description: 'DESCRIPTION', -// }, -// }, -// }, -// }; - -// var resultTheme = copyProps(theme, {}); -// resultTheme.INFO = config.log.theme.INFO; -// resultTheme.WARN = config.log.theme.WARN; -// resultTheme.ERROR = config.log.theme.ERROR; - -// var resultMsgs = copyProps(msgs, {}); -// resultMsgs.tasks.description = config.log.msgs.tasks.description; - -// var opts = { -// gulpfile: env.configPath, -// }; - -// var result = overrideEnvConfig(env, config, opts); -// expect(result).toEqual({ -// cwd: '/path/to/cwd', -// preload: ['preload', 'a', 'b'], -// configNameSearch: 'configNameSearch', -// configPath: '/path/of/config/path', -// configBase: '/path/of/config/base', -// modulePath: '/path/of/module/path', -// modulePackage: { name: 'modulePackage' }, -// configFiles: { aaa: {} }, -// config: { -// flags: { -// gulpfile: "/path/of/config/path", -// silent: false, -// }, -// log: { -// theme: resultTheme, -// msgs: resultMsgs, -// }, -// }, -// }); -// expect(result).toBe(env); -// done(); -// }); - -// it('Should not cause error if config is empty', function(done) { -// var env = { -// cwd: '/path/to/cwd', -// preload: 'preload', -// configNameSearch: 'configNameSearch', -// configPath: '/path/of/config/path', -// configBase: '/path/of/config/base', -// modulePath: '/path/of/module/path', -// modulePackage: { name: 'modulePackage' }, -// configFiles: { aaa: {} }, -// }; - -// var config = {}; - -// var result = overrideEnvConfig(env, config, {}); -// expect(result).toEqual({ -// cwd: '/path/to/cwd', -// preload: 'preload', -// configNameSearch: 'configNameSearch', -// configPath: '/path/of/config/path', -// configBase: '/path/of/config/base', -// modulePath: '/path/of/module/path', -// modulePackage: { name: 'modulePackage' }, -// configFiles: { aaa: {} }, -// config: { -// flags: {}, -// log: { -// theme: theme, -// msgs: msgs, -// }, -// }, -// }); -// expect(result).toBe(env); -// done(); -// }); - -// it('Should not cause error if config.flags and config.log is empty', function(done) { -// var env = {}; - -// var config = { -// flags: {}, -// log: {}, -// }; - -// var result = overrideEnvConfig(env, config, {}); -// expect(result).toEqual({ -// config: { -// flags: {}, -// log: { -// theme: theme, -// msgs: msgs, -// }, -// }, -// }); -// expect(result).toBe(env); -// done(); -// }); -// }); diff --git a/test/lib/theme.js b/test/lib/theme.js deleted file mode 100644 index 57e723a0..00000000 --- a/test/lib/theme.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - -var expect = require('expect'); - -// describe('lib: theme', function() { - -// it('styles', function(done) { -// if (process.env.CI) { -// this.skip(); -// return; -// } - -// expect(theme.reset('hello', 'world')).toEqual('\x1B[0mhello world\x1B[0m'); -// expect(theme.bold('hello', 'world')).toEqual('\x1B[1mhello world\x1B[22m'); -// expect(theme.dim('hello', 'world')).toEqual('\x1B[2mhello world\x1B[22m'); -// expect(theme.italic('hello', 'world')).toEqual('\x1B[3mhello world\x1B[23m'); -// expect(theme.underline('hello', 'world')).toEqual('\x1B[4mhello world\x1B[24m'); -// expect(theme.inverse('hello', 'world')).toEqual('\x1B[7mhello world\x1B[27m'); -// expect(theme.hidden('hello', 'world')).toEqual('\x1B[8mhello world\x1B[28m'); -// expect(theme.strikethrough('hello', 'world')).toEqual('\x1B[9mhello world\x1B[29m'); -// expect(theme.visible('hello', 'world')).toEqual('hello world'); - -// expect(theme.black('hello', 'world')).toEqual('\x1B[30mhello world\x1B[39m'); -// expect(theme.red('hello', 'world')).toEqual('\x1B[31mhello world\x1B[39m'); -// expect(theme.green('hello', 'world')).toEqual('\x1B[32mhello world\x1B[39m'); -// expect(theme.yellow('hello', 'world')).toEqual('\x1B[33mhello world\x1B[39m'); -// expect(theme.blue('hello', 'world')).toEqual('\x1B[34mhello world\x1B[39m'); -// expect(theme.magenta('hello', 'world')).toEqual('\x1B[35mhello world\x1B[39m'); -// expect(theme.cyan('hello', 'world')).toEqual('\x1B[36mhello world\x1B[39m'); -// expect(theme.white('hello', 'world')).toEqual('\x1B[37mhello world\x1B[39m'); -// expect(theme.blackBright('hello', 'world')).toEqual('\x1B[90mhello world\x1B[39m'); -// expect(theme.gray('hello', 'world')).toEqual('\x1B[90mhello world\x1B[39m'); -// expect(theme.grey('hello', 'world')).toEqual('\x1B[90mhello world\x1B[39m'); -// expect(theme.redBright('hello', 'world')).toEqual('\x1B[91mhello world\x1B[39m'); -// expect(theme.greenBright('hello', 'world')).toEqual('\x1B[92mhello world\x1B[39m'); -// expect(theme.yellowBright('hello', 'world')).toEqual('\x1B[93mhello world\x1B[39m'); -// expect(theme.blueBright('hello', 'world')).toEqual('\x1B[94mhello world\x1B[39m'); -// expect(theme.magentaBright('hello', 'world')).toEqual('\x1B[95mhello world\x1B[39m'); -// expect(theme.cyanBright('hello', 'world')).toEqual('\x1B[96mhello world\x1B[39m'); -// expect(theme.whiteBright('hello', 'world')).toEqual('\x1B[97mhello world\x1B[39m'); - -// expect(theme.bgBlack('hello', 'world')).toEqual('\x1B[40mhello world\x1B[49m'); -// expect(theme.bgRed('hello', 'world')).toEqual('\x1B[41mhello world\x1B[49m'); -// expect(theme.bgGreen('hello', 'world')).toEqual('\x1B[42mhello world\x1B[49m'); -// expect(theme.bgYellow('hello', 'world')).toEqual('\x1B[43mhello world\x1B[49m'); -// expect(theme.bgBlue('hello', 'world')).toEqual('\x1B[44mhello world\x1B[49m'); -// expect(theme.bgMagenta('hello', 'world')).toEqual('\x1B[45mhello world\x1B[49m'); -// expect(theme.bgCyan('hello', 'world')).toEqual('\x1B[46mhello world\x1B[49m'); -// expect(theme.bgWhite('hello', 'world')).toEqual('\x1B[47mhello world\x1B[49m'); -// expect(theme.bgBlackBright('hello', 'world')).toEqual('\x1B[100mhello world\x1B[49m'); -// expect(theme.bgGray('hello', 'world')).toEqual('\x1B[100mhello world\x1B[49m'); -// expect(theme.bgGrey('hello', 'world')).toEqual('\x1B[100mhello world\x1B[49m'); -// expect(theme.bgRedBright('hello', 'world')).toEqual('\x1B[101mhello world\x1B[49m'); -// expect(theme.bgGreenBright('hello', 'world')).toEqual('\x1B[102mhello world\x1B[49m'); -// expect(theme.bgYellowBright('hello', 'world')).toEqual('\x1B[103mhello world\x1B[49m'); -// expect(theme.bgBlueBright('hello', 'world')).toEqual('\x1B[104mhello world\x1B[49m'); -// expect(theme.bgMagentaBright('hello', 'world')).toEqual('\x1B[105mhello world\x1B[49m'); -// expect(theme.bgCyanBright('hello', 'world')).toEqual('\x1B[106mhello world\x1B[49m'); -// expect(theme.bgWhiteBright('hello', 'world')).toEqual('\x1B[107mhello world\x1B[49m'); - -// done(); -// }); - -// it('templates', function(done) { -// if (process.env.CI) { -// this.skip(); -// return; -// } - -// /* eslint new-cap: 0 */ -// expect(theme.NOW('HH:mm')).toMatch(/^\d{2}:\d{2}$/); - -// expect(format(theme, '{HELP.DESC: {1}}', 'hello')).toEqual('\x1B[90mhello\x1B[39m'); -// expect(format(theme, '{DESC: {1}}', 'hello')).toEqual('hello'); -// expect(format(theme, '{PATH: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); -// expect(format(theme, '{PID: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); -// expect(format(theme, '{MODULE: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); -// expect(format(theme, '{VERSION: {1}}', 'hello')).toEqual('hello'); -// expect(format(theme, '{TITLE: {1}}', 'hello')).toEqual('\x1B[1mhello\x1B[22m'); -// expect(format(theme, '{TASK: {1}}', 'hello')).toEqual('\x1B[36mhello\x1B[39m'); -// expect(format(theme, '{OPTION: {1}}', 'hello')).toEqual('\x1B[34mhello\x1B[39m'); -// expect(format(theme, '{DURATION: {1}}', 'hello')).toEqual('\x1B[35mhello\x1B[39m'); - -// expect(format(theme, '{TASKS.BRANCH: {1}}', 'hello')).toEqual('hello'); -// expect(format(theme, '{TASKS.NAME: {1}}', 'hello')).toEqual('\x1B[36mhello\x1B[39m'); -// expect(format(theme, '{TASKS.OPTION: {1}}', 'hello')).toEqual('\x1B[34mhello\x1B[39m'); -// expect(format(theme, '{TASKS.DESC: {1}}', 'hello')).toEqual('hello'); -// expect(format(theme, '{TASKS.CHILD: {1}}', 'hello')).toEqual('hello'); - -// expect(format(theme, '{INFO: {1}}', 'hello')).toEqual('hello'); -// expect(format(theme, '{WARN: {1}}', 'hello')).toEqual('\x1B[33mhello\x1B[39m'); -// expect(format(theme, '{ERROR: {1}}', 'hello')).toEqual('\x1B[31mhello\x1B[39m'); - -// /* eslint no-control-regex: 0 */ -// expect(format(theme, '{TIMESTAMP: {1}}', 'HH:mm:ss')).toMatch(/^\[\x1B\[90m\d{2}:\d{2}:\d{2}\x1B\[39m\] $/); - -// expect(format(theme, '{IF: {1}?{2}}', true, 'hello')).toEqual('hello'); -// expect(format(theme, '{IF: {1}?{2}}', false, 'hello')).toEqual(''); -// done(); -// }); -// }); From 8b85be147522d8d170d01d3c5118a438fa54ad26 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 14:58:52 -0700 Subject: [PATCH 25/25] remove extra test step --- .github/workflows/dev.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index da91898f..90a12261 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -56,12 +56,6 @@ jobs: # Run test without coverage because a behavior about esm is different with nyc or not run: npm test - - name: Run tests with coloring - run: npx mocha test/lib/theme.js - env: - FORCE_COLOR: 2 - CI: "" - coveralls: needs: test name: Finish up