magic-carpet
v0.0.4
Published
npm-scripts JS shell runnig simplified like magic
Downloads
6,006
Maintainers
Readme
Magic Carpet
Takes care of running your javascript npm-scripts and includes tools to make js shell scripts work like magic.
Inspired by scripty
Install
npm install magic-carpet
Usage
- From your module's root, create a scripts directory
- If you want to define an npm script named "magic:command", write an executable file at scripts/magic/command.js
- Declare your "magic:command" script in "scripts" in your package.json:
{
"scripts": {
"foo:bar": "magic-carpet"
}
}
- Run the magic:command
npm magic:command
Shell helpers
runAndExit
The runAndExit can be helpful when running simple shell commands one after the other.
file: scripts/magic/command.js
const { runAndExit } = require('magic-carpet');
runAndExit(`
echo "Magic Carpet"
&& cross-env NODE_ENV=test mocha
--reporter=dot
--config=.mocharc-e2e.js
--public=src
&& yarn lint
`);
shellArguments
If for any reason you need to get the shell arguments passed to yarn and pass
them along to the apps you are calling then you can do that by using the
shellArguments
helper in the javascript shell application
const { runAndExit, shellArguments } = require('magic-carpet');
runAndExit(`
yarn workspace workspace-name start ${shellArguments()}
`);
npmCommand
The utility npmCommand will get the full npm or yarn command name being invoked. This can be useful when printing help screens.
const { runAndExit, npmCommand } = require('magic-carpet');
if {process.argv.includes('--help')) {
console.log(`
${npmCommand()}
Some other helpfull information
`.trim());
process.exit(0);
}
runAndExit(`
echo "normal operation"
`);