From be0955ccd31f80ad83d11ede2d98137ade1df750 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 4 Feb 2024 13:34:12 +0900 Subject: [PATCH 01/43] feat: make log messages and styles configurable with theme. --- .eslintrc | 2 +- .github/workflows/dev.yml | 6 + README.md | 2 + index.js | 80 +++----- lib/shared/completion.js | 12 +- lib/shared/log/messages.js | 175 ++++++++++++++++++ lib/shared/log/tasks.js | 49 +++-- lib/shared/log/theme.js | 63 +++++++ lib/shared/log/timestamp.js | 53 ++++++ lib/shared/log/to-console.js | 21 ++- lib/shared/options/make-help.js | 17 ++ lib/shared/options/parser.js | 49 +---- lib/versioned/^3.7.0/index.js | 19 +- lib/versioned/^3.7.0/log/events.js | 22 +-- lib/versioned/^3.7.0/log/tasks-description.js | 18 ++ lib/versioned/^4.0.0-alpha.1/index.js | 29 ++- lib/versioned/^4.0.0-alpha.2/index.js | 29 ++- lib/versioned/^4.0.0/index.js | 29 ++- .../^4.0.0/log/check-task-not-found.js | 11 ++ lib/versioned/^4.0.0/log/events.js | 24 +-- lib/versioned/^4.0.0/log/sync-task.js | 10 +- lib/versioned/^4.0.0/log/tasks-description.js | 18 ++ package.json | 5 +- test/lib/config-cli-flags.js | 2 +- test/lib/config-env-flags.js | 112 ----------- test/lib/format-hrtime.js | 2 +- test/lib/merge-configs.js | 119 ------------ test/lib/theme.js | 103 +++++++++++ test/lib/timestamp.js | 57 ++++++ 29 files changed, 671 insertions(+), 467 deletions(-) create mode 100644 lib/shared/log/messages.js create mode 100644 lib/shared/log/theme.js create mode 100644 lib/shared/log/timestamp.js create mode 100644 lib/shared/options/make-help.js create mode 100644 lib/versioned/^3.7.0/log/tasks-description.js create mode 100644 lib/versioned/^4.0.0/log/check-task-not-found.js create mode 100644 lib/versioned/^4.0.0/log/tasks-description.js delete mode 100644 test/lib/config-env-flags.js delete mode 100644 test/lib/merge-configs.js create mode 100644 test/lib/theme.js create mode 100644 test/lib/timestamp.js diff --git a/.eslintrc b/.eslintrc index 331ecbe0..8451f905 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,7 +2,7 @@ "extends": "gulp", "rules": { "max-len": [1, 130], - "max-statements": [1, 40], + "max-statements": [1, 60], "no-console": "off" } } diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 90a12261..da91898f 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -56,6 +56,12 @@ 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 diff --git a/README.md b/README.md index bde183fd..02abed5e 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,8 @@ Supported configurations properties: | 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 | +| log.messages.* | Configure log messages. | +| log.theme.* | Configure log theme. | ## Flags diff --git a/index.js b/index.js index 935f8928..1f928acb 100644 --- a/index.js +++ b/index.js @@ -3,19 +3,22 @@ var fs = require('fs'); var path = require('path'); var log = require('gulplog'); - var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); -var chalk = require('chalk'); +var format = require('theming-log').format; + 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 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 theme = require('./lib/shared/log/theme'); +var msgs = require('./lib/shared/log/messages'); var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); @@ -55,22 +58,15 @@ var cli = new Liftoff({ var opts = parser.argv; cli.on('preload:before', function(name) { - log.info('Preloading external module:', chalk.magenta(name)); + log.info(msgs.info.preloadBefore, name); }); cli.on('preload:success', function(name) { - log.info('Preloaded external module:', chalk.magenta(name)); + log.info(msgs.info.preloadSuccess, name); }); cli.on('preload:failure', function(name, error) { - log.warn( - chalk.yellow('Failed to preload external module:'), - chalk.magenta(name) - ); - /* istanbul ignore else */ - if (error) { - log.warn(chalk.yellow(error.toString())); - } + log.warn(msgs.warn.preloadFailure, name, Boolean(error), error.toString()); }); cli.on('loader:success', function(name) { @@ -79,26 +75,16 @@ 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('Loaded external module:', chalk.magenta(name)); + log.info(msgs.info.loaderSuccess, name); } }); cli.on('loader:failure', function(name, error) { - log.warn( - chalk.yellow('Failed to load external module:'), - chalk.magenta(name) - ); - /* istanbul ignore else */ - if (error) { - log.warn(chalk.yellow(error.toString())); - } + log.warn(msgs.warn.loaderFailure, name, Boolean(error), error.toString()); }); cli.on('respawn', function(flags, child) { - var nodeFlags = chalk.magenta(flags.join(', ')); - var pid = chalk.magenta(child.pid); - log.info('Node flags detected:', nodeFlags); - log.info('Respawned to PID:', pid); + log.info(msgs.info.respawn, flags.join(', '), child.pid); }); function run() { @@ -133,14 +119,14 @@ function onExecute(env) { } if (env.config.flags.help) { - parser.showHelp(console.log); + 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) { - console.log('CLI version:', cliVersion); - console.log('Local version:', env.modulePackage.version || 'Unknown'); + var gulpVersion = env.modulePackage.version || 'Unknown'; + console.log(format(theme, msgs.info.version, cliVersion, gulpVersion)); exit(0); } @@ -150,31 +136,20 @@ function onExecute(env) { fs.existsSync(path.join(env.cwd, 'package.json')) && !fs.existsSync(path.join(env.cwd, 'node_modules')); - /* istanbul ignore next */ - var missingGulpMessage = - missingNodeModules - ? 'Local modules not found in' - : 'Local gulp not found in'; - log.error( - chalk.red(missingGulpMessage), - chalk.magenta(tildify(env.cwd)) - ); var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); - /* istanbul ignore next */ - var installCommand = - missingNodeModules - ? hasYarn - ? 'yarn install' - : 'npm install' - : hasYarn - ? 'yarn add gulp' - : 'npm install gulp'; - log.error(chalk.red('Try running: ' + installCommand)); + var hasNpm = !hasYarn; + + /* istanbul ignore if */ + 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(chalk.red('No gulpfile found')); + log.error(msgs.error.gulpfileNotFound); exit(1); } @@ -182,19 +157,14 @@ function onExecute(env) { // we let them chdir as needed if (process.cwd() !== env.cwd) { process.chdir(env.cwd); - log.info( - 'Working directory changed to', - chalk.magenta(tildify(env.cwd)) - ); + log.info(msgs.info.cwdChanged, tildify(env.cwd)); } // Find the correct CLI version to run var range = findRange(env.modulePackage.version, ranges); if (!range) { - log.error( - chalk.red('Unsupported gulp version', env.modulePackage.version) - ); + log.error(msgs.error.badGulpVersion, env.modulePackage.version); exit(1); } diff --git a/lib/shared/completion.js b/lib/shared/completion.js index 3a47023d..1f1a7cc3 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 theme = require('./log/theme'); +var msgs = require('./log/messages'); module.exports = function(name) { if (typeof name !== 'string') { - throw new Error('Missing completion type'); + 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( - 'echo "gulp autocompletion rules for', - '\'' + name + '\'', - 'not found"' - ); + console.log(format(theme, msgs.error.unknownCompletionType, name)); process.exit(5); } }; diff --git a/lib/shared/log/messages.js b/lib/shared/log/messages.js new file mode 100644 index 00000000..642f94aa --- /dev/null +++ b/lib/shared/log/messages.js @@ -0,0 +1,175 @@ +'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: { + gulpfile: + '{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: { + gulpfile: + '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}}', + + version: + '{DESC: CLI version}: {VERSION: {1:CLI version}}\n' + + '{DESC: Local version}: {VERSION: {2:gulp version}}', + + 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: { + 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:task}}\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 2d59fe35..1a6db4ed 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -1,7 +1,10 @@ 'use strict'; var log = require('gulplog'); -var chalk = require('chalk'); +var stringWidth = require('string-width'); +var format = require('theming-log').format; +var theme = require('./theme'); +var msgs = require('./messages'); var isObject = require('../is-object'); function logTasks(tree, opts, getTask) { @@ -39,12 +42,14 @@ function printTaskTree(tree, opts) { }); lines.forEach(function(line) { - var s = line.label; - if (line.desc) { - var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' '; - s += spaces + line.desc; + if (line.fmt == null) { + log.info(line.label); + } else 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); } - log.info(s); }); } @@ -81,21 +86,27 @@ function addTaskToLines(task, lines, isLast, isLeaf) { var line = {}; if (task.depth === 1) { - line.label = chalk.white(taskBars) + chalk.white(task.label); + line.fmt = msgs.tasks.topTask; + line.bars = taskBars; + line.name = task.label; } else { - line.label = chalk.white(taskBars) + chalk.cyan(task.label); + line.fmt = msgs.tasks.childTask; + line.bars = taskBars; + line.name = task.label; } + line.width = stringWidth(format(theme, line.fmt, line.bars, line.name)); + if (typeof task.desc === 'string' && task.desc) { - line.desc = chalk.white(task.desc); + line.desc = task.desc; } lines.push(line); - var maxLabelWidth = line.label.length - if (!isObject(task.flags)) { - return maxLabelWidth; + return line.width; } + var maxLabelWidth = line.width; + var flagBars = task.bars; if (isLast) { flagBars += ' '; @@ -114,13 +125,17 @@ function addTaskToLines(task, lines, isLast, isLeaf) { 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]); + line.fmt = msgs.tasks.option; + line.bars = flagBars; + line.name = ent[0]; + line.width = stringWidth(format(theme, line.fmt, line.bars, line.name)); - maxLabelWidth = Math.max(maxLabelWidth, line.label.length); + maxLabelWidth = Math.max(maxLabelWidth, line.width); - if (typeof ent[1] !== 'string' || !ent[1]) return; - line.desc = chalk.white('…' + ent[1]); + if (typeof ent[1] == 'string' && ent[1]) { + line.desc = ent[1]; + } + lines.push(line); } return maxLabelWidth; diff --git a/lib/shared/log/theme.js b/lib/shared/log/theme.js new file mode 100644 index 00000000..4f8d002a --- /dev/null +++ b/lib/shared/log/theme.js @@ -0,0 +1,63 @@ +'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/shared/log/timestamp.js b/lib/shared/log/timestamp.js new file mode 100644 index 00000000..99c71d46 --- /dev/null +++ b/lib/shared/log/timestamp.js @@ -0,0 +1,53 @@ +'use strict'; + +function timestamp(format) { + 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; +} + +function noop() { + return ""; +} + +function align(v, n) { + return String(v).padStart(n, '0').slice(-n); +} + +module.exports = timestamp; diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 43650af1..9bcf3335 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -1,6 +1,7 @@ 'use strict'; -var fancyLog = require('fancy-log'); +var themingLog = require('theming-log'); +var theme = require('./theme'); /* istanbul ignore next */ function noop() {} @@ -14,15 +15,23 @@ var levels = [ 'debug', // -LLLL: Logs all log levels. ]; +function consoleLog(s) { + if (s != null) console.log(s); +} + +function consoleError(s) { + if (s != null) console.error(s); +} + function cleanup(log) { levels.forEach(removeListeners); function removeListeners(level) { if (level === 'error') { log.removeListener(level, noop); - log.removeListener(level, fancyLog.error); + log.removeListener(level, consoleError); } else { - log.removeListener(level, fancyLog); + log.removeListener(level, consoleLog); } } } @@ -48,10 +57,12 @@ function toConsole(log, opts) { }) .forEach(function(level) { if (level === 'error') { - log.on(level, fancyLog.error); + log.on(level, consoleError); } else { - log.on(level, fancyLog); + log.on(level, consoleLog); } + + log[level] = themingLog(theme, log[level]); }); } diff --git a/lib/shared/options/make-help.js b/lib/shared/options/make-help.js new file mode 100644 index 00000000..d2b45d14 --- /dev/null +++ b/lib/shared/options/make-help.js @@ -0,0 +1,17 @@ +'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])); + }); + + return parser; +} + +module.exports = makeHelp; diff --git a/lib/shared/options/parser.js b/lib/shared/options/parser.js index 67594a05..3326aaba 100644 --- a/lib/shared/options/parser.js +++ b/lib/shared/options/parser.js @@ -1,128 +1,81 @@ 'use strict'; -var chalk = require('chalk'); var yargs = require('yargs'); -var usage = - '\n' + chalk.bold('Usage:') + - ' gulp ' + chalk.blue('[options]') + ' tasks'; - var options = { help: { alias: 'h', type: 'boolean', - desc: chalk.gray( - 'Show this help.'), }, version: { alias: 'v', type: 'boolean', - desc: chalk.gray( - 'Print the global and local gulp versions.'), }, preload: { type: 'string', requiresArg: true, - desc: chalk.gray( - 'Will preload a module before running the gulpfile. ' + - 'This is useful for transpilers but also has other applications.'), }, gulpfile: { alias: 'f', type: 'string', requiresArg: true, - desc: chalk.gray( - 'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' + - 'This will set the CWD to the gulpfile directory as well.'), }, cwd: { type: 'string', requiresArg: true, - desc: chalk.gray( - 'Manually set the CWD. The search for the gulpfile, ' + - 'as well as the relativity of all requires will be from here.'), }, tasks: { alias: 'T', type: 'boolean', - desc: chalk.gray( - 'Print the task dependency tree for the loaded gulpfile.'), }, 'tasks-simple': { type: 'boolean', - desc: chalk.gray( - 'Print a plaintext list of tasks for the loaded gulpfile.'), }, 'tasks-json': { - desc: chalk.gray( - 'Print the task dependency tree, ' + - 'in JSON format, for the loaded gulpfile.'), }, 'tasks-depth': { alias: 'depth', type: 'number', requiresArg: true, default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Specify the depth of the task dependency tree.'), }, 'compact-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Reduce the output of task dependency tree by printing ' + - 'only top tasks and their child tasks.'), }, 'sort-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Will sort top tasks of task dependency tree.'), }, color: { type: 'boolean', - desc: chalk.gray( - 'Will force gulp and gulp plugins to display colors, ' + - 'even when no color support is detected.'), }, 'no-color': { type: 'boolean', - desc: chalk.gray( - 'Will force gulp and gulp plugins to not display colors, ' + - 'even when color support is detected.'), }, silent: { alias: 'S', type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Suppress all gulp logging.'), }, continue: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Continue execution of tasks upon failure.'), }, series: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: chalk.gray( - 'Run tasks given on the CLI in series (the default is parallel).'), }, '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. - desc: chalk.gray( - 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' + - '-LLL is default.'), } }; var parser = yargs .help(false).version(false).detectLocale(false) - .usage(usage).options(options); + .options(options); module.exports = parser; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index a5cc2a9f..7da49d19 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -1,10 +1,10 @@ 'use strict'; var fs = require('fs'); - var log = require('gulplog'); var stdout = require('mute-stdout'); -var chalk = require('chalk'); + +var msgs = require('../../shared/log/messages'); var taskTree = require('./task-tree'); var copyTree = require('../../shared/log/copy-tree'); @@ -14,6 +14,7 @@ var logTasks = require('../../shared/log/tasks'); var exit = require('../../shared/exit'); var logEvents = require('./log/events'); var logTasksSimple = require('./log/tasks-simple'); +var getTasksDescription = require('./log/tasks-description'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); @@ -37,7 +38,7 @@ function execute(env) { exit(1); } - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info(msgs.info.usingGulpfile, tildify(env.configPath)); var gulpInst = require(env.modulePath); logEvents(gulpInst); @@ -53,22 +54,14 @@ function execute(env) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - 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.label = getTasksDescription(env); return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; }); } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; - } else { - tree.label = 'Tasks for ' + tildify(env.configPath); - } + tree.label = getTasksDescription(env); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index a20de7ce..09a428cf 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -2,8 +2,7 @@ var log = require('gulplog'); var formatTime = require('../../../shared/log/format-hrtime'); -var chalk = require('chalk'); - +var msgs = require('../../../shared/log/messages'); var exit = require('../../../shared/exit'); var formatError = require('../format-error'); @@ -26,33 +25,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('Starting', '\'' + chalk.cyan(e.task) + '\'...'); + log.info(msgs.info.taskStart, e.task); }); gulpInst.on('task_stop', function(e) { var time = formatTime(e.hrDuration); - log.info( - 'Finished', '\'' + chalk.cyan(e.task) + '\'', - 'after', chalk.magenta(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( - '\'' + chalk.cyan(e.task) + '\'', - chalk.red('errored after'), - chalk.magenta(time) - ); - log.error(msg); + log.error(msgs.error.taskError, e.task, time, Boolean(msg), msg); }); gulpInst.on('task_not_found', function(err) { - log.error( - chalk.red('Task \'' + err.task + '\' is not in your gulpfile') - ); - log.error('Please check the documentation for proper gulpfile formatting'); + log.error(msgs.error.taskNotFound, err.task); exit(1); }); } diff --git a/lib/versioned/^3.7.0/log/tasks-description.js b/lib/versioned/^3.7.0/log/tasks-description.js new file mode 100644 index 00000000..031ff59e --- /dev/null +++ b/lib/versioned/^3.7.0/log/tasks-description.js @@ -0,0 +1,18 @@ +'use strict'; + +var format = require('theming-log').format; +var tildify = require('../../../shared/tildify'); +var theme = require('../../../shared/log/theme'); +var msgs = require('../../../shared/log/messages'); + +function getTasksDescription(env) { + var desc; + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = msgs.tasks.gulpfile; + } + return format(theme, desc, tildify(env.configPath)); +} + +module.exports = getTasksDescription; diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index c9c5ffc3..845a1b85 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -1,10 +1,10 @@ 'use strict'; var fs = require('fs'); - var log = require('gulplog'); var stdout = require('mute-stdout'); -var chalk = require('chalk'); + +var msgs = require('../../shared/log/messages'); var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -13,6 +13,8 @@ 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 getTasksDescription = require('../^4.0.0/log/tasks-description'); var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); @@ -53,23 +55,16 @@ function execute(env) { } 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.label = getTasksDescription(env); 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.label = getTasksDescription(env); tree.nodes = gulpInst.tree({ deep: true }); var output = JSON.stringify(copyTree(tree, opts)); @@ -79,7 +74,7 @@ function execute(env) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info(msgs.info.usingGulpfile, tildify(env.configPath)); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -87,8 +82,12 @@ function execute(env) { } }); } catch (err) { - log.error(chalk.red(err.message)); - log.error('To list available tasks, try running: gulp --tasks'); + var taskName = checkTaskNotFound(err); + if (taskName) { + log.error(msgs.error.taskNotFound, taskName); + } else { + 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 3d1763a6..058559ae 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -1,10 +1,10 @@ 'use strict'; var fs = require('fs'); - var log = require('gulplog'); var stdout = require('mute-stdout'); -var chalk = require('chalk'); + +var msgs = require('../../shared/log/messages'); var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -13,6 +13,8 @@ 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 getTasksDescription = require('../^4.0.0/log/tasks-description'); var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); @@ -55,21 +57,12 @@ 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; - } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); - } - + tree.label = getTasksDescription(env); 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); - } + tree.label = getTasksDescription(env); var output = JSON.stringify(copyTree(tree, opts)); @@ -79,7 +72,7 @@ function execute(env) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info(msgs.info.usingGulpfile, tildify(env.configPath)); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -87,8 +80,12 @@ function execute(env) { } }); } catch (err) { - log.error(chalk.red(err.message)); - log.error('To list available tasks, try running: gulp --tasks'); + var taskName = checkTaskNotFound(err); + if (taskName) { + log.error(msgs.error.taskNotFound, taskName); + } else { + 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 d6883587..a46a8cef 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -1,11 +1,11 @@ 'use strict'; var fs = require('fs'); - var log = require('gulplog'); var stdout = require('mute-stdout'); -var chalk = require('chalk'); +var msgs = require('../../shared/log/messages'); + var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -13,6 +13,8 @@ var logTasks = require('../../shared/log/tasks'); var logEvents = require('./log/events'); var logSyncTask = require('./log/sync-task'); var logTasksSimple = require('./log/tasks-simple'); +var checkTaskNotFound = require('./log/check-task-not-found'); +var getTasksDescription = require('./log/tasks-description'); var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); @@ -55,21 +57,12 @@ 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; - } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); - } - + tree.label = getTasksDescription(env); 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); - } + tree.label = getTasksDescription(env); var output = JSON.stringify(copyTree(tree, opts)); @@ -79,7 +72,7 @@ function execute(env) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info(msgs.info.usingGulpfile, tildify(env.configPath)); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -87,8 +80,12 @@ function execute(env) { } }); } catch (err) { - log.error(chalk.red(err.message)); - log.error('To list available tasks, try running: gulp --tasks'); + var taskName = checkTaskNotFound(err); + if (taskName) { + log.error(msgs.error.taskNotFound, taskName); + } else { + log.error(msgs.error.failToRun, err.message); + } 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 new file mode 100644 index 00000000..fb45d7fd --- /dev/null +++ b/lib/versioned/^4.0.0/log/check-task-not-found.js @@ -0,0 +1,11 @@ +'use strict'; + +function checkTaskNotFound(err) { + var result = /^Task never defined: +(.*)$/.exec(err.message); + /* istanbul ignore else */ + if (result) { + return result[1]; + } +} + +module.exports = checkTaskNotFound; diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index 0fb82c5c..0897b88e 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -2,8 +2,7 @@ var log = require('gulplog'); var formatTime = require('../../../shared/log/format-hrtime'); - -var chalk = require('chalk'); +var msgs = require('../../../shared/log/messages'); var formatError = require('../format-error'); // Wire up logging events @@ -16,34 +15,29 @@ 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]('Starting', '\'' + chalk.cyan(evt.name) + '\'...'); + log[level](msgs.info.taskStart, evt.name); }); gulpInst.on('stop', function(evt) { var time = formatTime(evt.duration); /* istanbul ignore next */ var level = evt.branch ? 'debug' : 'info'; - log[level]( - 'Finished', '\'' + chalk.cyan(evt.name) + '\'', - 'after', chalk.magenta(time) - ); + log[level](msgs.info.taskStop, evt.name, time); }); gulpInst.on('error', function(evt) { var msg = formatError(evt); - var time = formatTime(evt.duration); - var level = evt.branch ? 'debug' : 'error'; - log[level]( - '\'' + chalk.cyan(evt.name) + '\'', - chalk.red('errored after'), - chalk.magenta(time) - ); + var firstOutput = false; // If we haven't logged this before, log it and add to list if (loggedErrors.indexOf(evt.error) === -1) { - log.error(msg); + firstOutput = true; 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 ff380f10..b0719d27 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,7 +1,7 @@ 'use strict'; var log = require('gulplog'); -var chalk = require('chalk'); +var msgs = require('../../../shared/log/messages'); var tasks = {}; @@ -18,13 +18,7 @@ function warn() { process.exitCode = 1; - log.warn( - chalk.red('The following tasks did not complete:'), - chalk.cyan(taskNames) - ); - log.warn( - chalk.red('Did you forget to signal async completion?') - ); + log.warn(msgs.warn.taskNotComplete, taskNames); } function start(e) { diff --git a/lib/versioned/^4.0.0/log/tasks-description.js b/lib/versioned/^4.0.0/log/tasks-description.js new file mode 100644 index 00000000..031ff59e --- /dev/null +++ b/lib/versioned/^4.0.0/log/tasks-description.js @@ -0,0 +1,18 @@ +'use strict'; + +var format = require('theming-log').format; +var tildify = require('../../../shared/tildify'); +var theme = require('../../../shared/log/theme'); +var msgs = require('../../../shared/log/messages'); + +function getTasksDescription(env) { + var desc; + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = msgs.tasks.gulpfile; + } + return format(theme, desc, tildify(env.configPath)); +} + +module.exports = getTasksDescription; diff --git a/package.json b/package.json index 47ff7595..361490ed 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,14 @@ "dependencies": { "chalk": "^4.1.2", "copy-props": "^4.0.0", - "fancy-log": "^2.0.0", "gulplog": "^2.0.1", "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" }, @@ -50,8 +51,8 @@ "eslint-config-gulp": "^5.0.1", "expect": "^27.5.1", "gulp": "^4.0.2", - "marked-man": "^0.7.0", "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/config-cli-flags.js b/test/lib/config-cli-flags.js index e70a0d92..d78e07a1 100644 --- a/test/lib/config-cli-flags.js +++ b/test/lib/config-cli-flags.js @@ -3,7 +3,7 @@ var expect = require('expect'); var mergeCliOpts = require('../../lib/shared/config/cli-flags'); -describe('lib: config/cli-flags', function() { +describe('lib: cli-flags', function() { it('Should copy only config props specified to cli flags', function(done) { var opts = {}; 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/format-hrtime.js b/test/lib/format-hrtime.js index 71eb9989..d520c3a1 100644 --- a/test/lib/format-hrtime.js +++ b/test/lib/format-hrtime.js @@ -3,7 +3,7 @@ var expect = require('expect'); var formatHrtime = require('../../lib/shared/log/format-hrtime'); -describe('format-hrtime', function() { +describe('lib: format-hrtime', function() { describe('should convert hrtime to string: unit is "h"', function() { it('should be no decimal part if integer part greater than 10', function(done) { expect(formatHrtime([36000, 100])).toEqual('10 h'); 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(); - }); - -}); diff --git a/test/lib/theme.js b/test/lib/theme.js new file mode 100644 index 00000000..7329a137 --- /dev/null +++ b/test/lib/theme.js @@ -0,0 +1,103 @@ +'use strict'; + +var expect = require('expect'); +var format = require('theming-log').format; +var theme = require('../../lib/shared/log/theme'); + +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(); + }); +}); diff --git a/test/lib/timestamp.js b/test/lib/timestamp.js new file mode 100644 index 00000000..ae827ecd --- /dev/null +++ b/test/lib/timestamp.js @@ -0,0 +1,57 @@ +'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 903416447279b79b448e8cf1b0b0a8e3a10dfa2f Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 11 Feb 2024 23:24:45 +0900 Subject: [PATCH 02/43] feat: enable to override log messages and theme with a config file. --- .gitignore | 1 + index.js | 6 +- .../config/{env-flags.js => env-config.js} | 15 +- lib/shared/config/merge-configs.js | 1 + lib/shared/log/messages.js | 2 +- lib/shared/log/tasks.js | 4 +- lib/shared/log/timestamp.js | 2 + lib/shared/log/to-console.js | 5 +- lib/versioned/^3.7.0/index.js | 4 +- lib/versioned/^3.7.0/log/tasks-description.js | 12 +- 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 +- .../^4.0.0/log/check-task-not-found.js | 22 +- lib/versioned/^4.0.0/log/tasks-description.js | 12 +- test/config-theme-and-msgs.js | 561 ++++++++++++++++++ test/execution-errors.js | 91 ++- .../config/theming/help/flags/help.txt | 21 + .../config/theming/help/usage/help.txt | 39 ++ .../theming/error/badGulpVersion/.gulp.js | 10 + .../theming/error/badGulpVersion/gulpfile.js | 3 + .../badGulpVersion/node_modules/gulp/index.js | 0 .../node_modules/gulp/package.json | 15 + .../config/theming/error/failToRun/.gulp.js | 8 + .../theming/error/failToRun/gulpfile.js | 3 + .../theming/error/gulpNotFound/.gulp.js | 10 + .../theming/error/gulpfileNotFound/.gulp.js | 7 + .../theming/error/noCompletionType/.gulp.js | 7 + .../error/noCompletionType/gulpfile.js | 3 + .../error/nodeModulesNotFound/.gulp.js | 12 + .../error/nodeModulesNotFound/package.json | 12 + .../config/theming/error/taskError/.gulp.js | 10 + .../theming/error/taskError/gulpfile.js | 3 + .../theming/error/taskNotFound/.gulp.js | 11 + .../theming/error/taskNotFound/gulpfile.js | 3 + .../error/unknownCompletionType/.gulp.js | 10 + .../error/unknownCompletionType/gulpfile.js | 3 + .../config/theming/help/flags/.gulp.js | 28 + .../config/theming/help/usage/.gulp.js | 7 + .../config/theming/info/cwdChanged/.gulp.js | 10 + .../theming/info/cwdChanged/gulpfile.js | 3 + .../theming/info/loaderSuccess/.gulp.js | 10 + .../info/loaderSuccess/gulpfile.babel.js | 3 + .../theming/info/preloadBefore/.gulp.js | 10 + .../theming/info/preloadBefore/gulpfile.js | 3 + .../theming/info/preloadBefore/preload.js | 1 + .../theming/info/preloadSuccess/.gulp.js | 10 + .../theming/info/preloadSuccess/gulpfile.js | 3 + .../theming/info/preloadSuccess/preload.js | 1 + .../config/theming/info/respawn/.gulp.js | 10 + .../config/theming/info/respawn/gulpfile.js | 3 + .../config/theming/info/taskStart/.gulp.js | 10 + .../config/theming/info/taskStart/gulpfile.js | 3 + .../config/theming/info/taskStop/.gulp.js | 10 + .../config/theming/info/taskStop/gulpfile.js | 3 + .../theming/info/usingGulpfile/.gulp.js | 10 + .../theming/info/usingGulpfile/gulpfile.js | 3 + .../config/theming/info/version/.gulp.js | 10 + .../config/theming/tasks/childTask/.gulp.js | 10 + .../theming/tasks/childTask/gulpfile.js | 27 + .../config/theming/tasks/gulpfile/.gulp.json | 10 + .../config/theming/tasks/gulpfile/gulpfile.js | 3 + .../theming/tasks/gulpfile/remove/.gulp.json | 10 + .../theming/tasks/gulpfile/remove/gulpfile.js | 3 + .../config/theming/tasks/option/.gulp.js | 10 + .../config/theming/tasks/option/gulpfile.js | 27 + .../config/theming/tasks/topTask/.gulp.js | 10 + .../config/theming/tasks/topTask/gulpfile.js | 27 + .../theming/tasksJson/gulpfile/.gulp.json | 10 + .../theming/tasksJson/gulpfile/gulpfile.js | 3 + .../theming/warn/loaderFailure/.gulp.js | 10 + .../warn/loaderFailure/gulpfile.coffee | 1 + .../theming/warn/preloadFailure/.gulp.js | 10 + .../theming/warn/preloadFailure/gulpfile.js | 3 + .../theming/warn/taskNotComplete/.gulp.js | 10 + .../theming/warn/taskNotComplete/gulpfile.js | 3 + test/fixtures/errors/yarn/yarn.lock | 0 test/flags-tasks.js | 4 +- test/lib/check-task-not-found.js | 28 + 79 files changed, 1289 insertions(+), 39 deletions(-) rename lib/shared/config/{env-flags.js => env-config.js} (78%) create mode 100644 test/config-theme-and-msgs.js create mode 100644 test/expected/config/theming/help/flags/help.txt create mode 100644 test/expected/config/theming/help/usage/help.txt create mode 100644 test/fixtures/config/theming/error/badGulpVersion/.gulp.js create mode 100644 test/fixtures/config/theming/error/badGulpVersion/gulpfile.js create mode 100644 test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/index.js create mode 100644 test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/package.json create mode 100644 test/fixtures/config/theming/error/failToRun/.gulp.js create mode 100644 test/fixtures/config/theming/error/failToRun/gulpfile.js create mode 100644 test/fixtures/config/theming/error/gulpNotFound/.gulp.js create mode 100644 test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js create mode 100644 test/fixtures/config/theming/error/noCompletionType/.gulp.js create mode 100644 test/fixtures/config/theming/error/noCompletionType/gulpfile.js create mode 100644 test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js create mode 100644 test/fixtures/config/theming/error/nodeModulesNotFound/package.json create mode 100644 test/fixtures/config/theming/error/taskError/.gulp.js create mode 100644 test/fixtures/config/theming/error/taskError/gulpfile.js create mode 100644 test/fixtures/config/theming/error/taskNotFound/.gulp.js create mode 100644 test/fixtures/config/theming/error/taskNotFound/gulpfile.js create mode 100644 test/fixtures/config/theming/error/unknownCompletionType/.gulp.js create mode 100644 test/fixtures/config/theming/error/unknownCompletionType/gulpfile.js create mode 100644 test/fixtures/config/theming/help/flags/.gulp.js create mode 100644 test/fixtures/config/theming/help/usage/.gulp.js create mode 100644 test/fixtures/config/theming/info/cwdChanged/.gulp.js create mode 100644 test/fixtures/config/theming/info/cwdChanged/gulpfile.js create mode 100644 test/fixtures/config/theming/info/loaderSuccess/.gulp.js create mode 100644 test/fixtures/config/theming/info/loaderSuccess/gulpfile.babel.js create mode 100644 test/fixtures/config/theming/info/preloadBefore/.gulp.js create mode 100644 test/fixtures/config/theming/info/preloadBefore/gulpfile.js create mode 100644 test/fixtures/config/theming/info/preloadBefore/preload.js create mode 100644 test/fixtures/config/theming/info/preloadSuccess/.gulp.js create mode 100644 test/fixtures/config/theming/info/preloadSuccess/gulpfile.js create mode 100644 test/fixtures/config/theming/info/preloadSuccess/preload.js create mode 100644 test/fixtures/config/theming/info/respawn/.gulp.js create mode 100644 test/fixtures/config/theming/info/respawn/gulpfile.js create mode 100644 test/fixtures/config/theming/info/taskStart/.gulp.js create mode 100644 test/fixtures/config/theming/info/taskStart/gulpfile.js create mode 100644 test/fixtures/config/theming/info/taskStop/.gulp.js create mode 100644 test/fixtures/config/theming/info/taskStop/gulpfile.js create mode 100644 test/fixtures/config/theming/info/usingGulpfile/.gulp.js create mode 100644 test/fixtures/config/theming/info/usingGulpfile/gulpfile.js create mode 100644 test/fixtures/config/theming/info/version/.gulp.js create mode 100644 test/fixtures/config/theming/tasks/childTask/.gulp.js create mode 100644 test/fixtures/config/theming/tasks/childTask/gulpfile.js create mode 100644 test/fixtures/config/theming/tasks/gulpfile/.gulp.json create mode 100644 test/fixtures/config/theming/tasks/gulpfile/gulpfile.js create mode 100644 test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json create mode 100644 test/fixtures/config/theming/tasks/gulpfile/remove/gulpfile.js create mode 100644 test/fixtures/config/theming/tasks/option/.gulp.js create mode 100644 test/fixtures/config/theming/tasks/option/gulpfile.js create mode 100644 test/fixtures/config/theming/tasks/topTask/.gulp.js create mode 100644 test/fixtures/config/theming/tasks/topTask/gulpfile.js create mode 100644 test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json create mode 100644 test/fixtures/config/theming/tasksJson/gulpfile/gulpfile.js create mode 100644 test/fixtures/config/theming/warn/loaderFailure/.gulp.js create mode 100644 test/fixtures/config/theming/warn/loaderFailure/gulpfile.coffee create mode 100644 test/fixtures/config/theming/warn/preloadFailure/.gulp.js create mode 100644 test/fixtures/config/theming/warn/preloadFailure/gulpfile.js create mode 100644 test/fixtures/config/theming/warn/taskNotComplete/.gulp.js create mode 100644 test/fixtures/config/theming/warn/taskNotComplete/gulpfile.js create mode 100644 test/fixtures/errors/yarn/yarn.lock create mode 100644 test/lib/check-task-not-found.js diff --git a/.gitignore b/.gitignore index 3b569a93..9ad73290 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.log node_modules !test/fixtures/errors/bad-gulp-version/node_modules/ +!test/fixtures/config/theming/error/badGulpVersion/node_modules/ build *.node components diff --git a/index.js b/index.js index 1f928acb..e2683894 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ var theme = require('./lib/shared/log/theme'); var msgs = require('./lib/shared/log/messages'); var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); -var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); +var overrideEnvByConfigAndCliOpts = require('./lib/shared/config/env-config'); // Get supported ranges var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); @@ -100,7 +100,7 @@ module.exports = run; function onPrepare(env) { var cfg = mergeProjectAndUserHomeConfigs(env); - env = overrideEnvFlagsByConfigAndCliOpts(env, cfg, opts); + env = overrideEnvByConfigAndCliOpts(env, cfg, opts); // Set up event listeners for logging again after configuring. toConsole(log, env.config.flags); @@ -131,7 +131,6 @@ function onExecute(env) { } if (!env.modulePath) { - /* istanbul ignore next */ var missingNodeModules = fs.existsSync(path.join(env.cwd, 'package.json')) && !fs.existsSync(path.join(env.cwd, 'node_modules')); @@ -139,7 +138,6 @@ function onExecute(env) { var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); var hasNpm = !hasYarn; - /* istanbul ignore if */ if (missingNodeModules) { log.error(msgs.error.nodeModulesNotFound, tildify(env.cwd), hasYarn, hasNpm); } else { diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-config.js similarity index 78% rename from lib/shared/config/env-flags.js rename to lib/shared/config/env-config.js index 59b4d4be..4fc34e54 100644 --- a/lib/shared/config/env-flags.js +++ b/lib/shared/config/env-config.js @@ -5,6 +5,9 @@ var copyProps = require('copy-props'); var mergeCliOpts = require('./cli-flags'); +var theme = require('../log/theme'); +var msgs = require('../log/messages'); + var toEnvFromConfig = { configPath: 'flags.gulpfile', configBase: 'flags.gulpfile', @@ -12,7 +15,7 @@ var toEnvFromConfig = { nodeFlags: 'flags.nodeFlags', }; -function overrideEnvFlags(env, config, cliOpts) { +function overrideEnvConfig(env, config, cliOpts) { cliOpts = mergeCliOpts(cliOpts, config); // This must reverse because `flags.gulpfile` determines 2 different properties @@ -21,10 +24,18 @@ function overrideEnvFlags(env, config, cliOpts) { env.config = { flags: cliOpts, + theme: theme, + msgs: msgs, }; if (config.description) { env.config.description = config.description; } + if (config.theme) { + copyProps(config.theme, env.config.theme); + } + if (config.msgs) { + copyProps(config.msgs, env.config.msgs); + } return env function convert(configInfo, envInfo) { @@ -53,4 +64,4 @@ function overrideEnvFlags(env, config, cliOpts) { } } -module.exports = overrideEnvFlags; +module.exports = overrideEnvConfig; diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js index 8202f182..e3c17a81 100644 --- a/lib/shared/config/merge-configs.js +++ b/lib/shared/config/merge-configs.js @@ -5,6 +5,7 @@ var path = require('path'); function mergeConfigs(env) { var cfg = {}; + /* istanbul ignore if */ if (env.configFiles.userHome) { copyConfig(env.config.userHome, cfg, env.configFiles.userHome); } diff --git a/lib/shared/log/messages.js b/lib/shared/log/messages.js index 642f94aa..c4f5937f 100644 --- a/lib/shared/log/messages.js +++ b/lib/shared/log/messages.js @@ -158,7 +158,7 @@ module.exports = { '{IF:{3:has cause}?\n{TIMESTAMP}{ERROR: {4:cause}}}', taskNotFound: - '{TIMESTAMP}{ERROR: Task never defined: {1:task}}\n' + + '{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: diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 1a6db4ed..b84791ed 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -15,7 +15,7 @@ function logTasks(tree, opts, getTask) { var maxDepth = opts.tasksDepth; if (typeof maxDepth !== 'number') { maxDepth = 50; - } else if (maxDepth < 1) { + } else /* istanbul ignore if */ if (maxDepth < 1) { maxDepth = 1; } @@ -38,7 +38,7 @@ function printTaskTree(tree, opts) { 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); + maxLabelWidth = Math.max(maxLabelWidth, w || /* istanbul ignore next */ 0); }); lines.forEach(function(line) { diff --git a/lib/shared/log/timestamp.js b/lib/shared/log/timestamp.js index 99c71d46..4e9dd9a6 100644 --- a/lib/shared/log/timestamp.js +++ b/lib/shared/log/timestamp.js @@ -1,6 +1,7 @@ 'use strict'; function timestamp(format) { + /* istanbul ignore if */ if (typeof format !== 'string') { return noop; } @@ -42,6 +43,7 @@ function timestamp(format) { return result; } +/* istanbul ignore next */ function noop() { return ""; } diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 9bcf3335..844343aa 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -16,11 +16,12 @@ var levels = [ ]; function consoleLog(s) { - if (s != null) console.log(s); + if (s) console.log(s); } function consoleError(s) { - if (s != null) console.error(s); + /* istanbul ignore else */ + if (s) console.error(s); } function cleanup(log) { diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 7da49d19..77c45b87 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -54,14 +54,14 @@ function execute(env) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, true); return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; }); } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, false); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^3.7.0/log/tasks-description.js b/lib/versioned/^3.7.0/log/tasks-description.js index 031ff59e..fe19e397 100644 --- a/lib/versioned/^3.7.0/log/tasks-description.js +++ b/lib/versioned/^3.7.0/log/tasks-description.js @@ -5,14 +5,22 @@ var tildify = require('../../../shared/tildify'); var theme = require('../../../shared/log/theme'); var msgs = require('../../../shared/log/messages'); -function getTasksDescription(env) { +function getTasksDescription(env, isBackslashEscaping) { var desc; if (env.config.description && typeof env.config.description === 'string') { desc = env.config.description; } else { desc = msgs.tasks.gulpfile; } - return format(theme, desc, tildify(env.configPath)); + var gulpfile = tildify(env.configPath); + if (isBackslashEscaping) { + gulpfile = escapeBackslash(gulpfile); + } + return format(theme, desc, gulpfile); +} + +function escapeBackslash(s) { + return s.replace(/\\/g, '\\\\'); } module.exports = getTasksDescription; diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 845a1b85..06d700e0 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -55,7 +55,7 @@ function execute(env) { } if (opts.tasks) { tree = {}; - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, true); tree.nodes = gulpInst.tree({ deep: true }); return logTasks(tree, opts, function(taskname) { @@ -64,7 +64,7 @@ function execute(env) { } if (opts.tasksJson) { tree = {}; - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, false); tree.nodes = gulpInst.tree({ deep: true }); var output = JSON.stringify(copyTree(tree, opts)); @@ -82,9 +82,9 @@ function execute(env) { } }); } catch (err) { - var taskName = checkTaskNotFound(err); - if (taskName) { - log.error(msgs.error.taskNotFound, taskName); + 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); } diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js index 058559ae..23a75047 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -57,12 +57,12 @@ function execute(env) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, true); return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, false); var output = JSON.stringify(copyTree(tree, opts)); @@ -80,9 +80,9 @@ function execute(env) { } }); } catch (err) { - var taskName = checkTaskNotFound(err); - if (taskName) { - log.error(msgs.error.taskNotFound, taskName); + 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); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index a46a8cef..cedd4290 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -57,12 +57,12 @@ function execute(env) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, true); return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, false); var output = JSON.stringify(copyTree(tree, opts)); @@ -80,9 +80,9 @@ function execute(env) { } }); } catch (err) { - var taskName = checkTaskNotFound(err); - if (taskName) { - log.error(msgs.error.taskNotFound, taskName); + 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); } 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 fb45d7fd..e996f212 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 @@ -1,10 +1,24 @@ 'use strict'; function checkTaskNotFound(err) { - var result = /^Task never defined: +(.*)$/.exec(err.message); - /* istanbul ignore else */ - if (result) { - return result[1]; + /* istanbul ignore if */ + if (!err || !err.message) { + return undefined; + } + var fixed0 = 'Task never defined: '; + var fixed1 = ' - did you mean? '; + + if (err.message.startsWith(fixed0)) { + var target = err.message.slice(fixed0.length); + var similar = undefined; + + var index = target.indexOf(fixed1); + if (index >= 0) { + similar = target.slice(index + fixed1.length); + target = target.slice(0, index); + } + + return { target: target, similar: similar }; } } diff --git a/lib/versioned/^4.0.0/log/tasks-description.js b/lib/versioned/^4.0.0/log/tasks-description.js index 031ff59e..fe19e397 100644 --- a/lib/versioned/^4.0.0/log/tasks-description.js +++ b/lib/versioned/^4.0.0/log/tasks-description.js @@ -5,14 +5,22 @@ var tildify = require('../../../shared/tildify'); var theme = require('../../../shared/log/theme'); var msgs = require('../../../shared/log/messages'); -function getTasksDescription(env) { +function getTasksDescription(env, isBackslashEscaping) { var desc; if (env.config.description && typeof env.config.description === 'string') { desc = env.config.description; } else { desc = msgs.tasks.gulpfile; } - return format(theme, desc, tildify(env.configPath)); + var gulpfile = tildify(env.configPath); + if (isBackslashEscaping) { + gulpfile = escapeBackslash(gulpfile); + } + return format(theme, desc, gulpfile); +} + +function escapeBackslash(s) { + return s.replace(/\\/g, '\\\\'); } module.exports = getTasksDescription; diff --git a/test/config-theme-and-msgs.js b/test/config-theme-and-msgs.js new file mode 100644 index 00000000..89032891 --- /dev/null +++ b/test/config-theme-and-msgs.js @@ -0,0 +1,561 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); +var fs = require('fs'); +var os = require('os'); + +var tildify = require('../lib/shared/tildify'); + +var baseDir = path.join(__dirname, 'fixtures/config/theming'); +var expectedDir = path.join(__dirname, 'expected/config/theming'); + +var eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var gulp = require('./tool/gulp-cmd'); + +describe('config: theme.* & msgs.*', function() { + + it('Should change help.usage with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'help/usage'); + var expected =fs.readFileSync(path.join(expectedDir, 'help/usage/help.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('--help'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(err); + } + }); + + it('Should change help.flags.* with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'help/flags'); + var expected =fs.readFileSync(path.join(expectedDir, 'help/flags/help.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('--help'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(err); + } + }); + + it('Should change tasks.gulpfile with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/gulpfile'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = '** ' + gulpfile + ' **\n' + + '└── default\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should remove task.gulpfile line output with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/gulpfile/remove'); + var expected = '└── default\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change tasks.topTask with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/topTask'); + 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' + + '│ └─┬ \n' + + '│ ├── taskA\n' + + '│ └── taskB\n' + + '├── **taskA** This is 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'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change tasks.option with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/option'); + 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' + + '│ └─┬ \n' + + '│ ├── taskA\n' + + '│ └── taskB\n' + + '├── taskA This is 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'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change tasks.childTask with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/childTask'); + 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' + + '│ └─┬ ****\n' + + '│ ├── **taskA**\n' + + '│ └── **taskB**\n' + + '├── taskA This is 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'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change tasksJson.gulpfile with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasksJson/gulpfile'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = JSON.stringify({ + label: '** ' + gulpfile + ' **', + nodes: [{ + label: 'default', + type: 'task', + nodes: [], + }], + }) + '\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks-json'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change info.preloadBefore with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/preloadBefore'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'PRELOADING **./preload**\n' + + 'Preloaded external module: ./preload\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload ./preload'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.preloadSuccess with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/preloadSuccess'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Preloading external module: ./preload\n' + + 'PRELOADDED **./preload**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload ./preload'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.loaderSuccess with .gulp.*', function(done) { + this.timeout(0); + + var cwd = path.join(baseDir, 'info/loaderSuccess'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.babel.js')); + var expected = 'LOADED **@babel/register**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('-f gulpfile.babel.js'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.respawn with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/respawn'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'RESPAWN BY **--lazy**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('--lazy'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.version with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/version'); + var expected = /gulp-cli @@v\d.\d.\d@@ | gulp @@v\d.\d.\d@@\n/; + + var opts = { cwd: cwd }; + exec(gulp('--version'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toMatch(expected); + done(err); + } + }); + + it('Should change info.cwdChanged with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/cwdChanged'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'CHANGE CWD TO **' + tildify(cwd) + '**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: baseDir }; + exec(gulp('--cwd ' + cwd), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.usingGulpfile with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/usingGulpfile'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'USING GULPFILE **' + gulpfile + '**\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.taskStart with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/taskStart'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Using gulpfile ' + gulpfile + '\n' + + 'START **default**\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.taskStop with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/taskStop'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'STOP **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(err); + } + }); + + it('Should change warn.preloadFailure with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'warn/preloadFailure'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Preloading external module: null-module\n' + + 'FAILED TO PRELOAD **null-module**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload null-module'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change warn.loaderFailure with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'warn/loaderFailure'); + var expected = 'FAIL TO LOAD **coffeescript/register**\n'; + + var opts = { cwd: cwd }; + exec(gulp('-f gulpfile.coffee'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).not.toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(); + } + }); + + it('Should change warn.taskNotComplete with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'warn/taskNotComplete'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'TASK **default** DID NOT COMPLETE\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(); + } + }); + + it('Should change error.gulpNotFound with .gulp.*', function(done) { + var dir = path.join(baseDir, 'error/gulpNotFound'); + var cwd = os.tmpdir(); + fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + if (os.platform() === 'darwin') { + cwd = path.join('/private', cwd); + } + var expected = 'GULP NOT FOUND IN **' + cwd + '**\n'; + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } finally { + fs.unlinkSync(path.join(cwd, '.gulp.js')); + } + } + }); + + it('Should change error.nodeModulesNotFound with .gulp.*', function(done) { + var dir = path.join(baseDir, 'error/nodeModulesNotFound'); + var cwd = os.tmpdir(); + fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); + fs.copyFileSync(path.join(dir, 'package.json'), path.join(cwd, 'package.json')); + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + if (os.platform() === 'darwin') { + cwd = path.join('/private', cwd); + } + var expected = 'LOCAL MODULE NOT FOUND **' + cwd + '**\n'; + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } finally { + fs.unlinkSync(path.join(cwd, '.gulp.js')); + fs.unlinkSync(path.join(cwd, 'package.json')); + } + } + }); + + it('Should change error.gulpfileNotFound with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/gulpfileNotFound'); + var expected = 'NO GULPFILE\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } + }); + + it('Should change error.badGulpVersion with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/badGulpVersion'); + var expected = 'BAD GULP VERSION **1.2.3**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } + }); + + it('Should change error.taskError with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/taskError'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expectedStdout = 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n'; + var expectedStderr = 'TASK ERROR: **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(eraseTime(stderr)).toEqual(expectedStderr); + expect(eraseTime(stdout)).toEqual(expectedStdout); + done(); + } + }); + + it('Should change error.taskNotFound with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/taskNotFound'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expectedStdout = 'Using gulpfile ' + gulpfile + '\n'; + var expectedStderr = 'TASK IS NOT FOUND: **defaults** SIMILAR ##default##'; + + var opts = { cwd: cwd }; + exec(gulp('defaults'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(eraseTime(stderr)).toMatch(expectedStderr); + expect(eraseTime(stdout)).toEqual(expectedStdout); + done(); + } + }); + + it('Should change error.failToRun with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/failToRun'); + var expected = 'FAIL TO RUN\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(expected); + expect(stdout).toEqual(''); + done(); + } + }); + + it('Should change error.noCompletionType with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/noCompletionType'); + var expected = 'NO COMPLETION TYPE'; + + var opts = { cwd: cwd }; + exec(gulp('--completion'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toMatch(expected); + expect(stdout).toEqual(''); + done(); + } + }); + + it('Should change error.unknownCompletionType with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/unknownCompletionType'); + var expected = 'GULP COMPLETION TYPE **xxx** IS NOT FOUND\n'; + + var opts = { cwd: cwd }; + exec(gulp('--completion=xxx'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(); + } + }); +}); diff --git a/test/execution-errors.js b/test/execution-errors.js index 769832a9..7b2fd1ec 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -4,6 +4,7 @@ var expect = require('expect'); var exec = require('child_process').exec; var path = require('path'); var os = require('os'); +var fs = require('fs'); var tildify = require('../lib/shared/tildify'); @@ -29,6 +30,21 @@ describe('execution error', function() { } }); + it('should output an error if a task is not defined but a similar task is found', function(done) { + var opts = { cwd: path.join(__dirname, './fixtures/gulpfiles') }; + exec(gulp('test0'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toMatch('Using gulpfile '); + expect(eraseTime(stderr)).toEqual( + 'Task never defined: test0 - did you mean? test1, test2, test3, test4, test5, test6, test7, test8\n' + + 'To list available tasks, try running: gulp --tasks\n'); + done(); + } + }); + it('should output an error if gulp version is unsupported', function(done) { var opts = { cwd: path.join(__dirname, './fixtures/errors/bad-gulp-version') }; exec(gulp(), opts, cb); @@ -42,7 +58,7 @@ describe('execution error', function() { } }); - it('should output an error if gulp is not found', function(done) { + it('should output an error if gulp is not found (npm)', function(done) { var opts = { cwd: os.tmpdir() }; exec(gulp(), opts, cb); @@ -55,6 +71,79 @@ describe('execution error', function() { } }); + it('should output an error if gulp is not found (yarn)', function(done) { + var cwd = os.tmpdir(); + var yarnOrig= path.join(__dirname, 'fixtures/errors/yarn/yarn.lock'); + var yarnLock = path.join(cwd, 'yarn.lock'); + + fs.copyFileSync(yarnOrig, yarnLock); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local gulp not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: yarn add gulp'); + done(); + } finally { + fs.unlinkSync(yarnLock); + } + } + }); + + it('should output an error if local modules are not found (npm)', function(done) { + var cwd = os.tmpdir(); + var pkgOrig = path.join(__dirname, 'fixtures/errors/package.json'); + var pkgJson = path.join(cwd, 'package.json'); + + fs.copyFileSync(pkgOrig, pkgJson); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local modules not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: npm install'); + done(); + } finally { + fs.unlinkSync(pkgJson); + } + } + }); + + it('should output an error if local modules are not found (yarn)', function(done) { + var cwd = os.tmpdir(); + var pkgOrig = path.join(__dirname, 'fixtures/errors/package.json'); + var pkgJson = path.join(cwd, 'package.json'); + var yarnOrig= path.join(__dirname, 'fixtures/errors/yarn/yarn.lock'); + var yarnLock = path.join(cwd, 'yarn.lock'); + + fs.copyFileSync(pkgOrig, pkgJson); + fs.copyFileSync(yarnOrig, yarnLock); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local modules not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: yarn install'); + done(); + } finally { + fs.unlinkSync(pkgJson); + fs.unlinkSync(yarnLock); + } + } + }); + it('should log a same error once', function(done) { var dir = path.join(__dirname, 'fixtures/gulpfiles'); var gulpfileName = 'gulpfile-dedup-errorlog.js'; diff --git a/test/expected/config/theming/help/flags/help.txt b/test/expected/config/theming/help/flags/help.txt new file mode 100644 index 00000000..3fae82da --- /dev/null +++ b/test/expected/config/theming/help/flags/help.txt @@ -0,0 +1,21 @@ + +Usage: gulp [options] tasks + +Options: + -h, --help **HELP** [boolean] + -v, --version **VERSION** [boolean] + --preload **PRELOAD** [string] + -f, --gulpfile **GULPFILE** [string] + --cwd **CWD** [string] + -T, --tasks **TASKS** [boolean] + --tasks-simple **TASKS SIMPLE** [boolean] + --tasks-json **TASKS JSON** + --tasks-depth, --depth **TASKS DEPTH** [number] + --compact-tasks **COMPACT TASKS** [boolean] + --sort-tasks **SORT_TASKS** [boolean] + --color **COLOR** [boolean] + --no-color **NO COLOR** [boolean] + -S, --silent **SILENT** [boolean] + --continue **CONTINUE** [boolean] + --series **SERIES** [boolean] + -L, --log-level **LOG LEVEL** [count] diff --git a/test/expected/config/theming/help/usage/help.txt b/test/expected/config/theming/help/usage/help.txt new file mode 100644 index 00000000..b03f78bd --- /dev/null +++ b/test/expected/config/theming/help/usage/help.txt @@ -0,0 +1,39 @@ +GULP USAGE + +Options: + -h, --help Show this help. [boolean] + -v, --version Print the global and local gulp versions.[boolean] + --preload Will preload a module before running the gulpfile. + This is useful for transpilers but also has other + applications. [string] + -f, --gulpfile Manually set path of gulpfile. Useful if you have + multiple gulpfiles. This will set the CWD to the + gulpfile directory as well. [string] + --cwd Manually set the CWD. The search for the gulpfile, + as well as the relativity of all requires will be + from here. [string] + -T, --tasks Print the task dependency tree for the loaded + gulpfile. [boolean] + --tasks-simple Print a plaintext list of tasks for the loaded + gulpfile. [boolean] + --tasks-json Print the task dependency tree, in JSON format, + for the loaded gulpfile. + --tasks-depth, --depth Specify the depth of the task dependency tree. + [number] + --compact-tasks Reduce the output of task dependency tree by + printing only top tasks and their child tasks. + [boolean] + --sort-tasks Will sort top tasks of task dependency tree. + [boolean] + --color Will force gulp and gulp plugins to display + colors, even when no color support is detected. + [boolean] + --no-color Will force gulp and gulp plugins to not display + colors, even when color support is detected. + [boolean] + -S, --silent Suppress all gulp logging. [boolean] + --continue Continue execution of tasks upon failure.[boolean] + --series Run tasks given on the CLI in series (the default + is parallel). [boolean] + -L, --log-level Set the loglevel. -L for least verbose and -LLLL + for most verbose. -LLL is default. [count] diff --git a/test/fixtures/config/theming/error/badGulpVersion/.gulp.js b/test/fixtures/config/theming/error/badGulpVersion/.gulp.js new file mode 100644 index 00000000..d923bd09 --- /dev/null +++ b/test/fixtures/config/theming/error/badGulpVersion/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + error: { + badGulpVersion: '{TIMESTAMP}BAD GULP VERSION {GulpVer:{1}}', + }, + }, + theme: { + GulpVer: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/badGulpVersion/gulpfile.js b/test/fixtures/config/theming/error/badGulpVersion/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/badGulpVersion/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/index.js b/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/package.json b/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/package.json new file mode 100644 index 00000000..dbe8ece4 --- /dev/null +++ b/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/package.json @@ -0,0 +1,15 @@ +{ + "name": "gulp", + "description": "Test Package for Testing!", + "version": "1.2.3", + "tags": [ + ], + "files": [ + ], + "licenses": [ + { + "type": "MIT", + "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" + } + ] +} diff --git a/test/fixtures/config/theming/error/failToRun/.gulp.js b/test/fixtures/config/theming/error/failToRun/.gulp.js new file mode 100644 index 00000000..c93d52de --- /dev/null +++ b/test/fixtures/config/theming/error/failToRun/.gulp.js @@ -0,0 +1,8 @@ +module.exports = { + msgs: { + info: null, // To cause failToRun error forcefully + error: { + failToRun: 'FAIL TO RUN', + }, + }, +}; diff --git a/test/fixtures/config/theming/error/failToRun/gulpfile.js b/test/fixtures/config/theming/error/failToRun/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/failToRun/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/error/gulpNotFound/.gulp.js b/test/fixtures/config/theming/error/gulpNotFound/.gulp.js new file mode 100644 index 00000000..3d8bb0b4 --- /dev/null +++ b/test/fixtures/config/theming/error/gulpNotFound/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + error: { + gulpNotFound: 'GULP NOT FOUND IN {CwdPath: {1}}', + }, + }, + theme: { + CwdPath: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js b/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js new file mode 100644 index 00000000..a96938cb --- /dev/null +++ b/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js @@ -0,0 +1,7 @@ +module.exports = { + msgs: { + error: { + gulpfileNotFound: '{TIMESTAMP}NO GULPFILE', + }, + }, +}; diff --git a/test/fixtures/config/theming/error/noCompletionType/.gulp.js b/test/fixtures/config/theming/error/noCompletionType/.gulp.js new file mode 100644 index 00000000..6817dbf5 --- /dev/null +++ b/test/fixtures/config/theming/error/noCompletionType/.gulp.js @@ -0,0 +1,7 @@ +module.exports = { + msgs: { + error: { + noCompletionType: 'NO COMPLETION TYPE', + }, + }, +}; diff --git a/test/fixtures/config/theming/error/noCompletionType/gulpfile.js b/test/fixtures/config/theming/error/noCompletionType/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/noCompletionType/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js b/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js new file mode 100644 index 00000000..2576d4cc --- /dev/null +++ b/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js @@ -0,0 +1,12 @@ +var os = require('os'); + +module.exports = { + msgs: { + error: { + nodeModulesNotFound: 'LOCAL MODULE NOT FOUND {Path: {1}}', + }, + }, + theme: { + Path: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/nodeModulesNotFound/package.json b/test/fixtures/config/theming/error/nodeModulesNotFound/package.json new file mode 100644 index 00000000..109ec6a8 --- /dev/null +++ b/test/fixtures/config/theming/error/nodeModulesNotFound/package.json @@ -0,0 +1,12 @@ +{ + "name": "nodeModulesNotFound", + "version": "1.0.0", + "description": "", + "main": ".gulp.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/test/fixtures/config/theming/error/taskError/.gulp.js b/test/fixtures/config/theming/error/taskError/.gulp.js new file mode 100644 index 00000000..534a1456 --- /dev/null +++ b/test/fixtures/config/theming/error/taskError/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + error: { + taskError: '{TIMESTAMP}TASK ERROR: {TaskName:{1}}', + }, + }, + theme: { + TaskName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/taskError/gulpfile.js b/test/fixtures/config/theming/error/taskError/gulpfile.js new file mode 100644 index 00000000..eeb90fd6 --- /dev/null +++ b/test/fixtures/config/theming/error/taskError/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + throw new Error('FAIL!'); +} diff --git a/test/fixtures/config/theming/error/taskNotFound/.gulp.js b/test/fixtures/config/theming/error/taskNotFound/.gulp.js new file mode 100644 index 00000000..12545808 --- /dev/null +++ b/test/fixtures/config/theming/error/taskNotFound/.gulp.js @@ -0,0 +1,11 @@ +module.exports = { + msgs: { + error: { + taskNotFound: '{TIMESTAMP}TASK IS NOT FOUND: {TaskName:{1}}{IF:{2}? SIMILAR {SimilarTasks:{3}}}', + }, + }, + theme: { + TaskName: '**{1}**', + SimilarTasks: '##{1}##', + }, +}; diff --git a/test/fixtures/config/theming/error/taskNotFound/gulpfile.js b/test/fixtures/config/theming/error/taskNotFound/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/taskNotFound/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js b/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js new file mode 100644 index 00000000..0676f0a8 --- /dev/null +++ b/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + error: { + unknownCompletionType: 'GULP COMPLETION TYPE {Type: {1}} IS NOT FOUND', + }, + }, + theme: { + Type: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/unknownCompletionType/gulpfile.js b/test/fixtures/config/theming/error/unknownCompletionType/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/unknownCompletionType/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/help/flags/.gulp.js b/test/fixtures/config/theming/help/flags/.gulp.js new file mode 100644 index 00000000..1a008528 --- /dev/null +++ b/test/fixtures/config/theming/help/flags/.gulp.js @@ -0,0 +1,28 @@ +module.exports = { + msgs: { + help: { + flags: { + help: '{help_desc: HELP}', + version: '{help_desc: VERSION}', + preload: '{help_desc: PRELOAD}', + gulpfile: '{help_desc: GULPFILE}', + cwd: '{help_desc: CWD}', + tasks: '{help_desc: TASKS}', + 'tasks-simple': '{help_desc: TASKS SIMPLE}', + 'tasks-json': '{help_desc: TASKS JSON}', + 'tasks-depth': '{help_desc: TASKS DEPTH}', + 'compact-tasks': '{help_desc: COMPACT TASKS}', + 'sort-tasks': '{help_desc: SORT_TASKS}', + color: '{help_desc: COLOR}', + 'no-color': '{help_desc: NO COLOR}', + silent: '{help_desc: SILENT}', + continue: '{help_desc: CONTINUE}', + series: '{help_desc: SERIES}', + 'log-level': '{help_desc: LOG LEVEL}', + }, + }, + }, + theme: { + help_desc: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/help/usage/.gulp.js b/test/fixtures/config/theming/help/usage/.gulp.js new file mode 100644 index 00000000..f96d44df --- /dev/null +++ b/test/fixtures/config/theming/help/usage/.gulp.js @@ -0,0 +1,7 @@ +module.exports = { + msgs: { + help: { + usage: 'GULP USAGE', + }, + }, +}; diff --git a/test/fixtures/config/theming/info/cwdChanged/.gulp.js b/test/fixtures/config/theming/info/cwdChanged/.gulp.js new file mode 100644 index 00000000..3c3c9380 --- /dev/null +++ b/test/fixtures/config/theming/info/cwdChanged/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + cwdChanged: '{TIMESTAMP}CHANGE CWD TO {CwdPath: {1}}', + }, + }, + theme: { + CwdPath: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/cwdChanged/gulpfile.js b/test/fixtures/config/theming/info/cwdChanged/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/cwdChanged/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/loaderSuccess/.gulp.js b/test/fixtures/config/theming/info/loaderSuccess/.gulp.js new file mode 100644 index 00000000..ec7df4a5 --- /dev/null +++ b/test/fixtures/config/theming/info/loaderSuccess/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + loaderSuccess: 'LOADED {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/loaderSuccess/gulpfile.babel.js b/test/fixtures/config/theming/info/loaderSuccess/gulpfile.babel.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/loaderSuccess/gulpfile.babel.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/preloadBefore/.gulp.js b/test/fixtures/config/theming/info/preloadBefore/.gulp.js new file mode 100644 index 00000000..a6744dda --- /dev/null +++ b/test/fixtures/config/theming/info/preloadBefore/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + preloadBefore: 'PRELOADING {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/preloadBefore/gulpfile.js b/test/fixtures/config/theming/info/preloadBefore/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadBefore/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/preloadBefore/preload.js b/test/fixtures/config/theming/info/preloadBefore/preload.js new file mode 100644 index 00000000..3b5d0c74 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadBefore/preload.js @@ -0,0 +1 @@ +global.preload = 'hello preload!'; diff --git a/test/fixtures/config/theming/info/preloadSuccess/.gulp.js b/test/fixtures/config/theming/info/preloadSuccess/.gulp.js new file mode 100644 index 00000000..bd6497e2 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadSuccess/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + preloadSuccess: 'PRELOADDED {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/preloadSuccess/gulpfile.js b/test/fixtures/config/theming/info/preloadSuccess/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadSuccess/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/preloadSuccess/preload.js b/test/fixtures/config/theming/info/preloadSuccess/preload.js new file mode 100644 index 00000000..3b5d0c74 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadSuccess/preload.js @@ -0,0 +1 @@ +global.preload = 'hello preload!'; diff --git a/test/fixtures/config/theming/info/respawn/.gulp.js b/test/fixtures/config/theming/info/respawn/.gulp.js new file mode 100644 index 00000000..8f6de9e3 --- /dev/null +++ b/test/fixtures/config/theming/info/respawn/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + respawn: 'RESPAWN BY {NodeFlag: {1}}', + }, + }, + theme: { + NodeFlag: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/respawn/gulpfile.js b/test/fixtures/config/theming/info/respawn/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/respawn/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/taskStart/.gulp.js b/test/fixtures/config/theming/info/taskStart/.gulp.js new file mode 100644 index 00000000..c1cef5d1 --- /dev/null +++ b/test/fixtures/config/theming/info/taskStart/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + taskStart: '{TIMESTAMP}START {Task: {1}}', + }, + }, + theme: { + Task: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/taskStart/gulpfile.js b/test/fixtures/config/theming/info/taskStart/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/taskStart/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/taskStop/.gulp.js b/test/fixtures/config/theming/info/taskStop/.gulp.js new file mode 100644 index 00000000..7c62298c --- /dev/null +++ b/test/fixtures/config/theming/info/taskStop/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + taskStop: '{TIMESTAMP}STOP {Task: {1}}', + }, + }, + theme: { + Task: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/taskStop/gulpfile.js b/test/fixtures/config/theming/info/taskStop/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/taskStop/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/usingGulpfile/.gulp.js b/test/fixtures/config/theming/info/usingGulpfile/.gulp.js new file mode 100644 index 00000000..cea0669a --- /dev/null +++ b/test/fixtures/config/theming/info/usingGulpfile/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + usingGulpfile: '{TIMESTAMP}USING GULPFILE {File:{1}}', + }, + }, + theme: { + File: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/usingGulpfile/gulpfile.js b/test/fixtures/config/theming/info/usingGulpfile/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/usingGulpfile/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/version/.gulp.js b/test/fixtures/config/theming/info/version/.gulp.js new file mode 100644 index 00000000..4183557c --- /dev/null +++ b/test/fixtures/config/theming/info/version/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + version: 'gulp-cli {VERSION: v{1}} | gulp {VERSION: v{2}}', + }, + }, + theme: { + VERSION: '@@{1}@@', + }, +}; diff --git a/test/fixtures/config/theming/tasks/childTask/.gulp.js b/test/fixtures/config/theming/tasks/childTask/.gulp.js new file mode 100644 index 00000000..545b70f9 --- /dev/null +++ b/test/fixtures/config/theming/tasks/childTask/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + tasks: { + childTask: '{1}{child_task: {2}}', + } + }, + theme: { + child_task: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/tasks/childTask/gulpfile.js b/test/fixtures/config/theming/tasks/childTask/gulpfile.js new file mode 100644 index 00000000..b61b53c3 --- /dev/null +++ b/test/fixtures/config/theming/tasks/childTask/gulpfile.js @@ -0,0 +1,27 @@ +const { series } = require('gulp'); + +function taskA(done) { + done(); +} +taskA.description = 'This is task A'; +taskA.flags = { + '--abc': 'is a flag for task A', +}; + +const taskB = function(done) { + done(); +} +taskB.description = 'This is task B'; +taskB.flags = { + '--def': 'is a flag for task B', +}; + +const defaults = series(taskA, taskB); +defaults.description = 'This is default task'; +defaults.flags = { + '--ghi': 'is a flag for default task', +}; + +exports.default = defaults; +exports.taskA = taskA; +exports.taskB = taskB; diff --git a/test/fixtures/config/theming/tasks/gulpfile/.gulp.json b/test/fixtures/config/theming/tasks/gulpfile/.gulp.json new file mode 100644 index 00000000..9255c31f --- /dev/null +++ b/test/fixtures/config/theming/tasks/gulpfile/.gulp.json @@ -0,0 +1,10 @@ +{ + "msgs": { + "tasks": { + "gulpfile": "{FILE: {1}}" + } + }, + "theme": { + "FILE": "** {1} **" + } +} diff --git a/test/fixtures/config/theming/tasks/gulpfile/gulpfile.js b/test/fixtures/config/theming/tasks/gulpfile/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/tasks/gulpfile/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json b/test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json new file mode 100644 index 00000000..2b9fdf1b --- /dev/null +++ b/test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json @@ -0,0 +1,10 @@ +{ + "msgs": { + "tasks": { + "gulpfile": null + } + }, + "theme": { + "FILE": "** {1} **" + } +} diff --git a/test/fixtures/config/theming/tasks/gulpfile/remove/gulpfile.js b/test/fixtures/config/theming/tasks/gulpfile/remove/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/tasks/gulpfile/remove/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/tasks/option/.gulp.js b/test/fixtures/config/theming/tasks/option/.gulp.js new file mode 100644 index 00000000..790af554 --- /dev/null +++ b/test/fixtures/config/theming/tasks/option/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + tasks: { + option: '{1}{OptionName: {2}}{IF:{3}?{4}» {5}}', + } + }, + theme: { + OptionName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/tasks/option/gulpfile.js b/test/fixtures/config/theming/tasks/option/gulpfile.js new file mode 100644 index 00000000..b61b53c3 --- /dev/null +++ b/test/fixtures/config/theming/tasks/option/gulpfile.js @@ -0,0 +1,27 @@ +const { series } = require('gulp'); + +function taskA(done) { + done(); +} +taskA.description = 'This is task A'; +taskA.flags = { + '--abc': 'is a flag for task A', +}; + +const taskB = function(done) { + done(); +} +taskB.description = 'This is task B'; +taskB.flags = { + '--def': 'is a flag for task B', +}; + +const defaults = series(taskA, taskB); +defaults.description = 'This is default task'; +defaults.flags = { + '--ghi': 'is a flag for default task', +}; + +exports.default = defaults; +exports.taskA = taskA; +exports.taskB = taskB; diff --git a/test/fixtures/config/theming/tasks/topTask/.gulp.js b/test/fixtures/config/theming/tasks/topTask/.gulp.js new file mode 100644 index 00000000..b9c00721 --- /dev/null +++ b/test/fixtures/config/theming/tasks/topTask/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + tasks: { + topTask: '{1}{TaskName: {2}}{IF:{3}?{4}{5}}', + } + }, + theme: { + TaskName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/tasks/topTask/gulpfile.js b/test/fixtures/config/theming/tasks/topTask/gulpfile.js new file mode 100644 index 00000000..b61b53c3 --- /dev/null +++ b/test/fixtures/config/theming/tasks/topTask/gulpfile.js @@ -0,0 +1,27 @@ +const { series } = require('gulp'); + +function taskA(done) { + done(); +} +taskA.description = 'This is task A'; +taskA.flags = { + '--abc': 'is a flag for task A', +}; + +const taskB = function(done) { + done(); +} +taskB.description = 'This is task B'; +taskB.flags = { + '--def': 'is a flag for task B', +}; + +const defaults = series(taskA, taskB); +defaults.description = 'This is default task'; +defaults.flags = { + '--ghi': 'is a flag for default task', +}; + +exports.default = defaults; +exports.taskA = taskA; +exports.taskB = taskB; diff --git a/test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json b/test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json new file mode 100644 index 00000000..9255c31f --- /dev/null +++ b/test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json @@ -0,0 +1,10 @@ +{ + "msgs": { + "tasks": { + "gulpfile": "{FILE: {1}}" + } + }, + "theme": { + "FILE": "** {1} **" + } +} diff --git a/test/fixtures/config/theming/tasksJson/gulpfile/gulpfile.js b/test/fixtures/config/theming/tasksJson/gulpfile/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/tasksJson/gulpfile/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/warn/loaderFailure/.gulp.js b/test/fixtures/config/theming/warn/loaderFailure/.gulp.js new file mode 100644 index 00000000..9875f824 --- /dev/null +++ b/test/fixtures/config/theming/warn/loaderFailure/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + warn: { + loaderFailure: '{TIMESTAMP}FAIL TO LOAD {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/warn/loaderFailure/gulpfile.coffee b/test/fixtures/config/theming/warn/loaderFailure/gulpfile.coffee new file mode 100644 index 00000000..1f8b8541 --- /dev/null +++ b/test/fixtures/config/theming/warn/loaderFailure/gulpfile.coffee @@ -0,0 +1 @@ +console.log 'hello' diff --git a/test/fixtures/config/theming/warn/preloadFailure/.gulp.js b/test/fixtures/config/theming/warn/preloadFailure/.gulp.js new file mode 100644 index 00000000..50e3bcc6 --- /dev/null +++ b/test/fixtures/config/theming/warn/preloadFailure/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + warn: { + preloadFailure: '{TIMESTAMP}FAILED TO PRELOAD {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/warn/preloadFailure/gulpfile.js b/test/fixtures/config/theming/warn/preloadFailure/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/warn/preloadFailure/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js b/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js new file mode 100644 index 00000000..df6bd57f --- /dev/null +++ b/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + warn: { + taskNotComplete: '{TIMESTAMP}TASK {TaskName: {1}} DID NOT COMPLETE', + }, + }, + theme: { + TaskName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/warn/taskNotComplete/gulpfile.js b/test/fixtures/config/theming/warn/taskNotComplete/gulpfile.js new file mode 100644 index 00000000..1e950f9a --- /dev/null +++ b/test/fixtures/config/theming/warn/taskNotComplete/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + //done(); +} diff --git a/test/fixtures/errors/yarn/yarn.lock b/test/fixtures/errors/yarn/yarn.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 4a1c689f..f43279c0 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -31,7 +31,7 @@ describe('flag: --tasks', function() { } }); - it('print the task list with description and flags', function(done) { + it('prints the task list with description and flags', function(done) { var opts = { cwd: baseDir }; exec(gulp( '--tasks', @@ -50,7 +50,7 @@ describe('flag: --tasks', function() { } }); - it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { + it('prints the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { var opts = { cwd: baseDir }; exec(gulp( '--tasks', diff --git a/test/lib/check-task-not-found.js b/test/lib/check-task-not-found.js new file mode 100644 index 00000000..932c753c --- /dev/null +++ b/test/lib/check-task-not-found.js @@ -0,0 +1,28 @@ +'use strict'; + +var expect = require('expect'); +var checkTaskNotFound = require('../../lib/versioned/^4.0.0/log/check-task-not-found'); + +describe('lib: checkTaskNotFound', function() { + + it('Should return target task and similar tasks if both are included in error message', function(done) { + var err = new Error('Task never defined: task2 - did you mean? task0, task1'); + expect(checkTaskNotFound(err)).toEqual({ + target: 'task2', + similar: 'task0, task1', + }); + done(); + }); + + it('Should return only target task if similar tasks is not included in error message', function(done) { + var err = new Error('Task never defined: task2'); + expect(checkTaskNotFound(err)).toEqual({ target: 'task2' }); + done(); + }); + + it('Should return undefined if error is other', function(done) { + var err = new Error('xxx'); + expect(checkTaskNotFound(err)).toBeUndefined(); + done(); + }); +}); From 2d3a80d5cdf98661e46f23914c649bde5708c3e6 Mon Sep 17 00:00:00 2001 From: sttk Date: Mon, 12 Feb 2024 17:33:58 +0900 Subject: [PATCH 03/43] fix: add handling for yargs message when cli options are invalid. --- index.js | 13 +++++- lib/shared/log/messages.js | 3 ++ lib/shared/options/parser.js | 3 ++ test/config-theme-and-msgs.js | 23 +++++++++-- .../theming/error/failToParseCliOpts/help.txt | 41 +++++++++++++++++++ .../theming/error/failToParseCliOpts/.gulp.js | 7 ++++ test/flags-help.js | 11 +++++ 7 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 test/expected/config/theming/error/failToParseCliOpts/help.txt create mode 100644 test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js diff --git a/index.js b/index.js index e2683894..ccfa53b3 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,13 @@ var cli = new Liftoff({ }, }); -var opts = parser.argv; +var opts = {}; +var optsErr; +try { + opts = parser.argv; +} catch (e) { + optsErr = e; +} cli.on('preload:before', function(name) { log.info(msgs.info.preloadBefore, name); @@ -118,6 +124,11 @@ 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); diff --git a/lib/shared/log/messages.js b/lib/shared/log/messages.js index c4f5937f..6e8f9927 100644 --- a/lib/shared/log/messages.js +++ b/lib/shared/log/messages.js @@ -138,6 +138,9 @@ module.exports = { }, 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}', diff --git a/lib/shared/options/parser.js b/lib/shared/options/parser.js index 3326aaba..52aa7e07 100644 --- a/lib/shared/options/parser.js +++ b/lib/shared/options/parser.js @@ -76,6 +76,9 @@ var options = { var parser = yargs .help(false).version(false).detectLocale(false) + .showHelpOnFail(false) + .exitProcess(false) + .fail(function(msg) { throw new Error(msg); }) .options(options); module.exports = parser; diff --git a/test/config-theme-and-msgs.js b/test/config-theme-and-msgs.js index 89032891..60c77558 100644 --- a/test/config-theme-and-msgs.js +++ b/test/config-theme-and-msgs.js @@ -19,7 +19,7 @@ describe('config: theme.* & msgs.*', function() { it('Should change help.usage with .gulp.*', function(done) { var cwd = path.join(baseDir, 'help/usage'); - var expected =fs.readFileSync(path.join(expectedDir, 'help/usage/help.txt'), 'utf8'); + var expected = fs.readFileSync(path.join(expectedDir, 'help/usage/help.txt'), 'utf8'); var opts = { cwd: cwd }; exec(gulp('--help'), opts, cb); @@ -27,14 +27,14 @@ describe('config: theme.* & msgs.*', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual(expected); + expect(stdout).toEqual(expected); done(err); } }); it('Should change help.flags.* with .gulp.*', function(done) { var cwd = path.join(baseDir, 'help/flags'); - var expected =fs.readFileSync(path.join(expectedDir, 'help/flags/help.txt'), 'utf8'); + var expected = fs.readFileSync(path.join(expectedDir, 'help/flags/help.txt'), 'utf8'); var opts = { cwd: cwd }; exec(gulp('--help'), opts, cb); @@ -42,7 +42,7 @@ describe('config: theme.* & msgs.*', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual(expected); + expect(stdout).toEqual(expected); done(err); } }); @@ -398,6 +398,21 @@ describe('config: theme.* & msgs.*', function() { } }); + it('Should change error.failToParseCliOpts with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/failToParseCliOpts'); + var expected = fs.readFileSync(path.join(expectedDir, 'error/failToParseCliOpts/help.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('-f'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } + }); + it('Should change error.gulpNotFound with .gulp.*', function(done) { var dir = path.join(baseDir, 'error/gulpNotFound'); var cwd = os.tmpdir(); diff --git a/test/expected/config/theming/error/failToParseCliOpts/help.txt b/test/expected/config/theming/error/failToParseCliOpts/help.txt new file mode 100644 index 00000000..5d37e6fa --- /dev/null +++ b/test/expected/config/theming/error/failToParseCliOpts/help.txt @@ -0,0 +1,41 @@ +**Not enough arguments following: f** + +Usage: gulp [options] tasks + +Options: + -h, --help Show this help. [boolean] + -v, --version Print the global and local gulp versions.[boolean] + --preload Will preload a module before running the gulpfile. + This is useful for transpilers but also has other + applications. [string] + -f, --gulpfile Manually set path of gulpfile. Useful if you have + multiple gulpfiles. This will set the CWD to the + gulpfile directory as well. [string] + --cwd Manually set the CWD. The search for the gulpfile, + as well as the relativity of all requires will be + from here. [string] + -T, --tasks Print the task dependency tree for the loaded + gulpfile. [boolean] + --tasks-simple Print a plaintext list of tasks for the loaded + gulpfile. [boolean] + --tasks-json Print the task dependency tree, in JSON format, + for the loaded gulpfile. + --tasks-depth, --depth Specify the depth of the task dependency tree. + [number] + --compact-tasks Reduce the output of task dependency tree by + printing only top tasks and their child tasks. + [boolean] + --sort-tasks Will sort top tasks of task dependency tree. + [boolean] + --color Will force gulp and gulp plugins to display + colors, even when no color support is detected. + [boolean] + --no-color Will force gulp and gulp plugins to not display + colors, even when color support is detected. + [boolean] + -S, --silent Suppress all gulp logging. [boolean] + --continue Continue execution of tasks upon failure.[boolean] + --series Run tasks given on the CLI in series (the default + is parallel). [boolean] + -L, --log-level Set the loglevel. -L for least verbose and -LLLL + for most verbose. -LLL is default. [count] diff --git a/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js b/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js new file mode 100644 index 00000000..0e606d8b --- /dev/null +++ b/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js @@ -0,0 +1,7 @@ +module.exports = { + msgs: { + error: { + failToParseCliOpts: '**{1}**', + }, + }, +}; diff --git a/test/flags-help.js b/test/flags-help.js index b1947b41..3007e288 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -58,4 +58,15 @@ describe('flag: --help', function() { } }); + it('show error message and help if options are invalid', function(done) { + var opts = { cwd: baseDir }; + exec(gulp('-f'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual('Not enough arguments following: f\n' + outputText); + done(); + } + }); }); From a39ab8c3010ca74907a0f4c94ace8fac7bb9d331 Mon Sep 17 00:00:00 2001 From: sttk Date: Mon, 12 Feb 2024 23:36:00 +0900 Subject: [PATCH 04/43] fix: rename msgs.tasks/tasksJson.gulpfile to msgs.tasks/tasksJson.description. --- lib/shared/log/messages.js | 4 +-- lib/shared/log/tasks.js | 7 +++-- lib/versioned/^3.7.0/index.js | 18 ++++++++++--- lib/versioned/^3.7.0/log/tasks-description.js | 26 ------------------- lib/versioned/^4.0.0-alpha.1/index.js | 18 ++++++++++--- lib/versioned/^4.0.0-alpha.2/index.js | 18 ++++++++++--- lib/versioned/^4.0.0/index.js | 18 ++++++++++--- lib/versioned/^4.0.0/log/tasks-description.js | 26 ------------------- test/config-theme-and-msgs.js | 8 +++--- .../gulpfile => tasks/description}/.gulp.json | 2 +- .../{gulpfile => description}/gulpfile.js | 0 .../tasks/description/remove/.gulp.json | 7 +++++ .../remove/gulpfile.js | 0 .../theming/tasks/gulpfile/remove/.gulp.json | 10 ------- .../description}/.gulp.json | 4 +-- .../{gulpfile => description}/gulpfile.js | 0 16 files changed, 79 insertions(+), 87 deletions(-) delete mode 100644 lib/versioned/^3.7.0/log/tasks-description.js delete mode 100644 lib/versioned/^4.0.0/log/tasks-description.js rename test/fixtures/config/theming/{tasksJson/gulpfile => tasks/description}/.gulp.json (70%) rename test/fixtures/config/theming/tasks/{gulpfile => description}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/tasks/description/remove/.gulp.json rename test/fixtures/config/theming/tasks/{gulpfile => description}/remove/gulpfile.js (100%) delete mode 100644 test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json rename test/fixtures/config/theming/{tasks/gulpfile => tasksJson/description}/.gulp.json (55%) rename test/fixtures/config/theming/tasksJson/{gulpfile => description}/gulpfile.js (100%) diff --git a/lib/shared/log/messages.js b/lib/shared/log/messages.js index 6e8f9927..a2803e3a 100644 --- a/lib/shared/log/messages.js +++ b/lib/shared/log/messages.js @@ -73,7 +73,7 @@ module.exports = { }, }, tasks: { - gulpfile: + description: '{DESC: Tasks for} {PATH: {1:gulpfile path}}', topTask: @@ -87,7 +87,7 @@ module.exports = { }, tasksJson: { - gulpfile: + description: 'Tasks for {1:gulpfile path}', }, diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index b84791ed..6dfa3e56 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -32,7 +32,6 @@ function logTasks(tree, opts, getTask) { function printTaskTree(tree, opts) { var lines = []; - lines.push({ label: tree.label }); var maxLabelWidth = 0; tree.nodes.forEach(function(node, idx, arr) { @@ -41,10 +40,10 @@ function printTaskTree(tree, opts) { maxLabelWidth = Math.max(maxLabelWidth, w || /* istanbul ignore next */ 0); }); + log.info('{1}', tree.label); + lines.forEach(function(line) { - if (line.fmt == null) { - log.info(line.label); - } else if (line.desc) { + if (line.desc) { var spaces = ' '.repeat(maxLabelWidth - line.width) + ' '; log.info(line.fmt, line.bars, line.name, true, spaces, line.desc); } else { diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 77c45b87..e3e63698 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -5,6 +5,8 @@ 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'); @@ -14,7 +16,6 @@ var logTasks = require('../../shared/log/tasks'); var exit = require('../../shared/exit'); var logEvents = require('./log/events'); var logTasksSimple = require('./log/tasks-simple'); -var getTasksDescription = require('./log/tasks-description'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); @@ -52,16 +53,27 @@ function execute(env) { if (opts.tasksSimple) { return logTasksSimple(env, gulpInst); } + var desc; if (opts.tasks) { + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = format(theme, msgs.tasks.description, tildify(env.configPath)); + } tree = taskTree(gulpInst.tasks); - tree.label = getTasksDescription(env, true); + tree.label = desc; return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; }); } if (opts.tasksJson) { + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + } tree = taskTree(gulpInst.tasks); - tree.label = getTasksDescription(env, false); + tree.label = desc; var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^3.7.0/log/tasks-description.js b/lib/versioned/^3.7.0/log/tasks-description.js deleted file mode 100644 index fe19e397..00000000 --- a/lib/versioned/^3.7.0/log/tasks-description.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -var format = require('theming-log').format; -var tildify = require('../../../shared/tildify'); -var theme = require('../../../shared/log/theme'); -var msgs = require('../../../shared/log/messages'); - -function getTasksDescription(env, isBackslashEscaping) { - var desc; - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = msgs.tasks.gulpfile; - } - var gulpfile = tildify(env.configPath); - if (isBackslashEscaping) { - gulpfile = escapeBackslash(gulpfile); - } - return format(theme, desc, gulpfile); -} - -function escapeBackslash(s) { - return s.replace(/\\/g, '\\\\'); -} - -module.exports = getTasksDescription; diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 06d700e0..9f03cf56 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -5,6 +5,8 @@ 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'); @@ -14,7 +16,6 @@ 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 getTasksDescription = require('../^4.0.0/log/tasks-description'); var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); @@ -53,9 +54,15 @@ function execute(env) { if (opts.tasksSimple) { return logTasksSimple(gulpInst.tree()); } + var desc; if (opts.tasks) { + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = format(theme, msgs.tasks.description, tildify(env.configPath)); + } tree = {}; - tree.label = getTasksDescription(env, true); + tree.label = desc; tree.nodes = gulpInst.tree({ deep: true }); return logTasks(tree, opts, function(taskname) { @@ -63,8 +70,13 @@ function execute(env) { }); } if (opts.tasksJson) { + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + } tree = {}; - tree.label = getTasksDescription(env, false); + tree.label = desc; 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 23a75047..5f546408 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -5,6 +5,8 @@ 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'); @@ -14,7 +16,6 @@ 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 getTasksDescription = require('../^4.0.0/log/tasks-description'); var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); @@ -55,14 +56,25 @@ function execute(env) { tree = gulpInst.tree(); return logTasksSimple(tree.nodes); } + var desc; if (opts.tasks) { + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = format(theme, msgs.tasks.description, tildify(env.configPath)); + } tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env, true); + tree.label = desc; return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + } tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env, false); + tree.label = desc; 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 cedd4290..35ff099d 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -5,6 +5,8 @@ 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'); @@ -14,7 +16,6 @@ var logEvents = require('./log/events'); var logSyncTask = require('./log/sync-task'); var logTasksSimple = require('./log/tasks-simple'); var checkTaskNotFound = require('./log/check-task-not-found'); -var getTasksDescription = require('./log/tasks-description'); var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); @@ -55,14 +56,25 @@ function execute(env) { tree = gulpInst.tree(); return logTasksSimple(tree.nodes); } + var desc; if (opts.tasks) { + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = format(theme, msgs.tasks.description, tildify(env.configPath)); + } tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env, true); + tree.label = desc; return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { + if (env.config.description && typeof env.config.description === 'string') { + desc = env.config.description; + } else { + desc = format(theme, msgs.tasksJson.description, tildify(env.configPath)); + } tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env, false); + tree.label = desc; var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^4.0.0/log/tasks-description.js b/lib/versioned/^4.0.0/log/tasks-description.js deleted file mode 100644 index fe19e397..00000000 --- a/lib/versioned/^4.0.0/log/tasks-description.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -var format = require('theming-log').format; -var tildify = require('../../../shared/tildify'); -var theme = require('../../../shared/log/theme'); -var msgs = require('../../../shared/log/messages'); - -function getTasksDescription(env, isBackslashEscaping) { - var desc; - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = msgs.tasks.gulpfile; - } - var gulpfile = tildify(env.configPath); - if (isBackslashEscaping) { - gulpfile = escapeBackslash(gulpfile); - } - return format(theme, desc, gulpfile); -} - -function escapeBackslash(s) { - return s.replace(/\\/g, '\\\\'); -} - -module.exports = getTasksDescription; diff --git a/test/config-theme-and-msgs.js b/test/config-theme-and-msgs.js index 60c77558..4b461cd3 100644 --- a/test/config-theme-and-msgs.js +++ b/test/config-theme-and-msgs.js @@ -47,8 +47,8 @@ describe('config: theme.* & msgs.*', function() { } }); - it('Should change tasks.gulpfile with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'tasks/gulpfile'); + it('Should change tasks.description with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/description'); var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); var expected = '** ' + gulpfile + ' **\n' + '└── default\n'; @@ -65,7 +65,7 @@ describe('config: theme.* & msgs.*', function() { }); it('Should remove task.gulpfile line output with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'tasks/gulpfile/remove'); + var cwd = path.join(baseDir, 'tasks/description/remove'); var expected = '└── default\n'; var opts = { cwd: cwd }; @@ -155,7 +155,7 @@ describe('config: theme.* & msgs.*', function() { }); it('Should change tasksJson.gulpfile with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'tasksJson/gulpfile'); + var cwd = path.join(baseDir, 'tasksJson/description'); var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); var expected = JSON.stringify({ label: '** ' + gulpfile + ' **', diff --git a/test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json b/test/fixtures/config/theming/tasks/description/.gulp.json similarity index 70% rename from test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json rename to test/fixtures/config/theming/tasks/description/.gulp.json index 9255c31f..9a898f1b 100644 --- a/test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json +++ b/test/fixtures/config/theming/tasks/description/.gulp.json @@ -1,7 +1,7 @@ { "msgs": { "tasks": { - "gulpfile": "{FILE: {1}}" + "description": "{FILE: {1}}" } }, "theme": { diff --git a/test/fixtures/config/theming/tasks/gulpfile/gulpfile.js b/test/fixtures/config/theming/tasks/description/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/tasks/gulpfile/gulpfile.js rename to test/fixtures/config/theming/tasks/description/gulpfile.js diff --git a/test/fixtures/config/theming/tasks/description/remove/.gulp.json b/test/fixtures/config/theming/tasks/description/remove/.gulp.json new file mode 100644 index 00000000..c1a3e304 --- /dev/null +++ b/test/fixtures/config/theming/tasks/description/remove/.gulp.json @@ -0,0 +1,7 @@ +{ + "msgs": { + "tasks": { + "description": null + } + } +} diff --git a/test/fixtures/config/theming/tasks/gulpfile/remove/gulpfile.js b/test/fixtures/config/theming/tasks/description/remove/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/tasks/gulpfile/remove/gulpfile.js rename to test/fixtures/config/theming/tasks/description/remove/gulpfile.js diff --git a/test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json b/test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json deleted file mode 100644 index 2b9fdf1b..00000000 --- a/test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "msgs": { - "tasks": { - "gulpfile": null - } - }, - "theme": { - "FILE": "** {1} **" - } -} diff --git a/test/fixtures/config/theming/tasks/gulpfile/.gulp.json b/test/fixtures/config/theming/tasksJson/description/.gulp.json similarity index 55% rename from test/fixtures/config/theming/tasks/gulpfile/.gulp.json rename to test/fixtures/config/theming/tasksJson/description/.gulp.json index 9255c31f..6917503e 100644 --- a/test/fixtures/config/theming/tasks/gulpfile/.gulp.json +++ b/test/fixtures/config/theming/tasksJson/description/.gulp.json @@ -1,7 +1,7 @@ { "msgs": { - "tasks": { - "gulpfile": "{FILE: {1}}" + "tasksJson": { + "description": "{FILE: {1}}" } }, "theme": { diff --git a/test/fixtures/config/theming/tasksJson/gulpfile/gulpfile.js b/test/fixtures/config/theming/tasksJson/description/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/tasksJson/gulpfile/gulpfile.js rename to test/fixtures/config/theming/tasksJson/description/gulpfile.js From 3a95fd305bf379ea0088ebadc863984535cec3da Mon Sep 17 00:00:00 2001 From: sttk Date: Tue, 13 Feb 2024 00:06:52 +0900 Subject: [PATCH 05/43] fix: modify positions of msgs and theme in config --- README.md | 2 +- lib/shared/config/env-config.js | 18 ++++--- .../theming/error/badGulpVersion/.gulp.js | 14 +++--- .../theming/error/failToParseCliOpts/.gulp.js | 8 ++-- .../config/theming/error/failToRun/.gulp.js | 10 ++-- .../theming/error/gulpNotFound/.gulp.js | 14 +++--- .../theming/error/gulpfileNotFound/.gulp.js | 8 ++-- .../theming/error/noCompletionType/.gulp.js | 8 ++-- .../error/nodeModulesNotFound/.gulp.js | 16 +++---- .../config/theming/error/taskError/.gulp.js | 14 +++--- .../theming/error/taskNotFound/.gulp.js | 16 ++++--- .../error/unknownCompletionType/.gulp.js | 14 +++--- .../config/theming/help/flags/.gulp.js | 48 ++++++++++--------- .../config/theming/help/usage/.gulp.js | 8 ++-- .../config/theming/info/cwdChanged/.gulp.js | 14 +++--- .../theming/info/loaderSuccess/.gulp.js | 14 +++--- .../theming/info/preloadBefore/.gulp.js | 14 +++--- .../theming/info/preloadSuccess/.gulp.js | 14 +++--- .../config/theming/info/respawn/.gulp.js | 14 +++--- .../config/theming/info/taskStart/.gulp.js | 14 +++--- .../config/theming/info/taskStop/.gulp.js | 14 +++--- .../theming/info/usingGulpfile/.gulp.js | 14 +++--- .../config/theming/info/version/.gulp.js | 14 +++--- .../config/theming/tasks/childTask/.gulp.js | 16 ++++--- .../theming/tasks/description/.gulp.json | 14 +++--- .../tasks/description/remove/.gulp.json | 8 ++-- .../config/theming/tasks/option/.gulp.js | 16 ++++--- .../config/theming/tasks/topTask/.gulp.js | 16 ++++--- .../theming/tasksJson/description/.gulp.json | 14 +++--- .../theming/warn/loaderFailure/.gulp.js | 14 +++--- .../theming/warn/preloadFailure/.gulp.js | 14 +++--- .../theming/warn/taskNotComplete/.gulp.js | 14 +++--- 32 files changed, 256 insertions(+), 194 deletions(-) diff --git a/README.md b/README.md index 02abed5e..46be9fb4 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Supported configurations properties: | 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 | -| log.messages.* | Configure log messages. | +| log.msgs.* | Configure log messages. | | log.theme.* | Configure log theme. | ## Flags diff --git a/lib/shared/config/env-config.js b/lib/shared/config/env-config.js index 4fc34e54..e534281f 100644 --- a/lib/shared/config/env-config.js +++ b/lib/shared/config/env-config.js @@ -24,17 +24,21 @@ function overrideEnvConfig(env, config, cliOpts) { env.config = { flags: cliOpts, - theme: theme, - msgs: msgs, + log: { + theme: theme, + msgs: msgs, + }, }; if (config.description) { env.config.description = config.description; } - if (config.theme) { - copyProps(config.theme, env.config.theme); - } - if (config.msgs) { - copyProps(config.msgs, env.config.msgs); + if (config.log) { + if (config.log.theme) { + copyProps(config.log.theme, env.config.log.theme); + } + if (config.log.msgs) { + copyProps(config.log.msgs, env.config.log.msgs); + } } return env diff --git a/test/fixtures/config/theming/error/badGulpVersion/.gulp.js b/test/fixtures/config/theming/error/badGulpVersion/.gulp.js index d923bd09..c2c8c93e 100644 --- a/test/fixtures/config/theming/error/badGulpVersion/.gulp.js +++ b/test/fixtures/config/theming/error/badGulpVersion/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - error: { - badGulpVersion: '{TIMESTAMP}BAD GULP VERSION {GulpVer:{1}}', + log: { + msgs: { + error: { + badGulpVersion: '{TIMESTAMP}BAD GULP VERSION {GulpVer:{1}}', + }, + }, + theme: { + GulpVer: '**{1}**', }, - }, - theme: { - GulpVer: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js b/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js index 0e606d8b..516acab9 100644 --- a/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js +++ b/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js @@ -1,7 +1,9 @@ module.exports = { - msgs: { - error: { - failToParseCliOpts: '**{1}**', + log: { + msgs: { + error: { + failToParseCliOpts: '**{1}**', + }, }, }, }; diff --git a/test/fixtures/config/theming/error/failToRun/.gulp.js b/test/fixtures/config/theming/error/failToRun/.gulp.js index c93d52de..508aa1e8 100644 --- a/test/fixtures/config/theming/error/failToRun/.gulp.js +++ b/test/fixtures/config/theming/error/failToRun/.gulp.js @@ -1,8 +1,10 @@ module.exports = { - msgs: { - info: null, // To cause failToRun error forcefully - error: { - failToRun: 'FAIL TO RUN', + log: { + msgs: { + info: null, // To cause failToRun error forcefully + error: { + failToRun: 'FAIL TO RUN', + }, }, }, }; diff --git a/test/fixtures/config/theming/error/gulpNotFound/.gulp.js b/test/fixtures/config/theming/error/gulpNotFound/.gulp.js index 3d8bb0b4..285358db 100644 --- a/test/fixtures/config/theming/error/gulpNotFound/.gulp.js +++ b/test/fixtures/config/theming/error/gulpNotFound/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - error: { - gulpNotFound: 'GULP NOT FOUND IN {CwdPath: {1}}', + log: { + msgs: { + error: { + gulpNotFound: 'GULP NOT FOUND IN {CwdPath: {1}}', + }, + }, + theme: { + CwdPath: '**{1}**', }, - }, - theme: { - CwdPath: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js b/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js index a96938cb..0524beae 100644 --- a/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js +++ b/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js @@ -1,7 +1,9 @@ module.exports = { - msgs: { - error: { - gulpfileNotFound: '{TIMESTAMP}NO GULPFILE', + log: { + msgs: { + error: { + gulpfileNotFound: '{TIMESTAMP}NO GULPFILE', + }, }, }, }; diff --git a/test/fixtures/config/theming/error/noCompletionType/.gulp.js b/test/fixtures/config/theming/error/noCompletionType/.gulp.js index 6817dbf5..42781159 100644 --- a/test/fixtures/config/theming/error/noCompletionType/.gulp.js +++ b/test/fixtures/config/theming/error/noCompletionType/.gulp.js @@ -1,7 +1,9 @@ module.exports = { - msgs: { - error: { - noCompletionType: 'NO COMPLETION TYPE', + log: { + msgs: { + error: { + noCompletionType: 'NO COMPLETION TYPE', + }, }, }, }; diff --git a/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js b/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js index 2576d4cc..4d21fdba 100644 --- a/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js +++ b/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js @@ -1,12 +1,12 @@ -var os = require('os'); - module.exports = { - msgs: { - error: { - nodeModulesNotFound: 'LOCAL MODULE NOT FOUND {Path: {1}}', + log: { + msgs: { + error: { + nodeModulesNotFound: 'LOCAL MODULE NOT FOUND {Path: {1}}', + }, + }, + theme: { + Path: '**{1}**', }, - }, - theme: { - Path: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/error/taskError/.gulp.js b/test/fixtures/config/theming/error/taskError/.gulp.js index 534a1456..346a9cc3 100644 --- a/test/fixtures/config/theming/error/taskError/.gulp.js +++ b/test/fixtures/config/theming/error/taskError/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - error: { - taskError: '{TIMESTAMP}TASK ERROR: {TaskName:{1}}', + log: { + msgs: { + error: { + taskError: '{TIMESTAMP}TASK ERROR: {TaskName:{1}}', + }, + }, + theme: { + TaskName: '**{1}**', }, - }, - theme: { - TaskName: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/error/taskNotFound/.gulp.js b/test/fixtures/config/theming/error/taskNotFound/.gulp.js index 12545808..42223bca 100644 --- a/test/fixtures/config/theming/error/taskNotFound/.gulp.js +++ b/test/fixtures/config/theming/error/taskNotFound/.gulp.js @@ -1,11 +1,13 @@ module.exports = { - msgs: { - error: { - taskNotFound: '{TIMESTAMP}TASK IS NOT FOUND: {TaskName:{1}}{IF:{2}? SIMILAR {SimilarTasks:{3}}}', + log: { + msgs: { + error: { + taskNotFound: '{TIMESTAMP}TASK IS NOT FOUND: {TaskName:{1}}{IF:{2}? SIMILAR {SimilarTasks:{3}}}', + }, + }, + theme: { + TaskName: '**{1}**', + SimilarTasks: '##{1}##', }, - }, - theme: { - TaskName: '**{1}**', - SimilarTasks: '##{1}##', }, }; diff --git a/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js b/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js index 0676f0a8..71d056a9 100644 --- a/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js +++ b/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - error: { - unknownCompletionType: 'GULP COMPLETION TYPE {Type: {1}} IS NOT FOUND', + log: { + msgs: { + error: { + unknownCompletionType: 'GULP COMPLETION TYPE {Type: {1}} IS NOT FOUND', + }, + }, + theme: { + Type: '**{1}**', }, - }, - theme: { - Type: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/help/flags/.gulp.js b/test/fixtures/config/theming/help/flags/.gulp.js index 1a008528..ea807c89 100644 --- a/test/fixtures/config/theming/help/flags/.gulp.js +++ b/test/fixtures/config/theming/help/flags/.gulp.js @@ -1,28 +1,30 @@ module.exports = { - msgs: { - help: { - flags: { - help: '{help_desc: HELP}', - version: '{help_desc: VERSION}', - preload: '{help_desc: PRELOAD}', - gulpfile: '{help_desc: GULPFILE}', - cwd: '{help_desc: CWD}', - tasks: '{help_desc: TASKS}', - 'tasks-simple': '{help_desc: TASKS SIMPLE}', - 'tasks-json': '{help_desc: TASKS JSON}', - 'tasks-depth': '{help_desc: TASKS DEPTH}', - 'compact-tasks': '{help_desc: COMPACT TASKS}', - 'sort-tasks': '{help_desc: SORT_TASKS}', - color: '{help_desc: COLOR}', - 'no-color': '{help_desc: NO COLOR}', - silent: '{help_desc: SILENT}', - continue: '{help_desc: CONTINUE}', - series: '{help_desc: SERIES}', - 'log-level': '{help_desc: LOG LEVEL}', + log: { + msgs: { + help: { + flags: { + help: '{help_desc: HELP}', + version: '{help_desc: VERSION}', + preload: '{help_desc: PRELOAD}', + gulpfile: '{help_desc: GULPFILE}', + cwd: '{help_desc: CWD}', + tasks: '{help_desc: TASKS}', + 'tasks-simple': '{help_desc: TASKS SIMPLE}', + 'tasks-json': '{help_desc: TASKS JSON}', + 'tasks-depth': '{help_desc: TASKS DEPTH}', + 'compact-tasks': '{help_desc: COMPACT TASKS}', + 'sort-tasks': '{help_desc: SORT_TASKS}', + color: '{help_desc: COLOR}', + 'no-color': '{help_desc: NO COLOR}', + silent: '{help_desc: SILENT}', + continue: '{help_desc: CONTINUE}', + series: '{help_desc: SERIES}', + 'log-level': '{help_desc: LOG LEVEL}', + }, }, }, - }, - theme: { - help_desc: '**{1}**', + theme: { + help_desc: '**{1}**', + }, }, }; diff --git a/test/fixtures/config/theming/help/usage/.gulp.js b/test/fixtures/config/theming/help/usage/.gulp.js index f96d44df..30e6e67d 100644 --- a/test/fixtures/config/theming/help/usage/.gulp.js +++ b/test/fixtures/config/theming/help/usage/.gulp.js @@ -1,7 +1,9 @@ module.exports = { - msgs: { - help: { - usage: 'GULP USAGE', + log: { + msgs: { + help: { + usage: 'GULP USAGE', + }, }, }, }; diff --git a/test/fixtures/config/theming/info/cwdChanged/.gulp.js b/test/fixtures/config/theming/info/cwdChanged/.gulp.js index 3c3c9380..d600f306 100644 --- a/test/fixtures/config/theming/info/cwdChanged/.gulp.js +++ b/test/fixtures/config/theming/info/cwdChanged/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - info: { - cwdChanged: '{TIMESTAMP}CHANGE CWD TO {CwdPath: {1}}', + log: { + msgs: { + info: { + cwdChanged: '{TIMESTAMP}CHANGE CWD TO {CwdPath: {1}}', + }, + }, + theme: { + CwdPath: '**{1}**', }, - }, - theme: { - CwdPath: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/info/loaderSuccess/.gulp.js b/test/fixtures/config/theming/info/loaderSuccess/.gulp.js index ec7df4a5..2a1b62d4 100644 --- a/test/fixtures/config/theming/info/loaderSuccess/.gulp.js +++ b/test/fixtures/config/theming/info/loaderSuccess/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - info: { - loaderSuccess: 'LOADED {ModuleName: {1}}', + log: { + msgs: { + info: { + loaderSuccess: 'LOADED {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', }, - }, - theme: { - ModuleName: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/info/preloadBefore/.gulp.js b/test/fixtures/config/theming/info/preloadBefore/.gulp.js index a6744dda..53dc5ce6 100644 --- a/test/fixtures/config/theming/info/preloadBefore/.gulp.js +++ b/test/fixtures/config/theming/info/preloadBefore/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - info: { - preloadBefore: 'PRELOADING {ModuleName: {1}}', + log: { + msgs: { + info: { + preloadBefore: 'PRELOADING {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', }, - }, - theme: { - ModuleName: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/info/preloadSuccess/.gulp.js b/test/fixtures/config/theming/info/preloadSuccess/.gulp.js index bd6497e2..2226a83d 100644 --- a/test/fixtures/config/theming/info/preloadSuccess/.gulp.js +++ b/test/fixtures/config/theming/info/preloadSuccess/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - info: { - preloadSuccess: 'PRELOADDED {ModuleName: {1}}', + log: { + msgs: { + info: { + preloadSuccess: 'PRELOADDED {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', }, - }, - theme: { - ModuleName: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/info/respawn/.gulp.js b/test/fixtures/config/theming/info/respawn/.gulp.js index 8f6de9e3..5be9dccc 100644 --- a/test/fixtures/config/theming/info/respawn/.gulp.js +++ b/test/fixtures/config/theming/info/respawn/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - info: { - respawn: 'RESPAWN BY {NodeFlag: {1}}', + log: { + msgs: { + info: { + respawn: 'RESPAWN BY {NodeFlag: {1}}', + }, + }, + theme: { + NodeFlag: '**{1}**', }, - }, - theme: { - NodeFlag: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/info/taskStart/.gulp.js b/test/fixtures/config/theming/info/taskStart/.gulp.js index c1cef5d1..1129f3ad 100644 --- a/test/fixtures/config/theming/info/taskStart/.gulp.js +++ b/test/fixtures/config/theming/info/taskStart/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - info: { - taskStart: '{TIMESTAMP}START {Task: {1}}', + log: { + msgs: { + info: { + taskStart: '{TIMESTAMP}START {Task: {1}}', + }, + }, + theme: { + Task: '**{1}**', }, - }, - theme: { - Task: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/info/taskStop/.gulp.js b/test/fixtures/config/theming/info/taskStop/.gulp.js index 7c62298c..d3355766 100644 --- a/test/fixtures/config/theming/info/taskStop/.gulp.js +++ b/test/fixtures/config/theming/info/taskStop/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - info: { - taskStop: '{TIMESTAMP}STOP {Task: {1}}', + log: { + msgs: { + info: { + taskStop: '{TIMESTAMP}STOP {Task: {1}}', + }, + }, + theme: { + Task: '**{1}**', }, - }, - theme: { - Task: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/info/usingGulpfile/.gulp.js b/test/fixtures/config/theming/info/usingGulpfile/.gulp.js index cea0669a..a44460a6 100644 --- a/test/fixtures/config/theming/info/usingGulpfile/.gulp.js +++ b/test/fixtures/config/theming/info/usingGulpfile/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - info: { - usingGulpfile: '{TIMESTAMP}USING GULPFILE {File:{1}}', + log: { + msgs: { + info: { + usingGulpfile: '{TIMESTAMP}USING GULPFILE {File:{1}}', + }, + }, + theme: { + File: '**{1}**', }, - }, - theme: { - File: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/info/version/.gulp.js b/test/fixtures/config/theming/info/version/.gulp.js index 4183557c..a876e2e2 100644 --- a/test/fixtures/config/theming/info/version/.gulp.js +++ b/test/fixtures/config/theming/info/version/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - info: { - version: 'gulp-cli {VERSION: v{1}} | gulp {VERSION: v{2}}', + log: { + msgs: { + info: { + version: 'gulp-cli {VERSION: v{1}} | gulp {VERSION: v{2}}', + }, + }, + theme: { + VERSION: '@@{1}@@', }, - }, - theme: { - VERSION: '@@{1}@@', }, }; diff --git a/test/fixtures/config/theming/tasks/childTask/.gulp.js b/test/fixtures/config/theming/tasks/childTask/.gulp.js index 545b70f9..51eb19f6 100644 --- a/test/fixtures/config/theming/tasks/childTask/.gulp.js +++ b/test/fixtures/config/theming/tasks/childTask/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - tasks: { - childTask: '{1}{child_task: {2}}', - } - }, - theme: { - child_task: '**{1}**', + log: { + msgs: { + tasks: { + childTask: '{1}{child_task: {2}}', + } + }, + theme: { + child_task: '**{1}**', + }, }, }; diff --git a/test/fixtures/config/theming/tasks/description/.gulp.json b/test/fixtures/config/theming/tasks/description/.gulp.json index 9a898f1b..64cf05b0 100644 --- a/test/fixtures/config/theming/tasks/description/.gulp.json +++ b/test/fixtures/config/theming/tasks/description/.gulp.json @@ -1,10 +1,12 @@ { - "msgs": { - "tasks": { - "description": "{FILE: {1}}" + "log": { + "msgs": { + "tasks": { + "description": "{FILE: {1}}" + } + }, + "theme": { + "FILE": "** {1} **" } - }, - "theme": { - "FILE": "** {1} **" } } diff --git a/test/fixtures/config/theming/tasks/description/remove/.gulp.json b/test/fixtures/config/theming/tasks/description/remove/.gulp.json index c1a3e304..b2004178 100644 --- a/test/fixtures/config/theming/tasks/description/remove/.gulp.json +++ b/test/fixtures/config/theming/tasks/description/remove/.gulp.json @@ -1,7 +1,9 @@ { - "msgs": { - "tasks": { - "description": null + "log": { + "msgs": { + "tasks": { + "description": null + } } } } diff --git a/test/fixtures/config/theming/tasks/option/.gulp.js b/test/fixtures/config/theming/tasks/option/.gulp.js index 790af554..33eada33 100644 --- a/test/fixtures/config/theming/tasks/option/.gulp.js +++ b/test/fixtures/config/theming/tasks/option/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - tasks: { - option: '{1}{OptionName: {2}}{IF:{3}?{4}» {5}}', - } - }, - theme: { - OptionName: '**{1}**', + log: { + msgs: { + tasks: { + option: '{1}{OptionName: {2}}{IF:{3}?{4}» {5}}', + } + }, + theme: { + OptionName: '**{1}**', + }, }, }; diff --git a/test/fixtures/config/theming/tasks/topTask/.gulp.js b/test/fixtures/config/theming/tasks/topTask/.gulp.js index b9c00721..90c2b2a3 100644 --- a/test/fixtures/config/theming/tasks/topTask/.gulp.js +++ b/test/fixtures/config/theming/tasks/topTask/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - tasks: { - topTask: '{1}{TaskName: {2}}{IF:{3}?{4}{5}}', - } - }, - theme: { - TaskName: '**{1}**', + log: { + msgs: { + tasks: { + topTask: '{1}{TaskName: {2}}{IF:{3}?{4}{5}}', + } + }, + theme: { + TaskName: '**{1}**', + }, }, }; diff --git a/test/fixtures/config/theming/tasksJson/description/.gulp.json b/test/fixtures/config/theming/tasksJson/description/.gulp.json index 6917503e..0a186d7f 100644 --- a/test/fixtures/config/theming/tasksJson/description/.gulp.json +++ b/test/fixtures/config/theming/tasksJson/description/.gulp.json @@ -1,10 +1,12 @@ { - "msgs": { - "tasksJson": { - "description": "{FILE: {1}}" + "log": { + "msgs": { + "tasksJson": { + "description": "{FILE: {1}}" + } + }, + "theme": { + "FILE": "** {1} **" } - }, - "theme": { - "FILE": "** {1} **" } } diff --git a/test/fixtures/config/theming/warn/loaderFailure/.gulp.js b/test/fixtures/config/theming/warn/loaderFailure/.gulp.js index 9875f824..816e2bdf 100644 --- a/test/fixtures/config/theming/warn/loaderFailure/.gulp.js +++ b/test/fixtures/config/theming/warn/loaderFailure/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - warn: { - loaderFailure: '{TIMESTAMP}FAIL TO LOAD {ModuleName: {1}}', + log: { + msgs: { + warn: { + loaderFailure: '{TIMESTAMP}FAIL TO LOAD {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', }, - }, - theme: { - ModuleName: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/warn/preloadFailure/.gulp.js b/test/fixtures/config/theming/warn/preloadFailure/.gulp.js index 50e3bcc6..ca3e42fe 100644 --- a/test/fixtures/config/theming/warn/preloadFailure/.gulp.js +++ b/test/fixtures/config/theming/warn/preloadFailure/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - warn: { - preloadFailure: '{TIMESTAMP}FAILED TO PRELOAD {ModuleName: {1}}', + log: { + msgs: { + warn: { + preloadFailure: '{TIMESTAMP}FAILED TO PRELOAD {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', }, - }, - theme: { - ModuleName: '**{1}**', }, }; diff --git a/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js b/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js index df6bd57f..38e5a949 100644 --- a/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js +++ b/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js @@ -1,10 +1,12 @@ module.exports = { - msgs: { - warn: { - taskNotComplete: '{TIMESTAMP}TASK {TaskName: {1}} DID NOT COMPLETE', + log: { + msgs: { + warn: { + taskNotComplete: '{TIMESTAMP}TASK {TaskName: {1}} DID NOT COMPLETE', + }, + }, + theme: { + TaskName: '**{1}**', }, - }, - theme: { - TaskName: '**{1}**', }, }; From 741ff5a1a63344a376ab3d744f325541371735de Mon Sep 17 00:00:00 2001 From: sttk Date: Tue, 13 Feb 2024 01:01:26 +0900 Subject: [PATCH 06/43] update: remove config.description because config.log.msgs.tasks.description is added. --- README.md | 1 - lib/shared/config/env-config.js | 3 -- lib/shared/log/tasks.js | 2 +- lib/versioned/^3.7.0/index.js | 15 +----- lib/versioned/^4.0.0-alpha.1/index.js | 15 +----- lib/versioned/^4.0.0-alpha.2/index.js | 15 +----- lib/versioned/^4.0.0/index.js | 15 +----- test/config-description.js | 72 --------------------------- test/fixtures/.gulp.json | 8 ++- test/fixtures/gulpfiles/.gulp.json | 11 +++- 10 files changed, 26 insertions(+), 131 deletions(-) delete mode 100644 test/config-description.js diff --git a/README.md b/README.md index 46be9fb4..915f0575 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,6 @@ Supported configurations properties: | Property | Description | |--------------------|-------------| -| description | Top-level description of the project/gulpfile (Replaces "Tasks for ~/path/of/gulpfile.js") | | 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. | diff --git a/lib/shared/config/env-config.js b/lib/shared/config/env-config.js index e534281f..18265465 100644 --- a/lib/shared/config/env-config.js +++ b/lib/shared/config/env-config.js @@ -29,9 +29,6 @@ function overrideEnvConfig(env, config, cliOpts) { msgs: msgs, }, }; - if (config.description) { - env.config.description = config.description; - } if (config.log) { if (config.log.theme) { copyProps(config.log.theme, env.config.log.theme); diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 6dfa3e56..8aa10ba6 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -40,7 +40,7 @@ function printTaskTree(tree, opts) { maxLabelWidth = Math.max(maxLabelWidth, w || /* istanbul ignore next */ 0); }); - log.info('{1}', tree.label); + log.info(msgs.tasks.description, tree.label); lines.forEach(function(line) { if (line.desc) { diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index e3e63698..321493a9 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -53,27 +53,16 @@ function execute(env) { if (opts.tasksSimple) { return logTasksSimple(env, gulpInst); } - var desc; if (opts.tasks) { - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = format(theme, msgs.tasks.description, tildify(env.configPath)); - } tree = taskTree(gulpInst.tasks); - tree.label = desc; + tree.label = tildify(env.configPath); return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; }); } if (opts.tasksJson) { - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = format(theme, msgs.tasksJson.description, tildify(env.configPath)); - } tree = taskTree(gulpInst.tasks); - tree.label = desc; + 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 9f03cf56..8e036922 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -54,15 +54,9 @@ function execute(env) { if (opts.tasksSimple) { return logTasksSimple(gulpInst.tree()); } - var desc; if (opts.tasks) { - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = format(theme, msgs.tasks.description, tildify(env.configPath)); - } tree = {}; - tree.label = desc; + tree.label = tildify(env.configPath); tree.nodes = gulpInst.tree({ deep: true }); return logTasks(tree, opts, function(taskname) { @@ -70,13 +64,8 @@ function execute(env) { }); } if (opts.tasksJson) { - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = format(theme, msgs.tasksJson.description, tildify(env.configPath)); - } tree = {}; - tree.label = desc; + 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 5f546408..ab787e1d 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -56,25 +56,14 @@ function execute(env) { tree = gulpInst.tree(); return logTasksSimple(tree.nodes); } - var desc; if (opts.tasks) { - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = format(theme, msgs.tasks.description, tildify(env.configPath)); - } tree = gulpInst.tree({ deep: true }); - tree.label = desc; + tree.label = tildify(env.configPath); return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = format(theme, msgs.tasksJson.description, tildify(env.configPath)); - } tree = gulpInst.tree({ deep: true }); - tree.label = desc; + 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 35ff099d..a73cf11a 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -56,25 +56,14 @@ function execute(env) { tree = gulpInst.tree(); return logTasksSimple(tree.nodes); } - var desc; if (opts.tasks) { - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = format(theme, msgs.tasks.description, tildify(env.configPath)); - } tree = gulpInst.tree({ deep: true }); - tree.label = desc; + tree.label = tildify(env.configPath); return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { - if (env.config.description && typeof env.config.description === 'string') { - desc = env.config.description; - } else { - desc = format(theme, msgs.tasksJson.description, tildify(env.configPath)); - } tree = gulpInst.tree({ deep: true }); - tree.label = desc; + tree.label = format(theme, msgs.tasksJson.description, tildify(env.configPath)); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/test/config-description.js b/test/config-description.js deleted file mode 100644 index ac85fd70..00000000 --- a/test/config-description.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var exec = require('child_process').exec; -var path = require('path'); -var fs = require('fs'); - -var sliceLines = require('./tool/slice-lines'); -var eraseTime = require('./tool/erase-time'); -var gulp = require('./tool/gulp-cmd'); - -var baseDir = path.join(__dirname, 'fixtures', 'config'); -var expectedDir = path.join(__dirname, 'expected', 'config'); - -describe('config: description', function() { - - it('Should configure with a .gulp.* file in cwd', function(done) { - var opts = { cwd: path.join(baseDir, 'foo/bar') }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); - expect(eraseTime(stdout)).toEqual(expected); - done(err); - } - }); - - it('Should configure with a .gulp.* file in cwd found up', function(done) { - var opts = { cwd: path.join(baseDir, 'foo/bar/baz') }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); - done(err); - } - }); - - it('Should configure with a .gulp.* file in cwd even if it is not a project root', function(done) { - var opts = { cwd: path.join(baseDir, 'foo/bar/quux') }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output2.txt'), 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); - done(err); - } - }); - - it('Should configure with a .gulp.* file in cwd by --cwd', function(done) { - var opts = { cwd: path.join(baseDir, 'qux') }; - exec(gulp( - '--tasks', - '--gulpfile ../foo/bar/gulpfile.js', - '--cwd .' - ), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), 'utf-8'); - expect(eraseTime(stdout)).toEqual(expected); - done(err); - } - }); -}); diff --git a/test/fixtures/.gulp.json b/test/fixtures/.gulp.json index 6aad6e7f..c0c87edd 100644 --- a/test/fixtures/.gulp.json +++ b/test/fixtures/.gulp.json @@ -1,3 +1,9 @@ { - "description" : "gulp-cli/test/fixtures" + "log": { + "msgs": { + "tasks": { + "description" : "gulp-cli/test/fixtures" + } + } + } } diff --git a/test/fixtures/gulpfiles/.gulp.json b/test/fixtures/gulpfiles/.gulp.json index 65158fad..0eae6480 100644 --- a/test/fixtures/gulpfiles/.gulp.json +++ b/test/fixtures/gulpfiles/.gulp.json @@ -1,3 +1,12 @@ { - "description" : "gulp-cli/test/fixtures/gulpfiles" + "log": { + "msgs": { + "tasks": { + "description" : "gulp-cli/test/fixtures/gulpfiles" + }, + "tasksJson": { + "description" : "gulp-cli/test/fixtures/gulpfiles" + } + } + } } From a4bfdd5f9a5ce3b765bd1834d303718f735cb656 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 17 Feb 2024 11:02:55 +0900 Subject: [PATCH 07/43] fix: remove a comment ignoring coverage --- lib/shared/log/tasks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 8aa10ba6..620179ac 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -37,7 +37,7 @@ function printTaskTree(tree, opts) { 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 || /* istanbul ignore next */ 0); + maxLabelWidth = Math.max(maxLabelWidth, w); }); log.info(msgs.tasks.description, tree.label); From 237cb584bca752b301d8cb0337c3b4d76d882418 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 17 Feb 2024 13:00:02 +0900 Subject: [PATCH 08/43] fix: remove a comment for ignoring coverage and add a test case --- lib/shared/log/tasks.js | 2 +- test/expected/flags-tasks-depth1.txt | 4 ++++ test/flags-tasks.js | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/expected/flags-tasks-depth1.txt diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 620179ac..2dc7a4d1 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -15,7 +15,7 @@ function logTasks(tree, opts, getTask) { var maxDepth = opts.tasksDepth; if (typeof maxDepth !== 'number') { maxDepth = 50; - } else /* istanbul ignore if */ if (maxDepth < 1) { + } else if (maxDepth < 1) { maxDepth = 1; } diff --git a/test/expected/flags-tasks-depth1.txt b/test/expected/flags-tasks-depth1.txt new file mode 100644 index 00000000..d973a446 --- /dev/null +++ b/test/expected/flags-tasks-depth1.txt @@ -0,0 +1,4 @@ +gulp-cli/test/fixtures/gulpfiles +├── taskC +├── taskB +└── default diff --git a/test/flags-tasks.js b/test/flags-tasks.js index f43279c0..5af06ba1 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -122,6 +122,24 @@ describe('flag: --tasks', function() { } }); + it('prints the top task only if negative tasks depth is specified', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--tasks-depth -1' + ), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + var filepath = path.join(expectedDir, 'flags-tasks-depth1.txt'); + var expected = fs.readFileSync(filepath, 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(expected); + done(err); + } + }); + it('prints the task list with --depth flag', function(done) { var opts = { cwd: baseDir }; exec(gulp( From ba976abe6376b0fb35ed68761320ac81f80fcd6a Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 17 Feb 2024 15:08:28 +0900 Subject: [PATCH 09/43] fix: add tests for overrideEnvConfig --- test/lib/override-env-config.js | 182 ++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 test/lib/override-env-config.js diff --git a/test/lib/override-env-config.js b/test/lib/override-env-config.js new file mode 100644 index 00000000..d65324f9 --- /dev/null +++ b/test/lib/override-env-config.js @@ -0,0 +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(); + }); +}); From d8e01e83c623ce238f243399e11e5c617e8885af Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 17 Feb 2024 15:25:31 +0900 Subject: [PATCH 10/43] fix: remove the version message from the configuration target --- index.js | 6 ++---- lib/shared/log/messages.js | 4 ---- test/config-theme-and-msgs.js | 15 --------------- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index ccfa53b3..ebf3eb01 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,6 @@ var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); -var format = require('theming-log').format; var exit = require('./lib/shared/exit'); var tildify = require('./lib/shared/tildify'); @@ -17,7 +16,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 theme = require('./lib/shared/log/theme'); var msgs = require('./lib/shared/log/messages'); var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); @@ -136,8 +134,8 @@ function onExecute(env) { // Anything that needs to print outside of the logging mechanism should use console.log if (env.config.flags.version) { - var gulpVersion = env.modulePackage.version || 'Unknown'; - console.log(format(theme, msgs.info.version, cliVersion, gulpVersion)); + console.log('CLI version:', cliVersion); + console.log('Local version:', env.modulePackage.version || 'Unknown'); exit(0); } diff --git a/lib/shared/log/messages.js b/lib/shared/log/messages.js index a2803e3a..b945b182 100644 --- a/lib/shared/log/messages.js +++ b/lib/shared/log/messages.js @@ -105,10 +105,6 @@ module.exports = { '{TIMESTAMP}{DESC: Node flags detected:} {OPTION: {1:node flags}}\n' + '{TIMESTAMP}{DESC: Respawned to PID: {PID: {2:pid}}', - version: - '{DESC: CLI version}: {VERSION: {1:CLI version}}\n' + - '{DESC: Local version}: {VERSION: {2:gulp version}}', - cwdChanged: '{TIMESTAMP}{DESC: Working directory changed to} {PATH: {1:cwd}}', diff --git a/test/config-theme-and-msgs.js b/test/config-theme-and-msgs.js index 4b461cd3..4bb1a851 100644 --- a/test/config-theme-and-msgs.js +++ b/test/config-theme-and-msgs.js @@ -257,21 +257,6 @@ describe('config: theme.* & msgs.*', function() { } }); - it('Should change info.version with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'info/version'); - var expected = /gulp-cli @@v\d.\d.\d@@ | gulp @@v\d.\d.\d@@\n/; - - var opts = { cwd: cwd }; - exec(gulp('--version'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toMatch(expected); - done(err); - } - }); - it('Should change info.cwdChanged with .gulp.*', function(done) { var cwd = path.join(baseDir, 'info/cwdChanged'); var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); From 883cc8e5bc2c0466e1bfab610a3ffe1a879ef923 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sat, 9 Mar 2024 20:34:20 -0700 Subject: [PATCH 11/43] 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 12/43] 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 13/43] 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 14/43] 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 15/43] 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 16/43] 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 17/43] 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 18/43] 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 77f42fe16751ddd30b9448f76362e97e925e235b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 15:34:41 -0700 Subject: [PATCH 19/43] 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 20/43] 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 6e5c79016ed96c05e3e2186b78c1466ff884f0ba Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 Mar 2024 16:18:45 -0700 Subject: [PATCH 21/43] 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 100006667f9452a51a73ee5d28212a9b52050486 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 11:56:02 -0700 Subject: [PATCH 22/43] 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 23/43] 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 24/43] 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 25/43] 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 26/43] 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 27/43] 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 28/43] 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 29/43] 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 30/43] 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 From 1cced0283d5cdefc2c520a4b2fe7fea163d7773f Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 16:03:00 -0700 Subject: [PATCH 31/43] cleanup messages --- messages.js | 127 +++++++++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 56 deletions(-) diff --git a/messages.js b/messages.js index 13e4c269..126b985e 100644 --- a/messages.js +++ b/messages.js @@ -1,70 +1,85 @@ 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"), - - DESCRIPTION: Symbol.for("GULP_CLI_DESCRIPTION"), - - 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"), - TASK_MISSING: Symbol.for("GULP_CLI_TASK_MISSING"), + /** + * Liftoff events + */ + PRELOAD_BEFORE: Symbol.for('GULP_CLI_PRELOAD_BEFORE'), + PRELOAD_SUCCESS: Symbol.for('GULP_CLI_PRELOAD_SUCCESS'), + PRELOAD_FAILURE: Symbol.for('GULP_CLI_PRELOAD_FAILURE'), + LOADER_SUCCESS: Symbol.for('GULP_CLI_LOADER_SUCCESS'), + LOADER_FAILURE: Symbol.for('GULP_CLI_LOADER_FAILURE'), + NODE_FLAGS: Symbol.for('GULP_CLI_NODE_FLAGS'), + RESPAWNED: Symbol.for('GULP_CLI_RESPAWNED'), - SYNC_TASK: Symbol.for("GULP_CLI_SYNC_TASK"), + /** + * Various problems that might occur + */ + GULPFILE_NOT_FOUND: Symbol.for('GULP_CLI_GULPFILE_NOT_FOUND'), + UNSUPPORTED_GULP_VERSION: Symbol.for('GULP_CLI_UNSUPPORTED_GULP_VERSION'), + 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'), - MISSING_NODE_MODULES: Symbol.for("GULP_CLI_MISSING_NODE_MODULES"), - MISSING_GULP: Symbol.for("GULP_CLI_MISSING_GULP"), + /** + * Other details + */ + CWD_CHANGED: Symbol.for('GULP_CLI_CWD_CHANGED'), + DESCRIPTION: Symbol.for('GULP_CLI_DESCRIPTION'), + GULPFILE: Symbol.for('GULP_CLI_GULPFILE'), - 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"), + /** + * Task system + */ + 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'), - COMPLETION_TYPE_MISSING: Symbol.for("GULP_CLI_COMPLETION_TYPE_MISSING"), - COMPLETION_TYPE_UNKNOWN: Symbol.for("GULP_CLI_COMPLETION_TYPE_UNKNOWN"), + /** + * Completions + */ + 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"), + PRELOAD_ERROR: Symbol.for('GULP_CLI_PRELOAD_ERROR'), + LOADER_ERROR: Symbol.for('GULP_CLI_LOADER_ERROR'), + ARGV_ERROR: Symbol.for('GULP_CLI_ARGV_ERROR'), + EXEC_ERROR: Symbol.for('GULP_CLI_EXEC_ERROR'), /** - * Messages used in the `--help` message + * Help */ - 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"), + 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"), - 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"), + /** + * Task tree + */ + 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'), }; From ee5385ee996a31370c750ce00db49d467308de7d Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 16:09:04 -0700 Subject: [PATCH 32/43] linting --- lib/shared/log/tasks.js | 5 +- lib/shared/translate.js | 428 ++++++++++++++++++---------------------- 2 files changed, 196 insertions(+), 237 deletions(-) diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index da286a09..2b5004ee 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -75,7 +75,10 @@ function logTasks(tree, opts, getTask, translate) { } function addTaskToLines(task, lines, isLast, isLeaf) { - 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); + 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 += translate.message(messages.BOX_DRAWINGS_LIGHT_HORIZONTAL); } else { diff --git a/lib/shared/translate.js b/lib/shared/translate.js index 4e2b4846..cc426fc9 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -18,244 +18,200 @@ Timestamp.prototype[util.inspect.custom] = function (depth, opts) { }; 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(tildify(data.cwd)); - } - - if (msg === messages.UNSUPPORTED_GULP_VERSION) { - return chalk.red('Unsupported gulp version', data) - } - - if (msg === messages.DESCRIPTION) { - return 'Tasks for ' + chalk.magenta(tildify(data.path)); - } - - if (msg === messages.GULPFILE) { - return 'Using gulpfile ' + chalk.magenta(tildify(data.path)); - } - - 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) { - 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'; + switch (msg) { + case messages.PRELOAD_BEFORE: { + return 'Preloading external module: ' + chalk.magenta(data); + } + case messages.PRELOAD_SUCCESS: { + return 'Preloaded external module: ' + chalk.magenta(data) + } + case messages.PRELOAD_FAILURE: { + return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data); + } + case messages.PRELOAD_ERROR: { + return chalk.yellow(data.toString()); + } + case messages.LOADER_SUCCESS: { + return 'Loaded external module: ' + chalk.magenta(data); + } + case messages.LOADER_FAILURE: { + return chalk.yellow('Failed to load external module: ') + chalk.magenta(data); + } + case messages.LOADER_ERROR: { + return chalk.yellow(data.toString()); + } + case messages.NODE_FLAGS: { + var nodeFlags = chalk.magenta(data.join(', ')); + return 'Node flags detected: ' + nodeFlags; + } + case messages.RESPAWNED: { + var pid = chalk.magenta(data); + return 'Respawned to PID: ' + pid; + } + case messages.GULPFILE_NOT_FOUND: { + return chalk.red('No gulpfile found'); + } + case messages.CWD_CHANGED: { + return 'Working directory changed to ' + chalk.magenta(tildify(data.cwd)); + } + case messages.UNSUPPORTED_GULP_VERSION: { + return chalk.red('Unsupported gulp version', data) + } + case messages.DESCRIPTION: { + return 'Tasks for ' + chalk.magenta(tildify(data.path)); + } + case messages.GULPFILE: { + return 'Using gulpfile ' + chalk.magenta(tildify(data.path)); + } + case messages.TASK_START: { + return "Starting '" + chalk.cyan(data.task) + "'..." + } + case messages.TASK_STOP: { + return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(data.duration); + } + case messages.TASK_ERROR: { + return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' +chalk.magenta(data.duration); + } + case messages.TASK_MISSING: { + 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'; + } + } + case 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?'); + } + case messages.MISSING_NODE_MODULES: { + return chalk.red('Local modules not found in') + ' ' + chalk.magenta(tildify(data.cwd)); + } + case messages.MISSING_GULP: { + return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(tildify(data.cwd)); + } + case messages.YARN_INSTALL: { + return chalk.red('Try running: yarn install'); + } + case messages.NPM_INSTALL: { + return chalk.red('Try running: npm install'); + } + case messages.YARN_INSTALL_GULP: { + return chalk.red('Try running: yarn add gulp'); + } + case messages.NPM_INSTALL_GULP: { + return chalk.red('Try running: npm install gulp'); + } + case messages.COMPLETION_TYPE_MISSING: { + return 'Missing completion type'; + } + case messages.COMPLETION_TYPE_UNKNOWN: { + return 'echo "gulp autocompletion rules for' + " '" + data.name + "' " + 'not found"' + } + case messages.ARGV_ERROR: { + return data.message; + } + case messages.EXEC_ERROR: { + return data.message; + } + case messages.USAGE: { + return '\n' + chalk.bold('Usage:') + ' gulp ' + chalk.blue('[options]') + ' tasks'; + } + case messages.FLAG_HELP: { + return chalk.gray('Show this help.'); + } + case messages.FLAG_VERSION: { + return chalk.gray('Print the global and local gulp versions.'); + } + case messages.FLAG_PRELOAD: { + return chalk.gray( + 'Will preload a module before running the gulpfile. ' + + 'This is useful for transpilers but also has other applications.' + ); + } + case 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.' + ) + } + case 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.' + ); + } + case messages.FLAG_TASKS: { + return chalk.gray('Print the task dependency tree for the loaded gulpfile.'); + } + case messages.FLAG_TASKS_SIMPLE: { + return chalk.gray('Print a plaintext list of tasks for the loaded gulpfile.'); + } + case messages.FLAG_TASKS_JSON: { + return chalk.gray( + 'Print the task dependency tree, ' + + 'in JSON format, for the loaded gulpfile.' + ); + } + case messages.FLAG_TASKS_DEPTH: { + return chalk.gray('Specify the depth of the task dependency tree.'); + } + case messages.FLAG_COMPACT_TASKS: { + return chalk.gray( + 'Reduce the output of task dependency tree by printing ' + + 'only top tasks and their child tasks.' + ); + } + case messages.FLAG_SORT_TASKS: { + return chalk.gray('Will sort top tasks of task dependency tree.'); + } + case messages.FLAG_COLOR: { + return chalk.gray( + 'Will force gulp and gulp plugins to display colors, ' + + 'even when no color support is detected.' + ); + } + case messages.FLAG_NO_COLOR: { + return chalk.gray( + 'Will force gulp and gulp plugins to not display colors, ' + + 'even when color support is detected.' + ); + } + case messages.FLAG_SILENT: { + return chalk.gray('Suppress all gulp logging.'); + } + case messages.FLAG_CONTINUE: { + return chalk.gray('Continue execution of tasks upon failure.'); + } + case messages.FLAG_SERIES: { + return chalk.gray('Run tasks given on the CLI in series (the default is parallel).'); + } + case messages.FLAG_LOG_LEVEL: { + return chalk.gray( + 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' + + '-LLL is default.' + ); + } + case messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT: { + return chalk.white('└'); + } + case messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT: { + return chalk.white('├'); + } + case messages.BOX_DRAWINGS_LIGHT_HORIZONTAL: { + return chalk.white('─'); + } + case messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL: { + return chalk.white('┬'); + } + case messages.BOX_DRAWINGS_LIGHT_VERTICAL: { + return chalk.white('│'); + } + default: { + return msg; } } - - 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(tildify(data.cwd)); - } - - if (msg === messages.MISSING_GULP) { - return chalk.red('Local gulp not found in') + ' ' + chalk.magenta(tildify(data.cwd)); - } - - 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.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('└'); - } - - 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() { From 7d8266ad26a3d68e8a31833559b4368153165b4b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 20:57:13 -0700 Subject: [PATCH 33/43] update all theme tests and fix some impl --- .gitignore | 2 +- index.js | 2 +- lib/shared/log/tasks.js | 6 +- lib/shared/log/to-console.js | 42 +- lib/shared/translate.js | 6 +- lib/versioned/^4.0.0/log/sync-task.js | 2 +- messages.js | 4 +- test/config-message-function.js | 462 +++++++++++++++ test/config-theme-and-msgs.js | 561 ------------------ .../help.txt => bad-flag.txt} | 0 .../{help/flags/help.txt => flags.txt} | 3 - .../{help/usage/help.txt => usage.txt} | 0 .../config/theming/ARGV_ERROR/.gulp.js | 10 + .../badGulpVersion => ARGV_ERROR}/gulpfile.js | 0 .../theming/COMPLETION_TYPE_MISSING/.gulp.js | 10 + .../gulpfile.js | 0 .../theming/COMPLETION_TYPE_UNKNOWN/.gulp.js | 10 + .../gulpfile.js | 0 .../config/theming/CWD_CHANGED/.gulp.js | 13 + .../taskNotFound => CWD_CHANGED}/gulpfile.js | 0 .../config/theming/DESCRIPTION/.gulp.js | 10 + .../gulpfile.js | 0 .../theming/DESCRIPTION/remove/.gulp.js | 10 + .../remove}/gulpfile.js | 0 .../config/theming/EXEC_ERROR/.gulp.js | 14 + .../preloadBefore => EXEC_ERROR}/gulpfile.js | 0 .../fixtures/config/theming/GULPFILE/.gulp.js | 14 + .../preloadSuccess => GULPFILE}/gulpfile.js | 0 .../config/theming/LOADER_FAILURE/.gulp.js | 15 + .../gulpfile.coffee | 0 .../config/theming/LOADER_SUCCESS/.gulp.js | 13 + .../gulpfile.babel.js | 0 .../config/theming/MISSING_GULP/.gulp.js | 16 + .../config/theming/MISSING_GULPFILE/.gulp.js | 10 + .../theming/MISSING_NODE_MODULES/.gulp.js | 14 + .../package.json | 0 .../config/theming/NODE_FLAGS/.gulp.js | 13 + .../{info/respawn => NODE_FLAGS}/gulpfile.js | 0 .../config/theming/PRELOAD_BEFORE/.gulp.js | 13 + .../taskStart => PRELOAD_BEFORE}/gulpfile.js | 0 .../preload.js | 0 .../config/theming/PRELOAD_FAILURE/.gulp.js | 13 + .../taskStop => PRELOAD_FAILURE}/gulpfile.js | 0 .../config/theming/PRELOAD_SUCCESS/.gulp.js | 13 + .../gulpfile.js | 0 .../preload.js | 0 .../config/theming/RESPAWNED/.gulp.js | 13 + .../description => RESPAWNED}/gulpfile.js | 0 .../config/theming/TASK_ERROR/.gulp.js | 14 + .../taskError => TASK_ERROR}/gulpfile.js | 0 .../config/theming/TASK_MISSING/.gulp.js | 14 + .../remove => TASK_MISSING}/gulpfile.js | 0 .../config/theming/TASK_START/.gulp.js | 13 + .../description => TASK_START}/gulpfile.js | 0 .../config/theming/TASK_STOP/.gulp.js | 13 + .../preloadFailure => TASK_STOP}/gulpfile.js | 0 .../config/theming/TASK_SYNC/.gulp.js | 10 + .../taskNotComplete => TASK_SYNC}/gulpfile.js | 0 .../theming/UNSUPPORTED_GULP_VERSION/.gulp.js | 10 + .../UNSUPPORTED_GULP_VERSION/gulpfile.js | 3 + .../node_modules/gulp/index.js | 0 .../node_modules/gulp/package.json | 0 test/fixtures/config/theming/USAGE/.gulp.js | 10 + .../theming/error/badGulpVersion/.gulp.js | 12 - .../theming/error/failToParseCliOpts/.gulp.js | 9 - .../config/theming/error/failToRun/.gulp.js | 10 - .../theming/error/gulpNotFound/.gulp.js | 12 - .../theming/error/gulpfileNotFound/.gulp.js | 9 - .../theming/error/noCompletionType/.gulp.js | 9 - .../error/nodeModulesNotFound/.gulp.js | 12 - .../config/theming/error/taskError/.gulp.js | 12 - .../theming/error/taskNotFound/.gulp.js | 13 - .../error/unknownCompletionType/.gulp.js | 12 - test/fixtures/config/theming/flags/.gulp.js | 77 +++ .../config/theming/help/flags/.gulp.js | 30 - .../config/theming/help/usage/.gulp.js | 9 - .../config/theming/info/cwdChanged/.gulp.js | 12 - .../theming/info/loaderSuccess/.gulp.js | 12 - .../theming/info/preloadBefore/.gulp.js | 12 - .../theming/info/preloadSuccess/.gulp.js | 12 - .../config/theming/info/respawn/.gulp.js | 12 - .../config/theming/info/taskStart/.gulp.js | 12 - .../config/theming/info/taskStop/.gulp.js | 12 - .../theming/info/usingGulpfile/.gulp.js | 12 - .../config/theming/info/version/.gulp.js | 12 - .../config/theming/tasks/childTask/.gulp.js | 12 - .../theming/tasks/childTask/gulpfile.js | 27 - .../theming/tasks/description/.gulp.json | 12 - .../tasks/description/remove/.gulp.json | 9 - .../config/theming/tasks/option/.gulp.js | 12 - .../config/theming/tasks/option/gulpfile.js | 27 - .../config/theming/tasks/topTask/.gulp.js | 12 - .../config/theming/tasks/topTask/gulpfile.js | 27 - .../theming/tasksJson/description/.gulp.json | 12 - .../theming/warn/loaderFailure/.gulp.js | 12 - .../theming/warn/preloadFailure/.gulp.js | 12 - .../theming/warn/taskNotComplete/.gulp.js | 12 - 97 files changed, 891 insertions(+), 1030 deletions(-) create mode 100644 test/config-message-function.js delete mode 100644 test/config-theme-and-msgs.js rename test/expected/config/theming/{error/failToParseCliOpts/help.txt => bad-flag.txt} (100%) rename test/expected/config/theming/{help/flags/help.txt => flags.txt} (97%) rename test/expected/config/theming/{help/usage/help.txt => usage.txt} (100%) create mode 100644 test/fixtures/config/theming/ARGV_ERROR/.gulp.js rename test/fixtures/config/theming/{error/badGulpVersion => ARGV_ERROR}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js rename test/fixtures/config/theming/{error/failToRun => COMPLETION_TYPE_MISSING}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js rename test/fixtures/config/theming/{error/noCompletionType => COMPLETION_TYPE_UNKNOWN}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/CWD_CHANGED/.gulp.js rename test/fixtures/config/theming/{error/taskNotFound => CWD_CHANGED}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/DESCRIPTION/.gulp.js rename test/fixtures/config/theming/{error/unknownCompletionType => DESCRIPTION}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js rename test/fixtures/config/theming/{info/cwdChanged => DESCRIPTION/remove}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/EXEC_ERROR/.gulp.js rename test/fixtures/config/theming/{info/preloadBefore => EXEC_ERROR}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/GULPFILE/.gulp.js rename test/fixtures/config/theming/{info/preloadSuccess => GULPFILE}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/LOADER_FAILURE/.gulp.js rename test/fixtures/config/theming/{warn/loaderFailure => LOADER_FAILURE}/gulpfile.coffee (100%) create mode 100644 test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js rename test/fixtures/config/theming/{info/loaderSuccess => LOADER_SUCCESS}/gulpfile.babel.js (100%) create mode 100644 test/fixtures/config/theming/MISSING_GULP/.gulp.js create mode 100644 test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js create mode 100644 test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js rename test/fixtures/config/theming/{error/nodeModulesNotFound => MISSING_NODE_MODULES}/package.json (100%) create mode 100644 test/fixtures/config/theming/NODE_FLAGS/.gulp.js rename test/fixtures/config/theming/{info/respawn => NODE_FLAGS}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js rename test/fixtures/config/theming/{info/taskStart => PRELOAD_BEFORE}/gulpfile.js (100%) rename test/fixtures/config/theming/{info/preloadBefore => PRELOAD_BEFORE}/preload.js (100%) create mode 100644 test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js rename test/fixtures/config/theming/{info/taskStop => PRELOAD_FAILURE}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js rename test/fixtures/config/theming/{info/usingGulpfile => PRELOAD_SUCCESS}/gulpfile.js (100%) rename test/fixtures/config/theming/{info/preloadSuccess => PRELOAD_SUCCESS}/preload.js (100%) create mode 100644 test/fixtures/config/theming/RESPAWNED/.gulp.js rename test/fixtures/config/theming/{tasks/description => RESPAWNED}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/TASK_ERROR/.gulp.js rename test/fixtures/config/theming/{error/taskError => TASK_ERROR}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/TASK_MISSING/.gulp.js rename test/fixtures/config/theming/{tasks/description/remove => TASK_MISSING}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/TASK_START/.gulp.js rename test/fixtures/config/theming/{tasksJson/description => TASK_START}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/TASK_STOP/.gulp.js rename test/fixtures/config/theming/{warn/preloadFailure => TASK_STOP}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/TASK_SYNC/.gulp.js rename test/fixtures/config/theming/{warn/taskNotComplete => TASK_SYNC}/gulpfile.js (100%) create mode 100644 test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js create mode 100644 test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/gulpfile.js rename test/fixtures/config/theming/{error/badGulpVersion => UNSUPPORTED_GULP_VERSION}/node_modules/gulp/index.js (100%) rename test/fixtures/config/theming/{error/badGulpVersion => UNSUPPORTED_GULP_VERSION}/node_modules/gulp/package.json (100%) create mode 100644 test/fixtures/config/theming/USAGE/.gulp.js delete mode 100644 test/fixtures/config/theming/error/badGulpVersion/.gulp.js delete mode 100644 test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js delete mode 100644 test/fixtures/config/theming/error/failToRun/.gulp.js delete mode 100644 test/fixtures/config/theming/error/gulpNotFound/.gulp.js delete mode 100644 test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js delete mode 100644 test/fixtures/config/theming/error/noCompletionType/.gulp.js delete mode 100644 test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js delete mode 100644 test/fixtures/config/theming/error/taskError/.gulp.js delete mode 100644 test/fixtures/config/theming/error/taskNotFound/.gulp.js delete mode 100644 test/fixtures/config/theming/error/unknownCompletionType/.gulp.js create mode 100644 test/fixtures/config/theming/flags/.gulp.js delete mode 100644 test/fixtures/config/theming/help/flags/.gulp.js delete mode 100644 test/fixtures/config/theming/help/usage/.gulp.js delete mode 100644 test/fixtures/config/theming/info/cwdChanged/.gulp.js delete mode 100644 test/fixtures/config/theming/info/loaderSuccess/.gulp.js delete mode 100644 test/fixtures/config/theming/info/preloadBefore/.gulp.js delete mode 100644 test/fixtures/config/theming/info/preloadSuccess/.gulp.js delete mode 100644 test/fixtures/config/theming/info/respawn/.gulp.js delete mode 100644 test/fixtures/config/theming/info/taskStart/.gulp.js delete mode 100644 test/fixtures/config/theming/info/taskStop/.gulp.js delete mode 100644 test/fixtures/config/theming/info/usingGulpfile/.gulp.js delete mode 100644 test/fixtures/config/theming/info/version/.gulp.js delete mode 100644 test/fixtures/config/theming/tasks/childTask/.gulp.js delete mode 100644 test/fixtures/config/theming/tasks/childTask/gulpfile.js delete mode 100644 test/fixtures/config/theming/tasks/description/.gulp.json delete mode 100644 test/fixtures/config/theming/tasks/description/remove/.gulp.json delete mode 100644 test/fixtures/config/theming/tasks/option/.gulp.js delete mode 100644 test/fixtures/config/theming/tasks/option/gulpfile.js delete mode 100644 test/fixtures/config/theming/tasks/topTask/.gulp.js delete mode 100644 test/fixtures/config/theming/tasks/topTask/gulpfile.js delete mode 100644 test/fixtures/config/theming/tasksJson/description/.gulp.json delete mode 100644 test/fixtures/config/theming/warn/loaderFailure/.gulp.js delete mode 100644 test/fixtures/config/theming/warn/preloadFailure/.gulp.js delete mode 100644 test/fixtures/config/theming/warn/taskNotComplete/.gulp.js diff --git a/.gitignore b/.gitignore index 9ad73290..c626059e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ *.log node_modules !test/fixtures/errors/bad-gulp-version/node_modules/ -!test/fixtures/config/theming/error/badGulpVersion/node_modules/ +!test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/ build *.node components diff --git a/index.js b/index.js index b0d50969..f842f2be 100644 --- a/index.js +++ b/index.js @@ -208,7 +208,7 @@ function onExecute(env, flags, translate) { } if (!env.configPath) { - log.error(messages.GULPFILE_NOT_FOUND); + log.error(messages.MISSING_GULPFILE); exit(1); } diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 2b5004ee..183feb46 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -1,6 +1,5 @@ 'use strict'; -var log = require('gulplog'); var stringWidth = require('string-width'); var isObject = require('../is-object'); @@ -46,7 +45,10 @@ function logTasks(tree, opts, getTask, translate) { var spaces = ' '.repeat(maxLabelWidth - line.width) + ' '; s += spaces + line.desc; } - log.info(s); + if (s) { + // We don't need timestamps here + console.log(s); + } }); } diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 2efb48b3..58b42a74 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -44,12 +44,16 @@ function toConsole(log, opts, translate) { }; function onError(msg, data) { - var timestamp = translate.timestamp(); - if (timestamp) { - process.stderr.write(timestamp + ' '); - } + // Get message and timestamp before printing anything to avoid + // logging a half message if there's an error in one of them var message = translate.message(msg, data); + var timestamp = translate.timestamp(); + if (message) { + // Ensure timestamp is not written without a message + if (timestamp) { + process.stderr.write(timestamp + ' '); + } console.error(message); } } @@ -57,34 +61,46 @@ function toConsole(log, opts, translate) { // onWarn, onInfo, and onDebug are currently all the same // implementation but separated to change independently function onWarn(msg, data) { + // Get message and timestamp before printing anything to avoid + // logging a half message if there's an error in one of them var timestamp = translate.timestamp(); - if (timestamp) { - process.stdout.write(timestamp + ' '); - } var message = translate.message(msg, data); + if (message) { + // Ensure timestamp is not written without a message + if (timestamp) { + process.stdout.write(timestamp + ' '); + } console.log(message); } } function onInfo(msg, data) { + // Get message and timestamp before printing anything to avoid + // logging a half message if there's an error in one of them var timestamp = translate.timestamp(); - if (timestamp) { - process.stdout.write(timestamp + ' '); - } var message = translate.message(msg, data); + if (message) { + // Ensure timestamp is not written without a message + if (timestamp) { + process.stdout.write(timestamp + ' '); + } console.log(message); } } function onDebug(msg, data) { + // Get message and timestamp before printing anything to avoid + // logging a half message if there's an error in one of them var timestamp = translate.timestamp(); - if (timestamp) { - process.stdout.write(timestamp + ' '); - } var message = translate.message(msg, data); + if (message) { + // Ensure timestamp is not written without a message + if (timestamp) { + process.stdout.write(timestamp + ' '); + } console.log(message); } } diff --git a/lib/shared/translate.js b/lib/shared/translate.js index cc426fc9..9d075e7f 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -48,7 +48,7 @@ function getDefaultMessage(msg, data) { var pid = chalk.magenta(data); return 'Respawned to PID: ' + pid; } - case messages.GULPFILE_NOT_FOUND: { + case messages.MISSING_GULPFILE: { return chalk.red('No gulpfile found'); } case messages.CWD_CHANGED: { @@ -81,7 +81,7 @@ function getDefaultMessage(msg, data) { '\nTo list available tasks, try running: gulp --tasks'; } } - case messages.SYNC_TASK: { + case messages.TASK_SYNC: { return chalk.red('The following tasks did not complete: ') + chalk.cyan(data) + "\n" + chalk.red('Did you forget to signal async completion?'); } @@ -256,7 +256,7 @@ function buildTranslations(cfg) { // Users can filter timestamps by explicitly returning `false` if (time === false) { - return false; + return ''; } return getDefaultTimestamp(); diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index aa4862d0..6f788ddd 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -20,7 +20,7 @@ function warn() { process.exitCode = 1; - log.warn(messages.SYNC_TASK, taskNames); + log.warn(messages.TASK_SYNC, taskNames); } function start(e) { diff --git a/messages.js b/messages.js index 126b985e..e545b6c3 100644 --- a/messages.js +++ b/messages.js @@ -13,8 +13,8 @@ module.exports = { /** * Various problems that might occur */ - GULPFILE_NOT_FOUND: Symbol.for('GULP_CLI_GULPFILE_NOT_FOUND'), UNSUPPORTED_GULP_VERSION: Symbol.for('GULP_CLI_UNSUPPORTED_GULP_VERSION'), + MISSING_GULPFILE: Symbol.for('GULP_CLI_MISSING_GULPFILE'), 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'), @@ -36,7 +36,7 @@ module.exports = { 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'), + TASK_SYNC: Symbol.for('GULP_CLI_TASK_SYNC'), /** * Completions diff --git a/test/config-message-function.js b/test/config-message-function.js new file mode 100644 index 00000000..18e07c65 --- /dev/null +++ b/test/config-message-function.js @@ -0,0 +1,462 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); +var fs = require('fs'); +var os = require('os'); + +var tildify = require('../lib/shared/tildify'); + +var baseDir = path.join(__dirname, 'fixtures/config/theming'); +var expectedDir = path.join(__dirname, 'expected/config/theming'); + +var eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +describe('config: message function', function() { + + it('can change USAGE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'USAGE'); + var expected = fs.readFileSync(path.join(expectedDir, 'usage.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('--help'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('can change flag descriptions with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'flags'); + var expected = fs.readFileSync(path.join(expectedDir, 'flags.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('--help'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('can change DESCRIPTION with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'DESCRIPTION'); + var expected = '**DESCRIPTION**\n' + + '└── default\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + // TODO: Do we want tests returning false for every message? + it('can remove DESCRIPTION line output with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'DESCRIPTION/remove'); + var expected = '└── default\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('can change DESCRIPTION for tasks-json with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'DESCRIPTION'); + var expected = JSON.stringify({ + label: '**DESCRIPTION**', + nodes: [{ + label: 'default', + type: 'task', + nodes: [], + }], + }) + '\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks-json'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('can change PRELOAD_BEFORE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'PRELOAD_BEFORE'); + var expected = 'PRELOADING **./preload**!\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload ./preload'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change PRELOAD_SUCCESS with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'PRELOAD_SUCCESS'); + var expected = 'PRELOADED **./preload**!\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload ./preload'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change LOADER_SUCCESS with .gulp.*', function(done) { + this.timeout(0); + + var cwd = path.join(baseDir, 'LOADER_SUCCESS'); + var expected = 'LOADED **@babel/register**!\n'; + + var opts = { cwd: cwd }; + exec(gulp('-f gulpfile.babel.js'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change NODE_FLAGS with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'NODE_FLAGS'); + var expected = 'RESPAWNED BY **--lazy**!\n'; + + var opts = { cwd: cwd }; + exec(gulp('--lazy'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change RESPAWNED with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'RESPAWNED'); + var expected = 'RESPAWN!\n'; + + var opts = { cwd: cwd }; + exec(gulp('--lazy'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change CWD_CHANGED with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'CWD_CHANGED'); + var expected = 'CHANGE CWD TO **' + cwd + '**\n'; + + var opts = { cwd: baseDir }; + exec(gulp('--cwd ' + cwd), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change GULPFILE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'GULPFILE'); + var expected = 'USING GULPFILE **abcxyz**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change TASK_START with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_START'); + var expected = 'START **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change TASK_STOP with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_STOP'); + var expected = 'STOP **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(err); + } + }); + + it('can change PRELOAD_FAILURE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'PRELOAD_FAILURE'); + var expected = 'FAILED TO PRELOAD **null-module**\n' + + var opts = { cwd: cwd }; + exec(gulp('--preload null-module'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('can change LOADER_FAILURE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'LOADER_FAILURE'); + var expected = 'FAIL TO LOAD **coffeescript/register**\n'; + + var opts = { cwd: cwd }; + exec(gulp('-f gulpfile.coffee'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).not.toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(); + } + }); + + it('can change TASK_SYNC with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_SYNC'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'TASK **default** DID NOT COMPLETE\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(); + } + }); + + it('can change ARGV_ERROR with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'ARGV_ERROR'); + var expected = fs.readFileSync(path.join(expectedDir, 'bad-flag.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('-f'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } + }); + + it('can change MISSING_GULP with .gulp.*', function(done) { + var dir = path.join(baseDir, 'MISSING_GULP'); + var cwd = os.tmpdir(); + fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + if (os.platform() === 'darwin') { + cwd = path.join('/private', cwd); + } + var expected = 'GULP NOT FOUND IN **' + cwd + '**\n'; + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } finally { + fs.unlinkSync(path.join(cwd, '.gulp.js')); + } + } + }); + + it('can change MISSING_NODE_MODULES with .gulp.*', function(done) { + var dir = path.join(baseDir, 'MISSING_NODE_MODULES'); + var cwd = os.tmpdir(); + fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); + fs.copyFileSync(path.join(dir, 'package.json'), path.join(cwd, 'package.json')); + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + if (os.platform() === 'darwin') { + cwd = path.join('/private', cwd); + } + var expected = 'LOCAL MODULE NOT FOUND **' + cwd + '**\n'; + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } finally { + fs.unlinkSync(path.join(cwd, '.gulp.js')); + fs.unlinkSync(path.join(cwd, 'package.json')); + } + } + }); + + it('can change MISSING_GULPFILE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'MISSING_GULPFILE'); + var expected = 'NO GULPFILE\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } + }); + + it('can change UNSUPPORTED_GULP_VERSION with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'UNSUPPORTED_GULP_VERSION'); + var expected = 'BAD GULP VERSION **1.2.3**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } + }); + + it('can change TASK_ERROR with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_ERROR'); + var expectedStdout = "Using gulpfile!\nStarting 'default'...\n"; + var expectedStderr = 'TASK ERROR: **default**'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(sliceLines(stderr, 0, 1)).toEqual(expectedStderr); + expect(eraseTime(stdout)).toEqual(expectedStdout); + done(); + } + }); + + it('can change TASK_MISSING with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_MISSING'); + var expectedStdout = 'Using gulpfile!\n'; + var expectedStderr = 'TASK IS NOT FOUND: **defaults** SIMILAR ##default##'; + + var opts = { cwd: cwd }; + exec(gulp('defaults'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(eraseTime(stderr)).toMatch(expectedStderr); + expect(eraseTime(stdout)).toEqual(expectedStdout); + done(); + } + }); + + it('can change EXEC_ERROR with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'EXEC_ERROR'); + var expected = 'FAIL TO RUN\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(eraseTime(stderr)).toEqual(expected); + expect(stdout).toEqual(''); + done(); + } + }); + + it('can change COMPLETION_TYPE_MISSING with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'COMPLETION_TYPE_MISSING'); + var expected = 'NO COMPLETION TYPE'; + + var opts = { cwd: cwd }; + exec(gulp('--completion'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toMatch(expected); + expect(stdout).toEqual(''); + done(); + } + }); + + it('can change COMPLETION_TYPE_UNKNOWN with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'COMPLETION_TYPE_UNKNOWN'); + var expected = 'GULP COMPLETION TYPE **xxx** IS NOT FOUND\n'; + + var opts = { cwd: cwd }; + exec(gulp('--completion=xxx'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(); + } + }); +}); diff --git a/test/config-theme-and-msgs.js b/test/config-theme-and-msgs.js deleted file mode 100644 index 4bf083e6..00000000 --- a/test/config-theme-and-msgs.js +++ /dev/null @@ -1,561 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var exec = require('child_process').exec; -var path = require('path'); -var fs = require('fs'); -var os = require('os'); - -var tildify = require('../lib/shared/tildify'); - -var baseDir = path.join(__dirname, 'fixtures/config/theming'); -var expectedDir = path.join(__dirname, 'expected/config/theming'); - -var eraseTime = require('./tool/erase-time'); -var eraseLapse = require('./tool/erase-lapse'); -var gulp = require('./tool/gulp-cmd'); - -describe.skip('config: theme.* & msgs.*', function() { - - it('Should change help.usage with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'help/usage'); - var expected = fs.readFileSync(path.join(expectedDir, 'help/usage/help.txt'), 'utf8'); - - var opts = { cwd: cwd }; - exec(gulp('--help'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toEqual(expected); - done(err); - } - }); - - it('Should change help.flags.* with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'help/flags'); - var expected = fs.readFileSync(path.join(expectedDir, 'help/flags/help.txt'), 'utf8'); - - var opts = { cwd: cwd }; - exec(gulp('--help'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toEqual(expected); - done(err); - } - }); - - it('Should change tasks.description with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'tasks/description'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = '** ' + gulpfile + ' **\n' + - '└── default\n'; - - var opts = { cwd: cwd }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toEqual(expected); - done(err); - } - }); - - it('Should remove task.gulpfile line output with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'tasks/description/remove'); - var expected = '└── default\n'; - - var opts = { cwd: cwd }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toEqual(expected); - done(err); - } - }); - - it('Should change tasks.topTask with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'tasks/topTask'); - 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' + - '│ └─┬ \n' + - '│ ├── taskA\n' + - '│ └── taskB\n' + - '├── **taskA** This is 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'; - - var opts = { cwd: cwd }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toEqual(expected); - done(err); - } - }); - - it('Should change tasks.option with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'tasks/option'); - 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' + - '│ └─┬ \n' + - '│ ├── taskA\n' + - '│ └── taskB\n' + - '├── taskA This is 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'; - - var opts = { cwd: cwd }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toEqual(expected); - done(err); - } - }); - - it('Should change tasks.childTask with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'tasks/childTask'); - 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' + - '│ └─┬ ****\n' + - '│ ├── **taskA**\n' + - '│ └── **taskB**\n' + - '├── taskA This is 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'; - - var opts = { cwd: cwd }; - exec(gulp('--tasks'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toEqual(expected); - done(err); - } - }); - - it('Should change tasksJson.gulpfile with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'tasksJson/description'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = JSON.stringify({ - label: '** ' + gulpfile + ' **', - nodes: [{ - label: 'default', - type: 'task', - nodes: [], - }], - }) + '\n'; - - var opts = { cwd: cwd }; - exec(gulp('--tasks-json'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toEqual(expected); - done(err); - } - }); - - it('Should change info.preloadBefore with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'info/preloadBefore'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = 'PRELOADING **./preload**\n' + - 'Preloaded external module: ./preload\n' + - 'Using gulpfile ' + gulpfile + '\n' + - 'Starting \'default\'...\n' + - 'Finished \'default\' after ?\n'; - - var opts = { cwd: cwd }; - exec(gulp('--preload ./preload'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseLapse(eraseTime(stdout))).toEqual(expected); - done(err); - } - }); - - it('Should change info.preloadSuccess with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'info/preloadSuccess'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = 'Preloading external module: ./preload\n' + - 'PRELOADDED **./preload**\n' + - 'Using gulpfile ' + gulpfile + '\n' + - 'Starting \'default\'...\n' + - 'Finished \'default\' after ?\n'; - - var opts = { cwd: cwd }; - exec(gulp('--preload ./preload'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseLapse(eraseTime(stdout))).toEqual(expected); - done(err); - } - }); - - it('Should change info.loaderSuccess with .gulp.*', function(done) { - this.timeout(0); - - var cwd = path.join(baseDir, 'info/loaderSuccess'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.babel.js')); - var expected = 'LOADED **@babel/register**\n' + - 'Using gulpfile ' + gulpfile + '\n' + - 'Starting \'default\'...\n' + - 'Finished \'default\' after ?\n'; - - var opts = { cwd: cwd }; - exec(gulp('-f gulpfile.babel.js'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseLapse(eraseTime(stdout))).toEqual(expected); - done(err); - } - }); - - it('Should change info.respawn with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'info/respawn'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = 'RESPAWN BY **--lazy**\n' + - 'Using gulpfile ' + gulpfile + '\n' + - 'Starting \'default\'...\n' + - 'Finished \'default\' after ?\n'; - - var opts = { cwd: cwd }; - exec(gulp('--lazy'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseLapse(eraseTime(stdout))).toEqual(expected); - done(err); - } - }); - - it('Should change info.cwdChanged with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'info/cwdChanged'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = 'CHANGE CWD TO **' + tildify(cwd) + '**\n' + - 'Using gulpfile ' + gulpfile + '\n' + - 'Starting \'default\'...\n' + - 'Finished \'default\' after ?\n'; - - var opts = { cwd: baseDir }; - exec(gulp('--cwd ' + cwd), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseLapse(eraseTime(stdout))).toEqual(expected); - done(err); - } - }); - - it('Should change info.usingGulpfile with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'info/usingGulpfile'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = 'USING GULPFILE **' + gulpfile + '**\n' + - 'Starting \'default\'...\n' + - 'Finished \'default\' after ?\n'; - - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseLapse(eraseTime(stdout))).toEqual(expected); - done(err); - } - }); - - it('Should change info.taskStart with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'info/taskStart'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = 'Using gulpfile ' + gulpfile + '\n' + - 'START **default**\n' + - 'Finished \'default\' after ?\n'; - - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseLapse(eraseTime(stdout))).toEqual(expected); - done(err); - } - }); - - it('Should change info.taskStop with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'info/taskStop'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = 'Using gulpfile ' + gulpfile + '\n' + - 'Starting \'default\'...\n' + - 'STOP **default**\n'; - - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual(expected); - done(err); - } - }); - - it('Should change warn.preloadFailure with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'warn/preloadFailure'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = 'Preloading external module: null-module\n' + - 'FAILED TO PRELOAD **null-module**\n' + - 'Using gulpfile ' + gulpfile + '\n' + - 'Starting \'default\'...\n' + - 'Finished \'default\' after ?\n'; - - var opts = { cwd: cwd }; - exec(gulp('--preload null-module'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseLapse(eraseTime(stdout))).toEqual(expected); - done(err); - } - }); - - it('Should change warn.loaderFailure with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'warn/loaderFailure'); - var expected = 'FAIL TO LOAD **coffeescript/register**\n'; - - var opts = { cwd: cwd }; - exec(gulp('-f gulpfile.coffee'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stderr).not.toEqual(''); - expect(eraseTime(stdout)).toEqual(expected); - done(); - } - }); - - it('Should change warn.taskNotComplete with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'warn/taskNotComplete'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expected = 'Using gulpfile ' + gulpfile + '\n' + - 'Starting \'default\'...\n' + - 'TASK **default** DID NOT COMPLETE\n'; - - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual(expected); - done(); - } - }); - - it('Should change error.failToParseCliOpts with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'error/failToParseCliOpts'); - var expected = fs.readFileSync(path.join(expectedDir, 'error/failToParseCliOpts/help.txt'), 'utf8'); - - var opts = { cwd: cwd }; - exec(gulp('-f'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stdout).toEqual(''); - expect(stderr).toEqual(expected); - done(); - } - }); - - it('Should change error.gulpNotFound with .gulp.*', function(done) { - var dir = path.join(baseDir, 'error/gulpNotFound'); - var cwd = os.tmpdir(); - fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); - - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - if (os.platform() === 'darwin') { - cwd = path.join('/private', cwd); - } - var expected = 'GULP NOT FOUND IN **' + cwd + '**\n'; - - function cb(err, stdout, stderr) { - try { - expect(err).not.toBeNull(); - expect(stdout).toEqual(''); - expect(stderr).toEqual(expected); - done(); - } finally { - fs.unlinkSync(path.join(cwd, '.gulp.js')); - } - } - }); - - it('Should change error.nodeModulesNotFound with .gulp.*', function(done) { - var dir = path.join(baseDir, 'error/nodeModulesNotFound'); - var cwd = os.tmpdir(); - fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); - fs.copyFileSync(path.join(dir, 'package.json'), path.join(cwd, 'package.json')); - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - if (os.platform() === 'darwin') { - cwd = path.join('/private', cwd); - } - var expected = 'LOCAL MODULE NOT FOUND **' + cwd + '**\n'; - - function cb(err, stdout, stderr) { - try { - expect(err).not.toBeNull(); - expect(stdout).toEqual(''); - expect(stderr).toEqual(expected); - done(); - } finally { - fs.unlinkSync(path.join(cwd, '.gulp.js')); - fs.unlinkSync(path.join(cwd, 'package.json')); - } - } - }); - - it('Should change error.gulpfileNotFound with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'error/gulpfileNotFound'); - var expected = 'NO GULPFILE\n'; - - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual(expected); - done(); - } - }); - - it('Should change error.badGulpVersion with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'error/badGulpVersion'); - var expected = 'BAD GULP VERSION **1.2.3**\n'; - - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual(expected); - done(); - } - }); - - it('Should change error.taskError with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'error/taskError'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expectedStdout = 'Using gulpfile ' + gulpfile + '\n' + - 'Starting \'default\'...\n'; - var expectedStderr = 'TASK ERROR: **default**\n'; - - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(eraseTime(stderr)).toEqual(expectedStderr); - expect(eraseTime(stdout)).toEqual(expectedStdout); - done(); - } - }); - - it('Should change error.taskNotFound with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'error/taskNotFound'); - var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); - var expectedStdout = 'Using gulpfile ' + gulpfile + '\n'; - var expectedStderr = 'TASK IS NOT FOUND: **defaults** SIMILAR ##default##'; - - var opts = { cwd: cwd }; - exec(gulp('defaults'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(eraseTime(stderr)).toMatch(expectedStderr); - expect(eraseTime(stdout)).toEqual(expectedStdout); - done(); - } - }); - - it('Should change error.failToRun with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'error/failToRun'); - var expected = 'FAIL TO RUN\n'; - - var opts = { cwd: cwd }; - exec(gulp(), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stderr).toEqual(expected); - expect(stdout).toEqual(''); - done(); - } - }); - - it('Should change error.noCompletionType with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'error/noCompletionType'); - var expected = 'NO COMPLETION TYPE'; - - var opts = { cwd: cwd }; - exec(gulp('--completion'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stderr).toMatch(expected); - expect(stdout).toEqual(''); - done(); - } - }); - - it('Should change error.unknownCompletionType with .gulp.*', function(done) { - var cwd = path.join(baseDir, 'error/unknownCompletionType'); - var expected = 'GULP COMPLETION TYPE **xxx** IS NOT FOUND\n'; - - var opts = { cwd: cwd }; - exec(gulp('--completion=xxx'), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stderr).toEqual(''); - expect(stdout).toEqual(expected); - done(); - } - }); -}); diff --git a/test/expected/config/theming/error/failToParseCliOpts/help.txt b/test/expected/config/theming/bad-flag.txt similarity index 100% rename from test/expected/config/theming/error/failToParseCliOpts/help.txt rename to test/expected/config/theming/bad-flag.txt diff --git a/test/expected/config/theming/help/flags/help.txt b/test/expected/config/theming/flags.txt similarity index 97% rename from test/expected/config/theming/help/flags/help.txt rename to test/expected/config/theming/flags.txt index 3fae82da..a9da43fc 100644 --- a/test/expected/config/theming/help/flags/help.txt +++ b/test/expected/config/theming/flags.txt @@ -1,6 +1,3 @@ - -Usage: gulp [options] tasks - Options: -h, --help **HELP** [boolean] -v, --version **VERSION** [boolean] diff --git a/test/expected/config/theming/help/usage/help.txt b/test/expected/config/theming/usage.txt similarity index 100% rename from test/expected/config/theming/help/usage/help.txt rename to test/expected/config/theming/usage.txt diff --git a/test/fixtures/config/theming/ARGV_ERROR/.gulp.js b/test/fixtures/config/theming/ARGV_ERROR/.gulp.js new file mode 100644 index 00000000..c25cbdc6 --- /dev/null +++ b/test/fixtures/config/theming/ARGV_ERROR/.gulp.js @@ -0,0 +1,10 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.ARGV_ERROR) { + return '**' + data.message + '**'; + } + } +}; diff --git a/test/fixtures/config/theming/error/badGulpVersion/gulpfile.js b/test/fixtures/config/theming/ARGV_ERROR/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/error/badGulpVersion/gulpfile.js rename to test/fixtures/config/theming/ARGV_ERROR/gulpfile.js diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js new file mode 100644 index 00000000..fa268ca7 --- /dev/null +++ b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js @@ -0,0 +1,10 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function(msg) { + if (msg === messages.COMPLETION_TYPE_MISSING) { + return 'NO COMPLETION TYPE'; + } + } +}; diff --git a/test/fixtures/config/theming/error/failToRun/gulpfile.js b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/error/failToRun/gulpfile.js rename to test/fixtures/config/theming/COMPLETION_TYPE_MISSING/gulpfile.js diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js new file mode 100644 index 00000000..2b53d569 --- /dev/null +++ b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js @@ -0,0 +1,10 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function(msg, data) { + if (msg === messages.COMPLETION_TYPE_UNKNOWN) { + return 'GULP COMPLETION TYPE **' + data.name + '** IS NOT FOUND'; + } + } +}; diff --git a/test/fixtures/config/theming/error/noCompletionType/gulpfile.js b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/error/noCompletionType/gulpfile.js rename to test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/gulpfile.js diff --git a/test/fixtures/config/theming/CWD_CHANGED/.gulp.js b/test/fixtures/config/theming/CWD_CHANGED/.gulp.js new file mode 100644 index 00000000..22444169 --- /dev/null +++ b/test/fixtures/config/theming/CWD_CHANGED/.gulp.js @@ -0,0 +1,13 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.CWD_CHANGED) { + return 'CHANGE CWD TO **' + data.cwd + '**'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/error/taskNotFound/gulpfile.js b/test/fixtures/config/theming/CWD_CHANGED/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/error/taskNotFound/gulpfile.js rename to test/fixtures/config/theming/CWD_CHANGED/gulpfile.js diff --git a/test/fixtures/config/theming/DESCRIPTION/.gulp.js b/test/fixtures/config/theming/DESCRIPTION/.gulp.js new file mode 100644 index 00000000..787bf358 --- /dev/null +++ b/test/fixtures/config/theming/DESCRIPTION/.gulp.js @@ -0,0 +1,10 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.DESCRIPTION) { + return '**DESCRIPTION**'; + } + } +}; diff --git a/test/fixtures/config/theming/error/unknownCompletionType/gulpfile.js b/test/fixtures/config/theming/DESCRIPTION/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/error/unknownCompletionType/gulpfile.js rename to test/fixtures/config/theming/DESCRIPTION/gulpfile.js diff --git a/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js b/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js new file mode 100644 index 00000000..45d7321a --- /dev/null +++ b/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js @@ -0,0 +1,10 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.DESCRIPTION) { + return false; + } + } +}; diff --git a/test/fixtures/config/theming/info/cwdChanged/gulpfile.js b/test/fixtures/config/theming/DESCRIPTION/remove/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/info/cwdChanged/gulpfile.js rename to test/fixtures/config/theming/DESCRIPTION/remove/gulpfile.js diff --git a/test/fixtures/config/theming/EXEC_ERROR/.gulp.js b/test/fixtures/config/theming/EXEC_ERROR/.gulp.js new file mode 100644 index 00000000..4c7d1eb0 --- /dev/null +++ b/test/fixtures/config/theming/EXEC_ERROR/.gulp.js @@ -0,0 +1,14 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg) { + if (msg === messages.EXEC_ERROR) { + return 'FAIL TO RUN'; + } + + if (msg === messages.GULPFILE) { + throw new Error('Crash before task execution'); + } + } +}; diff --git a/test/fixtures/config/theming/info/preloadBefore/gulpfile.js b/test/fixtures/config/theming/EXEC_ERROR/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/info/preloadBefore/gulpfile.js rename to test/fixtures/config/theming/EXEC_ERROR/gulpfile.js diff --git a/test/fixtures/config/theming/GULPFILE/.gulp.js b/test/fixtures/config/theming/GULPFILE/.gulp.js new file mode 100644 index 00000000..7cf24b82 --- /dev/null +++ b/test/fixtures/config/theming/GULPFILE/.gulp.js @@ -0,0 +1,14 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.GULPFILE) { + return 'USING GULPFILE **abcxyz**'; + } + + // Silence all other messages for test + return false; + } +}; + diff --git a/test/fixtures/config/theming/info/preloadSuccess/gulpfile.js b/test/fixtures/config/theming/GULPFILE/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/info/preloadSuccess/gulpfile.js rename to test/fixtures/config/theming/GULPFILE/gulpfile.js diff --git a/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js b/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js new file mode 100644 index 00000000..a68faf18 --- /dev/null +++ b/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js @@ -0,0 +1,15 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function(msg, data) { + if (msg === messages.LOADER_FAILURE) { + return 'FAIL TO LOAD **' + data + '**'; + } + + if (msg === messages.LOADER_ERROR) { + // Silence for test + return false; + } + } +}; diff --git a/test/fixtures/config/theming/warn/loaderFailure/gulpfile.coffee b/test/fixtures/config/theming/LOADER_FAILURE/gulpfile.coffee similarity index 100% rename from test/fixtures/config/theming/warn/loaderFailure/gulpfile.coffee rename to test/fixtures/config/theming/LOADER_FAILURE/gulpfile.coffee diff --git a/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js b/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js new file mode 100644 index 00000000..dc00b2db --- /dev/null +++ b/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js @@ -0,0 +1,13 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.LOADER_SUCCESS) { + return 'LOADED **' + data + '**!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/info/loaderSuccess/gulpfile.babel.js b/test/fixtures/config/theming/LOADER_SUCCESS/gulpfile.babel.js similarity index 100% rename from test/fixtures/config/theming/info/loaderSuccess/gulpfile.babel.js rename to test/fixtures/config/theming/LOADER_SUCCESS/gulpfile.babel.js diff --git a/test/fixtures/config/theming/MISSING_GULP/.gulp.js b/test/fixtures/config/theming/MISSING_GULP/.gulp.js new file mode 100644 index 00000000..3388e767 --- /dev/null +++ b/test/fixtures/config/theming/MISSING_GULP/.gulp.js @@ -0,0 +1,16 @@ +module.exports = { + message: function(msg, data) { + // Using `Symbol.for()` to avoid node_modules + if (msg === Symbol.for('GULP_CLI_MISSING_GULP')) { + return 'GULP NOT FOUND IN **' + data.cwd + '**'; + } + + if (msg === Symbol.for('GULP_CLI_NPM_INSTALL_GULP')) { + // Silence for test + return false; + } + }, + timestamp: function () { + return false; + } +}; diff --git a/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js b/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js new file mode 100644 index 00000000..eb140ec5 --- /dev/null +++ b/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js @@ -0,0 +1,10 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg) { + if (msg === messages.MISSING_GULPFILE) { + return 'NO GULPFILE'; + } + } +}; diff --git a/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js b/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js new file mode 100644 index 00000000..07a70017 --- /dev/null +++ b/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js @@ -0,0 +1,14 @@ +module.exports = { + message: function(msg, data) { + // Using `Symbol.for()` to avoid node_modules + if (msg === Symbol.for('GULP_CLI_MISSING_NODE_MODULES')) { + return 'LOCAL MODULE NOT FOUND **' + data.cwd + '**'; + } + + if (msg === Symbol.for('GULP_CLI_NPM_INSTALL')) { + // Silence for test + return false; + } + } +}; + diff --git a/test/fixtures/config/theming/error/nodeModulesNotFound/package.json b/test/fixtures/config/theming/MISSING_NODE_MODULES/package.json similarity index 100% rename from test/fixtures/config/theming/error/nodeModulesNotFound/package.json rename to test/fixtures/config/theming/MISSING_NODE_MODULES/package.json diff --git a/test/fixtures/config/theming/NODE_FLAGS/.gulp.js b/test/fixtures/config/theming/NODE_FLAGS/.gulp.js new file mode 100644 index 00000000..e40f7c26 --- /dev/null +++ b/test/fixtures/config/theming/NODE_FLAGS/.gulp.js @@ -0,0 +1,13 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.NODE_FLAGS) { + return 'RESPAWNED BY **' + data + '**!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/info/respawn/gulpfile.js b/test/fixtures/config/theming/NODE_FLAGS/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/info/respawn/gulpfile.js rename to test/fixtures/config/theming/NODE_FLAGS/gulpfile.js diff --git a/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js b/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js new file mode 100644 index 00000000..cd0fa559 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js @@ -0,0 +1,13 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.PRELOAD_BEFORE) { + return 'PRELOADING **' + data + '**!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/info/taskStart/gulpfile.js b/test/fixtures/config/theming/PRELOAD_BEFORE/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/info/taskStart/gulpfile.js rename to test/fixtures/config/theming/PRELOAD_BEFORE/gulpfile.js diff --git a/test/fixtures/config/theming/info/preloadBefore/preload.js b/test/fixtures/config/theming/PRELOAD_BEFORE/preload.js similarity index 100% rename from test/fixtures/config/theming/info/preloadBefore/preload.js rename to test/fixtures/config/theming/PRELOAD_BEFORE/preload.js diff --git a/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js b/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js new file mode 100644 index 00000000..cd190836 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js @@ -0,0 +1,13 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function(msg, data) { + if (msg === messages.PRELOAD_FAILURE) { + return 'FAILED TO PRELOAD **' + data + '**'; + } + + // Silence everything else for test + return false; + } +}; diff --git a/test/fixtures/config/theming/info/taskStop/gulpfile.js b/test/fixtures/config/theming/PRELOAD_FAILURE/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/info/taskStop/gulpfile.js rename to test/fixtures/config/theming/PRELOAD_FAILURE/gulpfile.js diff --git a/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js b/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js new file mode 100644 index 00000000..1993da34 --- /dev/null +++ b/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js @@ -0,0 +1,13 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.PRELOAD_SUCCESS) { + return 'PRELOADED **' + data + '**!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/info/usingGulpfile/gulpfile.js b/test/fixtures/config/theming/PRELOAD_SUCCESS/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/info/usingGulpfile/gulpfile.js rename to test/fixtures/config/theming/PRELOAD_SUCCESS/gulpfile.js diff --git a/test/fixtures/config/theming/info/preloadSuccess/preload.js b/test/fixtures/config/theming/PRELOAD_SUCCESS/preload.js similarity index 100% rename from test/fixtures/config/theming/info/preloadSuccess/preload.js rename to test/fixtures/config/theming/PRELOAD_SUCCESS/preload.js diff --git a/test/fixtures/config/theming/RESPAWNED/.gulp.js b/test/fixtures/config/theming/RESPAWNED/.gulp.js new file mode 100644 index 00000000..704ab23e --- /dev/null +++ b/test/fixtures/config/theming/RESPAWNED/.gulp.js @@ -0,0 +1,13 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg) { + if (msg === messages.RESPAWNED) { + return 'RESPAWN!'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/tasks/description/gulpfile.js b/test/fixtures/config/theming/RESPAWNED/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/tasks/description/gulpfile.js rename to test/fixtures/config/theming/RESPAWNED/gulpfile.js diff --git a/test/fixtures/config/theming/TASK_ERROR/.gulp.js b/test/fixtures/config/theming/TASK_ERROR/.gulp.js new file mode 100644 index 00000000..db0d12e0 --- /dev/null +++ b/test/fixtures/config/theming/TASK_ERROR/.gulp.js @@ -0,0 +1,14 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function(msg, data) { + if (msg === messages.GULPFILE) { + return 'Using gulpfile!'; + } + + if (msg === messages.TASK_ERROR) { + return 'TASK ERROR: **' + data.task + '**'; + } + } +}; diff --git a/test/fixtures/config/theming/error/taskError/gulpfile.js b/test/fixtures/config/theming/TASK_ERROR/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/error/taskError/gulpfile.js rename to test/fixtures/config/theming/TASK_ERROR/gulpfile.js diff --git a/test/fixtures/config/theming/TASK_MISSING/.gulp.js b/test/fixtures/config/theming/TASK_MISSING/.gulp.js new file mode 100644 index 00000000..b7dac4b1 --- /dev/null +++ b/test/fixtures/config/theming/TASK_MISSING/.gulp.js @@ -0,0 +1,14 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function(msg, data) { + if (msg === messages.GULPFILE) { + return 'Using gulpfile!'; + } + + if (msg === messages.TASK_MISSING) { + return 'TASK IS NOT FOUND: **' + data.task + '** SIMILAR ##' + data.similar.join('') + '##'; + } + } +}; diff --git a/test/fixtures/config/theming/tasks/description/remove/gulpfile.js b/test/fixtures/config/theming/TASK_MISSING/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/tasks/description/remove/gulpfile.js rename to test/fixtures/config/theming/TASK_MISSING/gulpfile.js diff --git a/test/fixtures/config/theming/TASK_START/.gulp.js b/test/fixtures/config/theming/TASK_START/.gulp.js new file mode 100644 index 00000000..05e06b93 --- /dev/null +++ b/test/fixtures/config/theming/TASK_START/.gulp.js @@ -0,0 +1,13 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.TASK_START) { + return 'START **' + data.task + '**'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/tasksJson/description/gulpfile.js b/test/fixtures/config/theming/TASK_START/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/tasksJson/description/gulpfile.js rename to test/fixtures/config/theming/TASK_START/gulpfile.js diff --git a/test/fixtures/config/theming/TASK_STOP/.gulp.js b/test/fixtures/config/theming/TASK_STOP/.gulp.js new file mode 100644 index 00000000..a07e24f7 --- /dev/null +++ b/test/fixtures/config/theming/TASK_STOP/.gulp.js @@ -0,0 +1,13 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.TASK_STOP) { + return 'STOP **' + data.task + '**'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/warn/preloadFailure/gulpfile.js b/test/fixtures/config/theming/TASK_STOP/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/warn/preloadFailure/gulpfile.js rename to test/fixtures/config/theming/TASK_STOP/gulpfile.js diff --git a/test/fixtures/config/theming/TASK_SYNC/.gulp.js b/test/fixtures/config/theming/TASK_SYNC/.gulp.js new file mode 100644 index 00000000..c6d11013 --- /dev/null +++ b/test/fixtures/config/theming/TASK_SYNC/.gulp.js @@ -0,0 +1,10 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function(msg, data) { + if (msg === messages.TASK_SYNC) { + return 'TASK **' + data + '** DID NOT COMPLETE'; + } + } +}; diff --git a/test/fixtures/config/theming/warn/taskNotComplete/gulpfile.js b/test/fixtures/config/theming/TASK_SYNC/gulpfile.js similarity index 100% rename from test/fixtures/config/theming/warn/taskNotComplete/gulpfile.js rename to test/fixtures/config/theming/TASK_SYNC/gulpfile.js diff --git a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js new file mode 100644 index 00000000..5f41b6ad --- /dev/null +++ b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js @@ -0,0 +1,10 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.UNSUPPORTED_GULP_VERSION) { + return 'BAD GULP VERSION **' + data + '**'; + } + } +}; diff --git a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/gulpfile.js b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/index.js b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/index.js similarity index 100% rename from test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/index.js rename to test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/index.js diff --git a/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/package.json b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json similarity index 100% rename from test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/package.json rename to test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json diff --git a/test/fixtures/config/theming/USAGE/.gulp.js b/test/fixtures/config/theming/USAGE/.gulp.js new file mode 100644 index 00000000..9d7d9386 --- /dev/null +++ b/test/fixtures/config/theming/USAGE/.gulp.js @@ -0,0 +1,10 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.USAGE) { + return 'GULP USAGE'; + } + } +}; diff --git a/test/fixtures/config/theming/error/badGulpVersion/.gulp.js b/test/fixtures/config/theming/error/badGulpVersion/.gulp.js deleted file mode 100644 index c2c8c93e..00000000 --- a/test/fixtures/config/theming/error/badGulpVersion/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - error: { - badGulpVersion: '{TIMESTAMP}BAD GULP VERSION {GulpVer:{1}}', - }, - }, - theme: { - GulpVer: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js b/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js deleted file mode 100644 index 516acab9..00000000 --- a/test/fixtures/config/theming/error/failToParseCliOpts/.gulp.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - log: { - msgs: { - error: { - failToParseCliOpts: '**{1}**', - }, - }, - }, -}; diff --git a/test/fixtures/config/theming/error/failToRun/.gulp.js b/test/fixtures/config/theming/error/failToRun/.gulp.js deleted file mode 100644 index 508aa1e8..00000000 --- a/test/fixtures/config/theming/error/failToRun/.gulp.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - log: { - msgs: { - info: null, // To cause failToRun error forcefully - error: { - failToRun: 'FAIL TO RUN', - }, - }, - }, -}; diff --git a/test/fixtures/config/theming/error/gulpNotFound/.gulp.js b/test/fixtures/config/theming/error/gulpNotFound/.gulp.js deleted file mode 100644 index 285358db..00000000 --- a/test/fixtures/config/theming/error/gulpNotFound/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - error: { - gulpNotFound: 'GULP NOT FOUND IN {CwdPath: {1}}', - }, - }, - theme: { - CwdPath: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js b/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js deleted file mode 100644 index 0524beae..00000000 --- a/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - log: { - msgs: { - error: { - gulpfileNotFound: '{TIMESTAMP}NO GULPFILE', - }, - }, - }, -}; diff --git a/test/fixtures/config/theming/error/noCompletionType/.gulp.js b/test/fixtures/config/theming/error/noCompletionType/.gulp.js deleted file mode 100644 index 42781159..00000000 --- a/test/fixtures/config/theming/error/noCompletionType/.gulp.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - log: { - msgs: { - error: { - noCompletionType: 'NO COMPLETION TYPE', - }, - }, - }, -}; diff --git a/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js b/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js deleted file mode 100644 index 4d21fdba..00000000 --- a/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - error: { - nodeModulesNotFound: 'LOCAL MODULE NOT FOUND {Path: {1}}', - }, - }, - theme: { - Path: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/error/taskError/.gulp.js b/test/fixtures/config/theming/error/taskError/.gulp.js deleted file mode 100644 index 346a9cc3..00000000 --- a/test/fixtures/config/theming/error/taskError/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - error: { - taskError: '{TIMESTAMP}TASK ERROR: {TaskName:{1}}', - }, - }, - theme: { - TaskName: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/error/taskNotFound/.gulp.js b/test/fixtures/config/theming/error/taskNotFound/.gulp.js deleted file mode 100644 index 42223bca..00000000 --- a/test/fixtures/config/theming/error/taskNotFound/.gulp.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = { - log: { - msgs: { - error: { - taskNotFound: '{TIMESTAMP}TASK IS NOT FOUND: {TaskName:{1}}{IF:{2}? SIMILAR {SimilarTasks:{3}}}', - }, - }, - theme: { - TaskName: '**{1}**', - SimilarTasks: '##{1}##', - }, - }, -}; diff --git a/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js b/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js deleted file mode 100644 index 71d056a9..00000000 --- a/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - error: { - unknownCompletionType: 'GULP COMPLETION TYPE {Type: {1}} IS NOT FOUND', - }, - }, - theme: { - Type: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/flags/.gulp.js b/test/fixtures/config/theming/flags/.gulp.js new file mode 100644 index 00000000..0ce6f928 --- /dev/null +++ b/test/fixtures/config/theming/flags/.gulp.js @@ -0,0 +1,77 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (msg, data) { + if (msg === messages.FLAG_HELP) { + return '**HELP**'; + } + + if (msg === messages.FLAG_VERSION) { + return '**VERSION**'; + } + + if (msg === messages.FLAG_PRELOAD) { + return '**PRELOAD**'; + } + + if (msg === messages.FLAG_GULPFILE) { + return '**GULPFILE**'; + } + + if (msg === messages.FLAG_CWD) { + return '**CWD**'; + } + + if (msg === messages.FLAG_TASKS) { + return '**TASKS**'; + } + + if (msg === messages.FLAG_TASKS_SIMPLE) { + return '**TASKS SIMPLE**'; + } + + if (msg === messages.FLAG_TASKS_JSON) { + return '**TASKS JSON**'; + } + + if (msg === messages.FLAG_TASKS_DEPTH) { + return '**TASKS DEPTH**'; + } + + if (msg === messages.FLAG_COMPACT_TASKS) { + return '**COMPACT TASKS**'; + } + + if (msg === messages.FLAG_SORT_TASKS) { + return '**SORT_TASKS**'; + } + + if (msg === messages.FLAG_COLOR) { + return '**COLOR**'; + } + + if (msg === messages.FLAG_NO_COLOR) { + return '**NO COLOR**'; + } + + if (msg === messages.FLAG_SILENT) { + return '**SILENT**'; + } + + if (msg === messages.FLAG_CONTINUE) { + return '**CONTINUE**'; + } + + if (msg === messages.FLAG_SERIES) { + return '**SERIES**'; + } + + if (msg === messages.FLAG_LOG_LEVEL) { + return '**LOG LEVEL**'; + } + + // Silence all other messages for test + return false; + } +}; diff --git a/test/fixtures/config/theming/help/flags/.gulp.js b/test/fixtures/config/theming/help/flags/.gulp.js deleted file mode 100644 index ea807c89..00000000 --- a/test/fixtures/config/theming/help/flags/.gulp.js +++ /dev/null @@ -1,30 +0,0 @@ -module.exports = { - log: { - msgs: { - help: { - flags: { - help: '{help_desc: HELP}', - version: '{help_desc: VERSION}', - preload: '{help_desc: PRELOAD}', - gulpfile: '{help_desc: GULPFILE}', - cwd: '{help_desc: CWD}', - tasks: '{help_desc: TASKS}', - 'tasks-simple': '{help_desc: TASKS SIMPLE}', - 'tasks-json': '{help_desc: TASKS JSON}', - 'tasks-depth': '{help_desc: TASKS DEPTH}', - 'compact-tasks': '{help_desc: COMPACT TASKS}', - 'sort-tasks': '{help_desc: SORT_TASKS}', - color: '{help_desc: COLOR}', - 'no-color': '{help_desc: NO COLOR}', - silent: '{help_desc: SILENT}', - continue: '{help_desc: CONTINUE}', - series: '{help_desc: SERIES}', - 'log-level': '{help_desc: LOG LEVEL}', - }, - }, - }, - theme: { - help_desc: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/help/usage/.gulp.js b/test/fixtures/config/theming/help/usage/.gulp.js deleted file mode 100644 index 30e6e67d..00000000 --- a/test/fixtures/config/theming/help/usage/.gulp.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - log: { - msgs: { - help: { - usage: 'GULP USAGE', - }, - }, - }, -}; diff --git a/test/fixtures/config/theming/info/cwdChanged/.gulp.js b/test/fixtures/config/theming/info/cwdChanged/.gulp.js deleted file mode 100644 index d600f306..00000000 --- a/test/fixtures/config/theming/info/cwdChanged/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - info: { - cwdChanged: '{TIMESTAMP}CHANGE CWD TO {CwdPath: {1}}', - }, - }, - theme: { - CwdPath: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/info/loaderSuccess/.gulp.js b/test/fixtures/config/theming/info/loaderSuccess/.gulp.js deleted file mode 100644 index 2a1b62d4..00000000 --- a/test/fixtures/config/theming/info/loaderSuccess/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - info: { - loaderSuccess: 'LOADED {ModuleName: {1}}', - }, - }, - theme: { - ModuleName: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/info/preloadBefore/.gulp.js b/test/fixtures/config/theming/info/preloadBefore/.gulp.js deleted file mode 100644 index 53dc5ce6..00000000 --- a/test/fixtures/config/theming/info/preloadBefore/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - info: { - preloadBefore: 'PRELOADING {ModuleName: {1}}', - }, - }, - theme: { - ModuleName: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/info/preloadSuccess/.gulp.js b/test/fixtures/config/theming/info/preloadSuccess/.gulp.js deleted file mode 100644 index 2226a83d..00000000 --- a/test/fixtures/config/theming/info/preloadSuccess/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - info: { - preloadSuccess: 'PRELOADDED {ModuleName: {1}}', - }, - }, - theme: { - ModuleName: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/info/respawn/.gulp.js b/test/fixtures/config/theming/info/respawn/.gulp.js deleted file mode 100644 index 5be9dccc..00000000 --- a/test/fixtures/config/theming/info/respawn/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - info: { - respawn: 'RESPAWN BY {NodeFlag: {1}}', - }, - }, - theme: { - NodeFlag: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/info/taskStart/.gulp.js b/test/fixtures/config/theming/info/taskStart/.gulp.js deleted file mode 100644 index 1129f3ad..00000000 --- a/test/fixtures/config/theming/info/taskStart/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - info: { - taskStart: '{TIMESTAMP}START {Task: {1}}', - }, - }, - theme: { - Task: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/info/taskStop/.gulp.js b/test/fixtures/config/theming/info/taskStop/.gulp.js deleted file mode 100644 index d3355766..00000000 --- a/test/fixtures/config/theming/info/taskStop/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - info: { - taskStop: '{TIMESTAMP}STOP {Task: {1}}', - }, - }, - theme: { - Task: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/info/usingGulpfile/.gulp.js b/test/fixtures/config/theming/info/usingGulpfile/.gulp.js deleted file mode 100644 index a44460a6..00000000 --- a/test/fixtures/config/theming/info/usingGulpfile/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - info: { - usingGulpfile: '{TIMESTAMP}USING GULPFILE {File:{1}}', - }, - }, - theme: { - File: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/info/version/.gulp.js b/test/fixtures/config/theming/info/version/.gulp.js deleted file mode 100644 index a876e2e2..00000000 --- a/test/fixtures/config/theming/info/version/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - info: { - version: 'gulp-cli {VERSION: v{1}} | gulp {VERSION: v{2}}', - }, - }, - theme: { - VERSION: '@@{1}@@', - }, - }, -}; diff --git a/test/fixtures/config/theming/tasks/childTask/.gulp.js b/test/fixtures/config/theming/tasks/childTask/.gulp.js deleted file mode 100644 index 51eb19f6..00000000 --- a/test/fixtures/config/theming/tasks/childTask/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - tasks: { - childTask: '{1}{child_task: {2}}', - } - }, - theme: { - child_task: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/tasks/childTask/gulpfile.js b/test/fixtures/config/theming/tasks/childTask/gulpfile.js deleted file mode 100644 index b61b53c3..00000000 --- a/test/fixtures/config/theming/tasks/childTask/gulpfile.js +++ /dev/null @@ -1,27 +0,0 @@ -const { series } = require('gulp'); - -function taskA(done) { - done(); -} -taskA.description = 'This is task A'; -taskA.flags = { - '--abc': 'is a flag for task A', -}; - -const taskB = function(done) { - done(); -} -taskB.description = 'This is task B'; -taskB.flags = { - '--def': 'is a flag for task B', -}; - -const defaults = series(taskA, taskB); -defaults.description = 'This is default task'; -defaults.flags = { - '--ghi': 'is a flag for default task', -}; - -exports.default = defaults; -exports.taskA = taskA; -exports.taskB = taskB; diff --git a/test/fixtures/config/theming/tasks/description/.gulp.json b/test/fixtures/config/theming/tasks/description/.gulp.json deleted file mode 100644 index 64cf05b0..00000000 --- a/test/fixtures/config/theming/tasks/description/.gulp.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "log": { - "msgs": { - "tasks": { - "description": "{FILE: {1}}" - } - }, - "theme": { - "FILE": "** {1} **" - } - } -} diff --git a/test/fixtures/config/theming/tasks/description/remove/.gulp.json b/test/fixtures/config/theming/tasks/description/remove/.gulp.json deleted file mode 100644 index b2004178..00000000 --- a/test/fixtures/config/theming/tasks/description/remove/.gulp.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "log": { - "msgs": { - "tasks": { - "description": null - } - } - } -} diff --git a/test/fixtures/config/theming/tasks/option/.gulp.js b/test/fixtures/config/theming/tasks/option/.gulp.js deleted file mode 100644 index 33eada33..00000000 --- a/test/fixtures/config/theming/tasks/option/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - tasks: { - option: '{1}{OptionName: {2}}{IF:{3}?{4}» {5}}', - } - }, - theme: { - OptionName: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/tasks/option/gulpfile.js b/test/fixtures/config/theming/tasks/option/gulpfile.js deleted file mode 100644 index b61b53c3..00000000 --- a/test/fixtures/config/theming/tasks/option/gulpfile.js +++ /dev/null @@ -1,27 +0,0 @@ -const { series } = require('gulp'); - -function taskA(done) { - done(); -} -taskA.description = 'This is task A'; -taskA.flags = { - '--abc': 'is a flag for task A', -}; - -const taskB = function(done) { - done(); -} -taskB.description = 'This is task B'; -taskB.flags = { - '--def': 'is a flag for task B', -}; - -const defaults = series(taskA, taskB); -defaults.description = 'This is default task'; -defaults.flags = { - '--ghi': 'is a flag for default task', -}; - -exports.default = defaults; -exports.taskA = taskA; -exports.taskB = taskB; diff --git a/test/fixtures/config/theming/tasks/topTask/.gulp.js b/test/fixtures/config/theming/tasks/topTask/.gulp.js deleted file mode 100644 index 90c2b2a3..00000000 --- a/test/fixtures/config/theming/tasks/topTask/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - tasks: { - topTask: '{1}{TaskName: {2}}{IF:{3}?{4}{5}}', - } - }, - theme: { - TaskName: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/tasks/topTask/gulpfile.js b/test/fixtures/config/theming/tasks/topTask/gulpfile.js deleted file mode 100644 index b61b53c3..00000000 --- a/test/fixtures/config/theming/tasks/topTask/gulpfile.js +++ /dev/null @@ -1,27 +0,0 @@ -const { series } = require('gulp'); - -function taskA(done) { - done(); -} -taskA.description = 'This is task A'; -taskA.flags = { - '--abc': 'is a flag for task A', -}; - -const taskB = function(done) { - done(); -} -taskB.description = 'This is task B'; -taskB.flags = { - '--def': 'is a flag for task B', -}; - -const defaults = series(taskA, taskB); -defaults.description = 'This is default task'; -defaults.flags = { - '--ghi': 'is a flag for default task', -}; - -exports.default = defaults; -exports.taskA = taskA; -exports.taskB = taskB; diff --git a/test/fixtures/config/theming/tasksJson/description/.gulp.json b/test/fixtures/config/theming/tasksJson/description/.gulp.json deleted file mode 100644 index 0a186d7f..00000000 --- a/test/fixtures/config/theming/tasksJson/description/.gulp.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "log": { - "msgs": { - "tasksJson": { - "description": "{FILE: {1}}" - } - }, - "theme": { - "FILE": "** {1} **" - } - } -} diff --git a/test/fixtures/config/theming/warn/loaderFailure/.gulp.js b/test/fixtures/config/theming/warn/loaderFailure/.gulp.js deleted file mode 100644 index 816e2bdf..00000000 --- a/test/fixtures/config/theming/warn/loaderFailure/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - warn: { - loaderFailure: '{TIMESTAMP}FAIL TO LOAD {ModuleName: {1}}', - }, - }, - theme: { - ModuleName: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/warn/preloadFailure/.gulp.js b/test/fixtures/config/theming/warn/preloadFailure/.gulp.js deleted file mode 100644 index ca3e42fe..00000000 --- a/test/fixtures/config/theming/warn/preloadFailure/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - warn: { - preloadFailure: '{TIMESTAMP}FAILED TO PRELOAD {ModuleName: {1}}', - }, - }, - theme: { - ModuleName: '**{1}**', - }, - }, -}; diff --git a/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js b/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js deleted file mode 100644 index 38e5a949..00000000 --- a/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - log: { - msgs: { - warn: { - taskNotComplete: '{TIMESTAMP}TASK {TaskName: {1}} DID NOT COMPLETE', - }, - }, - theme: { - TaskName: '**{1}**', - }, - }, -}; From a53d0e7239d50eccde3a3dc3f421d33e95d703f6 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 17 Mar 2024 21:06:34 -0700 Subject: [PATCH 34/43] reduce the package.json files in tests --- .../config/theming/MISSING_NODE_MODULES/package.json | 11 +++-------- .../node_modules/gulp/package.json | 12 +----------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/test/fixtures/config/theming/MISSING_NODE_MODULES/package.json b/test/fixtures/config/theming/MISSING_NODE_MODULES/package.json index 109ec6a8..71897b01 100644 --- a/test/fixtures/config/theming/MISSING_NODE_MODULES/package.json +++ b/test/fixtures/config/theming/MISSING_NODE_MODULES/package.json @@ -1,12 +1,7 @@ { - "name": "nodeModulesNotFound", + "name": "node-modules-not-found", + "private": true, "version": "1.0.0", "description": "", - "main": ".gulp.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC" + "main": ".gulp.js" } diff --git a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json index dbe8ece4..3585a2f6 100644 --- a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json +++ b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/node_modules/gulp/package.json @@ -1,15 +1,5 @@ { "name": "gulp", "description": "Test Package for Testing!", - "version": "1.2.3", - "tags": [ - ], - "files": [ - ], - "licenses": [ - { - "type": "MIT", - "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" - } - ] + "version": "1.2.3" } From 655727a5d390cdd33743295794d85653fac6fe0c Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Wed, 20 Mar 2024 18:45:51 -0700 Subject: [PATCH 35/43] pass message to the timestamp function --- lib/shared/log/to-console.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 58b42a74..e9d524f6 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -47,7 +47,7 @@ function toConsole(log, opts, translate) { // Get message and timestamp before printing anything to avoid // logging a half message if there's an error in one of them var message = translate.message(msg, data); - var timestamp = translate.timestamp(); + var timestamp = translate.timestamp(msg, data); if (message) { // Ensure timestamp is not written without a message @@ -63,8 +63,8 @@ function toConsole(log, opts, translate) { function onWarn(msg, data) { // Get message and timestamp before printing anything to avoid // logging a half message if there's an error in one of them - var timestamp = translate.timestamp(); var message = translate.message(msg, data); + var timestamp = translate.timestamp(msg, data); if (message) { // Ensure timestamp is not written without a message @@ -78,8 +78,8 @@ function toConsole(log, opts, translate) { function onInfo(msg, data) { // Get message and timestamp before printing anything to avoid // logging a half message if there's an error in one of them - var timestamp = translate.timestamp(); var message = translate.message(msg, data); + var timestamp = translate.timestamp(msg, data); if (message) { // Ensure timestamp is not written without a message @@ -93,8 +93,8 @@ function toConsole(log, opts, translate) { function onDebug(msg, data) { // Get message and timestamp before printing anything to avoid // logging a half message if there's an error in one of them - var timestamp = translate.timestamp(); var message = translate.message(msg, data); + var timestamp = translate.timestamp(msg, data); if (message) { // Ensure timestamp is not written without a message From a2bd8d09a1241f3b40475f644ab6d08edc3c0717 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Wed, 20 Mar 2024 19:47:00 -0700 Subject: [PATCH 36/43] combine tag and data into one object --- index.js | 38 ++++++------ lib/shared/completion.js | 4 +- lib/shared/log/tasks.js | 16 ++--- lib/shared/log/to-console.js | 24 ++++---- lib/shared/options/cli-options.js | 34 +++++------ lib/shared/options/make-help.js | 4 +- lib/shared/translate.js | 58 ++++++++++++------- lib/versioned/^3.7.0/index.js | 6 +- lib/versioned/^3.7.0/log/events.js | 14 ++--- lib/versioned/^4.0.0/index.js | 10 ++-- lib/versioned/^4.0.0/log/events.js | 12 ++-- lib/versioned/^4.0.0/log/sync-task.js | 2 +- messages.js | 3 +- test/config-message-function.js | 23 ++++++-- test/fixtures/.gulp.js | 4 +- .../config/theming/ARGV_ERROR/.gulp.js | 4 +- .../theming/COMPLETION_TYPE_MISSING/.gulp.js | 4 +- .../theming/COMPLETION_TYPE_UNKNOWN/.gulp.js | 4 +- .../config/theming/CWD_CHANGED/.gulp.js | 4 +- .../config/theming/DESCRIPTION/.gulp.js | 4 +- .../theming/DESCRIPTION/remove/.gulp.js | 4 +- .../config/theming/EXEC_ERROR/.gulp.js | 6 +- .../fixtures/config/theming/GULPFILE/.gulp.js | 4 +- .../config/theming/LOADER_FAILURE/.gulp.js | 8 +-- .../config/theming/LOADER_SUCCESS/.gulp.js | 6 +- .../config/theming/MISSING_GULP/.gulp.js | 6 +- .../config/theming/MISSING_GULPFILE/.gulp.js | 4 +- .../theming/MISSING_NODE_MODULES/.gulp.js | 6 +- .../config/theming/NODE_FLAGS/.gulp.js | 6 +- .../config/theming/PRELOAD_BEFORE/.gulp.js | 6 +- .../config/theming/PRELOAD_FAILURE/.gulp.js | 6 +- .../config/theming/PRELOAD_SUCCESS/.gulp.js | 6 +- .../config/theming/RESPAWNED/.gulp.js | 4 +- .../config/theming/TASK_ERROR/.gulp.js | 15 +++-- .../config/theming/TASK_FAILURE/.gulp.js | 17 ++++++ .../config/theming/TASK_FAILURE/gulpfile.js | 3 + .../config/theming/TASK_MISSING/.gulp.js | 6 +- .../config/theming/TASK_START/.gulp.js | 4 +- .../config/theming/TASK_STOP/.gulp.js | 4 +- .../config/theming/TASK_SYNC/.gulp.js | 6 +- .../theming/UNSUPPORTED_GULP_VERSION/.gulp.js | 6 +- test/fixtures/config/theming/USAGE/.gulp.js | 4 +- test/fixtures/config/theming/flags/.gulp.js | 36 ++++++------ test/fixtures/gulpfiles/.gulp.js | 4 +- 44 files changed, 246 insertions(+), 203 deletions(-) create mode 100644 test/fixtures/config/theming/TASK_FAILURE/.gulp.js create mode 100644 test/fixtures/config/theming/TASK_FAILURE/gulpfile.js diff --git a/index.js b/index.js index f842f2be..cbca8f1b 100644 --- a/index.js +++ b/index.js @@ -69,17 +69,17 @@ var opts = parser.parse(); var cleanupListeners = toConsole(log, opts, buildTranslations()); cli.on('preload:before', function(name) { - log.info(messages.PRELOAD_BEFORE, name); + log.info({ tag: messages.PRELOAD_BEFORE, name: name }); }); cli.on('preload:success', function(name) { - log.info(messages.PRELOAD_SUCCESS, name); + log.info({ tag: messages.PRELOAD_SUCCESS, name: name }); }); cli.on('preload:failure', function(name, error) { - log.warn(messages.PRELOAD_FAILURE, name); + log.warn({ tag: messages.PRELOAD_FAILURE, name: name }); if (error) { - log.warn(messages.PRELOAD_ERROR, error); + log.warn({ tag: messages.PRELOAD_ERROR, error: error }); } }); @@ -89,20 +89,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(messages.LOADER_SUCCESS, name); + log.info({ tag: messages.LOADER_SUCCESS, name: name }); } }); cli.on('loader:failure', function(name, error) { - log.warn(messages.LOADER_FAILURE, name); + log.warn({ tag: messages.LOADER_FAILURE, name: name }); if (error) { - log.warn(messages.LOADER_ERROR, error); + log.warn({ tag: messages.LOADER_ERROR, error: error }); } }); cli.on('respawn', function(flags, child) { - log.info(messages.NODE_FLAGS, flags); - log.info(messages.RESPAWNED, child.pid); + log.info({ tag: messages.NODE_FLAGS, flags: flags }); + log.info({ tag: messages.RESPAWNED, pid: child.pid }); }); function run() { @@ -127,7 +127,7 @@ function onFail(message, error) { var cfg = arrayFind(env.config, isDefined); var translate = buildTranslations(cfg); - var errorMsg = translate.message(messages.ARGV_ERROR, { message: message, error: error }); + var errorMsg = translate.message({ tag: messages.ARGV_ERROR, message: message, error: error }); if (errorMsg) { console.error(errorMsg); } @@ -190,25 +190,25 @@ function onExecute(env, flags, translate) { var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); if (missingNodeModules) { - log.error(messages.MISSING_NODE_MODULES, { cwd: env.cwd }); + log.error({ tag: messages.MISSING_NODE_MODULES, cwd: env.cwd }); if (hasYarn) { - log.error(messages.YARN_INSTALL) + log.error({ tag: messages.YARN_INSTALL }) } else { - log.error(messages.NPM_INSTALL) + log.error({ tag: messages.NPM_INSTALL }) } } else { - log.error(messages.MISSING_GULP, { cwd: env.cwd }); + log.error({ tag: messages.MISSING_GULP, cwd: env.cwd }); if (hasYarn) { - log.error(messages.YARN_INSTALL_GULP); + log.error({ tag: messages.YARN_INSTALL_GULP }); } else { - log.error(messages.NPM_INSTALL_GULP); + log.error({ tag: messages.NPM_INSTALL_GULP }); } } exit(1); } if (!env.configPath) { - log.error(messages.MISSING_GULPFILE); + log.error({ tag: messages.MISSING_GULPFILE }); exit(1); } @@ -216,14 +216,14 @@ 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, { cwd: env.cwd }); + log.info({ tag: messages.CWD_CHANGED, cwd: env.cwd }); } // Find the correct CLI version to run var range = findRange(env.modulePackage.version, ranges); if (!range) { - log.error(messages.UNSUPPORTED_GULP_VERSION, env.modulePackage.version); + log.error({ tag: messages.UNSUPPORTED_GULP_VERSION, version: env.modulePackage.version }); exit(1); } diff --git a/lib/shared/completion.js b/lib/shared/completion.js index ecbbd630..4257e524 100644 --- a/lib/shared/completion.js +++ b/lib/shared/completion.js @@ -8,14 +8,14 @@ var messages = require('../../messages'); module.exports = function(name, translate) { if (typeof name !== 'string') { - throw new Error(translate.message(messages.COMPLETION_TYPE_MISSING)); + throw new Error(translate.message({ tag: 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(translate.message(messages.COMPLETION_TYPE_UNKNOWN, { name: name })); + console.log(translate.message({ tag: messages.COMPLETION_TYPE_UNKNOWN, name: name })); process.exit(5); } }; diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 183feb46..733df796 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -65,7 +65,7 @@ function logTasks(tree, opts, getTask, translate) { var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); if (!isLeaf) { - bars += (isLast ? ' ' : translate.message(messages.BOX_DRAWINGS_LIGHT_VERTICAL)); + bars += (isLast ? ' ' : translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_VERTICAL })); bars += ' ' node.nodes.forEach(function(node, idx, arr) { var isLast = idx === arr.length - 1; @@ -78,13 +78,13 @@ function logTasks(tree, opts, getTask, translate) { function addTaskToLines(task, lines, isLast, isLeaf) { 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); + ? translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT }) + : translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT })) + + translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_HORIZONTAL }); if (isLeaf) { - taskBars += translate.message(messages.BOX_DRAWINGS_LIGHT_HORIZONTAL); + taskBars += translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_HORIZONTAL }); } else { - taskBars += translate.message(messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL); + taskBars += translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL }); } taskBars += ' '; @@ -111,14 +111,14 @@ function logTasks(tree, opts, getTask, translate) { if (isLast) { flagBars += ' '; } else { - flagBars += translate.message(messages.BOX_DRAWINGS_LIGHT_VERTICAL); + flagBars += translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_VERTICAL }); } flagBars += ' '; if (isLeaf) { flagBars += ' '; } else { - flagBars += translate.message(messages.BOX_DRAWINGS_LIGHT_VERTICAL); + flagBars += translate.message({ tag: messages.BOX_DRAWINGS_LIGHT_VERTICAL }); } flagBars += ' '; diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index e9d524f6..a3be2c48 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -43,11 +43,11 @@ function toConsole(log, opts, translate) { log.removeListener('debug', onDebug); }; - function onError(msg, data) { + function onError(msg) { // Get message and timestamp before printing anything to avoid // logging a half message if there's an error in one of them - var message = translate.message(msg, data); - var timestamp = translate.timestamp(msg, data); + var message = translate.message(msg); + var timestamp = translate.timestamp(msg); if (message) { // Ensure timestamp is not written without a message @@ -60,11 +60,11 @@ function toConsole(log, opts, translate) { // onWarn, onInfo, and onDebug are currently all the same // implementation but separated to change independently - function onWarn(msg, data) { + function onWarn(msg) { // Get message and timestamp before printing anything to avoid // logging a half message if there's an error in one of them - var message = translate.message(msg, data); - var timestamp = translate.timestamp(msg, data); + var message = translate.message(msg); + var timestamp = translate.timestamp(msg); if (message) { // Ensure timestamp is not written without a message @@ -75,11 +75,11 @@ function toConsole(log, opts, translate) { } } - function onInfo(msg, data) { + function onInfo(msg) { // Get message and timestamp before printing anything to avoid // logging a half message if there's an error in one of them - var message = translate.message(msg, data); - var timestamp = translate.timestamp(msg, data); + var message = translate.message(msg); + var timestamp = translate.timestamp(msg); if (message) { // Ensure timestamp is not written without a message @@ -90,11 +90,11 @@ function toConsole(log, opts, translate) { } } - function onDebug(msg, data) { + function onDebug(msg) { // Get message and timestamp before printing anything to avoid // logging a half message if there's an error in one of them - var message = translate.message(msg, data); - var timestamp = translate.timestamp(msg, data); + var message = translate.message(msg); + var timestamp = translate.timestamp(msg); if (message) { // Ensure timestamp is not written without a message diff --git a/lib/shared/options/cli-options.js b/lib/shared/options/cli-options.js index a1f048a3..558eaa97 100644 --- a/lib/shared/options/cli-options.js +++ b/lib/shared/options/cli-options.js @@ -7,88 +7,88 @@ var options = { help: { alias: 'h', type: 'boolean', - message: messages.FLAG_HELP, + tag: messages.FLAG_HELP, }, version: { alias: 'v', type: 'boolean', - message: messages.FLAG_VERSION, + tag: messages.FLAG_VERSION, }, preload: { type: 'string', requiresArg: true, - message: messages.FLAG_PRELOAD, + tag: messages.FLAG_PRELOAD, }, gulpfile: { alias: 'f', type: 'string', requiresArg: true, - message: messages.FLAG_GULPFILE, + tag: messages.FLAG_GULPFILE, }, cwd: { type: 'string', requiresArg: true, - message: messages.FLAG_CWD, + tag: messages.FLAG_CWD, }, tasks: { alias: 'T', type: 'boolean', - message: messages.FLAG_TASKS, + tag: messages.FLAG_TASKS, }, 'tasks-simple': { type: 'boolean', - message: messages.FLAG_TASKS_SIMPLE, + tag: messages.FLAG_TASKS_SIMPLE, }, 'tasks-json': { - message: messages.FLAG_TASKS_JSON, + tag: 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, + tag: messages.FLAG_TASKS_DEPTH, }, 'compact-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - message: messages.FLAG_COMPACT_TASKS, + tag: messages.FLAG_COMPACT_TASKS, }, 'sort-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - message: messages.FLAG_SORT_TASKS, + tag: messages.FLAG_SORT_TASKS, }, color: { type: 'boolean', - message: messages.FLAG_COLOR, + tag: messages.FLAG_COLOR, }, 'no-color': { type: 'boolean', - message: messages.FLAG_NO_COLOR, + tag: messages.FLAG_NO_COLOR, }, silent: { alias: 'S', type: 'boolean', default: undefined, // To detect if this cli option is specified. - message: messages.FLAG_SILENT, + tag: messages.FLAG_SILENT, }, continue: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - message: messages.FLAG_CONTINUE, + tag: messages.FLAG_CONTINUE, }, series: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - message: messages.FLAG_SERIES, + tag: 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, + tag: messages.FLAG_LOG_LEVEL, } }; diff --git a/lib/shared/options/make-help.js b/lib/shared/options/make-help.js index 8fec2f17..f4c111ab 100644 --- a/lib/shared/options/make-help.js +++ b/lib/shared/options/make-help.js @@ -6,14 +6,14 @@ var cliOptions = require('./cli-options'); var messages = require("../../../messages"); function makeHelp(parser, translate) { - var usage = translate.message(messages.USAGE); + var usage = translate.message({ tag: messages.USAGE }); if (usage) { parser.usage(usage); } Object.keys(cliOptions).forEach(function (flag) { var opt = cliOptions[flag]; - var description = translate.message(opt.message); + var description = translate.message({ tag: opt.tag }); if (description) { parser.describe(flag, description); } diff --git a/lib/shared/translate.js b/lib/shared/translate.js index 9d075e7f..9877ab2f 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -7,6 +7,7 @@ var chalk = require('chalk'); var messages = require('../../messages'); var tildify = require('./tildify'); +var formatTime = require('./log/format-hrtime'); function Timestamp() { this.now = new Date(); @@ -17,35 +18,35 @@ Timestamp.prototype[util.inspect.custom] = function (depth, opts) { return '[' + opts.stylize(timestamp, 'date') + ']'; }; -function getDefaultMessage(msg, data) { - switch (msg) { +function getDefaultMessage(data) { + switch (data.tag) { case messages.PRELOAD_BEFORE: { - return 'Preloading external module: ' + chalk.magenta(data); + return 'Preloading external module: ' + chalk.magenta(data.name); } case messages.PRELOAD_SUCCESS: { - return 'Preloaded external module: ' + chalk.magenta(data) + return 'Preloaded external module: ' + chalk.magenta(data.name) } case messages.PRELOAD_FAILURE: { - return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data); + return chalk.yellow('Failed to preload external module: ') + chalk.magenta(data.name); } case messages.PRELOAD_ERROR: { - return chalk.yellow(data.toString()); + return chalk.yellow(data.error.toString()); } case messages.LOADER_SUCCESS: { - return 'Loaded external module: ' + chalk.magenta(data); + return 'Loaded external module: ' + chalk.magenta(data.name); } case messages.LOADER_FAILURE: { - return chalk.yellow('Failed to load external module: ') + chalk.magenta(data); + return chalk.yellow('Failed to load external module: ') + chalk.magenta(data.name); } case messages.LOADER_ERROR: { - return chalk.yellow(data.toString()); + return chalk.yellow(data.error.toString()); } case messages.NODE_FLAGS: { - var nodeFlags = chalk.magenta(data.join(', ')); + var nodeFlags = chalk.magenta(data.flags.join(', ')); return 'Node flags detected: ' + nodeFlags; } case messages.RESPAWNED: { - var pid = chalk.magenta(data); + var pid = chalk.magenta(data.pid); return 'Respawned to PID: ' + pid; } case messages.MISSING_GULPFILE: { @@ -55,7 +56,7 @@ function getDefaultMessage(msg, data) { return 'Working directory changed to ' + chalk.magenta(tildify(data.cwd)); } case messages.UNSUPPORTED_GULP_VERSION: { - return chalk.red('Unsupported gulp version', data) + return chalk.red('Unsupported gulp version', data.version) } case messages.DESCRIPTION: { return 'Tasks for ' + chalk.magenta(tildify(data.path)); @@ -67,10 +68,10 @@ function getDefaultMessage(msg, data) { return "Starting '" + chalk.cyan(data.task) + "'..." } case messages.TASK_STOP: { - return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(data.duration); + return "Finished '" + chalk.cyan(data.task) + "' after " + chalk.magenta(formatTime(data.duration)); } - case messages.TASK_ERROR: { - return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' +chalk.magenta(data.duration); + case messages.TASK_FAILURE: { + return "'" + chalk.cyan(data.task) + "' " + chalk.red('errored after') + ' ' + chalk.magenta(formatTime(data.duration)); } case messages.TASK_MISSING: { if (data.similar) { @@ -82,7 +83,7 @@ function getDefaultMessage(msg, data) { } } case messages.TASK_SYNC: { - return chalk.red('The following tasks did not complete: ') + chalk.cyan(data) + "\n" + return chalk.red('The following tasks did not complete: ') + chalk.cyan(data.tasks) + "\n" + chalk.red('Did you forget to signal async completion?'); } case messages.MISSING_NODE_MODULES: { @@ -115,6 +116,9 @@ function getDefaultMessage(msg, data) { case messages.EXEC_ERROR: { return data.message; } + case messages.TASK_ERROR: { + return data.message; + } case messages.USAGE: { return '\n' + chalk.bold('Usage:') + ' gulp ' + chalk.blue('[options]') + ' tasks'; } @@ -209,7 +213,7 @@ function getDefaultMessage(msg, data) { return chalk.white('│'); } default: { - return msg; + return data; } } } @@ -222,10 +226,15 @@ function buildTranslations(cfg) { cfg = cfg || {}; return { - message: function (msg, data) { + message: function (data) { + // Don't allow an `undefined` message through + if (typeof data === 'undefined') { + data = Object.create(null); + } + var message; if (typeof cfg.message === 'function') { - message = cfg.message(msg, data); + message = cfg.message(data); } // If the user has provided a message, return it @@ -241,12 +250,17 @@ function buildTranslations(cfg) { // 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); + return getDefaultMessage(data); }, - timestamp: function () { + timestamp: function (data) { + // Don't allow an `undefined` message through + if (typeof data === 'undefined') { + data = Object.create(null); + } + var time; if (typeof cfg.timestamp === 'function') { - time = cfg.timestamp(); + time = cfg.timestamp(data); } // If the user has provided a timestamp, return it diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index c4987cf8..fbaa86f9 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -36,7 +36,7 @@ function execute(env, opts, translate) { exit(1); } - log.info(messages.GULPFILE, { path: env.configPath }); + log.info({ tag: messages.GULPFILE, path: env.configPath }); var gulpInst = require(env.modulePath); logEvents(gulpInst); @@ -52,14 +52,14 @@ function execute(env, opts, translate) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - tree.label = translate.message(messages.DESCRIPTION, { path: env.configPath }); + tree.label = translate.message({ tag: 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, { path: env.configPath }); + tree.label = translate.message({ tag: messages.DESCRIPTION, path: env.configPath }); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index 3375a1e4..09f9c393 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -1,7 +1,6 @@ 'use strict'; var log = require('gulplog'); -var formatTime = require('../../../shared/log/format-hrtime'); var exit = require('../../../shared/exit'); var formatError = require('../format-error'); @@ -27,23 +26,20 @@ 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(messages.TASK_START, { task: e.task }); + log.info({ tag: messages.TASK_START, task: e.task }); }); gulpInst.on('task_stop', function(e) { - var time = formatTime(e.hrDuration); - log.info(messages.TASK_STOP, { task: e.task, duration: time }); + log.info({ tag: messages.TASK_STOP, task: e.task, duration: e.hrDuration }); }); gulpInst.on('task_err', function(e) { - var msg = formatError(e); - var time = formatTime(e.hrDuration); - log.error(messages.TASK_ERROR, { task: e.task, duration: time }); - log.error(msg); + log.error({ tag: messages.TASK_FAILURE, task: e.task, duration: e.hrDuration }); + log.error({ tag: messages.TASK_ERROR, message: formatError(e) }); }); gulpInst.on('task_not_found', function(err) { - log.error(messages.TASK_MISSING, { task: err.task }); + log.error({ tag: messages.TASK_MISSING, task: err.task }); exit(1); }); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index d31a4f69..c2aa461d 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -55,13 +55,13 @@ function execute(env, opts, translate) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - tree.label = translate.message(messages.DESCRIPTION, { path: env.configPath }); + tree.label = translate.message({ tag: 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, { path: env.configPath }); + tree.label = translate.message({ tag: messages.DESCRIPTION, path: env.configPath }); var output = JSON.stringify(copyTree(tree, opts)); @@ -71,7 +71,7 @@ function execute(env, opts, translate) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info(messages.GULPFILE, { path: env.configPath }); + log.info({ tag: messages.GULPFILE, path: env.configPath }); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -81,9 +81,9 @@ function execute(env, opts, translate) { } catch (err) { var task = checkTaskNotFound(err); if (task) { - log.error(messages.TASK_MISSING, { task: task.target, similar: task.similar }); + log.error({ tag: messages.TASK_MISSING, task: task.target, similar: task.similar }); } else { - log.error(messages.EXEC_ERROR, { message: err.message, error: err }); + log.error({ tag: messages.EXEC_ERROR, message: err.message, error: err }); } exit(1); } diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index ba4635ef..b023683c 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -1,7 +1,6 @@ 'use strict'; var log = require('gulplog'); -var formatTime = require('../../../shared/log/format-hrtime'); var formatError = require('../format-error'); // TODO: make into `@gulpjs/messages` @@ -17,25 +16,22 @@ 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](messages.TASK_START, { task: evt.name }); + log[level]({ tag: 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](messages.TASK_STOP, { task: evt.name, duration: time }); + log[level]({ tag: messages.TASK_STOP, task: evt.name, duration: evt.duration }); }); gulpInst.on('error', function(evt) { - var msg = formatError(evt); - var time = formatTime(evt.duration); var level = evt.branch ? 'debug' : 'error'; - log[level](messages.TASK_ERROR, { task: evt.name, duration: time }); + log[level]({ tag: messages.TASK_FAILURE, task: evt.name, duration: evt.duration }); // If we haven't logged this before, log it and add to list if (loggedErrors.indexOf(evt.error) === -1) { - log.error(msg); + log.error({ tag: messages.TASK_ERROR, message: formatError(evt) }); loggedErrors.push(evt.error); } }); diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index 6f788ddd..30cdc25f 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -20,7 +20,7 @@ function warn() { process.exitCode = 1; - log.warn(messages.TASK_SYNC, taskNames); + log.warn({ tag: messages.TASK_SYNC, tasks: taskNames }); } function start(e) { diff --git a/messages.js b/messages.js index e545b6c3..96ba5ab4 100644 --- a/messages.js +++ b/messages.js @@ -34,7 +34,7 @@ module.exports = { */ 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_FAILURE: Symbol.for('GULP_CLI_TASK_FAILURE'), TASK_MISSING: Symbol.for('GULP_CLI_TASK_MISSING'), TASK_SYNC: Symbol.for('GULP_CLI_TASK_SYNC'), @@ -51,6 +51,7 @@ module.exports = { LOADER_ERROR: Symbol.for('GULP_CLI_LOADER_ERROR'), ARGV_ERROR: Symbol.for('GULP_CLI_ARGV_ERROR'), EXEC_ERROR: Symbol.for('GULP_CLI_EXEC_ERROR'), + TASK_ERROR: Symbol.for('GULP_CLI_TASK_ERROR'), /** * Help diff --git a/test/config-message-function.js b/test/config-message-function.js index 18e07c65..d5b9a1bd 100644 --- a/test/config-message-function.js +++ b/test/config-message-function.js @@ -13,7 +13,6 @@ var expectedDir = path.join(__dirname, 'expected/config/theming'); var eraseTime = require('./tool/erase-time'); var eraseLapse = require('./tool/erase-lapse'); -var sliceLines = require('./tool/slice-lines'); var gulp = require('./tool/gulp-cmd'); describe('config: message function', function() { @@ -383,18 +382,32 @@ describe('config: message function', function() { } }); + it('can change TASK_FAILURE with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'TASK_FAILURE'); + var expectedStderr = 'TASK FAILURE: **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expectedStderr); + done(); + } + }); + it('can change TASK_ERROR with .gulp.*', function(done) { var cwd = path.join(baseDir, 'TASK_ERROR'); - var expectedStdout = "Using gulpfile!\nStarting 'default'...\n"; - var expectedStderr = 'TASK ERROR: **default**'; + var expectedStderr = '**TASK ERROR**\n'; var opts = { cwd: cwd }; exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); - expect(sliceLines(stderr, 0, 1)).toEqual(expectedStderr); - expect(eraseTime(stdout)).toEqual(expectedStdout); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expectedStderr); done(); } }); diff --git a/test/fixtures/.gulp.js b/test/fixtures/.gulp.js index ad18e9c8..8b7b1924 100644 --- a/test/fixtures/.gulp.js +++ b/test/fixtures/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../messages'); module.exports = { - message: function (msg) { - if (msg === messages.DESCRIPTION) { + message: function (data) { + if (data.tag === messages.DESCRIPTION) { return "gulp-cli/test/fixtures"; } } diff --git a/test/fixtures/config/theming/ARGV_ERROR/.gulp.js b/test/fixtures/config/theming/ARGV_ERROR/.gulp.js index c25cbdc6..cd948f16 100644 --- a/test/fixtures/config/theming/ARGV_ERROR/.gulp.js +++ b/test/fixtures/config/theming/ARGV_ERROR/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.ARGV_ERROR) { + message: function (data) { + if (data.tag === messages.ARGV_ERROR) { return '**' + data.message + '**'; } } diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js index fa268ca7..03edae29 100644 --- a/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js +++ b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function(msg) { - if (msg === messages.COMPLETION_TYPE_MISSING) { + message: function (data) { + if (data.tag === messages.COMPLETION_TYPE_MISSING) { return 'NO COMPLETION TYPE'; } } diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js index 2b53d569..6dd1a493 100644 --- a/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js +++ b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function(msg, data) { - if (msg === messages.COMPLETION_TYPE_UNKNOWN) { + message: function (data) { + if (data.tag === messages.COMPLETION_TYPE_UNKNOWN) { return 'GULP COMPLETION TYPE **' + data.name + '** IS NOT FOUND'; } } diff --git a/test/fixtures/config/theming/CWD_CHANGED/.gulp.js b/test/fixtures/config/theming/CWD_CHANGED/.gulp.js index 22444169..0e4b2b0a 100644 --- a/test/fixtures/config/theming/CWD_CHANGED/.gulp.js +++ b/test/fixtures/config/theming/CWD_CHANGED/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.CWD_CHANGED) { + message: function (data) { + if (data.tag === messages.CWD_CHANGED) { return 'CHANGE CWD TO **' + data.cwd + '**'; } diff --git a/test/fixtures/config/theming/DESCRIPTION/.gulp.js b/test/fixtures/config/theming/DESCRIPTION/.gulp.js index 787bf358..0ba801d2 100644 --- a/test/fixtures/config/theming/DESCRIPTION/.gulp.js +++ b/test/fixtures/config/theming/DESCRIPTION/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.DESCRIPTION) { + message: function (data) { + if (data.tag === messages.DESCRIPTION) { return '**DESCRIPTION**'; } } diff --git a/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js b/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js index 45d7321a..5018b7be 100644 --- a/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js +++ b/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.DESCRIPTION) { + message: function (data) { + if (data.tag === messages.DESCRIPTION) { return false; } } diff --git a/test/fixtures/config/theming/EXEC_ERROR/.gulp.js b/test/fixtures/config/theming/EXEC_ERROR/.gulp.js index 4c7d1eb0..ef99982f 100644 --- a/test/fixtures/config/theming/EXEC_ERROR/.gulp.js +++ b/test/fixtures/config/theming/EXEC_ERROR/.gulp.js @@ -2,12 +2,12 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg) { - if (msg === messages.EXEC_ERROR) { + message: function (data) { + if (data.tag === messages.EXEC_ERROR) { return 'FAIL TO RUN'; } - if (msg === messages.GULPFILE) { + if (data.tag === messages.GULPFILE) { throw new Error('Crash before task execution'); } } diff --git a/test/fixtures/config/theming/GULPFILE/.gulp.js b/test/fixtures/config/theming/GULPFILE/.gulp.js index 7cf24b82..40f3a74b 100644 --- a/test/fixtures/config/theming/GULPFILE/.gulp.js +++ b/test/fixtures/config/theming/GULPFILE/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.GULPFILE) { + message: function (data) { + if (data.tag === messages.GULPFILE) { return 'USING GULPFILE **abcxyz**'; } diff --git a/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js b/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js index a68faf18..15d7a56d 100644 --- a/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js +++ b/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js @@ -2,12 +2,12 @@ var messages = require('../../../../../messages'); module.exports = { - message: function(msg, data) { - if (msg === messages.LOADER_FAILURE) { - return 'FAIL TO LOAD **' + data + '**'; + message: function (data) { + if (data.tag === messages.LOADER_FAILURE) { + return 'FAIL TO LOAD **' + data.name + '**'; } - if (msg === messages.LOADER_ERROR) { + if (data.tag === messages.LOADER_ERROR) { // Silence for test return false; } diff --git a/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js b/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js index dc00b2db..471d725b 100644 --- a/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js +++ b/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js @@ -2,9 +2,9 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.LOADER_SUCCESS) { - return 'LOADED **' + data + '**!'; + message: function (data) { + if (data.tag === messages.LOADER_SUCCESS) { + return 'LOADED **' + data.name + '**!'; } // Silence all other messages for test diff --git a/test/fixtures/config/theming/MISSING_GULP/.gulp.js b/test/fixtures/config/theming/MISSING_GULP/.gulp.js index 3388e767..a01c5ca4 100644 --- a/test/fixtures/config/theming/MISSING_GULP/.gulp.js +++ b/test/fixtures/config/theming/MISSING_GULP/.gulp.js @@ -1,11 +1,11 @@ module.exports = { - message: function(msg, data) { + message: function (data) { // Using `Symbol.for()` to avoid node_modules - if (msg === Symbol.for('GULP_CLI_MISSING_GULP')) { + if (data.tag === Symbol.for('GULP_CLI_MISSING_GULP')) { return 'GULP NOT FOUND IN **' + data.cwd + '**'; } - if (msg === Symbol.for('GULP_CLI_NPM_INSTALL_GULP')) { + if (data.tag === Symbol.for('GULP_CLI_NPM_INSTALL_GULP')) { // Silence for test return false; } diff --git a/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js b/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js index eb140ec5..9f9066e5 100644 --- a/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js +++ b/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg) { - if (msg === messages.MISSING_GULPFILE) { + message: function (data) { + if (data.tag === messages.MISSING_GULPFILE) { return 'NO GULPFILE'; } } diff --git a/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js b/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js index 07a70017..80cca25d 100644 --- a/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js +++ b/test/fixtures/config/theming/MISSING_NODE_MODULES/.gulp.js @@ -1,11 +1,11 @@ module.exports = { - message: function(msg, data) { + message: function (data) { // Using `Symbol.for()` to avoid node_modules - if (msg === Symbol.for('GULP_CLI_MISSING_NODE_MODULES')) { + if (data.tag === Symbol.for('GULP_CLI_MISSING_NODE_MODULES')) { return 'LOCAL MODULE NOT FOUND **' + data.cwd + '**'; } - if (msg === Symbol.for('GULP_CLI_NPM_INSTALL')) { + if (data.tag === Symbol.for('GULP_CLI_NPM_INSTALL')) { // Silence for test return false; } diff --git a/test/fixtures/config/theming/NODE_FLAGS/.gulp.js b/test/fixtures/config/theming/NODE_FLAGS/.gulp.js index e40f7c26..1f548732 100644 --- a/test/fixtures/config/theming/NODE_FLAGS/.gulp.js +++ b/test/fixtures/config/theming/NODE_FLAGS/.gulp.js @@ -2,9 +2,9 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.NODE_FLAGS) { - return 'RESPAWNED BY **' + data + '**!'; + message: function (data) { + if (data.tag === messages.NODE_FLAGS) { + return 'RESPAWNED BY **' + data.flags + '**!'; } // Silence all other messages for test diff --git a/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js b/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js index cd0fa559..12af60d4 100644 --- a/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js +++ b/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js @@ -2,9 +2,9 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.PRELOAD_BEFORE) { - return 'PRELOADING **' + data + '**!'; + message: function (data) { + if (data.tag === messages.PRELOAD_BEFORE) { + return 'PRELOADING **' + data.name + '**!'; } // Silence all other messages for test diff --git a/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js b/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js index cd190836..2863ad2e 100644 --- a/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js +++ b/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js @@ -2,9 +2,9 @@ var messages = require('../../../../../messages'); module.exports = { - message: function(msg, data) { - if (msg === messages.PRELOAD_FAILURE) { - return 'FAILED TO PRELOAD **' + data + '**'; + message: function (data) { + if (data.tag === messages.PRELOAD_FAILURE) { + return 'FAILED TO PRELOAD **' + data.name + '**'; } // Silence everything else for test diff --git a/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js b/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js index 1993da34..8b17305f 100644 --- a/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js +++ b/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js @@ -2,9 +2,9 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.PRELOAD_SUCCESS) { - return 'PRELOADED **' + data + '**!'; + message: function (data) { + if (data.tag === messages.PRELOAD_SUCCESS) { + return 'PRELOADED **' + data.name + '**!'; } // Silence all other messages for test diff --git a/test/fixtures/config/theming/RESPAWNED/.gulp.js b/test/fixtures/config/theming/RESPAWNED/.gulp.js index 704ab23e..c695811e 100644 --- a/test/fixtures/config/theming/RESPAWNED/.gulp.js +++ b/test/fixtures/config/theming/RESPAWNED/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg) { - if (msg === messages.RESPAWNED) { + message: function (data) { + if (data.tag === messages.RESPAWNED) { return 'RESPAWN!'; } diff --git a/test/fixtures/config/theming/TASK_ERROR/.gulp.js b/test/fixtures/config/theming/TASK_ERROR/.gulp.js index db0d12e0..38f76533 100644 --- a/test/fixtures/config/theming/TASK_ERROR/.gulp.js +++ b/test/fixtures/config/theming/TASK_ERROR/.gulp.js @@ -2,13 +2,16 @@ var messages = require('../../../../../messages'); module.exports = { - message: function(msg, data) { - if (msg === messages.GULPFILE) { - return 'Using gulpfile!'; + message: function (data) { + if (data.tag === messages.TASK_ERROR) { + return '**TASK ERROR**'; } - if (msg === messages.TASK_ERROR) { - return 'TASK ERROR: **' + data.task + '**'; - } + // Silence everything else for test + return false; + }, + timestamp: function () { + // Silence timestamps for test + return false; } }; diff --git a/test/fixtures/config/theming/TASK_FAILURE/.gulp.js b/test/fixtures/config/theming/TASK_FAILURE/.gulp.js new file mode 100644 index 00000000..0d1849be --- /dev/null +++ b/test/fixtures/config/theming/TASK_FAILURE/.gulp.js @@ -0,0 +1,17 @@ +// TODO: make into `@gulpjs/messages` +var messages = require('../../../../../messages'); + +module.exports = { + message: function (data) { + if (data.tag === messages.TASK_FAILURE) { + return 'TASK FAILURE: **' + data.task + '**'; + } + + // Silence everything else for test + return false; + }, + timestamp: function () { + // Silence timestamps for test + return false; + } +}; diff --git a/test/fixtures/config/theming/TASK_FAILURE/gulpfile.js b/test/fixtures/config/theming/TASK_FAILURE/gulpfile.js new file mode 100644 index 00000000..eeb90fd6 --- /dev/null +++ b/test/fixtures/config/theming/TASK_FAILURE/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + throw new Error('FAIL!'); +} diff --git a/test/fixtures/config/theming/TASK_MISSING/.gulp.js b/test/fixtures/config/theming/TASK_MISSING/.gulp.js index b7dac4b1..90038f16 100644 --- a/test/fixtures/config/theming/TASK_MISSING/.gulp.js +++ b/test/fixtures/config/theming/TASK_MISSING/.gulp.js @@ -2,12 +2,12 @@ var messages = require('../../../../../messages'); module.exports = { - message: function(msg, data) { - if (msg === messages.GULPFILE) { + message: function (data) { + if (data.tag === messages.GULPFILE) { return 'Using gulpfile!'; } - if (msg === messages.TASK_MISSING) { + if (data.tag === messages.TASK_MISSING) { return 'TASK IS NOT FOUND: **' + data.task + '** SIMILAR ##' + data.similar.join('') + '##'; } } diff --git a/test/fixtures/config/theming/TASK_START/.gulp.js b/test/fixtures/config/theming/TASK_START/.gulp.js index 05e06b93..9e6b462d 100644 --- a/test/fixtures/config/theming/TASK_START/.gulp.js +++ b/test/fixtures/config/theming/TASK_START/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.TASK_START) { + message: function (data) { + if (data.tag === messages.TASK_START) { return 'START **' + data.task + '**'; } diff --git a/test/fixtures/config/theming/TASK_STOP/.gulp.js b/test/fixtures/config/theming/TASK_STOP/.gulp.js index a07e24f7..5d382759 100644 --- a/test/fixtures/config/theming/TASK_STOP/.gulp.js +++ b/test/fixtures/config/theming/TASK_STOP/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.TASK_STOP) { + message: function (data) { + if (data.tag === messages.TASK_STOP) { return 'STOP **' + data.task + '**'; } diff --git a/test/fixtures/config/theming/TASK_SYNC/.gulp.js b/test/fixtures/config/theming/TASK_SYNC/.gulp.js index c6d11013..217f23dd 100644 --- a/test/fixtures/config/theming/TASK_SYNC/.gulp.js +++ b/test/fixtures/config/theming/TASK_SYNC/.gulp.js @@ -2,9 +2,9 @@ var messages = require('../../../../../messages'); module.exports = { - message: function(msg, data) { - if (msg === messages.TASK_SYNC) { - return 'TASK **' + data + '** DID NOT COMPLETE'; + message: function (data) { + if (data.tag === messages.TASK_SYNC) { + return 'TASK **' + data.tasks + '** DID NOT COMPLETE'; } } }; diff --git a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js index 5f41b6ad..94ec7785 100644 --- a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js +++ b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js @@ -2,9 +2,9 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.UNSUPPORTED_GULP_VERSION) { - return 'BAD GULP VERSION **' + data + '**'; + message: function (data) { + if (data.tag === messages.UNSUPPORTED_GULP_VERSION) { + return 'BAD GULP VERSION **' + data.version + '**'; } } }; diff --git a/test/fixtures/config/theming/USAGE/.gulp.js b/test/fixtures/config/theming/USAGE/.gulp.js index 9d7d9386..ce54d263 100644 --- a/test/fixtures/config/theming/USAGE/.gulp.js +++ b/test/fixtures/config/theming/USAGE/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.USAGE) { + message: function (data) { + if (data.tag === messages.USAGE) { return 'GULP USAGE'; } } diff --git a/test/fixtures/config/theming/flags/.gulp.js b/test/fixtures/config/theming/flags/.gulp.js index 0ce6f928..907a2554 100644 --- a/test/fixtures/config/theming/flags/.gulp.js +++ b/test/fixtures/config/theming/flags/.gulp.js @@ -2,72 +2,72 @@ var messages = require('../../../../../messages'); module.exports = { - message: function (msg, data) { - if (msg === messages.FLAG_HELP) { + message: function (data) { + if (data.tag === messages.FLAG_HELP) { return '**HELP**'; } - if (msg === messages.FLAG_VERSION) { + if (data.tag === messages.FLAG_VERSION) { return '**VERSION**'; } - if (msg === messages.FLAG_PRELOAD) { + if (data.tag === messages.FLAG_PRELOAD) { return '**PRELOAD**'; } - if (msg === messages.FLAG_GULPFILE) { + if (data.tag === messages.FLAG_GULPFILE) { return '**GULPFILE**'; } - if (msg === messages.FLAG_CWD) { + if (data.tag === messages.FLAG_CWD) { return '**CWD**'; } - if (msg === messages.FLAG_TASKS) { + if (data.tag === messages.FLAG_TASKS) { return '**TASKS**'; } - if (msg === messages.FLAG_TASKS_SIMPLE) { + if (data.tag === messages.FLAG_TASKS_SIMPLE) { return '**TASKS SIMPLE**'; } - if (msg === messages.FLAG_TASKS_JSON) { + if (data.tag === messages.FLAG_TASKS_JSON) { return '**TASKS JSON**'; } - if (msg === messages.FLAG_TASKS_DEPTH) { + if (data.tag === messages.FLAG_TASKS_DEPTH) { return '**TASKS DEPTH**'; } - if (msg === messages.FLAG_COMPACT_TASKS) { + if (data.tag === messages.FLAG_COMPACT_TASKS) { return '**COMPACT TASKS**'; } - if (msg === messages.FLAG_SORT_TASKS) { + if (data.tag === messages.FLAG_SORT_TASKS) { return '**SORT_TASKS**'; } - if (msg === messages.FLAG_COLOR) { + if (data.tag === messages.FLAG_COLOR) { return '**COLOR**'; } - if (msg === messages.FLAG_NO_COLOR) { + if (data.tag === messages.FLAG_NO_COLOR) { return '**NO COLOR**'; } - if (msg === messages.FLAG_SILENT) { + if (data.tag === messages.FLAG_SILENT) { return '**SILENT**'; } - if (msg === messages.FLAG_CONTINUE) { + if (data.tag === messages.FLAG_CONTINUE) { return '**CONTINUE**'; } - if (msg === messages.FLAG_SERIES) { + if (data.tag === messages.FLAG_SERIES) { return '**SERIES**'; } - if (msg === messages.FLAG_LOG_LEVEL) { + if (data.tag === messages.FLAG_LOG_LEVEL) { return '**LOG LEVEL**'; } diff --git a/test/fixtures/gulpfiles/.gulp.js b/test/fixtures/gulpfiles/.gulp.js index a4eb937f..4612d094 100644 --- a/test/fixtures/gulpfiles/.gulp.js +++ b/test/fixtures/gulpfiles/.gulp.js @@ -2,8 +2,8 @@ var messages = require('../../../messages'); module.exports = { - message: function (msg) { - if (msg === messages.DESCRIPTION) { + message: function (data) { + if (data.tag === messages.DESCRIPTION) { return "gulp-cli/test/fixtures/gulpfiles"; } } From 3cbda52875668ec6d9be5c9adff1492a9754a3f3 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Wed, 20 Mar 2024 19:47:46 -0700 Subject: [PATCH 37/43] remove todo --- test/config-message-function.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/config-message-function.js b/test/config-message-function.js index d5b9a1bd..08c7d7b5 100644 --- a/test/config-message-function.js +++ b/test/config-message-function.js @@ -63,7 +63,6 @@ describe('config: message function', function() { } }); - // TODO: Do we want tests returning false for every message? it('can remove DESCRIPTION line output with .gulp.*', function(done) { var cwd = path.join(baseDir, 'DESCRIPTION/remove'); var expected = '└── default\n'; From 9d3fc1797e8dc0e349414696b66bf3eaca424b1b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 21 Mar 2024 18:08:41 -0700 Subject: [PATCH 38/43] remove leftover file --- .../^4.0.0/log/check-task-not-found.js | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 lib/versioned/^4.0.0/log/check-task-not-found.js 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 deleted file mode 100644 index 84d1a050..00000000 --- a/lib/versioned/^4.0.0/log/check-task-not-found.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -function checkTaskNotFound(err) { - /* istanbul ignore if */ - if (!err || !err.message) { - return undefined; - } - var fixed0 = 'Task never defined: '; - var fixed1 = ' - did you mean? '; - - if (err.message.startsWith(fixed0)) { - var target = err.message.slice(fixed0.length); - var similar = undefined; - - var index = target.indexOf(fixed1); - if (index >= 0) { - similar = target.slice(index + fixed1.length).split(', '); - target = target.slice(0, index); - } - - if (similar && similar.length) { - return { target: target, similar: similar }; - } else { - return { target: target }; - } - } -} - -module.exports = checkTaskNotFound; From 8ff5be5348c6a10335d80ef19b8ff15895ee9130 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 21 Mar 2024 18:17:08 -0700 Subject: [PATCH 39/43] fix merge leftover --- lib/versioned/^4.0.0/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index fcd3c04e..bf08088c 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -12,7 +12,6 @@ var logEvents = require('./log/events'); var logSyncTask = require('./log/sync-task'); var normalizeError = require('./normalize-error'); var logTasksSimple = require('./log/tasks-simple'); -var checkTaskNotFound = require('./log/check-task-not-found'); var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); From 22ed426f25ad6bf404eff2cfdfa71e1fa6d6a68e Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 21 Mar 2024 18:19:50 -0700 Subject: [PATCH 40/43] message handling for task names/descriptions, task flags/descriptions --- .eslintrc | 2 +- lib/shared/log/tasks.js | 10 +++++----- lib/shared/translate.js | 12 ++++++++++++ messages.js | 4 ++++ test/expected/by-unwrap-and-not-by-unwrap.txt | 8 ++++---- test/expected/with-desc-and-flags.txt | 4 ++-- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.eslintrc b/.eslintrc index 8451f905..c35bface 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,7 +2,7 @@ "extends": "gulp", "rules": { "max-len": [1, 130], - "max-statements": [1, 60], + "max-statements": [1, 65], "no-console": "off" } } diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 733df796..1911bc35 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -90,14 +90,14 @@ function logTasks(tree, opts, getTask, translate) { var line = {}; if (task.depth === 1) { - line.label = taskBars + task.label + line.label = taskBars + translate.message({ tag: messages.TASK_NAME, name: task.label }); } else { - line.label = taskBars + task.label; + line.label = taskBars + translate.message({ tag: messages.TASK_NAME, name: task.label }); } line.width = stringWidth(line.label); if (typeof task.desc === 'string' && task.desc) { - line.desc = task.desc; + line.desc = translate.message({ tag: messages.TASK_DESCRIPTION, description: task.desc }); } lines.push(line); @@ -127,13 +127,13 @@ function logTasks(tree, opts, getTask, translate) { function addFlagsToLines(ent) { if (typeof ent[0] !== 'string' || !ent[0]) return; var line = {}; - line.label = flagBars + ent[0]; + line.label = flagBars + translate.message({ tag: messages.TASK_FLAG, flag: ent[0] }); line.width = stringWidth(line.label); maxLabelWidth = Math.max(maxLabelWidth, line.width); if (typeof ent[1] === 'string' && ent[1] !== '') { - line.desc = ent[1]; + line.desc = translate.message({ tag: messages.TASK_FLAG_DESCRIPTION, description: ent[1] }); } lines.push(line); } diff --git a/lib/shared/translate.js b/lib/shared/translate.js index 9877ab2f..147d88ff 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -197,6 +197,18 @@ function getDefaultMessage(data) { '-LLL is default.' ); } + case messages.TASK_NAME: { + return chalk.cyan(data.name); + } + case messages.TASK_DESCRIPTION: { + return chalk.white(data.description); + } + case messages.TASK_FLAG: { + return chalk.magenta(data.flag); + } + case messages.TASK_FLAG_DESCRIPTION: { + return chalk.white('…' + data.description); + } case messages.BOX_DRAWINGS_LIGHT_UP_AND_RIGHT: { return chalk.white('└'); } diff --git a/messages.js b/messages.js index 96ba5ab4..1729007d 100644 --- a/messages.js +++ b/messages.js @@ -78,6 +78,10 @@ module.exports = { /** * Task tree */ + TASK_NAME: Symbol.for('GULP_CLI_TASK_NAME'), + TASK_DESCRIPTION: Symbol.for('GULP_CLI_TASK_DESCRIPTION'), + TASK_FLAG: Symbol.for('GULP_CLI_TASK_FLAG'), + TASK_FLAG_DESCRIPTION: Symbol.for('GULP_CLI_TASK_FLAG_DESCRIPTION'), 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/expected/by-unwrap-and-not-by-unwrap.txt b/test/expected/by-unwrap-and-not-by-unwrap.txt index fe35039d..22de5a7f 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 eb2f80dc..34e85d2c 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 From ff19cd5651902df6822ce20167fa26330e1ba953 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 21 Mar 2024 18:23:46 -0700 Subject: [PATCH 41/43] add documentation --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1e9089e0..bfb6c6d1 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,8 @@ Supported configurations properties: | flags.tasksDepth | Set default depth of task dependency tree. | | flags.silent | Silence logging by default | | flags.series | Run tasks given on the CLI in series (the default is parallel) | +| message(data) | A function used to translate messages that pass through gulp-cli. Can receive an object like `{ tag: Symbol(), ...props }` where the `tag` is a symbol from `@gulpjs/messages`. The string returned from this function will be logged. If `false` is explicitly returned, no message will be logged. | +| timestamp(data) | A function used to provide timestamps for gulp-cli. Can receive an object like `{ tag: Symbol(), ...props }` where the `tag` is a symbol from `@gulpjs/messages`. The string returned from this function will be output before any messages. If `false` is explicitly returned, no timestamp will be output. | ## Flags From 8e2b4909190338095800b4b9f99d473e266c9936 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 21 Mar 2024 18:30:34 -0700 Subject: [PATCH 42/43] try-catch around user code --- lib/shared/translate.js | 14 ++++++++++++-- test/config-message-function.js | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/shared/translate.js b/lib/shared/translate.js index 147d88ff..e3362630 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -246,7 +246,12 @@ function buildTranslations(cfg) { var message; if (typeof cfg.message === 'function') { - message = cfg.message(data); + try { + message = cfg.message(data); + } catch (err) { + console.error('A problem occurred with the user-defined `message()` function.'); + console.error('Please correct your `.gulp.*` config file.'); + } } // If the user has provided a message, return it @@ -272,7 +277,12 @@ function buildTranslations(cfg) { var time; if (typeof cfg.timestamp === 'function') { - time = cfg.timestamp(data); + try { + time = cfg.timestamp(data); + } catch (err) { + console.error('A problem occurred with the user-defined `timestamp()` function.'); + console.error('Please correct your `.gulp.*` config file.'); + } } // If the user has provided a timestamp, return it diff --git a/test/config-message-function.js b/test/config-message-function.js index 08c7d7b5..e39c1ede 100644 --- a/test/config-message-function.js +++ b/test/config-message-function.js @@ -427,7 +427,8 @@ describe('config: message function', function() { } }); - it('can change EXEC_ERROR with .gulp.*', function(done) { + // Would need to hook gulp to test this + it.skip('can change EXEC_ERROR with .gulp.*', function(done) { var cwd = path.join(baseDir, 'EXEC_ERROR'); var expected = 'FAIL TO RUN\n'; From da31e9c0264d62a3ad2443ac2719bdbdddacc7ae Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 22 Mar 2024 20:51:11 -0700 Subject: [PATCH 43/43] messages package --- index.js | 4 +- lib/shared/completion.js | 3 +- lib/shared/log/tasks.js | 5 +- lib/shared/options/cli-options.js | 3 +- lib/shared/options/make-help.js | 3 +- lib/shared/translate.js | 3 +- lib/versioned/^3.7.0/index.js | 4 +- lib/versioned/^3.7.0/log/events.js | 5 +- lib/versioned/^4.0.0/index.js | 4 +- lib/versioned/^4.0.0/log/events.js | 5 +- lib/versioned/^4.0.0/log/sync-task.js | 4 +- messages.js | 90 ------------------- package.json | 1 + test/fixtures/.gulp.js | 3 +- .../config/theming/ARGV_ERROR/.gulp.js | 3 +- .../theming/COMPLETION_TYPE_MISSING/.gulp.js | 3 +- .../theming/COMPLETION_TYPE_UNKNOWN/.gulp.js | 3 +- .../config/theming/CWD_CHANGED/.gulp.js | 3 +- .../config/theming/DESCRIPTION/.gulp.js | 3 +- .../theming/DESCRIPTION/remove/.gulp.js | 3 +- .../config/theming/EXEC_ERROR/.gulp.js | 3 +- .../fixtures/config/theming/GULPFILE/.gulp.js | 3 +- .../config/theming/LOADER_FAILURE/.gulp.js | 3 +- .../config/theming/LOADER_SUCCESS/.gulp.js | 3 +- .../config/theming/MISSING_GULPFILE/.gulp.js | 3 +- .../config/theming/NODE_FLAGS/.gulp.js | 3 +- .../config/theming/PRELOAD_BEFORE/.gulp.js | 3 +- .../config/theming/PRELOAD_FAILURE/.gulp.js | 3 +- .../config/theming/PRELOAD_SUCCESS/.gulp.js | 3 +- .../config/theming/RESPAWNED/.gulp.js | 3 +- .../config/theming/TASK_ERROR/.gulp.js | 3 +- .../config/theming/TASK_FAILURE/.gulp.js | 3 +- .../config/theming/TASK_MISSING/.gulp.js | 3 +- .../config/theming/TASK_START/.gulp.js | 3 +- .../config/theming/TASK_STOP/.gulp.js | 3 +- .../config/theming/TASK_SYNC/.gulp.js | 3 +- .../theming/UNSUPPORTED_GULP_VERSION/.gulp.js | 3 +- test/fixtures/config/theming/USAGE/.gulp.js | 3 +- test/fixtures/config/theming/flags/.gulp.js | 3 +- test/fixtures/gulpfiles/.gulp.js | 3 +- 40 files changed, 42 insertions(+), 173 deletions(-) delete mode 100644 messages.js diff --git a/index.js b/index.js index cbca8f1b..3491a7a6 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ var yargs = require('yargs'); var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); +var messages = require('@gulpjs/messages'); var findRange = require('semver-greatest-satisfied-range'); var exit = require('./lib/shared/exit'); @@ -22,9 +23,6 @@ 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 var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); diff --git a/lib/shared/completion.js b/lib/shared/completion.js index 4257e524..d637d140 100644 --- a/lib/shared/completion.js +++ b/lib/shared/completion.js @@ -3,8 +3,7 @@ var fs = require('fs'); var path = require('path'); -// TODO: make into `@gulpjs/messages` -var messages = require('../../messages'); +var messages = require('@gulpjs/messages'); module.exports = function(name, translate) { if (typeof name !== 'string') { diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 1911bc35..0590ef4a 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -1,10 +1,9 @@ 'use strict'; var stringWidth = require('string-width'); -var isObject = require('../is-object'); +var messages = require('@gulpjs/messages'); -// TODO: make into `@gulpjs/messages` -var messages = require('../../../messages'); +var isObject = require('../is-object'); function logTasks(tree, opts, getTask, translate) { if (opts.sortTasks) { diff --git a/lib/shared/options/cli-options.js b/lib/shared/options/cli-options.js index 558eaa97..b84c7948 100644 --- a/lib/shared/options/cli-options.js +++ b/lib/shared/options/cli-options.js @@ -1,7 +1,6 @@ 'use strict'; -// TODO: make into `@gulpjs/messages` -var messages = require("../../../messages"); +var messages = require('@gulpjs/messages'); var options = { help: { diff --git a/lib/shared/options/make-help.js b/lib/shared/options/make-help.js index f4c111ab..7a56387f 100644 --- a/lib/shared/options/make-help.js +++ b/lib/shared/options/make-help.js @@ -2,8 +2,7 @@ var cliOptions = require('./cli-options'); -// TODO: make into `@gulpjs/messages` -var messages = require("../../../messages"); +var messages = require('@gulpjs/messages'); function makeHelp(parser, translate) { var usage = translate.message({ tag: messages.USAGE }); diff --git a/lib/shared/translate.js b/lib/shared/translate.js index e3362630..00c29ae6 100644 --- a/lib/shared/translate.js +++ b/lib/shared/translate.js @@ -3,8 +3,7 @@ var util = require('util'); var chalk = require('chalk'); -// TODO: make into `@gulpjs/messages` -var messages = require('../../messages'); +var messages = require('@gulpjs/messages'); var tildify = require('./tildify'); var formatTime = require('./log/format-hrtime'); diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index fbaa86f9..bce66146 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -4,6 +4,7 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); +var messages = require('@gulpjs/messages'); var taskTree = require('./task-tree'); var copyTree = require('../../shared/log/copy-tree'); @@ -15,9 +16,6 @@ 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) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index 09f9c393..3fb63398 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -1,12 +1,11 @@ 'use strict'; var log = require('gulplog'); +var messages = require('@gulpjs/messages'); + var exit = require('../../../shared/exit'); var formatError = require('../format-error'); -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../messages'); - // Wire up logging events function logEvents(gulpInst) { diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index bf08088c..4adb9164 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -4,6 +4,7 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); +var messages = require('@gulpjs/messages'); var exit = require('../../shared/exit'); @@ -18,9 +19,6 @@ 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) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index b023683c..af20f656 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -1,10 +1,9 @@ 'use strict'; var log = require('gulplog'); -var formatError = require('../format-error'); +var messages = require('@gulpjs/messages'); -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../messages'); +var formatError = require('../format-error'); // Wire up logging events function logEvents(gulpInst) { diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index 30cdc25f..70c38a78 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,9 +1,7 @@ 'use strict'; var log = require('gulplog'); - -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../messages') +var messages = require('@gulpjs/messages'); var tasks = {}; diff --git a/messages.js b/messages.js deleted file mode 100644 index 1729007d..00000000 --- a/messages.js +++ /dev/null @@ -1,90 +0,0 @@ -module.exports = { - /** - * Liftoff events - */ - PRELOAD_BEFORE: Symbol.for('GULP_CLI_PRELOAD_BEFORE'), - PRELOAD_SUCCESS: Symbol.for('GULP_CLI_PRELOAD_SUCCESS'), - PRELOAD_FAILURE: Symbol.for('GULP_CLI_PRELOAD_FAILURE'), - LOADER_SUCCESS: Symbol.for('GULP_CLI_LOADER_SUCCESS'), - LOADER_FAILURE: Symbol.for('GULP_CLI_LOADER_FAILURE'), - NODE_FLAGS: Symbol.for('GULP_CLI_NODE_FLAGS'), - RESPAWNED: Symbol.for('GULP_CLI_RESPAWNED'), - - /** - * Various problems that might occur - */ - UNSUPPORTED_GULP_VERSION: Symbol.for('GULP_CLI_UNSUPPORTED_GULP_VERSION'), - MISSING_GULPFILE: Symbol.for('GULP_CLI_MISSING_GULPFILE'), - 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'), - - /** - * Other details - */ - CWD_CHANGED: Symbol.for('GULP_CLI_CWD_CHANGED'), - DESCRIPTION: Symbol.for('GULP_CLI_DESCRIPTION'), - GULPFILE: Symbol.for('GULP_CLI_GULPFILE'), - - /** - * Task system - */ - TASK_START: Symbol.for('GULP_CLI_TASK_START'), - TASK_STOP: Symbol.for('GULP_CLI_TASK_STOP'), - TASK_FAILURE: Symbol.for('GULP_CLI_TASK_FAILURE'), - TASK_MISSING: Symbol.for('GULP_CLI_TASK_MISSING'), - TASK_SYNC: Symbol.for('GULP_CLI_TASK_SYNC'), - - /** - * Completions - */ - COMPLETION_TYPE_MISSING: Symbol.for('GULP_CLI_COMPLETION_TYPE_MISSING'), - COMPLETION_TYPE_UNKNOWN: Symbol.for('GULP_CLI_COMPLETION_TYPE_UNKNOWN'), - - /** - * Errors - */ - PRELOAD_ERROR: Symbol.for('GULP_CLI_PRELOAD_ERROR'), - LOADER_ERROR: Symbol.for('GULP_CLI_LOADER_ERROR'), - ARGV_ERROR: Symbol.for('GULP_CLI_ARGV_ERROR'), - EXEC_ERROR: Symbol.for('GULP_CLI_EXEC_ERROR'), - TASK_ERROR: Symbol.for('GULP_CLI_TASK_ERROR'), - - /** - * Help - */ - 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'), - - /** - * Task tree - */ - TASK_NAME: Symbol.for('GULP_CLI_TASK_NAME'), - TASK_DESCRIPTION: Symbol.for('GULP_CLI_TASK_DESCRIPTION'), - TASK_FLAG: Symbol.for('GULP_CLI_TASK_FLAG'), - TASK_FLAG_DESCRIPTION: Symbol.for('GULP_CLI_TASK_FLAG_DESCRIPTION'), - 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/package.json b/package.json index 5e304dd5..d67c575d 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "cover": "nyc mocha --async-only --timeout 5000 test/lib test" }, "dependencies": { + "@gulpjs/messages": "^1.0.0", "chalk": "^4.1.2", "copy-props": "^4.0.0", "gulplog": "^2.1.0", diff --git a/test/fixtures/.gulp.js b/test/fixtures/.gulp.js index 8b7b1924..c2ca66b9 100644 --- a/test/fixtures/.gulp.js +++ b/test/fixtures/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/ARGV_ERROR/.gulp.js b/test/fixtures/config/theming/ARGV_ERROR/.gulp.js index cd948f16..674530d6 100644 --- a/test/fixtures/config/theming/ARGV_ERROR/.gulp.js +++ b/test/fixtures/config/theming/ARGV_ERROR/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js index 03edae29..0d1b6b4d 100644 --- a/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js +++ b/test/fixtures/config/theming/COMPLETION_TYPE_MISSING/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js index 6dd1a493..5db07839 100644 --- a/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js +++ b/test/fixtures/config/theming/COMPLETION_TYPE_UNKNOWN/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/CWD_CHANGED/.gulp.js b/test/fixtures/config/theming/CWD_CHANGED/.gulp.js index 0e4b2b0a..abdb16ba 100644 --- a/test/fixtures/config/theming/CWD_CHANGED/.gulp.js +++ b/test/fixtures/config/theming/CWD_CHANGED/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/DESCRIPTION/.gulp.js b/test/fixtures/config/theming/DESCRIPTION/.gulp.js index 0ba801d2..6bfacc09 100644 --- a/test/fixtures/config/theming/DESCRIPTION/.gulp.js +++ b/test/fixtures/config/theming/DESCRIPTION/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js b/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js index 5018b7be..8031c96d 100644 --- a/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js +++ b/test/fixtures/config/theming/DESCRIPTION/remove/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/EXEC_ERROR/.gulp.js b/test/fixtures/config/theming/EXEC_ERROR/.gulp.js index ef99982f..853d150c 100644 --- a/test/fixtures/config/theming/EXEC_ERROR/.gulp.js +++ b/test/fixtures/config/theming/EXEC_ERROR/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/GULPFILE/.gulp.js b/test/fixtures/config/theming/GULPFILE/.gulp.js index 40f3a74b..cbc5684f 100644 --- a/test/fixtures/config/theming/GULPFILE/.gulp.js +++ b/test/fixtures/config/theming/GULPFILE/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js b/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js index 15d7a56d..6ae4c154 100644 --- a/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js +++ b/test/fixtures/config/theming/LOADER_FAILURE/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js b/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js index 471d725b..2079b8ac 100644 --- a/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js +++ b/test/fixtures/config/theming/LOADER_SUCCESS/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js b/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js index 9f9066e5..f5c441a7 100644 --- a/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js +++ b/test/fixtures/config/theming/MISSING_GULPFILE/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/NODE_FLAGS/.gulp.js b/test/fixtures/config/theming/NODE_FLAGS/.gulp.js index 1f548732..33127d58 100644 --- a/test/fixtures/config/theming/NODE_FLAGS/.gulp.js +++ b/test/fixtures/config/theming/NODE_FLAGS/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js b/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js index 12af60d4..a9ccf495 100644 --- a/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js +++ b/test/fixtures/config/theming/PRELOAD_BEFORE/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js b/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js index 2863ad2e..fc2a1570 100644 --- a/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js +++ b/test/fixtures/config/theming/PRELOAD_FAILURE/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js b/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js index 8b17305f..177818cc 100644 --- a/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js +++ b/test/fixtures/config/theming/PRELOAD_SUCCESS/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/RESPAWNED/.gulp.js b/test/fixtures/config/theming/RESPAWNED/.gulp.js index c695811e..1b79a3c7 100644 --- a/test/fixtures/config/theming/RESPAWNED/.gulp.js +++ b/test/fixtures/config/theming/RESPAWNED/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/TASK_ERROR/.gulp.js b/test/fixtures/config/theming/TASK_ERROR/.gulp.js index 38f76533..77f9004a 100644 --- a/test/fixtures/config/theming/TASK_ERROR/.gulp.js +++ b/test/fixtures/config/theming/TASK_ERROR/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/TASK_FAILURE/.gulp.js b/test/fixtures/config/theming/TASK_FAILURE/.gulp.js index 0d1849be..af699b5e 100644 --- a/test/fixtures/config/theming/TASK_FAILURE/.gulp.js +++ b/test/fixtures/config/theming/TASK_FAILURE/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/TASK_MISSING/.gulp.js b/test/fixtures/config/theming/TASK_MISSING/.gulp.js index 90038f16..153f09fa 100644 --- a/test/fixtures/config/theming/TASK_MISSING/.gulp.js +++ b/test/fixtures/config/theming/TASK_MISSING/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/TASK_START/.gulp.js b/test/fixtures/config/theming/TASK_START/.gulp.js index 9e6b462d..671c2c5c 100644 --- a/test/fixtures/config/theming/TASK_START/.gulp.js +++ b/test/fixtures/config/theming/TASK_START/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/TASK_STOP/.gulp.js b/test/fixtures/config/theming/TASK_STOP/.gulp.js index 5d382759..23eee49b 100644 --- a/test/fixtures/config/theming/TASK_STOP/.gulp.js +++ b/test/fixtures/config/theming/TASK_STOP/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/TASK_SYNC/.gulp.js b/test/fixtures/config/theming/TASK_SYNC/.gulp.js index 217f23dd..a4911fe5 100644 --- a/test/fixtures/config/theming/TASK_SYNC/.gulp.js +++ b/test/fixtures/config/theming/TASK_SYNC/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js index 94ec7785..47159f8f 100644 --- a/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js +++ b/test/fixtures/config/theming/UNSUPPORTED_GULP_VERSION/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/USAGE/.gulp.js b/test/fixtures/config/theming/USAGE/.gulp.js index ce54d263..0c064d41 100644 --- a/test/fixtures/config/theming/USAGE/.gulp.js +++ b/test/fixtures/config/theming/USAGE/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/config/theming/flags/.gulp.js b/test/fixtures/config/theming/flags/.gulp.js index 907a2554..72020819 100644 --- a/test/fixtures/config/theming/flags/.gulp.js +++ b/test/fixtures/config/theming/flags/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) { diff --git a/test/fixtures/gulpfiles/.gulp.js b/test/fixtures/gulpfiles/.gulp.js index 4612d094..33b2e061 100644 --- a/test/fixtures/gulpfiles/.gulp.js +++ b/test/fixtures/gulpfiles/.gulp.js @@ -1,5 +1,4 @@ -// TODO: make into `@gulpjs/messages` -var messages = require('../../../messages'); +var messages = require('@gulpjs/messages'); module.exports = { message: function (data) {