diffwiki-core 0.2.0-rc.202607210925.6d32f39 → 0.2.0-rc.f44d17c
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/index.cjs +59 -74
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +59 -74
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -126,28 +126,51 @@ function collectionDir(name) {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
// src/config.ts
|
|
129
|
-
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
130
|
-
|
|
131
|
-
// src/collections.ts
|
|
132
|
-
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
133
|
-
|
|
134
|
-
// src/registry.ts
|
|
135
129
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
136
130
|
function isMissing(err) {
|
|
137
131
|
return err?.code === "ENOENT";
|
|
138
132
|
}
|
|
133
|
+
async function readConfig() {
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(await import_promises.default.readFile(configPath(), "utf8"));
|
|
136
|
+
} catch (err) {
|
|
137
|
+
if (isMissing(err)) return {};
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function writeConfig(config) {
|
|
142
|
+
await import_promises.default.mkdir(resolveHome(), { recursive: true });
|
|
143
|
+
await import_promises.default.writeFile(configPath(), `${JSON.stringify(config, null, 2)}
|
|
144
|
+
`, "utf8");
|
|
145
|
+
}
|
|
146
|
+
async function setConfigValue(key, value) {
|
|
147
|
+
const config = await readConfig();
|
|
148
|
+
config[key] = value;
|
|
149
|
+
await writeConfig(config);
|
|
150
|
+
}
|
|
151
|
+
async function getConfigValue(key) {
|
|
152
|
+
const config = await readConfig();
|
|
153
|
+
const value = config[key];
|
|
154
|
+
return typeof value === "string" ? value : void 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/registry.ts
|
|
158
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
159
|
+
function isMissing2(err) {
|
|
160
|
+
return err?.code === "ENOENT";
|
|
161
|
+
}
|
|
139
162
|
async function readRegistry() {
|
|
140
163
|
try {
|
|
141
|
-
const parsed = JSON.parse(await
|
|
164
|
+
const parsed = JSON.parse(await import_promises2.default.readFile(registryPath(), "utf8"));
|
|
142
165
|
return { version: parsed.version ?? 1, collections: parsed.collections ?? [] };
|
|
143
166
|
} catch (err) {
|
|
144
|
-
if (
|
|
167
|
+
if (isMissing2(err)) return { version: 1, collections: [] };
|
|
145
168
|
throw err;
|
|
146
169
|
}
|
|
147
170
|
}
|
|
148
171
|
async function writeRegistry(registry) {
|
|
149
|
-
await
|
|
150
|
-
await
|
|
172
|
+
await import_promises2.default.mkdir(resolveHome(), { recursive: true });
|
|
173
|
+
await import_promises2.default.writeFile(registryPath(), `${JSON.stringify(registry, null, 2)}
|
|
151
174
|
`, "utf8");
|
|
152
175
|
}
|
|
153
176
|
async function registerCollection(entry) {
|
|
@@ -166,7 +189,29 @@ async function unregisterCollection(name) {
|
|
|
166
189
|
await writeRegistry(registry);
|
|
167
190
|
}
|
|
168
191
|
|
|
192
|
+
// src/slugify.ts
|
|
193
|
+
function slugify(input) {
|
|
194
|
+
const slug = input.toLowerCase().replace(/^#+\s*/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80).replace(/-+$/g, "");
|
|
195
|
+
return slug.length > 0 ? slug : "untitled";
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/frontmatter.ts
|
|
199
|
+
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
200
|
+
function parseArticle(raw) {
|
|
201
|
+
const { data, content } = (0, import_gray_matter.default)(raw);
|
|
202
|
+
const title = typeof data.title === "string" ? data.title : "";
|
|
203
|
+
const tags = Array.isArray(data.tags) ? data.tags.map((t) => String(t)) : [];
|
|
204
|
+
return { title, tags, body: content.replace(/^\n+/, "") };
|
|
205
|
+
}
|
|
206
|
+
function serializeArticle(article) {
|
|
207
|
+
const front = { title: article.title, tags: article.tags };
|
|
208
|
+
if (article.created) front.created = article.created;
|
|
209
|
+
if (article.updated) front.updated = article.updated;
|
|
210
|
+
return import_gray_matter.default.stringify(article.body, front);
|
|
211
|
+
}
|
|
212
|
+
|
|
169
213
|
// src/collections.ts
|
|
214
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
170
215
|
async function listCollections() {
|
|
171
216
|
return (await readRegistry()).collections;
|
|
172
217
|
}
|
|
@@ -176,7 +221,7 @@ async function findCollection(name) {
|
|
|
176
221
|
async function createCollection(name) {
|
|
177
222
|
if (await findCollection(name)) throw new CollectionExistsError(name);
|
|
178
223
|
const dir = collectionDir(name);
|
|
179
|
-
await
|
|
224
|
+
await import_promises3.default.mkdir(dir, { recursive: true });
|
|
180
225
|
const entry = {
|
|
181
226
|
name,
|
|
182
227
|
type: "global",
|
|
@@ -191,64 +236,11 @@ async function removeCollection(name) {
|
|
|
191
236
|
if (!entry) throw new CollectionNotFoundError(name);
|
|
192
237
|
await unregisterCollection(name);
|
|
193
238
|
if (entry.type === "global") {
|
|
194
|
-
await
|
|
239
|
+
await import_promises3.default.rm(entry.path, { recursive: true, force: true });
|
|
195
240
|
}
|
|
196
241
|
return entry;
|
|
197
242
|
}
|
|
198
243
|
|
|
199
|
-
// src/config.ts
|
|
200
|
-
function isMissing2(err) {
|
|
201
|
-
return err?.code === "ENOENT";
|
|
202
|
-
}
|
|
203
|
-
async function readConfig() {
|
|
204
|
-
try {
|
|
205
|
-
return JSON.parse(await import_promises3.default.readFile(configPath(), "utf8"));
|
|
206
|
-
} catch (err) {
|
|
207
|
-
if (isMissing2(err)) return {};
|
|
208
|
-
throw err;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
async function writeConfig(config) {
|
|
212
|
-
await import_promises3.default.mkdir(resolveHome(), { recursive: true });
|
|
213
|
-
await import_promises3.default.writeFile(configPath(), `${JSON.stringify(config, null, 2)}
|
|
214
|
-
`, "utf8");
|
|
215
|
-
}
|
|
216
|
-
async function setConfigValue(key, value) {
|
|
217
|
-
if (key === "defaultCollection" && !await findCollection(value)) {
|
|
218
|
-
throw new CollectionNotFoundError(value);
|
|
219
|
-
}
|
|
220
|
-
const config = await readConfig();
|
|
221
|
-
config[key] = value;
|
|
222
|
-
await writeConfig(config);
|
|
223
|
-
}
|
|
224
|
-
async function getConfigValue(key) {
|
|
225
|
-
const config = await readConfig();
|
|
226
|
-
const value = config[key];
|
|
227
|
-
return typeof value === "string" ? value : void 0;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// src/slugify.ts
|
|
231
|
-
function slugify(input) {
|
|
232
|
-
const slug = input.toLowerCase().replace(/^#+\s*/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80).replace(/-+$/g, "");
|
|
233
|
-
return slug.length > 0 ? slug : "untitled";
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// src/frontmatter.ts
|
|
237
|
-
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
238
|
-
function parseArticle(raw) {
|
|
239
|
-
const { data, content } = (0, import_gray_matter.default)(raw);
|
|
240
|
-
const title = typeof data.title === "string" ? data.title : "";
|
|
241
|
-
const tags = Array.isArray(data.tags) ? data.tags.map((t) => String(t)) : [];
|
|
242
|
-
const created = typeof data.created === "string" ? data.created : void 0;
|
|
243
|
-
return { title, tags, created, body: content.replace(/^\n+/, "") };
|
|
244
|
-
}
|
|
245
|
-
function serializeArticle(article) {
|
|
246
|
-
const front = { title: article.title, tags: article.tags };
|
|
247
|
-
if (article.created) front.created = article.created;
|
|
248
|
-
if (article.updated) front.updated = article.updated;
|
|
249
|
-
return import_gray_matter.default.stringify(article.body, front);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
244
|
// src/articles.ts
|
|
253
245
|
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
254
246
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
@@ -283,11 +275,7 @@ async function resolveCollectionDir(name) {
|
|
|
283
275
|
return { name: coll, dir: entry.path };
|
|
284
276
|
}
|
|
285
277
|
function ensureMdPath(file) {
|
|
286
|
-
|
|
287
|
-
const dir = import_node_path2.default.dirname(file);
|
|
288
|
-
const base = slugify(import_node_path2.default.basename(file));
|
|
289
|
-
const rel = dir === "." ? `${base}.md` : import_node_path2.default.join(dir, `${base}.md`);
|
|
290
|
-
return rel;
|
|
278
|
+
return /\.mdx?$/.test(file) ? file : `${file}.md`;
|
|
291
279
|
}
|
|
292
280
|
async function createArticle(opts) {
|
|
293
281
|
const { collection, title } = parseAddTarget(opts.target);
|
|
@@ -319,7 +307,6 @@ async function updateArticleBody(target, body) {
|
|
|
319
307
|
serializeArticle({
|
|
320
308
|
title: parsed.title,
|
|
321
309
|
tags: parsed.tags,
|
|
322
|
-
created: parsed.created,
|
|
323
310
|
updated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
324
311
|
body
|
|
325
312
|
}),
|
|
@@ -336,7 +323,6 @@ async function mutateTags(target, fn) {
|
|
|
336
323
|
serializeArticle({
|
|
337
324
|
title: parsed.title,
|
|
338
325
|
tags,
|
|
339
|
-
created: parsed.created,
|
|
340
326
|
updated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
341
327
|
body: parsed.body
|
|
342
328
|
}),
|
|
@@ -428,8 +414,7 @@ async function query(term, collection) {
|
|
|
428
414
|
let targets;
|
|
429
415
|
if (collection) {
|
|
430
416
|
const one = await findCollection(collection);
|
|
431
|
-
|
|
432
|
-
targets = [one];
|
|
417
|
+
targets = one ? [one] : [];
|
|
433
418
|
} else {
|
|
434
419
|
targets = await listCollections();
|
|
435
420
|
}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -52,28 +52,51 @@ function collectionDir(name) {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// src/config.ts
|
|
55
|
-
import fs3 from "fs/promises";
|
|
56
|
-
|
|
57
|
-
// src/collections.ts
|
|
58
|
-
import fs2 from "fs/promises";
|
|
59
|
-
|
|
60
|
-
// src/registry.ts
|
|
61
55
|
import fs from "fs/promises";
|
|
62
56
|
function isMissing(err) {
|
|
63
57
|
return err?.code === "ENOENT";
|
|
64
58
|
}
|
|
59
|
+
async function readConfig() {
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(await fs.readFile(configPath(), "utf8"));
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (isMissing(err)) return {};
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function writeConfig(config) {
|
|
68
|
+
await fs.mkdir(resolveHome(), { recursive: true });
|
|
69
|
+
await fs.writeFile(configPath(), `${JSON.stringify(config, null, 2)}
|
|
70
|
+
`, "utf8");
|
|
71
|
+
}
|
|
72
|
+
async function setConfigValue(key, value) {
|
|
73
|
+
const config = await readConfig();
|
|
74
|
+
config[key] = value;
|
|
75
|
+
await writeConfig(config);
|
|
76
|
+
}
|
|
77
|
+
async function getConfigValue(key) {
|
|
78
|
+
const config = await readConfig();
|
|
79
|
+
const value = config[key];
|
|
80
|
+
return typeof value === "string" ? value : void 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/registry.ts
|
|
84
|
+
import fs2 from "fs/promises";
|
|
85
|
+
function isMissing2(err) {
|
|
86
|
+
return err?.code === "ENOENT";
|
|
87
|
+
}
|
|
65
88
|
async function readRegistry() {
|
|
66
89
|
try {
|
|
67
|
-
const parsed = JSON.parse(await
|
|
90
|
+
const parsed = JSON.parse(await fs2.readFile(registryPath(), "utf8"));
|
|
68
91
|
return { version: parsed.version ?? 1, collections: parsed.collections ?? [] };
|
|
69
92
|
} catch (err) {
|
|
70
|
-
if (
|
|
93
|
+
if (isMissing2(err)) return { version: 1, collections: [] };
|
|
71
94
|
throw err;
|
|
72
95
|
}
|
|
73
96
|
}
|
|
74
97
|
async function writeRegistry(registry) {
|
|
75
|
-
await
|
|
76
|
-
await
|
|
98
|
+
await fs2.mkdir(resolveHome(), { recursive: true });
|
|
99
|
+
await fs2.writeFile(registryPath(), `${JSON.stringify(registry, null, 2)}
|
|
77
100
|
`, "utf8");
|
|
78
101
|
}
|
|
79
102
|
async function registerCollection(entry) {
|
|
@@ -92,7 +115,29 @@ async function unregisterCollection(name) {
|
|
|
92
115
|
await writeRegistry(registry);
|
|
93
116
|
}
|
|
94
117
|
|
|
118
|
+
// src/slugify.ts
|
|
119
|
+
function slugify(input) {
|
|
120
|
+
const slug = input.toLowerCase().replace(/^#+\s*/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80).replace(/-+$/g, "");
|
|
121
|
+
return slug.length > 0 ? slug : "untitled";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/frontmatter.ts
|
|
125
|
+
import matter from "gray-matter";
|
|
126
|
+
function parseArticle(raw) {
|
|
127
|
+
const { data, content } = matter(raw);
|
|
128
|
+
const title = typeof data.title === "string" ? data.title : "";
|
|
129
|
+
const tags = Array.isArray(data.tags) ? data.tags.map((t) => String(t)) : [];
|
|
130
|
+
return { title, tags, body: content.replace(/^\n+/, "") };
|
|
131
|
+
}
|
|
132
|
+
function serializeArticle(article) {
|
|
133
|
+
const front = { title: article.title, tags: article.tags };
|
|
134
|
+
if (article.created) front.created = article.created;
|
|
135
|
+
if (article.updated) front.updated = article.updated;
|
|
136
|
+
return matter.stringify(article.body, front);
|
|
137
|
+
}
|
|
138
|
+
|
|
95
139
|
// src/collections.ts
|
|
140
|
+
import fs3 from "fs/promises";
|
|
96
141
|
async function listCollections() {
|
|
97
142
|
return (await readRegistry()).collections;
|
|
98
143
|
}
|
|
@@ -102,7 +147,7 @@ async function findCollection(name) {
|
|
|
102
147
|
async function createCollection(name) {
|
|
103
148
|
if (await findCollection(name)) throw new CollectionExistsError(name);
|
|
104
149
|
const dir = collectionDir(name);
|
|
105
|
-
await
|
|
150
|
+
await fs3.mkdir(dir, { recursive: true });
|
|
106
151
|
const entry = {
|
|
107
152
|
name,
|
|
108
153
|
type: "global",
|
|
@@ -117,64 +162,11 @@ async function removeCollection(name) {
|
|
|
117
162
|
if (!entry) throw new CollectionNotFoundError(name);
|
|
118
163
|
await unregisterCollection(name);
|
|
119
164
|
if (entry.type === "global") {
|
|
120
|
-
await
|
|
165
|
+
await fs3.rm(entry.path, { recursive: true, force: true });
|
|
121
166
|
}
|
|
122
167
|
return entry;
|
|
123
168
|
}
|
|
124
169
|
|
|
125
|
-
// src/config.ts
|
|
126
|
-
function isMissing2(err) {
|
|
127
|
-
return err?.code === "ENOENT";
|
|
128
|
-
}
|
|
129
|
-
async function readConfig() {
|
|
130
|
-
try {
|
|
131
|
-
return JSON.parse(await fs3.readFile(configPath(), "utf8"));
|
|
132
|
-
} catch (err) {
|
|
133
|
-
if (isMissing2(err)) return {};
|
|
134
|
-
throw err;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
async function writeConfig(config) {
|
|
138
|
-
await fs3.mkdir(resolveHome(), { recursive: true });
|
|
139
|
-
await fs3.writeFile(configPath(), `${JSON.stringify(config, null, 2)}
|
|
140
|
-
`, "utf8");
|
|
141
|
-
}
|
|
142
|
-
async function setConfigValue(key, value) {
|
|
143
|
-
if (key === "defaultCollection" && !await findCollection(value)) {
|
|
144
|
-
throw new CollectionNotFoundError(value);
|
|
145
|
-
}
|
|
146
|
-
const config = await readConfig();
|
|
147
|
-
config[key] = value;
|
|
148
|
-
await writeConfig(config);
|
|
149
|
-
}
|
|
150
|
-
async function getConfigValue(key) {
|
|
151
|
-
const config = await readConfig();
|
|
152
|
-
const value = config[key];
|
|
153
|
-
return typeof value === "string" ? value : void 0;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// src/slugify.ts
|
|
157
|
-
function slugify(input) {
|
|
158
|
-
const slug = input.toLowerCase().replace(/^#+\s*/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80).replace(/-+$/g, "");
|
|
159
|
-
return slug.length > 0 ? slug : "untitled";
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// src/frontmatter.ts
|
|
163
|
-
import matter from "gray-matter";
|
|
164
|
-
function parseArticle(raw) {
|
|
165
|
-
const { data, content } = matter(raw);
|
|
166
|
-
const title = typeof data.title === "string" ? data.title : "";
|
|
167
|
-
const tags = Array.isArray(data.tags) ? data.tags.map((t) => String(t)) : [];
|
|
168
|
-
const created = typeof data.created === "string" ? data.created : void 0;
|
|
169
|
-
return { title, tags, created, body: content.replace(/^\n+/, "") };
|
|
170
|
-
}
|
|
171
|
-
function serializeArticle(article) {
|
|
172
|
-
const front = { title: article.title, tags: article.tags };
|
|
173
|
-
if (article.created) front.created = article.created;
|
|
174
|
-
if (article.updated) front.updated = article.updated;
|
|
175
|
-
return matter.stringify(article.body, front);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
170
|
// src/articles.ts
|
|
179
171
|
import fs4 from "fs/promises";
|
|
180
172
|
import path2 from "path";
|
|
@@ -209,11 +201,7 @@ async function resolveCollectionDir(name) {
|
|
|
209
201
|
return { name: coll, dir: entry.path };
|
|
210
202
|
}
|
|
211
203
|
function ensureMdPath(file) {
|
|
212
|
-
|
|
213
|
-
const dir = path2.dirname(file);
|
|
214
|
-
const base = slugify(path2.basename(file));
|
|
215
|
-
const rel = dir === "." ? `${base}.md` : path2.join(dir, `${base}.md`);
|
|
216
|
-
return rel;
|
|
204
|
+
return /\.mdx?$/.test(file) ? file : `${file}.md`;
|
|
217
205
|
}
|
|
218
206
|
async function createArticle(opts) {
|
|
219
207
|
const { collection, title } = parseAddTarget(opts.target);
|
|
@@ -245,7 +233,6 @@ async function updateArticleBody(target, body) {
|
|
|
245
233
|
serializeArticle({
|
|
246
234
|
title: parsed.title,
|
|
247
235
|
tags: parsed.tags,
|
|
248
|
-
created: parsed.created,
|
|
249
236
|
updated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
250
237
|
body
|
|
251
238
|
}),
|
|
@@ -262,7 +249,6 @@ async function mutateTags(target, fn) {
|
|
|
262
249
|
serializeArticle({
|
|
263
250
|
title: parsed.title,
|
|
264
251
|
tags,
|
|
265
|
-
created: parsed.created,
|
|
266
252
|
updated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
267
253
|
body: parsed.body
|
|
268
254
|
}),
|
|
@@ -354,8 +340,7 @@ async function query(term, collection) {
|
|
|
354
340
|
let targets;
|
|
355
341
|
if (collection) {
|
|
356
342
|
const one = await findCollection(collection);
|
|
357
|
-
|
|
358
|
-
targets = [one];
|
|
343
|
+
targets = one ? [one] : [];
|
|
359
344
|
} else {
|
|
360
345
|
targets = await listCollections();
|
|
361
346
|
}
|