magic-carpet

0.0.4 • Public • Published

npm version Build Status

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

  1. From your module's root, create a scripts directory
  2. If you want to define an npm script named "magic:command", write an executable file at scripts/magic/command.js
  3. Declare your "magic:command" script in "scripts" in your package.json:
{
  "scripts": {
    "foo:bar": "magic-carpet"
  }
}
  1. 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"
`);

Package Sidebar

Install

npm i magic-carpet

Weekly Downloads

398

Version

0.0.4

License

none

Unpacked Size

7.77 kB

Total Files

22

Last publish

Collaborators

  • agirorn