Skip to content

Commit

Permalink
refactor(public/exec): uses series individually in order to log scope…
Browse files Browse the repository at this point in the history
…s before each run
  • Loading branch information
rafamel committed May 6, 2019
1 parent 5600b8e commit e46f0bb
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions src/public/exec/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import join from 'command-join';
import { NODE_PATH, KPO_PATH } from '~/constants';
import { IMultiExecOptions } from '~/types';
import chalk from 'chalk';
import { oneLine } from 'common-tags';
import errors from '~/utils/errors';
import logger from '~/utils/logger';

/**
* Options taken by `stream`
Expand Down Expand Up @@ -70,38 +70,29 @@ function stream(
.concat(args.length ? ['--'].concat(args) : []);
});

await (options.parallel
? parallel.fn(commands.map(join), {
...options,
cwd: undefined,
names: children.map((child) => '@' + child.name)
})
: series
.fn(
commands.reduce(
(acc: string[], cmd, i) =>
acc.concat([
join([
NODE_PATH,
'-e',
oneLine`console.log(
"${i === 0 ? 'Scope:' : '\\nScope:'}
${chalk.bold.yellow('@' + children[i].name)}"
)`
]),
join(cmd)
]),
[]
),
{ ...options, cwd: undefined }
)
if (options.parallel) {
await parallel.fn(commands.map(join), {
...options,
cwd: undefined,
names: children.map((child) => '@' + child.name)
});
} else {
for (let i = 0; i < commands.length; i++) {
logger.info(
(i === 0 ? 'Scope: ' : '\nScope: ') +
chalk.bold.yellow('@' + children[i].name)
);
await series
.fn(join(commands[i]), { ...options, cwd: undefined })
.catch(async (err) => {
throw new errors.WrappedError(
'Series commands execution failed',
`Stream failed for ${children[i].name}: ${join(argv)}`,
null,
err
);
}));
});
}
}
};
}

Expand Down

0 comments on commit e46f0bb

Please sign in to comment.