{"id":19513049,"url":"https://github.com/invrs/task-env","last_synced_at":"2026-04-29T14:03:13.811Z","repository":{"id":65514701,"uuid":"118650462","full_name":"invrs/task-env","owner":"invrs","description":"A framework for building reusable JS tasks","archived":false,"fork":false,"pushed_at":"2018-08-01T03:45:44.000Z","size":782,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-08T12:10:03.667Z","etag":null,"topics":["cli","exec","json","store","task"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/invrs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-23T18:19:28.000Z","updated_at":"2023-02-13T18:19:44.000Z","dependencies_parsed_at":"2023-01-26T21:05:16.891Z","dependency_job_id":null,"html_url":"https://github.com/invrs/task-env","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invrs%2Ftask-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invrs%2Ftask-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invrs%2Ftask-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invrs%2Ftask-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/invrs","download_url":"https://codeload.github.com/invrs/task-env/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240762316,"owners_count":19853458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","exec","json","store","task"],"created_at":"2024-11-10T23:28:35.686Z","updated_at":"2026-04-29T14:03:08.772Z","avatar_url":"https://github.com/invrs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Task Env\n\nA framework for building reusable JS tasks.\n\n| Feature                                     | Built With                                                     |\n| ------------------------------------------- | -------------------------------------------------------------- |\n| [Parse CLI arguments](#write-some-code)     | [mri](https://github.com/lukeed/mri#readme)                    |\n| [Interact with the CLI](#interact)          | [Inquirer.js](https://github.com/SBoudrias/Inquirer.js#readme) |\n| [Execute commands](#execute-commands)       | [commandland](https://github.com/winton/commandland#readme)    |\n| [JSON and text store](#json-and-text-store) | [dot-store](https://github.com/invrs/dot-store#readme)         |\n\n## Install\n\n```bash\nnpm install --save-dev task-env\n```\n\n## Create an executable\n\n```bash\ntouch run\nchmod +x run\n```\n\n## Write some code\n\n```js\n#!/usr/bin/env node\n\nrequire(\"task-env\")({\n  args: process.argv.slice(2),\n  tasks: [\n    {\n      sayHello: ({ hello }) =\u003e {\n        console.log(\"\u003e\", hello)\n      },\n    },\n  ],\n})\n```\n\n## Run your task\n\n```bash\n./run sayHello --hello=hi\n\u003e hi\n```\n\n## Package tasks\n\nExport task:\n\n```js\nexport function sayHello({ hello }) {\n  console.log(hello)\n}\n```\n\nRequire task:\n\n```js\n#!/usr/bin/env node\n\nrequire(\"task-env\")({\n  args: process.argv.slice(2),\n  tasks: [require(\"./say-hello\")],\n})\n```\n\n## Interact\n\n```js\nexport async function happy({ ask }) {\n  let { happy } = await ask([\n    {\n      type: \"confirm\",\n      name: \"happy\",\n      message: \"Are you happy?\",\n    },\n  ])\n}\n```\n\nSee the [Inquirer.js `prompt` docs](https://github.com/SBoudrias/Inquirer.js#methods) for available options.\n\n## Call other tasks\n\n```js\nexport function sayHello({ tasks }) {\n  tasks.say({ text: \"hello\" })\n}\n\nexport function say({ text }) {\n  console.log(\"\u003e\", text)\n}\n```\n\nCalling through `tasks` binds the CLI arguments and helper functions, as if the task were called via CLI.\n\n## Execute commands\n\n```js\nexport async function ls({ run }) {\n  await run(\"ls\", [\"/\"])\n}\n```\n\nSee the [commandland docs](https://github.com/winton/commandland#execution-options) for available options.\n\n## JSON and text store\n\nTask env uses [dot-store](https://github.com/invrs/dot-store#readme) to provide an immutable store with atomic filesystem persistence.\n\nCreate a directory with some JSON files:\n\n```json\n{\n  \"users\": {\n    \"bob\": {\n      \"key\": \"~/.ssh/bob_rsa\"\n    }\n  }\n}\n```\n\nThe `stores` option allows you to define multiple named stores:\n\n```js\n#!/usr/bin/env node\n\nrequire(\"task-env\")({\n  args: process.argv.slice(2),\n  stores: {\n    config: {\n      pattern: \"**/*\",\n      root: __dirname,\n    },\n  },\n  tasks: [require(\"./tasks/user\")],\n})\n```\n\nWithin your task, get and set JSON using dot-style property strings:\n\n```js\nexport async function user({ config, name, key }) {\n  if (key) {\n    await config.set(`users.${name}.key`, key)\n  }\n\n  console.log(\"\u003e\", config.get(`users.${name}`))\n}\n```\n\nRun via CLI:\n\n```bash\n./run user --name=bob --key=~/.ssh/id_rsa\n\u003e { key: \"~/.ssh/id_rsa\" }\n```\n\n## All options\n\n| Option   | Example                                       | Purpose                                      |\n| -------- | --------------------------------------------- | -------------------------------------------- |\n| alias    | `{h: [\"help\"]}`                               | CLI arguments aliases                        |\n| preSetup | `[config=\u003econfig]`                            | Pre-setup functions (before argv parsing)    |\n| setup    | `[config=\u003econfig]`                            | Setup functions                              |\n| stores   | `{store: {root: __dirname, pattern: \"**/*\"}}` | [Store configurations](#json-and-text-store) |\n| teardown | `[args=\u003e{}]`                                  | Teardown functions                           |\n| tasks    | `[{ task: ({})=\u003e{} }]`                        | Task functions                               |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvrs%2Ftask-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finvrs%2Ftask-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvrs%2Ftask-env/lists"}