booty is a convention for writing development tasks for JavaScript (Node.js) projects, via npm run hooks.
Tasks are implemented using modern JavaScript code. We can use a directory like tasks/ to house task definitions.
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.
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(); }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.
{
"name": "@mcandre/hello-booty",
"scripts": {
"all": "./tasks/all",
"groceries": "./tasks/groceries",
"clean": "./tasks/clean"
},
"type": "module"
}Compared to modern task runners, the npm run system has some quirks:
npm runaccepts only one task name at a time. To trigger multiple tasks, either submit separatenpm run <task a>,npm run <task b>commands, or create an aggregate task that invokes the subtasks.npm runhas no concept of a default task. We can adopt the conventionnpm run all, in reverence to traditional makefiles.
- Grunt is largely unmaintained, and increases the attack surface.
- Gulp is terrible at CLI tasks, and increases the attack surface.
- Make isn't JavaScript.
- Node.js 20+
Prior art, personal plugs, and tools for developing software (including non-JS projects)!
- Inspiration from nobuild - a convention for C/C++ build systems
- bashate - shell script linter
- Gradle - JVM build system
- lake - Lua task runner
- Leiningen + lein-exec - Clojure task runner
- Mage - Go task runner
- mcandre/linters - curated linter collection
- mcandre/tinyrick - Rust task runner
- npm, Grunt - Node.js task runners
- POSIX make - general purpose task runner
- Rake - Ruby task runner
- Rebar3 - Erlang build system
- sbt - Scala build system
- Shake - Haskell task runner
🍑