@keg-hub/cli-utils v0.9.0
Keg-Hub Cli-Utils
- Common utility methods for developing Node CLI's and writing custom tasks
- This makes the process faster easier, and removes code duplication across projects
Install
With yarn
yarn add @keg-hub/cli-utilsWith npm
npm install @keg-hub/cli-utilsCLI task setup
runTask- Find and execute a task- This method allows resolving a task based on the passed in tasks object and arguments
- It's recommended to add a call it from a node script within your project
Then add a reference to that script in your
package.json - scriptssectionThis allows calling it from a package manager such as
yarnornpmlike this =>// In your package.json file "scripts": { // ...other scripts "task": "node ./tasks/runTask.js", } // In tasks/runTask.js const { runTask } = require('@keg-hub/cli-utils') const taskDefinitions = require('./taskDefinitions') runTask( // Object containing all tasks definitions for the project taskDefinitions, // Default params passed to all tasks { env: process.env.NODE_ENV || 'local' } )This above script can then be called like this =>
yarn task <task-name> <task-options>- Assuming a
starttask definition exists, runningyarn task startwill call the start task
- Assuming a
This method will handle
- Loading the global config defined at
~/.kegConfig/cli.config.jsonif it exists - Parsing options relative to a task-definitions
optionsproperty- They are then passed to the task as the
paramskey of theargsobject
- They are then passed to the task as the
- Loading the global config defined at
setAppRoot- Register a taps root directoryWhen calling custom tasks outside of the
keg-cli, calling this method is recommended- It ensures that in
mono-repoorsym-linkedsituations, the project root can be properly resolved That said, in most cases calling this method is NOT needed
- But, since nothing is inversely affected by it, it's recommended to set it and forget it
Add it to the top of a tasks script file like this =>
const { setAppRoot } = require('@keg-hub/cli-utils') setAppRoot(appRoot) module.exports = { customTask: { ...taskDefinition } }See tap-vistapps-app
tasks/index.jsfile for an example
- It ensures that in
registerTasks- Register Custom Tasks- In most situations calling
registerTasksis NOT needed- It could be used when passing the tasks in the first argument of
runTaskis not possible- For example in a third-party package installed as a node module
- It must be called prior to the call to the
runTaskmethod to ensure the tasks are loaded- It takes a single
Objectargument that should contain key/value pairs task name/definitions For example =>registerTasks({ taskName: { ...taskDefinition } })
- It takes a single
- It could be used when passing the tasks in the first argument of
- In most situations calling
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago