kooper

0.2.0 • Public • Published

kooper

Lightweight task automator in NodeJS with no dependencies.

NPM Version


kooper is a lightweight task automator written in NodeJS with no external dependencies.

Installation

npm install -g kooper

Running

By default, kooper will look for kooper.json configuration file inside the executing directory.

kooper

To specify a configuration file you just need to add the path to the configuration file.

kooper someconfig.json

If you need to run a specific task you can use the -t or --task parameter to specify one or more tasks to run. The task name is the object key of the configuration file

kooper -t task1
kooper -t task1,task2
kooper -t task1 -t task2
kooper --task task1

Configuration file

The configuration file defines the tasks for kooper and it uses the object key for the task name. All paths used in the configuration file are relative to the it's location.

A task executable accepts 3 parameters:

Parameter Description
exec Executable command.
cwd (optional) Directory from where the command needs to be executed
args (optional) Array of arguments
condition (optional) javascript boolean condition

If the task has multiple executions, it can be stacked inside tasks array as in example2 task below.

The run parameter defines if a task should run when kooper is initialized. Setting it to false will not run when initialized. This can be overriden by using the -t | --task command line parameter or using the in app command

watch

Using watch property, it'll execute the task for every file changed in the specified path.

The watch command will generate local variables {path} and {type} which are replaced whithin the task values.

{path} will give the relative path of the changed file {type} changed or removed

watchStack

It works like watch property, but it'll wait a while before executing the task to call only once when multiple files are changed, such as in a copy or delete actions.

Example

{
    "example1": { # Simply running Typescript in watch mode
        "exec": "tsc",
        "cwd": "./",
        "args": [
            "-w",
            "-p",
            "./"
        ]
    },
    "example2": { # Run list directory and after print out "done"
        "run": false,
        "tasks": [
            {
                "exec": "ls",
                "cwd": "./"
            },
            {
                "exec": "echo",
                "args": [
                    "done"
                ]
            }
        ]
    },
    "example3": { # Watch for any file change
        "watch": "./",
        "tasks": [
            {
                # Will only execute if the path is cooper.json
                "condition": "{path} == 'cooper.json'",
                "exec": "echo",
                "args": [
                    "{path}"
                ]
            }
        ]
    },
    "example4": {
        "watchStack": "./",
        "tasks": [
            {
                "exec": "./doSomething.sh"
            }
        ]
    },

}

In app commands

While kooper is running there's 2 commands you can use.

run [task]

By typing run with the task name, it'll run the specified task.

> kooper         # initializing kooper
run example2     # invoke example2 task

stop [task]

By typing stop with the task name, it'll kill the specified running task.

> kooper         # initializing kooper
stop example2     # stop example2 task

Package Sidebar

Install

npm i kooper

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

16 kB

Total Files

3

Last publish

Collaborators

  • keitakun