diff options
| author | Lily <[email protected]> | 2026-07-28 16:12:21 +1000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-07-28 16:12:21 +1000 |
| commit | c11e17573334dfb487a8e1cc25fa84fa9e138f5c (patch) | |
| tree | e91dbd19b524f9432da6bcb86b1fc193e0d02e26 /scripts/link-commands.js | |
| parent | 6a2f098e72e71437154ec00506e8e736aa8e1026 (diff) | |
| download | bnu-c11e17573334dfb487a8e1cc25fa84fa9e138f5c.tar.gz bnu-c11e17573334dfb487a8e1cc25fa84fa9e138f5c.zip | |
Refactor coreutils into single-call command modules (#1)
* Refactor to single call
Diffstat (limited to 'scripts/link-commands.js')
| -rwxr-xr-x | scripts/link-commands.js | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/scripts/link-commands.js b/scripts/link-commands.js index 617f64e..e595f88 100755 --- a/scripts/link-commands.js +++ b/scripts/link-commands.js @@ -2,18 +2,17 @@ import { chmod, mkdir, writeFile } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; -import { commandNames } from "../src/coreutils.js"; +import { commandNames } from "../src/shared/catalog.js"; const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); const targetDir = resolve(process.argv[2] ?? "dist/bin"); -const bnu = resolve(root, "bin/bnu.js"); const bun = shellQuote(process.execPath); -const bnuScript = shellQuote(bnu); await mkdir(targetDir, { recursive: true }); for (const command of commandNames) { const path = resolve(targetDir, command); + const commandScript = shellQuote(resolve(root, "src/commands", `${command}.js`)); const script = command === "pwd" ? `#!/bin/sh saved_pwd=$PWD @@ -21,9 +20,9 @@ actual_pwd=$(command pwd -P 2>/dev/null || :) test -n "$actual_pwd" && saved_pwd=$actual_pwd if [ \${#saved_pwd} -gt 4000 ]; then cd / || exit 1 - BNU_LONG_PWD=$saved_pwd PWD=$saved_pwd exec ${bun} ${bnuScript} pwd "$@" + BNU_LONG_PWD=$saved_pwd PWD=$saved_pwd exec ${bun} ${commandScript} "$@" fi -exec ${bun} ${bnuScript} pwd "$@" +exec ${bun} ${commandScript} "$@" ` : command === "tail" || command === "tac" || command === "timeout" ? `#!/bin/sh @@ -31,9 +30,9 @@ if [ ! -e /proc/$$/fd/0 ]; then BNU_STDIN_CLOSED=1 export BNU_STDIN_CLOSED fi -exec ${bun} ${bnuScript} ${command} "$@" +exec ${bun} ${commandScript} "$@" ` - : `#!/bin/sh\nexec ${bun} ${bnuScript} ${command} "$@"\n`; + : `#!/bin/sh\nexec ${bun} ${commandScript} "$@"\n`; await writeFile(path, script); await chmod(path, 0o755); } |
