mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-09 06:28:59 +02:00
refactor(gen-skill-docs): extract parsePathFlag; fix rewriteSectionBase docstring
--out-dir and --link-root shared near-identical inline parsing; one helper now owns it. The rewriteSectionBase docstring said 'no-op when --out-dir is unset' but the gate is the link root (which --link-root can set independently) — it now describes the real behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
61e8df677c
commit
8079803f2a
+14
-19
@@ -158,15 +158,17 @@ const EXPLAIN_LEVEL: 'default' | 'terse' = (() => {
|
||||
// Conductor workspace — byte-compat pinned by gen-skill-docs-out-dir tests)
|
||||
// and the former TREE_MUTATING tests, which render into a mkdtemp instead
|
||||
// of mutating the live tree. Default (unset) = in-place, unchanged.
|
||||
const OUT_DIR_ARG = process.argv.find(a => a.startsWith('--out-dir'));
|
||||
const OUT_DIR: string | null = (() => {
|
||||
if (!OUT_DIR_ARG) return null;
|
||||
const val = OUT_DIR_ARG.includes('=')
|
||||
? OUT_DIR_ARG.split('=')[1]
|
||||
: process.argv[process.argv.indexOf(OUT_DIR_ARG) + 1];
|
||||
if (!val) throw new Error('--out-dir requires a directory path');
|
||||
/** Parse `--flag <path>` / `--flag=<path>` into an absolute path, or null when absent. */
|
||||
function parsePathFlag(flag: string): string | null {
|
||||
const arg = process.argv.find(a => a.startsWith(flag));
|
||||
if (!arg) return null;
|
||||
const val = arg.includes('=')
|
||||
? arg.split('=')[1]
|
||||
: process.argv[process.argv.indexOf(arg) + 1];
|
||||
if (!val) throw new Error(`${flag} requires a directory path`);
|
||||
return path.resolve(val);
|
||||
})();
|
||||
}
|
||||
const OUT_DIR: string | null = parsePathFlag('--out-dir');
|
||||
|
||||
// #2692: callers that render into a TMP dir and atomically swap it into place
|
||||
// (bin/gstack-config gbrain-refresh, setup — the #2569 pattern) must pass the
|
||||
@@ -175,22 +177,15 @@ const OUT_DIR: string | null = (() => {
|
||||
// Read dies after the swap. Defaults to OUT_DIR for direct-render callers
|
||||
// (bin/dev-setup, scripts/dev-skill.ts, mkdtemp tests), where out-dir IS the
|
||||
// serving path.
|
||||
const LINK_ROOT_ARG = process.argv.find(a => a.startsWith('--link-root'));
|
||||
const LINK_ROOT: string | null = (() => {
|
||||
if (!LINK_ROOT_ARG) return OUT_DIR;
|
||||
const val = LINK_ROOT_ARG.includes('=')
|
||||
? LINK_ROOT_ARG.split('=')[1]
|
||||
: process.argv[process.argv.indexOf(LINK_ROOT_ARG) + 1];
|
||||
if (!val) throw new Error('--link-root requires a directory path');
|
||||
return path.resolve(val);
|
||||
})();
|
||||
const LINK_ROOT: string | null = parsePathFlag('--link-root') ?? OUT_DIR;
|
||||
|
||||
/**
|
||||
* When rendering to an out-dir, repoint the literal section-base path at the
|
||||
* out-dir so section Reads resolve to the rendered copy, not the global install.
|
||||
* link root (--link-root, defaulting to --out-dir) so section Reads resolve
|
||||
* to the SERVED copy, not the global install.
|
||||
* Surgical: ONLY paths containing `/sections/` are rewritten — bin/, browse/,
|
||||
* docs/ references keep pointing at `~/.claude/skills/gstack` (the global
|
||||
* install, which still works). No-op when --out-dir is unset.
|
||||
* install, which still works). No-op when neither flag is set.
|
||||
*/
|
||||
function rewriteSectionBase(content: string): string {
|
||||
if (!LINK_ROOT) return content;
|
||||
|
||||
Reference in New Issue
Block a user