diffwiki 0.2.0-rc.202607210907.c99416d
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/dist/bin.js +151 -0
- package/package.json +29 -0
package/dist/bin.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import {
|
|
6
|
+
addTags,
|
|
7
|
+
createArticle,
|
|
8
|
+
createCollection,
|
|
9
|
+
doctor,
|
|
10
|
+
getConfigValue,
|
|
11
|
+
initRepoWiki,
|
|
12
|
+
listCollections,
|
|
13
|
+
query,
|
|
14
|
+
removeArticle,
|
|
15
|
+
removeTags,
|
|
16
|
+
setConfigValue,
|
|
17
|
+
setTags,
|
|
18
|
+
updateArticleBody
|
|
19
|
+
} from "diffwiki-core";
|
|
20
|
+
|
|
21
|
+
// src/version.ts
|
|
22
|
+
import { readFileSync } from "fs";
|
|
23
|
+
import { fileURLToPath } from "url";
|
|
24
|
+
import { dirname, join } from "path";
|
|
25
|
+
var here = dirname(fileURLToPath(import.meta.url));
|
|
26
|
+
var pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8"));
|
|
27
|
+
var version = pkg.version;
|
|
28
|
+
|
|
29
|
+
// src/runtime.ts
|
|
30
|
+
import { DiffwikiError } from "diffwiki-core";
|
|
31
|
+
function withErrors(fn) {
|
|
32
|
+
return async (...args) => {
|
|
33
|
+
try {
|
|
34
|
+
await fn(...args);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error instanceof DiffwikiError) {
|
|
37
|
+
console.error(`\u2716 ${error.message}`);
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
var collect = (value, previous) => previous.concat([value]);
|
|
46
|
+
var splitTags = (raw) => raw.flatMap((t) => t.split(",")).map((t) => t.trim()).filter((t) => t.length > 0);
|
|
47
|
+
|
|
48
|
+
// src/cli.ts
|
|
49
|
+
var icon = (level) => level === "ok" ? "\u2713" : level === "warn" ? "!" : "\u2716";
|
|
50
|
+
function createProgram() {
|
|
51
|
+
const program = new Command();
|
|
52
|
+
program.name("diffwiki").description("A git-based knowledge base").version(version).showHelpAfterError();
|
|
53
|
+
program.command("list").description("List all collections").action(
|
|
54
|
+
withErrors(async () => {
|
|
55
|
+
const collections = await listCollections();
|
|
56
|
+
if (collections.length === 0) {
|
|
57
|
+
console.log("No collections yet. Create one with: diffwiki create <name>");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
for (const c of collections) {
|
|
61
|
+
console.log(`${c.name} [${c.type}] ${c.path}`);
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
program.command("create").description("Create a new global collection").argument("<name>", "collection name").action(
|
|
66
|
+
withErrors(async (name) => {
|
|
67
|
+
const entry = await createCollection(name);
|
|
68
|
+
console.log(`Created collection "${entry.name}" at ${entry.path}`);
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
program.command("add").description("Add an article to a collection").requiredOption("-p, --path <target>", '"[collection:]title"').option("-t, --tag <tag>", "tag (repeatable, comma-separated)", collect, []).argument("[body]", "markdown body").action(
|
|
72
|
+
withErrors(async (body, opts) => {
|
|
73
|
+
const article = await createArticle({
|
|
74
|
+
target: opts.path,
|
|
75
|
+
tags: splitTags(opts.tag),
|
|
76
|
+
body
|
|
77
|
+
});
|
|
78
|
+
console.log(article.path);
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
program.command("update").description("Replace an article's body").requiredOption("-p, --path <target>", '"collection:path"').argument("<body>", "new markdown body").action(
|
|
82
|
+
withErrors(async (body, opts) => {
|
|
83
|
+
const article = await updateArticleBody(opts.path, body);
|
|
84
|
+
console.log(`Updated ${article.path}`);
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
program.command("remove").description("Delete an article").requiredOption("-p, --path <target>", '"collection:path"').action(
|
|
88
|
+
withErrors(async (opts) => {
|
|
89
|
+
const removed = await removeArticle(opts.path);
|
|
90
|
+
console.log(`Removed ${removed}`);
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
const registerTagCommand = (name, fn) => {
|
|
94
|
+
program.command(name).requiredOption("-p, --path <target>", '"collection:path"').argument("<tags>", "comma-separated tags").action(
|
|
95
|
+
withErrors(async (tags, opts) => {
|
|
96
|
+
const article = await fn(opts.path, splitTags([tags]));
|
|
97
|
+
console.log(`${article.path} \u2192 tags: ${article.tags.join(", ") || "(none)"}`);
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
registerTagCommand("add-tags", addTags);
|
|
102
|
+
registerTagCommand("remove-tags", removeTags);
|
|
103
|
+
registerTagCommand("update-tags", setTags);
|
|
104
|
+
program.command("query").description("Search articles (dummy \u2014 QMD coming later)").option("-c, --collection <name>", "limit to a collection").argument("[term]", "search term", "").action(
|
|
105
|
+
withErrors(async (term, opts) => {
|
|
106
|
+
const hits = await query(term, opts.collection);
|
|
107
|
+
console.log(`(dummy search \u2014 QMD coming later) ${hits.length} result(s)`);
|
|
108
|
+
for (const hit of hits) {
|
|
109
|
+
console.log(`${hit.collection} ${hit.title} ${hit.path}`);
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
program.command("init").description("Initialize an in-repo wiki and register it globally").option("-c, --collection <name>", "collection name (default: repo name)").option("-p, --path <path>", "wiki path within the repo (default: wiki)").action(
|
|
114
|
+
withErrors(async (opts) => {
|
|
115
|
+
const entry = await initRepoWiki({
|
|
116
|
+
cwd: process.cwd(),
|
|
117
|
+
collection: opts.collection,
|
|
118
|
+
wikiPath: opts.path
|
|
119
|
+
});
|
|
120
|
+
console.log(`Initialized repo wiki "${entry.name}" at ${entry.path}`);
|
|
121
|
+
console.log("Registered globally \u2014 discoverable via: diffwiki list");
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
program.command("config-set").description("Set a config value (e.g. defaultCollection)").argument("<key>", "config key").argument("<value>", "config value").action(
|
|
125
|
+
withErrors(async (key, value) => {
|
|
126
|
+
await setConfigValue(key, value);
|
|
127
|
+
console.log(`Set ${key} = ${value}`);
|
|
128
|
+
})
|
|
129
|
+
);
|
|
130
|
+
program.command("config-get").description("Read a config value").argument("<key>", "config key").action(
|
|
131
|
+
withErrors(async (key) => {
|
|
132
|
+
const value = await getConfigValue(key);
|
|
133
|
+
console.log(value ?? "(unset)");
|
|
134
|
+
})
|
|
135
|
+
);
|
|
136
|
+
program.command("doctor").description("Diagnose configuration issues").action(
|
|
137
|
+
withErrors(async () => {
|
|
138
|
+
const diagnostics = await doctor();
|
|
139
|
+
for (const d of diagnostics) {
|
|
140
|
+
console.log(`${icon(d.level)} ${d.message}`);
|
|
141
|
+
}
|
|
142
|
+
if (diagnostics.some((d) => d.level === "error")) {
|
|
143
|
+
process.exitCode = 1;
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
);
|
|
147
|
+
return program;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/bin.ts
|
|
151
|
+
createProgram().parseAsync(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "diffwiki",
|
|
3
|
+
"version": "0.2.0-rc.202607210907.c99416d",
|
|
4
|
+
"description": "diffwiki command-line interface",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"diffwiki": "./dist/bin.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"commander": "^13.0.0",
|
|
18
|
+
"diffwiki-core": "0.2.0-rc.202607210907.c99416d"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.0.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"test": "vitest run --passWithNoTests",
|
|
26
|
+
"lint": "eslint src tests --no-error-on-unmatched-pattern && tsc --noEmit",
|
|
27
|
+
"lint:fix": "eslint src tests --no-error-on-unmatched-pattern --fix"
|
|
28
|
+
}
|
|
29
|
+
}
|