mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-23 13:20:48 +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)
|
// Conductor workspace — byte-compat pinned by gen-skill-docs-out-dir tests)
|
||||||
// and the former TREE_MUTATING tests, which render into a mkdtemp instead
|
// and the former TREE_MUTATING tests, which render into a mkdtemp instead
|
||||||
// of mutating the live tree. Default (unset) = in-place, unchanged.
|
// of mutating the live tree. Default (unset) = in-place, unchanged.
|
||||||
const OUT_DIR_ARG = process.argv.find(a => a.startsWith('--out-dir'));
|
/** Parse `--flag <path>` / `--flag=<path>` into an absolute path, or null when absent. */
|
||||||
const OUT_DIR: string | null = (() => {
|
function parsePathFlag(flag: string): string | null {
|
||||||
if (!OUT_DIR_ARG) return null;
|
const arg = process.argv.find(a => a.startsWith(flag));
|
||||||
const val = OUT_DIR_ARG.includes('=')
|
if (!arg) return null;
|
||||||
? OUT_DIR_ARG.split('=')[1]
|
const val = arg.includes('=')
|
||||||
: process.argv[process.argv.indexOf(OUT_DIR_ARG) + 1];
|
? arg.split('=')[1]
|
||||||
if (!val) throw new Error('--out-dir requires a directory path');
|
: process.argv[process.argv.indexOf(arg) + 1];
|
||||||
|
if (!val) throw new Error(`${flag} requires a directory path`);
|
||||||
return path.resolve(val);
|
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
|
// #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
|
// (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
|
// 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
|
// (bin/dev-setup, scripts/dev-skill.ts, mkdtemp tests), where out-dir IS the
|
||||||
// serving path.
|
// serving path.
|
||||||
const LINK_ROOT_ARG = process.argv.find(a => a.startsWith('--link-root'));
|
const LINK_ROOT: string | null = parsePathFlag('--link-root') ?? OUT_DIR;
|
||||||
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);
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When rendering to an out-dir, repoint the literal section-base path at the
|
* 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/,
|
* Surgical: ONLY paths containing `/sections/` are rewritten — bin/, browse/,
|
||||||
* docs/ references keep pointing at `~/.claude/skills/gstack` (the global
|
* 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 {
|
function rewriteSectionBase(content: string): string {
|
||||||
if (!LINK_ROOT) return content;
|
if (!LINK_ROOT) return content;
|
||||||
|
|||||||
Reference in New Issue
Block a user