Skip to content

hhy5277/maid

 
 

Repository files navigation

maid

NPM version NPM downloads CircleCI donate chat

Markdown driven task runner.

Table of Contents

Install

You can install Maid globally:

# For npm users
npm i -g maid
# For Yarn users
yarn global add maid

Or if you want to ensure that your teammates are using the same version as you, it's recommended to install Maid locally:

# For npm users
npm i -D maid
# For Yarn users
yarn add maid --dev

PRO TIP: you can use npx or yarn command to run any locally installed executable that is inside node_modules/.bin/, e.g. use yarn maid to run the locally installed maid command.

What is a maidfile?

A maidfile is where you define tasks, in Markdown!

📝 maidfile.md:

## lint

It uses ESLint to ensure code quality.

```bash
eslint --fix
```

## build

Build our main app

<!-- Following line is a maid command for running task -->
Run task `build:demo` after this

```bash
# note that you can directly call binaries inside node_modules/.bin
# just like how `npm scripts` works
babel src -d lib
```

## build:demo

You can use JavaScript to write to task script too!

```js
const webpack = require('webpack')

// Async task should return a Promise
module.exports = () => new Promise((resolve, reject) => {
  const compiler = webpack(require('./webpack.config'))
  compiler.run((err, stats) => {
    if (err) return reject(err)
    console.log(stats.toString('minimal'))
    resolve()
  })
})
```

Each task is defined as a heading 2 section, the value of heading 2 will be used as task name, the following paragraphs (optional) will be used as task description, the following code block (optional) will be used as task script.

Currently the code block language can be sh bash js javascript.

Now run maid help to display the help for this maidfile:

❯ maid help

  lint        It uses ESLint to ensure code quality.
  build       Build our main app
  build:demo  You can use JavaScript to write to task script too!

❯ maid help "build*"

  build       Build our main app
  build:demo  You can use JavaScript to write to task script too!

To run a task, you can directly run maid <task_name>

❯ maid build
[13:46:38] Starting 'build'...
🎉  Successfully compiled 3 files with Babel.
[13:46:38] Finished 'build' after 363 ms...
[13:46:38] Starting 'build:demo'...
webpack compiled in 734ms.
[13:46:38] Finished 'build:demo' after 734 ms...

# to get minimal logs
❯ maid build --quiet
🎉  Successfully compiled 3 files with Babel.
webpack compiled in 734ms.

Run tasks before/after a task

You can even run tasks before or after a task:

## build

Run task `deploy` after this

```bash
webpack --config config/webpack.config.js
```

## deploy

```bash
gh-pages -d dist
```

Basically blockquotes like Run task `deploy` after this is treated specially, in this case if you run maid build, it will also run deploy task when build task is finished.

The syntax is simple: Run tasks? <taskNames> (before|after) this (in parallel)? where each task name is surrounded by a pair of backticks: `.

Examples:

  • Run task `build` after this.
  • Run tasks `build:app` `start:server` before this.
  • Run tasks `build:server` `build:client` before this in parallel.

Task hooks

Like npm scripts, when you run a command called build, when it's finised we will also run postbuild task.

Hook syntax:

  • pre<taskName>: Run before a specific task.
  • post<taskName>: Run after a specific task.
  • afterAll: Run after all tasks.
  • beforeAll: Run before all tasks.

Advanced

Code block languages

bash/sh

Read command line arguments

The CLI arguments are passed to executed script, so you can access it like this:

## log

```bash
echo $1
```

Then run maid log nice and it will print nice in the console.

js/javascript

The JS script will also be evaluated.

## log

```js
console.log(process.argv)
```
Asynchronous task

For asynchonous tasks, you can export a function which returns Promise:

## build

```js
module.exports = async () => {
  const files = await readFiles('./')
  await buildFiles(files)
}
```

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

maid © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

github.com/egoist · GitHub @egoist · Twitter @_egoistlily

About

Markdown driven task runner.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%