Skip to content

Commit

Permalink
load user messages and timestamps, integrate with liftoff 5
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Mar 17, 2024
1 parent ac44fe2 commit 1000066
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 307 deletions.
38 changes: 22 additions & 16 deletions index.js
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
179 changes: 0 additions & 179 deletions lib/shared/config/env-config.js

This file was deleted.

23 changes: 13 additions & 10 deletions lib/shared/log/tasks.js
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 1000066

Please sign in to comment.