From f5118872627b074c63e01f06fc287718eb6e8c3e Mon Sep 17 00:00:00 2001 From: versnic <37933264+versnic@users.noreply.github.com> Date: Wed, 11 Nov 2026 14:41:02 +0100 Subject: [PATCH] docs: shorten the lib file headers to two lines Each lib file now starts with what it is for and which files use it. The details the long headers held moved next to the code they describe. CONTRIBUTING.md and the pull request template no longer ask contributors to keep a long header up to date. --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- CONTRIBUTING.md | 2 +- lib/aliases.js | 18 ++--- lib/args.js | 24 +----- lib/cli.js | 69 +---------------- lib/commands.js | 14 +--- lib/config.js | 26 ++----- lib/fuzzy.js | 15 +--- lib/json.js | 13 +--- lib/list.js | 129 ++++++------------------------- lib/package-managers.js | 33 ++------ lib/prompts.js | 64 ++------------- lib/screen.js | 21 ++--- lib/state.js | 34 +++----- lib/terminal.js | 29 ++----- lib/ui.js | 52 +------------ lib/width.js | 19 +---- lib/workspace.js | 35 +-------- 18 files changed, 95 insertions(+), 504 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e494a69..2ab73af 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -15,6 +15,6 @@ - [ ] The title follows Conventional Commits (`feat:`, `fix:`, `docs:`, …) and is lowercase - [ ] Tests cover the change, or it needs none -- [ ] The README describes the change, and the header comment of each touched `lib/` file is up to date +- [ ] The README describes the change - [ ] The roadmap is updated if this completes a roadmap item - [ ] Tested in a real terminal with a temporary configuration (`DEV_WORKSPACE_CONFIG`), if the change affects what the CLI shows or does diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1badcc1..94386dd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -76,7 +76,7 @@ Menus use the list in `list.js`, which owns the terminal while it is open; free- Every colour comes from the theme in `ui.js`: `color()` for plain output, `styleText()` for the list, and `inquirerTheme()` for the `@inquirer/prompts` questions. Do not write ANSI codes elsewhere, so `NO_COLOR` and `FORCE_COLOR` are always respected. Ask for the `accent` style, never for cyan or another colour by name, so the user's chosen accent (`setAccent()`) reaches every screen. -Each file in `lib/` starts with a comment describing what it contains and how it is used. Keep that comment accurate when you change the file. +Each file in `lib/` starts with two comment lines: what the file is for, and which files use it. Update them only if your change makes them wrong, for example a new file that imports it. Explain how something works in a comment next to the code instead, where it is easier to keep right. Modules receive their side effects (file system, prompts, process spawning) as parameters with real defaults, so tests can replace them with fakes. Tests live in `test/`, one file per module. diff --git a/lib/aliases.js b/lib/aliases.js index 18d90eb..3eee9d6 100644 --- a/lib/aliases.js +++ b/lib/aliases.js @@ -1,14 +1,5 @@ -// Custom command aliases (`--add-alias`, `--remove-alias`, `--list-aliases`). -// -// An alias is a small launcher file written next to the installed -// `dev-workspace` command, which is found by searching PATH. On Windows each -// alias has three launchers (cmd, PowerShell, Git Bash); elsewhere one shell -// script. Every launcher carries a marker comment, so listing and removing -// only ever touch files this module created. The built-in `dws` command is -// not an alias: it comes from the `bin` field in package.json. -// -// Used by cli.js. Every exported function accepts `{ env, platform }` so tests -// can simulate any operating system and PATH. +// Custom command aliases: `--add-alias`, `--remove-alias` and `--list-aliases`. +// Used by cli.js. import { chmod, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises' import path from 'node:path' @@ -71,6 +62,11 @@ async function isFile(file) { } } +// An alias is a launcher file written next to the installed `dev-workspace` +// command: three on Windows (cmd, PowerShell, Git Bash), one shell script +// elsewhere. Every exported function takes `{ env, platform }`, so tests can +// simulate any system and PATH. +// // Return the first file on PATH that runs as `name`, or null. export async function findCommand(name, options) { const settings = defaults(options) diff --git a/lib/args.js b/lib/args.js index 8894ffd..cb0afa0 100644 --- a/lib/args.js +++ b/lib/args.js @@ -1,28 +1,12 @@ -// Command-line parsing and the `--help` text. -// -// parseCliArgs() turns process arguments into an options object using Node's -// built-in parseArgs, and replaces its errors with a message pointing to -// `--help`. Up to two positional arguments select a project and a script -// (direct mode); everything after `--` is kept, untouched, as the script's -// arguments. -// -// formatHelp() builds the `--help` text, which must list every option defined -// here. It colours headings, commands and placeholders through the given -// function (ui.color), commands in the accent, so NO_COLOR, FORCE_COLOR, -// non-TTY output and the chosen accent are respected; with no function it -// returns plain text. --set-color accepts the names in ui.ACCENTS. -// -// splitArguments() splits arguments typed at the "Run with arguments…" prompt -// into a list, honouring single and double quotes. No shell is involved, so -// nothing else is special. -// -// Used by cli.js, whose start() decides what each option does, and by -// prompts.js. +// Reading the command-line options, and the `--help` text. +// Used by cli.js and prompts.js. import { parseArgs } from 'node:util' import { ACCENTS } from './ui.js' +// The `--help` text, which must list every option parseCliArgs() accepts. +// `color` is ui.color, so NO_COLOR and the accent are respected. export function formatHelp(color = value => String(value)) { return ` ${color('Usage:', 'bold')} ${color('dev-workspace', 'accent')} [options] [project [script] [-- arguments]] diff --git a/lib/cli.js b/lib/cli.js index ec95a00..0ad8605 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,70 +1,5 @@ -// The CLI itself: option handling, workspace setup and the interactive menus. -// -// start() first applies the saved accent colour (ui.setAccent), then -// handles one-shot options (help, formatted with ui.color, version, aliases, -// the mouse and colour settings, reset, clearing the history) and otherwise -// runs the main loop: load or configure the workspace, list its projects -// (recently used ones first, each with its script count, Git branch and -// package manager: projectDetails(); the branch is coloured, main, master -// and trunk in one colour and any other branch in another), list a project's scripts with its -// detected package manager, run the chosen script with that tool, optionally -// with arguments, then offer to run it again. Every menu shows the header -// box from ui.js, with the project as a breadcrumb and its package manager -// as the tag; empty and error states are shown in the box's screen, as the -// list's body. The workspace is chosen from a list of the common workspace -// folders that exist (suggestWorkspaces()), with "Enter another path" for -// any other folder; without any of them, the path prompt opens directly. -// On the first run, the accent colour is asked next (chooseColor()), with -// each choice previewed as the cursor reaches it, and saved with the -// workspace; --set-color changes it later. -// Changing the workspace from the project list (⚙ Workspace) opens the same -// list, and Escape there, or at the path prompt, keeps the current one. -// Workspace paths typed at the prompt or passed with --workspace go through -// resolveDirectoryInput(), so ~, quotes and escaped spaces work without a -// shell. -// -// The menus are drawn on the alternate screen (screen.js). The CLI leaves it -// (ui.leaveScreen) before a script runs, so its output stays on the normal -// screen, and whenever the menus end, before any error or "Goodbye!". -// -// The run screen, on the normal screen: the header box with the project and -// script as breadcrumb (ui.drawHeader, drawn once with list.js), the command -// (`▶ npm run build`), the script's output, then the result: `✔ build -// finished in 4.2s` in green, or `✖ build failed · exit 1 · 0.8s` in red, -// with the signal name in place of the exit code when a signal stopped it. -// The duration is measured with clock.now() and shown by formatDuration(). -// The Run again / Back to scripts buttons follow (waitAfterCommand). -// -// Menus and questions need a terminal for input: without one, and without -// a script to run directly, run() fails with a message saying so. -// -// Direct mode: `dev-workspace ` opens that project's scripts, and -// `dev-workspace