@plttn/mkd 0.2.0 → 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/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
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
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
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
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
-
26
- // src/index.ts
27
- var import_cmd_ts6 = require("cmd-ts");
28
- var import_pwd_fs = require("pwd-fs");
29
-
30
- // src/lib/deps.ts
31
- var defaultConfig = {
32
- blogDir: "./src/blog",
33
- titleKey: "title",
34
- author: "",
35
- publishedAtKey: "publishedAt",
36
- modifiedAtKey: "updatedAt",
37
- authorKey: "author",
38
- draftKey: "draft",
39
- descriptionKey: "description",
40
- tagsKey: "tags"
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
- try {
44
- const raw = await pfs.read("./mkd.json");
45
- if (!raw.trim()) {
46
- return defaultConfig;
47
- }
48
- const parsed = JSON.parse(raw);
49
- if (!isRecord(parsed)) {
50
- return defaultConfig;
51
- }
52
- const { $schema: _schema, ...config } = parsed;
53
- return {
54
- ...defaultConfig,
55
- ...config
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
- return typeof value === "object" && value !== null && !Array.isArray(value);
63
+ return typeof value === "object" && value !== null && !Array.isArray(value);
63
64
  }
64
-
65
- // src/commands/new.ts
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
- return (0, import_cmd_ts.command)({
74
- name: "new",
75
- description: "Create a new post",
76
- args: {
77
- new: (0, import_cmd_ts.restPositionals)({
78
- type: import_cmd_ts.string,
79
- displayName: "file",
80
- description: "name of the new post"
81
- })
82
- },
83
- handler: async ({ new: titleArray }) => {
84
- (0, import_prompts.intro)("Create a new post");
85
- let title;
86
- if (titleArray.length === 0) {
87
- title = await generateTitle();
88
- if (title === "") {
89
- return;
90
- }
91
- } else {
92
- title = titleArray.join(" ");
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
- const description = await makeDescription(title);
104
- const data = {
105
- [config.titleKey]: title,
106
- [config.publishedAtKey]: "3000-01-01T00:00:00Z",
107
- [config.authorKey]: config.author,
108
- [config.draftKey]: true,
109
- [config.descriptionKey]: description,
110
- [config.tagsKey]: []
111
- };
112
- return import_gray_matter.default.stringify("", data);
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
- const description = await (0, import_prompts.text)({
116
- message: "Enter a description for the post:",
117
- defaultValue: title
118
- });
119
- if ((0, import_prompts.isCancel)(description)) {
120
- return "";
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
- const title = await (0, import_prompts.text)({
126
- message: "Enter a title for the post:",
127
- validate: (value) => {
128
- if (!value) {
129
- return "Title required";
130
- }
131
- return void 0;
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
- // src/commands/publish.ts
141
- var import_cmd_ts2 = require("cmd-ts");
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
- const files = await pfs.readdir(config.blogDir);
149
- const posts = [];
150
- for (const file of files) {
151
- const content = await pfs.read(`${config.blogDir}/${file}`);
152
- posts.push({ file, content });
153
- }
154
- return posts;
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
- const { data } = (0, import_gray_matter2.default)(post.content);
158
- return data;
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
- return posts.map((post) => {
162
- const fm = parseFrontmatter(post);
163
- const title = String(fm[config.titleKey] ?? post.file);
164
- return {
165
- value: post.file,
166
- label: title,
167
- hint: post.file
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
- if (typeof selected === "symbol") return [];
173
- return posts.filter((p) => selected.includes(p.file));
154
+ if (typeof selected === "symbol") return [];
155
+ return posts.filter((p) => selected.includes(p.file));
174
156
  }
175
157
  function findPostByFile(posts, fileName) {
176
- return posts.find((p) => p.file === fileName);
158
+ return posts.find((p) => p.file === fileName);
177
159
  }
178
-
179
- // src/commands/publish.ts
160
+ //#endregion
161
+ //#region src/commands/publish.ts
180
162
  function makePublishCommand({ config, pfs }) {
181
- return (0, import_cmd_ts2.command)({
182
- name: "publish",
183
- description: "Undraft a post",
184
- args: {},
185
- handler: async () => {
186
- const posts = await readPosts(pfs, config);
187
- const drafts = posts.filter(
188
- (post) => parseFrontmatter(post)[config.draftKey] === true
189
- );
190
- const selected = await getPostsToPublish(drafts, config);
191
- for (const draft of selected) {
192
- await updateDraftFrontMatter(draft, { config, pfs });
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
- const options = postsToOptions(drafts, config);
199
- (0, import_prompts2.intro)("Publishing posts");
200
- const selected = await (0, import_prompts2.autocomplete)({
201
- message: "Select post to publish",
202
- options
203
- });
204
- if ((0, import_prompts2.isCancel)(selected)) {
205
- (0, import_prompts2.outro)("Publishing cancelled.");
206
- return [];
207
- }
208
- (0, import_prompts2.outro)("Posts undrafted...");
209
- return selectedValuesToPosts(
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
- const now = /* @__PURE__ */ new Date();
216
- const parsed = (0, import_gray_matter3.default)(draft.content);
217
- const fm = parsed.data;
218
- fm[deps.config.draftKey] = false;
219
- fm[deps.config.publishedAtKey] = now;
220
- const updatedContent = import_gray_matter3.default.stringify(parsed.content, fm);
221
- await deps.pfs.write(`${deps.config.blogDir}/${draft.file}`, updatedContent);
222
- return { ...draft, content: updatedContent };
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
- // src/commands/update.ts
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
- return (0, import_cmd_ts3.command)({
231
- name: "update",
232
- description: "Update a post's modified date",
233
- args: {},
234
- handler: async () => {
235
- const posts = await readPosts(pfs, config);
236
- const post = await getPostToUpdate(posts, config);
237
- if (!post) return;
238
- await updatePostDate(post, { config, pfs });
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
- const options = postsToOptions(posts, config);
244
- (0, import_prompts3.intro)("Update a post");
245
- const selected = await (0, import_prompts3.autocomplete)({
246
- message: "Select post to update",
247
- options
248
- });
249
- if ((0, import_prompts3.isCancel)(selected)) {
250
- (0, import_prompts3.outro)("Update cancelled.");
251
- return null;
252
- }
253
- (0, import_prompts3.outro)("Post updated.");
254
- const found = findPostByFile(posts, selected);
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
- const parsed = (0, import_gray_matter4.default)(post.content);
259
- const fm = parsed.data;
260
- fm[deps.config.modifiedAtKey] = /* @__PURE__ */ new Date();
261
- const updatedContent = import_gray_matter4.default.stringify(parsed.content, fm);
262
- await deps.pfs.write(`${deps.config.blogDir}/${post.file}`, updatedContent);
263
- return { ...post, content: updatedContent };
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
- // src/commands/unpublish.ts
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
- return (0, import_cmd_ts4.command)({
272
- name: "unpublish",
273
- description: "Unpublish a post",
274
- args: {},
275
- handler: async () => {
276
- const posts = await readPosts(pfs, config);
277
- const post = await getPostToUnpub(posts, config);
278
- if (!post) return;
279
- await unpubPost(post, { config, pfs });
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
- const options = postsToOptions(posts, config);
285
- (0, import_prompts4.intro)("Unpublish a post");
286
- const selected = await (0, import_prompts4.autocomplete)({
287
- message: "Select post to unpublish",
288
- options
289
- });
290
- if ((0, import_prompts4.isCancel)(selected)) {
291
- (0, import_prompts4.outro)("Unpublish cancelled.");
292
- return null;
293
- }
294
- (0, import_prompts4.outro)("Post unpublished.");
295
- const found = findPostByFile(posts, selected);
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
- const parsed = (0, import_gray_matter5.default)(post.content);
300
- const fm = parsed.data;
301
- fm[deps.config.draftKey] = true;
302
- const updatedContent = import_gray_matter5.default.stringify(parsed.content, fm);
303
- await deps.pfs.write(`${deps.config.blogDir}/${post.file}`, updatedContent);
304
- return { ...post, content: updatedContent };
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
- // src/commands/init.ts
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
- return (0, import_cmd_ts5.command)({
312
- name: "init",
313
- description: "Create or update mkd.json configuration",
314
- args: {},
315
- handler: async () => {
316
- (0, import_prompts5.intro)("Initialize mkd configuration");
317
- const blogDir = await (0, import_prompts5.text)({
318
- message: "Directory where generated posts are written",
319
- defaultValue: String(config.blogDir ?? "./src/blog")
320
- });
321
- if ((0, import_prompts5.isCancel)(blogDir)) {
322
- (0, import_prompts5.outro)("Init cancelled");
323
- return;
324
- }
325
- const author = await (0, import_prompts5.text)({
326
- message: "Default author",
327
- defaultValue: String(config.author ?? "")
328
- });
329
- if ((0, import_prompts5.isCancel)(author)) {
330
- (0, import_prompts5.outro)("Init cancelled");
331
- return;
332
- }
333
- const titleKey = await (0, import_prompts5.text)({
334
- message: "Title frontmatter key",
335
- defaultValue: String(config.titleKey ?? "title")
336
- });
337
- if ((0, import_prompts5.isCancel)(titleKey)) {
338
- (0, import_prompts5.outro)("Init cancelled");
339
- return;
340
- }
341
- const publishedAtKey = await (0, import_prompts5.text)({
342
- message: "Published date frontmatter key",
343
- defaultValue: String(config.publishedAtKey ?? "publishedAt")
344
- });
345
- if ((0, import_prompts5.isCancel)(publishedAtKey)) {
346
- (0, import_prompts5.outro)("Init cancelled");
347
- return;
348
- }
349
- const modifiedAtKey = await (0, import_prompts5.text)({
350
- message: "Modified date frontmatter key",
351
- defaultValue: String(config.modifiedAtKey ?? "updatedAt")
352
- });
353
- if ((0, import_prompts5.isCancel)(modifiedAtKey)) {
354
- (0, import_prompts5.outro)("Init cancelled");
355
- return;
356
- }
357
- const authorKey = await (0, import_prompts5.text)({
358
- message: "Author frontmatter key",
359
- defaultValue: String(config.authorKey ?? "author")
360
- });
361
- if ((0, import_prompts5.isCancel)(authorKey)) {
362
- (0, import_prompts5.outro)("Init cancelled");
363
- return;
364
- }
365
- const draftKey = await (0, import_prompts5.text)({
366
- message: "Draft frontmatter key",
367
- defaultValue: String(config.draftKey ?? "draft")
368
- });
369
- if ((0, import_prompts5.isCancel)(draftKey)) {
370
- (0, import_prompts5.outro)("Init cancelled");
371
- return;
372
- }
373
- const descriptionKey = await (0, import_prompts5.text)({
374
- message: "Description frontmatter key",
375
- defaultValue: String(config.descriptionKey ?? "description")
376
- });
377
- if ((0, import_prompts5.isCancel)(descriptionKey)) {
378
- (0, import_prompts5.outro)("Init cancelled");
379
- return;
380
- }
381
- const tagsKey = await (0, import_prompts5.text)({
382
- message: "Tags frontmatter key",
383
- defaultValue: String(config.tagsKey ?? "tags")
384
- });
385
- if ((0, import_prompts5.isCancel)(tagsKey)) {
386
- (0, import_prompts5.outro)("Init cancelled");
387
- return;
388
- }
389
- const newConfig = {
390
- blogDir: String(blogDir),
391
- author: String(author),
392
- publishedAtKey: String(publishedAtKey),
393
- modifiedAtKey: String(modifiedAtKey),
394
- authorKey: String(authorKey),
395
- draftKey: String(draftKey),
396
- descriptionKey: String(descriptionKey),
397
- tagsKey: String(tagsKey),
398
- titleKey: String(titleKey)
399
- };
400
- await pfs.write("./mkd.json", JSON.stringify(newConfig, null, 2) + "\n");
401
- (0, import_prompts5.outro)("Configuration saved to mkd.json");
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
- // src/index.ts
384
+ //#endregion
385
+ //#region src/index.ts
407
386
  async function main() {
408
- const pfs = new import_pwd_fs.PoweredFileSystem();
409
- const config = await loadConfig(pfs);
410
- const deps = { config, pfs };
411
- const app = (0, import_cmd_ts6.subcommands)({
412
- name: "mkd",
413
- cmds: {
414
- new: makeNewCommand(deps),
415
- publish: makePublishCommand(deps),
416
- update: makeUpdateCommand(deps),
417
- unpublish: makeUnPublishCommand(deps),
418
- init: makeInitCommand(deps)
419
- }
420
- });
421
- await (0, import_cmd_ts6.run)(app, process.argv.slice(2));
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
- console.error(error);
425
- process.exit(1);
404
+ console.error(error);
405
+ process.exit(1);
426
406
  });
407
+ //#endregion
408
+
427
409
  //# sourceMappingURL=index.cjs.map