Home

Awesome

booty: the biggest thing to happen to ECMAScript since Netscape

SUMMARY

booty is a convention for writing development tasks for JavaScript (Node.js) projects, via npm run hooks.

EXAMPLE

ABOUT

Tasks are implemented using modern JavaScript code. We can use a directory like tasks/ to house task definitions.

tasks/groceries

Here, a groceries task

#!/usr/bin/env node
'use strict';

import child_process from 'node:child_process';
import process from 'node:process';

export default function groceries() {
    child_process.execSync('echo milk...', { stdio: 'inherit' });
    child_process.execSync('echo eggs...', { stdio: 'inherit' });
    child_process.execSync('echo just browsing', { stdio: 'inherit' });
}

function main() {
    groceries();
}

if (import.meta.url === `file://${process.argv[1]}`) { main(); }

Take care to avoid colliding with conventional NPM life cycle task names.

tasks/clean

It's often a good idea to configure a clean task to automate resetting the development environment.

#!/usr/bin/env node
'use strict';

import fs from 'node:fs';
import process from 'node:process';

export default function clean() {
    console.log('removing junk files...');

    fs.rmSync('nosuchdirectory', { force: true, recursive: true });
    fs.rmSync('nosuchfile.dat', { force: true });
}

function main() {
    clean();
}

if (import.meta.url === `file://${process.argv[1]}`) { main(); }

tasks/all

Subtasks can be aggregated together into higher level tasks.

Let's prepare all our errands to trigger together.

#!/usr/bin/env node
'use strict';

import groceries from './groceries';
import clean from './clean';

import process from 'node:process';

function main() {
    groceries();
    clean();
}

if (import.meta.url === `file://${process.argv[1]}`) { main(); }

You can group or divide tasks into hierarchy shapes as needed, depending on the complexity of the tasks and the frequency of low level tasks.

Then, wire up each task to the npm run system.

package.json

{
    "name": "@mcandre/hello-booty",
    "scripts": {
        "all": "./tasks/all",
        "groceries": "./tasks/groceries",
        "clean": "./tasks/clean"
    },
    "type": "module"
}

NOTES

Compared to modern task runners, the npm run system has some quirks:

Why not _____?

REQUIREMENTS

SEE ALSO

🍑