Skip to content

Commit

Permalink
feat: improves logged messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed May 1, 2019
1 parent 9fad602 commit d1c7751
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/public/exec/parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ const parallel: IParallel = (() => {
null,
e
);
if (options.silent) logger.error(err.message);
else throw err;
if (options.silent) {
logger.error(err.message);
logger.debug(err);
} else {
throw err;
}
}
};
});
Expand Down
5 changes: 4 additions & 1 deletion src/public/exec/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const series: ISeries = (() => {
await core.exec(command, args || [], false, options);
} catch (e) {
err = e;
if (options.force || options.silent) logger.error(e.message);
if (options.force || options.silent) {
logger.error(e.message);
logger.debug(e);
}
if (!options.force) break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/public/kpo/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function run(tasks: string | string[]): (args?: string[]) => Promise<void> {

for (let path of tasks) {
const task = await core.task(path);
logger.info('\nRunning task: ' + chalk.bold.green(task.path));
logger.info('Running ' + chalk.bold.green(task.path));
await core.run(task.script, args || []);
logger.debug('Done with task: ' + task.path);
}
Expand Down
9 changes: 6 additions & 3 deletions src/public/tags/silent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import core from '~/core';
import asTag from '~/utils/as-tag';
import logger from '~/utils/logger';
import expose, { TExposedOverload } from '~/utils/expose';
import { ensure } from 'errorish';

export default expose(silent) as TExposedOverload<
typeof silent,
Expand All @@ -14,7 +15,7 @@ function silent(
...placeholders: any[]
): (args?: string[]) => Promise<void>;
/**
* String tag; executes a command that will always exit with code 0.
* String tag; executes a command that will always exit with code *0.*
* It is an *exposed* function: use `silent.fn` as tag instead in order to execute on call.
* @returns An asynchronous function -hence, calling `silent` won't have any effect until the returned function is called.
*/
Expand All @@ -23,8 +24,10 @@ function silent(...args: any[]): (args?: string[]) => Promise<void> {
try {
const command = asTag(args.shift(), ...args);
await core.exec(command, argv || [], false);
} catch (err) {
logger.error(err);
} catch (e) {
const err = ensure(e);
logger.error(err.message);
logger.debug(err);
}
};
}
7 changes: 3 additions & 4 deletions src/utils/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import logger from '~/utils/logger';
import { rejects } from 'errorish';
import onExit from 'signal-exit';
import uuid from 'uuid/v4';
import join from 'command-join';
import { IOfType, IExecOptions } from '~/types';

export const processes: IOfType<ChildProcess> = {};
Expand Down Expand Up @@ -42,9 +43,7 @@ export async function trunk(
if (!options.stdio) options.stdio = DEFAULT_STDIO;
if (!options.env) options.env = process.env;

logger.debug(
'Executing: ' + command + (args.length ? ` "${args.join('" "')}"` : '')
);
logger.debug('Executing: ' + join([command].concat(args)));
const id = uuid();
const ps = isFork
? fork(command, args, options)
Expand All @@ -55,7 +54,7 @@ export async function trunk(
ps.on('close', (code: number) => {
delete processes[id];
return code
? reject(Error(`"${command}" failed with code ${code}`))
? reject(Error(`${join([command])} failed with code ${code}`))
: resolve();
});
ps.on('error', (err: any) => {
Expand Down

0 comments on commit d1c7751

Please sign in to comment.