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');