-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(require): The module you require can now be an ES6 module
That's mostly just a side-effect of the clean-up I've been doing.
- Loading branch information
Kent C. Dodds
committed
May 20, 2016
1 parent
3ecdaf1
commit efb2645
Showing
7 changed files
with
203 additions
and
98 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env node | ||
import findUp from 'find-up' | ||
import merge from 'lodash.merge' | ||
import program from 'commander' | ||
import runPackageScript from '../index' | ||
import {getScriptsAndArgs, help, preloadModule, loadConfig} from '../bin-utils' | ||
import getLogger from '../get-logger' | ||
const log = getLogger() | ||
const FAIL_CODE = 1 | ||
|
||
program | ||
.version(require('../../package.json').version) | ||
.allowUnknownOption() | ||
.option('-s, --silent', 'Silent p-s output') | ||
.option('-p, --parallel <script-name1,script-name2>', 'Scripts to run in parallel (comma seprated)') | ||
.option('-c, --config <filepath>', 'Config file to use (defaults to nearest package-scripts.js)') | ||
.option('-l, --log-level <level>', 'The log level to use (error, warn, info [default])') | ||
.option('-r, --require <module>', 'Module to preload') | ||
.on('--help', onHelp) | ||
.parse(process.argv) | ||
|
||
if (process.argv.length < 3) { | ||
program.outputHelp() | ||
} else { | ||
loadAndRun() | ||
} | ||
|
||
function loadAndRun() { | ||
const scriptsAndArgs = getScriptsAndArgs(program) | ||
const psConfig = getPSConfig() | ||
|
||
runPackageScript({ | ||
scriptConfig: psConfig.scripts, | ||
scripts: scriptsAndArgs.scripts, | ||
args: scriptsAndArgs.args, | ||
options: merge(psConfig.options, { | ||
silent: program.silent, | ||
parallel: scriptsAndArgs.parallel, | ||
logLevel: program.logLevel, | ||
}), | ||
}, result => { | ||
if (result.error) { | ||
log.error(result.error) | ||
process.exit(FAIL_CODE) | ||
} | ||
process.exit(result.code) | ||
}) | ||
} | ||
|
||
function getPSConfig() { | ||
if (program.require) { | ||
preloadModule(program.require) | ||
} | ||
const config = loadConfig(program.config || findUp.sync('package-scripts.js')) | ||
if (!config) { | ||
process.exit(FAIL_CODE) | ||
} | ||
return config | ||
} | ||
|
||
function onHelp() { | ||
log.info(help(getPSConfig())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
__esModule: true, | ||
default: { | ||
scripts: { | ||
skywalker: `echo "That's impossible!!"`, | ||
}, | ||
options: {}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'hello' |