@plttn/mkd 0.2.1 → 0.2.2
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/README.md +5 -0
- package/dist/index.cjs +352 -370
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +384 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -404
- package/dist/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,421 +7,403 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
16
18
|
};
|
|
17
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let cmd_ts = require("cmd-ts");
|
|
25
|
+
let pwd_fs = require("pwd-fs");
|
|
26
|
+
let node_path = require("node:path");
|
|
27
|
+
node_path = __toESM(node_path, 1);
|
|
28
|
+
let _sindresorhus_slugify = require("@sindresorhus/slugify");
|
|
29
|
+
_sindresorhus_slugify = __toESM(_sindresorhus_slugify, 1);
|
|
30
|
+
let filenamify = require("filenamify");
|
|
31
|
+
filenamify = __toESM(filenamify, 1);
|
|
32
|
+
let gray_matter = require("gray-matter");
|
|
33
|
+
gray_matter = __toESM(gray_matter, 1);
|
|
34
|
+
let _clack_prompts = require("@clack/prompts");
|
|
35
|
+
//#region src/lib/deps.ts
|
|
36
|
+
const defaultConfig = {
|
|
37
|
+
blogDir: "./src/blog",
|
|
38
|
+
titleKey: "title",
|
|
39
|
+
author: "",
|
|
40
|
+
publishedAtKey: "publishedAt",
|
|
41
|
+
modifiedAtKey: "updatedAt",
|
|
42
|
+
authorKey: "author",
|
|
43
|
+
draftKey: "draft",
|
|
44
|
+
descriptionKey: "description",
|
|
45
|
+
tagsKey: "tags"
|
|
41
46
|
};
|
|
42
47
|
async function loadConfig(pfs) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
57
|
-
} catch {
|
|
58
|
-
return defaultConfig;
|
|
59
|
-
}
|
|
48
|
+
try {
|
|
49
|
+
const raw = await pfs.read("./mkd.json");
|
|
50
|
+
if (!raw.trim()) return defaultConfig;
|
|
51
|
+
const parsed = JSON.parse(raw);
|
|
52
|
+
if (!isRecord(parsed)) return defaultConfig;
|
|
53
|
+
const { $schema: _schema, ...config } = parsed;
|
|
54
|
+
return {
|
|
55
|
+
...defaultConfig,
|
|
56
|
+
...config
|
|
57
|
+
};
|
|
58
|
+
} catch {
|
|
59
|
+
return defaultConfig;
|
|
60
|
+
}
|
|
60
61
|
}
|
|
61
62
|
function isRecord(value) {
|
|
62
|
-
|
|
63
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var import_cmd_ts = require("cmd-ts");
|
|
67
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
68
|
-
var import_slugify = __toESM(require("@sindresorhus/slugify"), 1);
|
|
69
|
-
var import_filenamify = __toESM(require("filenamify"), 1);
|
|
70
|
-
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
71
|
-
var import_prompts = require("@clack/prompts");
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/commands/new.ts
|
|
72
67
|
function makeNewCommand({ config, pfs }) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const slug = (0, import_slugify.default)(title);
|
|
95
|
-
const fileName = (0, import_filenamify.default)(slug);
|
|
96
|
-
const frontmatter = await generateFrontmatter(title, config);
|
|
97
|
-
const filePath = import_node_path.default.join(config.blogDir, `${fileName}.md`);
|
|
98
|
-
await pfs.write(filePath, frontmatter);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
68
|
+
return (0, cmd_ts.command)({
|
|
69
|
+
name: "new",
|
|
70
|
+
description: "Create a new post",
|
|
71
|
+
args: { new: (0, cmd_ts.restPositionals)({
|
|
72
|
+
type: cmd_ts.string,
|
|
73
|
+
displayName: "file",
|
|
74
|
+
description: "name of the new post"
|
|
75
|
+
}) },
|
|
76
|
+
handler: async ({ new: titleArray }) => {
|
|
77
|
+
(0, _clack_prompts.intro)("Create a new post");
|
|
78
|
+
let title;
|
|
79
|
+
if (titleArray.length === 0) {
|
|
80
|
+
title = await generateTitle();
|
|
81
|
+
if (title === "") return;
|
|
82
|
+
} else title = titleArray.join(" ");
|
|
83
|
+
const fileName = (0, filenamify.default)((0, _sindresorhus_slugify.default)(title));
|
|
84
|
+
const frontmatter = await generateFrontmatter(title, config);
|
|
85
|
+
const filePath = node_path.default.join(config.blogDir, `${fileName}.md`);
|
|
86
|
+
await pfs.write(filePath, frontmatter);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
101
89
|
}
|
|
102
90
|
async function generateFrontmatter(title, config) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
91
|
+
const description = await makeDescription(title);
|
|
92
|
+
const data = {
|
|
93
|
+
[config.titleKey]: title,
|
|
94
|
+
[config.publishedAtKey]: /* @__PURE__ */ new Date("3000-01-01T00:00:00Z"),
|
|
95
|
+
[config.authorKey]: config.author,
|
|
96
|
+
[config.draftKey]: true,
|
|
97
|
+
[config.descriptionKey]: description,
|
|
98
|
+
[config.tagsKey]: []
|
|
99
|
+
};
|
|
100
|
+
return gray_matter.default.stringify("", data);
|
|
113
101
|
}
|
|
114
102
|
async function makeDescription(title) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
return description;
|
|
103
|
+
const description = await (0, _clack_prompts.text)({
|
|
104
|
+
message: "Enter a description for the post:",
|
|
105
|
+
defaultValue: title
|
|
106
|
+
});
|
|
107
|
+
if ((0, _clack_prompts.isCancel)(description)) return "";
|
|
108
|
+
return description;
|
|
123
109
|
}
|
|
124
110
|
async function generateTitle() {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
134
|
-
if ((0, import_prompts.isCancel)(title)) {
|
|
135
|
-
return "";
|
|
136
|
-
}
|
|
137
|
-
return title;
|
|
111
|
+
const title = await (0, _clack_prompts.text)({
|
|
112
|
+
message: "Enter a title for the post:",
|
|
113
|
+
validate: (value) => {
|
|
114
|
+
if (!value) return "Title required";
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
if ((0, _clack_prompts.isCancel)(title)) return "";
|
|
118
|
+
return title;
|
|
138
119
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var import_prompts2 = require("@clack/prompts");
|
|
143
|
-
var import_gray_matter3 = __toESM(require("gray-matter"), 1);
|
|
144
|
-
|
|
145
|
-
// src/lib/commands.ts
|
|
146
|
-
var import_gray_matter2 = __toESM(require("gray-matter"), 1);
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/lib/commands.ts
|
|
122
|
+
/** Read all files from the blog directory and return them as Post objects */
|
|
147
123
|
async function readPosts(pfs, config) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
124
|
+
const files = await pfs.readdir(config.blogDir);
|
|
125
|
+
const posts = [];
|
|
126
|
+
for (const file of files) {
|
|
127
|
+
const content = await pfs.read(`${config.blogDir}/${file}`);
|
|
128
|
+
posts.push({
|
|
129
|
+
file,
|
|
130
|
+
content
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return posts;
|
|
155
134
|
}
|
|
135
|
+
/** Parse frontmatter from a Post */
|
|
156
136
|
function parseFrontmatter(post) {
|
|
157
|
-
|
|
158
|
-
|
|
137
|
+
const { data } = (0, gray_matter.default)(post.content);
|
|
138
|
+
return data;
|
|
159
139
|
}
|
|
140
|
+
/** Convert Posts to prompt option objects (value/label/hint) */
|
|
160
141
|
function postsToOptions(posts, config) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
142
|
+
return posts.map((post) => {
|
|
143
|
+
const fm = parseFrontmatter(post);
|
|
144
|
+
const title = String(fm[config.titleKey] ?? post.file);
|
|
145
|
+
return {
|
|
146
|
+
value: post.file,
|
|
147
|
+
label: title,
|
|
148
|
+
hint: post.file
|
|
149
|
+
};
|
|
150
|
+
});
|
|
170
151
|
}
|
|
152
|
+
/** Take the raw selected values returned by the prompt and return matching Post[] */
|
|
171
153
|
function selectedValuesToPosts(selected, posts) {
|
|
172
|
-
|
|
173
|
-
|
|
154
|
+
if (typeof selected === "symbol") return [];
|
|
155
|
+
return posts.filter((p) => selected.includes(p.file));
|
|
174
156
|
}
|
|
175
157
|
function findPostByFile(posts, fileName) {
|
|
176
|
-
|
|
158
|
+
return posts.find((p) => p.file === fileName);
|
|
177
159
|
}
|
|
178
|
-
|
|
179
|
-
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/commands/publish.ts
|
|
180
162
|
function makePublishCommand({ config, pfs }) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
});
|
|
163
|
+
return (0, cmd_ts.command)({
|
|
164
|
+
name: "publish",
|
|
165
|
+
description: "Undraft a post",
|
|
166
|
+
args: {},
|
|
167
|
+
handler: async () => {
|
|
168
|
+
const selected = await getPostsToPublish((await readPosts(pfs, config)).filter((post) => parseFrontmatter(post)[config.draftKey] === true), config);
|
|
169
|
+
for (const draft of selected) await updateDraftFrontMatter(draft, {
|
|
170
|
+
config,
|
|
171
|
+
pfs
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
196
175
|
}
|
|
197
176
|
async function getPostsToPublish(drafts, config) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
Array.isArray(selected) ? selected : [selected],
|
|
211
|
-
drafts
|
|
212
|
-
);
|
|
177
|
+
const options = postsToOptions(drafts, config);
|
|
178
|
+
(0, _clack_prompts.intro)("Publishing posts");
|
|
179
|
+
const selected = await (0, _clack_prompts.autocomplete)({
|
|
180
|
+
message: "Select post to publish",
|
|
181
|
+
options
|
|
182
|
+
});
|
|
183
|
+
if ((0, _clack_prompts.isCancel)(selected)) {
|
|
184
|
+
(0, _clack_prompts.outro)("Publishing cancelled.");
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
(0, _clack_prompts.outro)("Posts undrafted...");
|
|
188
|
+
return selectedValuesToPosts(Array.isArray(selected) ? selected : [selected], drafts);
|
|
213
189
|
}
|
|
214
190
|
async function updateDraftFrontMatter(draft, deps) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
191
|
+
const now = /* @__PURE__ */ new Date();
|
|
192
|
+
const parsed = (0, gray_matter.default)(draft.content);
|
|
193
|
+
const fm = parsed.data;
|
|
194
|
+
fm[deps.config.draftKey] = false;
|
|
195
|
+
fm[deps.config.publishedAtKey] = now;
|
|
196
|
+
const updatedContent = gray_matter.default.stringify(parsed.content, fm);
|
|
197
|
+
await deps.pfs.write(`${deps.config.blogDir}/${draft.file}`, updatedContent);
|
|
198
|
+
return {
|
|
199
|
+
...draft,
|
|
200
|
+
content: updatedContent
|
|
201
|
+
};
|
|
223
202
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
var import_cmd_ts3 = require("cmd-ts");
|
|
227
|
-
var import_prompts3 = require("@clack/prompts");
|
|
228
|
-
var import_gray_matter4 = __toESM(require("gray-matter"), 1);
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/commands/update.ts
|
|
229
205
|
function makeUpdateCommand({ config, pfs }) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
206
|
+
return (0, cmd_ts.command)({
|
|
207
|
+
name: "update",
|
|
208
|
+
description: "Update a post's modified date",
|
|
209
|
+
args: {},
|
|
210
|
+
handler: async () => {
|
|
211
|
+
const post = await getPostToUpdate(await readPosts(pfs, config), config);
|
|
212
|
+
if (!post) return;
|
|
213
|
+
await updatePostDate(post, {
|
|
214
|
+
config,
|
|
215
|
+
pfs
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
});
|
|
241
219
|
}
|
|
242
220
|
async function getPostToUpdate(posts, config) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return found ?? null;
|
|
221
|
+
const options = postsToOptions(posts, config);
|
|
222
|
+
(0, _clack_prompts.intro)("Update a post");
|
|
223
|
+
const selected = await (0, _clack_prompts.autocomplete)({
|
|
224
|
+
message: "Select post to update",
|
|
225
|
+
options
|
|
226
|
+
});
|
|
227
|
+
if ((0, _clack_prompts.isCancel)(selected)) {
|
|
228
|
+
(0, _clack_prompts.outro)("Update cancelled.");
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
(0, _clack_prompts.outro)("Post updated.");
|
|
232
|
+
return findPostByFile(posts, selected) ?? null;
|
|
256
233
|
}
|
|
257
234
|
async function updatePostDate(post, deps) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
235
|
+
const parsed = (0, gray_matter.default)(post.content);
|
|
236
|
+
const fm = parsed.data;
|
|
237
|
+
fm[deps.config.modifiedAtKey] = /* @__PURE__ */ new Date();
|
|
238
|
+
const updatedContent = gray_matter.default.stringify(parsed.content, fm);
|
|
239
|
+
await deps.pfs.write(`${deps.config.blogDir}/${post.file}`, updatedContent);
|
|
240
|
+
return {
|
|
241
|
+
...post,
|
|
242
|
+
content: updatedContent
|
|
243
|
+
};
|
|
264
244
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
var import_cmd_ts4 = require("cmd-ts");
|
|
268
|
-
var import_prompts4 = require("@clack/prompts");
|
|
269
|
-
var import_gray_matter5 = __toESM(require("gray-matter"), 1);
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/commands/unpublish.ts
|
|
270
247
|
function makeUnPublishCommand({ config, pfs }) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
248
|
+
return (0, cmd_ts.command)({
|
|
249
|
+
name: "unpublish",
|
|
250
|
+
description: "Unpublish a post",
|
|
251
|
+
args: {},
|
|
252
|
+
handler: async () => {
|
|
253
|
+
const post = await getPostToUnpub(await readPosts(pfs, config), config);
|
|
254
|
+
if (!post) return;
|
|
255
|
+
await unpubPost(post, {
|
|
256
|
+
config,
|
|
257
|
+
pfs
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
});
|
|
282
261
|
}
|
|
283
262
|
async function getPostToUnpub(posts, config) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return found ?? null;
|
|
263
|
+
const options = postsToOptions(posts, config);
|
|
264
|
+
(0, _clack_prompts.intro)("Unpublish a post");
|
|
265
|
+
const selected = await (0, _clack_prompts.autocomplete)({
|
|
266
|
+
message: "Select post to unpublish",
|
|
267
|
+
options
|
|
268
|
+
});
|
|
269
|
+
if ((0, _clack_prompts.isCancel)(selected)) {
|
|
270
|
+
(0, _clack_prompts.outro)("Unpublish cancelled.");
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
(0, _clack_prompts.outro)("Post unpublished.");
|
|
274
|
+
return findPostByFile(posts, selected) ?? null;
|
|
297
275
|
}
|
|
298
276
|
async function unpubPost(post, deps) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
277
|
+
const parsed = (0, gray_matter.default)(post.content);
|
|
278
|
+
const fm = parsed.data;
|
|
279
|
+
fm[deps.config.draftKey] = true;
|
|
280
|
+
const updatedContent = gray_matter.default.stringify(parsed.content, fm);
|
|
281
|
+
await deps.pfs.write(`${deps.config.blogDir}/${post.file}`, updatedContent);
|
|
282
|
+
return {
|
|
283
|
+
...post,
|
|
284
|
+
content: updatedContent
|
|
285
|
+
};
|
|
305
286
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
var import_cmd_ts5 = require("cmd-ts");
|
|
309
|
-
var import_prompts5 = require("@clack/prompts");
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/commands/init.ts
|
|
310
289
|
function makeInitCommand({ config, pfs }) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
290
|
+
return (0, cmd_ts.command)({
|
|
291
|
+
name: "init",
|
|
292
|
+
description: "Create or update mkd.json configuration",
|
|
293
|
+
args: {},
|
|
294
|
+
handler: async () => {
|
|
295
|
+
(0, _clack_prompts.intro)("Initialize mkd configuration");
|
|
296
|
+
const blogDir = await (0, _clack_prompts.text)({
|
|
297
|
+
message: "Directory where generated posts are written",
|
|
298
|
+
defaultValue: String(config.blogDir ?? "./src/blog")
|
|
299
|
+
});
|
|
300
|
+
if ((0, _clack_prompts.isCancel)(blogDir)) {
|
|
301
|
+
(0, _clack_prompts.outro)("Init cancelled");
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const author = await (0, _clack_prompts.text)({
|
|
305
|
+
message: "Default author",
|
|
306
|
+
defaultValue: String(config.author ?? "")
|
|
307
|
+
});
|
|
308
|
+
if ((0, _clack_prompts.isCancel)(author)) {
|
|
309
|
+
(0, _clack_prompts.outro)("Init cancelled");
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const titleKey = await (0, _clack_prompts.text)({
|
|
313
|
+
message: "Title frontmatter key",
|
|
314
|
+
defaultValue: String(config.titleKey ?? "title")
|
|
315
|
+
});
|
|
316
|
+
if ((0, _clack_prompts.isCancel)(titleKey)) {
|
|
317
|
+
(0, _clack_prompts.outro)("Init cancelled");
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const publishedAtKey = await (0, _clack_prompts.text)({
|
|
321
|
+
message: "Published date frontmatter key",
|
|
322
|
+
defaultValue: String(config.publishedAtKey ?? "publishedAt")
|
|
323
|
+
});
|
|
324
|
+
if ((0, _clack_prompts.isCancel)(publishedAtKey)) {
|
|
325
|
+
(0, _clack_prompts.outro)("Init cancelled");
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const modifiedAtKey = await (0, _clack_prompts.text)({
|
|
329
|
+
message: "Modified date frontmatter key",
|
|
330
|
+
defaultValue: String(config.modifiedAtKey ?? "updatedAt")
|
|
331
|
+
});
|
|
332
|
+
if ((0, _clack_prompts.isCancel)(modifiedAtKey)) {
|
|
333
|
+
(0, _clack_prompts.outro)("Init cancelled");
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const authorKey = await (0, _clack_prompts.text)({
|
|
337
|
+
message: "Author frontmatter key",
|
|
338
|
+
defaultValue: String(config.authorKey ?? "author")
|
|
339
|
+
});
|
|
340
|
+
if ((0, _clack_prompts.isCancel)(authorKey)) {
|
|
341
|
+
(0, _clack_prompts.outro)("Init cancelled");
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const draftKey = await (0, _clack_prompts.text)({
|
|
345
|
+
message: "Draft frontmatter key",
|
|
346
|
+
defaultValue: String(config.draftKey ?? "draft")
|
|
347
|
+
});
|
|
348
|
+
if ((0, _clack_prompts.isCancel)(draftKey)) {
|
|
349
|
+
(0, _clack_prompts.outro)("Init cancelled");
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const descriptionKey = await (0, _clack_prompts.text)({
|
|
353
|
+
message: "Description frontmatter key",
|
|
354
|
+
defaultValue: String(config.descriptionKey ?? "description")
|
|
355
|
+
});
|
|
356
|
+
if ((0, _clack_prompts.isCancel)(descriptionKey)) {
|
|
357
|
+
(0, _clack_prompts.outro)("Init cancelled");
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const tagsKey = await (0, _clack_prompts.text)({
|
|
361
|
+
message: "Tags frontmatter key",
|
|
362
|
+
defaultValue: String(config.tagsKey ?? "tags")
|
|
363
|
+
});
|
|
364
|
+
if ((0, _clack_prompts.isCancel)(tagsKey)) {
|
|
365
|
+
(0, _clack_prompts.outro)("Init cancelled");
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const newConfig = {
|
|
369
|
+
blogDir: String(blogDir),
|
|
370
|
+
author: String(author),
|
|
371
|
+
publishedAtKey: String(publishedAtKey),
|
|
372
|
+
modifiedAtKey: String(modifiedAtKey),
|
|
373
|
+
authorKey: String(authorKey),
|
|
374
|
+
draftKey: String(draftKey),
|
|
375
|
+
descriptionKey: String(descriptionKey),
|
|
376
|
+
tagsKey: String(tagsKey),
|
|
377
|
+
titleKey: String(titleKey)
|
|
378
|
+
};
|
|
379
|
+
await pfs.write("./mkd.json", JSON.stringify(newConfig, null, 2) + "\n");
|
|
380
|
+
(0, _clack_prompts.outro)("Configuration saved to mkd.json");
|
|
381
|
+
}
|
|
382
|
+
});
|
|
404
383
|
}
|
|
405
|
-
|
|
406
|
-
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/index.ts
|
|
407
386
|
async function main() {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
387
|
+
const pfs = new pwd_fs.PoweredFileSystem();
|
|
388
|
+
const deps = {
|
|
389
|
+
config: await loadConfig(pfs),
|
|
390
|
+
pfs
|
|
391
|
+
};
|
|
392
|
+
await (0, cmd_ts.run)((0, cmd_ts.subcommands)({
|
|
393
|
+
name: "mkd",
|
|
394
|
+
cmds: {
|
|
395
|
+
new: makeNewCommand(deps),
|
|
396
|
+
publish: makePublishCommand(deps),
|
|
397
|
+
update: makeUpdateCommand(deps),
|
|
398
|
+
unpublish: makeUnPublishCommand(deps),
|
|
399
|
+
init: makeInitCommand(deps)
|
|
400
|
+
}
|
|
401
|
+
}), process.argv.slice(2));
|
|
422
402
|
}
|
|
423
403
|
main().catch((error) => {
|
|
424
|
-
|
|
425
|
-
|
|
404
|
+
console.error(error);
|
|
405
|
+
process.exit(1);
|
|
426
406
|
});
|
|
407
|
+
//#endregion
|
|
408
|
+
|
|
427
409
|
//# sourceMappingURL=index.cjs.map
|