Skip to content

Commit

Permalink
fix(cli): re-enable parallel scripts
Browse files Browse the repository at this point in the history
PR #29 broke the following case:

```
p-s -p lint,test
```

This commit fixes it by getting the scripts from the args first and
seeing if there are any scripts available to run. If not, then we show
the help message.
  • Loading branch information
Kent C. Dodds committed Jul 8, 2016
1 parent 52624f7 commit c7e5767
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
},
validate: {
description: 'This runs several scripts to make sure things look good before committing or on clean install',
script: 'p-s -p lint,build,cover && p-s check-coverage',
script: 'dist/bin/p-s.js -p lint,build,cover && p-s check-coverage',
},
addContributor: {
description: 'When new people contribute to the project, run this',
Expand Down
14 changes: 7 additions & 7 deletions src/bin-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ export {getScriptsAndArgs, help, getModuleRequirePath, preloadModule, loadConfig
/****** implementations ******/

function getScriptsAndArgs(program) {
let scripts, args, parallel
if (isEmpty(program.parallel)) {
scripts = program.args[0].split(',')
args = getArgs(program.args.slice(1), program.rawArgs, scripts)
parallel = false
} else {
let scripts = []
let args = ''
const parallel = !isEmpty(program.parallel)
if (parallel) {
scripts = program.parallel.split(',')
args = getArgs(program.args, program.rawArgs, scripts)
parallel = true
} else if (!isEmpty(program.args)) {
scripts = program.args[0].split(',')
args = getArgs(program.args.slice(1), program.rawArgs, scripts)
}
return {scripts, args, parallel}
}
Expand Down
9 changes: 9 additions & 0 deletions src/bin-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ test('getScriptsAndArgs: passes args to scripts', t => {
t.is(args, '--watch --verbose')
})

test('getScriptsAndArgs: returns empty scripts and args if not parallel and no args', t => {
const {args, scripts} = getScriptsAndArgs({
args: [],
rawArgs: ['node', 'p-s'],
})
t.is(scripts.length, 0)
t.is(args, '')
})

test('preloadModule: resolves a relative path', t => {
const relativePath = '../test/fixtures/my-module'
const val = preloadModule(relativePath)
Expand Down
4 changes: 2 additions & 2 deletions src/bin/p-s.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ program
.on('--help', onHelp)
.parse(process.argv)

if (program.args.length < 1) {
const scriptsAndArgs = getScriptsAndArgs(program)
if (scriptsAndArgs.scripts.length < 1) {
program.outputHelp()
} else {
loadAndRun()
}

function loadAndRun() {
const scriptsAndArgs = getScriptsAndArgs(program)
const psConfig = getPSConfig()

runPackageScript({
Expand Down

0 comments on commit c7e5767

Please sign in to comment.