2.14.7 • Published 6 years ago

task-env v2.14.7

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Task Env

A framework for building reusable JS tasks.

FeatureBuilt With
Parse CLI argumentsmri
Interact with the CLIInquirer.js
Execute commandscommandland
JSON and text storedot-store

Install

npm install --save-dev task-env

Create an executable

touch run
chmod +x run

Write some code

#!/usr/bin/env node

require("task-env")({
  args: process.argv.slice(2),
  tasks: [
    {
      sayHello: ({ hello }) => {
        console.log(">", hello)
      },
    },
  ],
})

Run your task

./run sayHello --hello=hi
> hi

Package tasks

Export task:

export function sayHello({ hello }) {
  console.log(hello)
}

Require task:

#!/usr/bin/env node

require("task-env")({
  args: process.argv.slice(2),
  tasks: [require("./say-hello")],
})

Interact

export async function happy({ ask }) {
  let { happy } = await ask([
    {
      type: "confirm",
      name: "happy",
      message: "Are you happy?",
    },
  ])
}

See the Inquirer.js prompt docs for available options.

Call other tasks

export function sayHello({ tasks }) {
  tasks.say({ text: "hello" })
}

export function say({ text }) {
  console.log(">", text)
}

Calling through tasks binds the CLI arguments and helper functions, as if the task were called via CLI.

Execute commands

export async function ls({ run }) {
  await run("ls", ["/"])
}

See the commandland docs for available options.

JSON and text store

Task env uses dot-store to provide an immutable store with atomic filesystem persistence.

Create a directory with some JSON files:

{
  "users": {
    "bob": {
      "key": "~/.ssh/bob_rsa"
    }
  }
}

The stores option allows you to define multiple named stores:

#!/usr/bin/env node

require("task-env")({
  args: process.argv.slice(2),
  stores: {
    config: {
      pattern: "**/*",
      root: __dirname,
    },
  },
  tasks: [require("./tasks/user")],
})

Within your task, get and set JSON using dot-style property strings:

export async function user({ config, name, key }) {
  if (key) {
    await config.set(`users.${name}.key`, key)
  }

  console.log(">", config.get(`users.${name}`))
}

Run via CLI:

./run user --name=bob --key=~/.ssh/id_rsa
> { key: "~/.ssh/id_rsa" }

All options

OptionExamplePurpose
alias{h: ["help"]}CLI arguments aliases
preSetup[config=>config]Pre-setup functions (before argv parsing)
setup[config=>config]Setup functions
stores{store: {root: __dirname, pattern: "**/*"}}Store configurations
teardown[args=>{}]Teardown functions
tasks[{ task: ({})=>{} }]Task functions
2.14.7

6 years ago

2.14.6

6 years ago

2.14.5

6 years ago

2.14.4

6 years ago

2.14.3

6 years ago

2.14.2

6 years ago

2.14.1

6 years ago

2.14.0

6 years ago

2.13.0

6 years ago

2.12.1

6 years ago

2.12.0

6 years ago

2.11.0

6 years ago

2.10.0

6 years ago

2.9.0

6 years ago

2.8.0

6 years ago

2.7.1

6 years ago

2.7.0

6 years ago

2.6.0

6 years ago

2.5.0

6 years ago

2.4.3

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago