thefill / xargv

Node package runner with ability to pass foreign args
MIT License
0 stars 0 forks source link

Xargv

Node package runner with ability to pass foreign args.

Code quality Coverage Greenkeeper badge CricleCi badge

npm version Open issues Types: TypeScript License: MIT

Main features

Guide

Installation

npm install --save xargv

or

yarn add xargv

or

pnpm --save xargv

Basic usage

Imagine a situation: you want to dynamically generate webpack config (webpack.config.js) based on provided args but webpack cli blocks you from passing any foreign values.

Below you will find way to deal with it.

Set argv config in the config file

In the root of the project provide .xargvrc file:

{
      // command name matches first ath passed to xargv
      "webpack": {
        // this is the path to cli you want to execute
        "binPath": "webpack/bin",
        // this is the env variable name all your extra args will be placed in
        "containerName": "ARGVX",
        // want to pass to xargv command args without --name? Thats the map of keys
        // for this values
        "unnamedArgKeys": [
            "unnamedA",
            "unnamedB"
        ],
        // thats the list of all args passed that should be passed as foreign vars
        "foreignKeys": [
            "unnamedA",
            "defaultA",
            "flagA",
            "inlineA"
        ],
        // This are args you dont want to define all over the package.json
        // did you noticed one of this values will endup as foreign var? Neat!
        "defaultArgs": {
            "defaultA": "defaultValueA",
            "defaultB": "defaultValueB"
        }
    }
}

Keep in mind you can define same config in the package.json file:

{
    [...]
    "xargv": {
        [...]
    }
}

As soon as you have config defined use it in one of the npm script's:

{
    [...]
    "scripts": {
        "start": "xargv webpack foreignValue nativeValue --nativeFlag --nativeInline nativeInlineValue nativeUnmatchedValue"
    }
}

Or via cli if you have installed package globally:

xargv webpack foreignValue nativeValue --nativeFlag --nativeInline nativeInlineValue nativeUnmatchedValue

For working examples please take a look at the repos example dir.

Documentation

Full API documentation for this package can be found here