@forwardimpact/libwiki 0.2.10 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/build-repo.js +20 -0
- package/src/commands/claim.js +30 -2
- package/src/commands/sync.js +2 -19
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fsAsync from "node:fs/promises";
|
|
3
|
+
import { Finder } from "@forwardimpact/libutil";
|
|
4
|
+
import { createScriptConfig } from "@forwardimpact/libconfig";
|
|
5
|
+
import { WikiRepo } from "./wiki-repo.js";
|
|
6
|
+
|
|
7
|
+
/** Construct a WikiRepo from CLI values and the working directory. */
|
|
8
|
+
export async function buildRepo(values, cwd = process.cwd()) {
|
|
9
|
+
const logger = { debug() {} };
|
|
10
|
+
const finder = new Finder(fsAsync, logger, { cwd: () => cwd });
|
|
11
|
+
const projectRoot = finder.findProjectRoot(cwd);
|
|
12
|
+
const wikiDir = path.resolve(projectRoot, values["wiki-root"] ?? "wiki");
|
|
13
|
+
|
|
14
|
+
const config = await createScriptConfig("wiki");
|
|
15
|
+
return new WikiRepo({
|
|
16
|
+
wikiDir,
|
|
17
|
+
parentDir: projectRoot,
|
|
18
|
+
resolveToken: () => config.ghToken(),
|
|
19
|
+
});
|
|
20
|
+
}
|
package/src/commands/claim.js
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
filterExpired,
|
|
10
10
|
} from "../active-claims.js";
|
|
11
11
|
import { createDefaultIo } from "../io.js";
|
|
12
|
+
import { buildRepo } from "../build-repo.js";
|
|
12
13
|
|
|
13
14
|
function projectRoot(io) {
|
|
14
15
|
const logger = { debug() {} };
|
|
@@ -33,8 +34,26 @@ function addDays(today, n) {
|
|
|
33
34
|
return d.toISOString().slice(0, 10);
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
async function pushWiki(repoFactory, values, io, message) {
|
|
38
|
+
if (!repoFactory) return;
|
|
39
|
+
try {
|
|
40
|
+
const repo = await repoFactory(values, io.cwd());
|
|
41
|
+
repo.inheritIdentity();
|
|
42
|
+
const result = repo.commitAndPush(message);
|
|
43
|
+
if (result.pushed) io.stdout("push: committed and pushed\n");
|
|
44
|
+
} catch (err) {
|
|
45
|
+
io.stderr(`push failed (saved locally): ${err.message}\n`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
36
49
|
/** Insert a row into MEMORY.md `## Active Claims`. Refuses if (agent, target) already present. */
|
|
37
|
-
export function runClaimCommand(
|
|
50
|
+
export async function runClaimCommand(
|
|
51
|
+
values,
|
|
52
|
+
_args,
|
|
53
|
+
cli,
|
|
54
|
+
io = createDefaultIo(),
|
|
55
|
+
repoFactory = buildRepo,
|
|
56
|
+
) {
|
|
38
57
|
const agent = values.agent || io.env.LIBEVAL_AGENT_PROFILE;
|
|
39
58
|
if (!agent) {
|
|
40
59
|
cli.usageError("claim requires --agent or LIBEVAL_AGENT_PROFILE");
|
|
@@ -62,10 +81,17 @@ export function runClaimCommand(values, _args, cli, io = createDefaultIo()) {
|
|
|
62
81
|
}
|
|
63
82
|
writeFileSync(memPath, result.text);
|
|
64
83
|
io.stdout(`claimed ${values.target} (expires ${expires})\n`);
|
|
84
|
+
await pushWiki(repoFactory, values, io, `wiki: claim ${values.target}`);
|
|
65
85
|
}
|
|
66
86
|
|
|
67
87
|
/** Remove a claim row. `--expired` cleans every row past expires_at. */
|
|
68
|
-
export function runReleaseCommand(
|
|
88
|
+
export async function runReleaseCommand(
|
|
89
|
+
values,
|
|
90
|
+
_args,
|
|
91
|
+
cli,
|
|
92
|
+
io = createDefaultIo(),
|
|
93
|
+
repoFactory = buildRepo,
|
|
94
|
+
) {
|
|
69
95
|
const memPath = memoryPath(values, io);
|
|
70
96
|
const text = readMemory(memPath);
|
|
71
97
|
|
|
@@ -84,6 +110,7 @@ export function runReleaseCommand(values, _args, cli, io = createDefaultIo()) {
|
|
|
84
110
|
}
|
|
85
111
|
writeFileSync(memPath, current);
|
|
86
112
|
io.stdout(`released ${count} expired claim(s)\n`);
|
|
113
|
+
await pushWiki(repoFactory, values, io, "wiki: release expired claims");
|
|
87
114
|
return;
|
|
88
115
|
}
|
|
89
116
|
|
|
@@ -102,5 +129,6 @@ export function runReleaseCommand(values, _args, cli, io = createDefaultIo()) {
|
|
|
102
129
|
io.stdout(`no matching claim for ${agent}/${values.target}\n`);
|
|
103
130
|
} else {
|
|
104
131
|
io.stdout(`released ${values.target}\n`);
|
|
132
|
+
await pushWiki(repoFactory, values, io, `wiki: release ${values.target}`);
|
|
105
133
|
}
|
|
106
134
|
}
|
package/src/commands/sync.js
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { Finder } from "@forwardimpact/libutil";
|
|
4
|
-
import { createScriptConfig } from "@forwardimpact/libconfig";
|
|
5
|
-
import { WikiRepo, WikiPullConflict } from "../wiki-repo.js";
|
|
6
|
-
|
|
7
|
-
async function buildRepo(values) {
|
|
8
|
-
const logger = { debug() {} };
|
|
9
|
-
const finder = new Finder(fsAsync, logger, process);
|
|
10
|
-
const projectRoot = finder.findProjectRoot(process.cwd());
|
|
11
|
-
const wikiDir = path.resolve(projectRoot, values["wiki-root"] ?? "wiki");
|
|
12
|
-
|
|
13
|
-
const config = await createScriptConfig("wiki");
|
|
14
|
-
return new WikiRepo({
|
|
15
|
-
wikiDir,
|
|
16
|
-
parentDir: projectRoot,
|
|
17
|
-
resolveToken: () => config.ghToken(),
|
|
18
|
-
});
|
|
19
|
-
}
|
|
1
|
+
import { WikiPullConflict } from "../wiki-repo.js";
|
|
2
|
+
import { buildRepo } from "../build-repo.js";
|
|
20
3
|
|
|
21
4
|
/** Commit all wiki changes and push them to the remote wiki repository. */
|
|
22
5
|
export async function runPushCommand(values, _args, cli) {
|