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 run
accepts only one task name at a time. To trigger multiple tasks, either submit separate npm run <task a>
, npm run <task b>
commands, or create an aggregate task that invokes the subtasks.npm run
has no concept of a default task. We can adopt the convention npm run all
, in reverence to traditional makefiles.🍑
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4