@geekity/cms 0.42.1 → 0.43.0

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.
Files changed (742) hide show
  1. package/admin/pages/federation/followers.njk +1 -1
  2. package/admin/static/editor.js +22 -21
  3. package/dist/admin/admin-bar.d.ts +2 -3
  4. package/dist/admin/admin-bar.d.ts.map +1 -1
  5. package/dist/admin/admin-bar.js +4 -5
  6. package/dist/admin/admin-bar.js.map +1 -1
  7. package/dist/admin/app-activity.d.ts +1 -1
  8. package/dist/admin/appearance.d.ts +5 -5
  9. package/dist/admin/appearance.js +5 -5
  10. package/dist/admin/comments.d.ts +3 -3
  11. package/dist/admin/comments.js +2 -2
  12. package/dist/admin/comments.js.map +1 -1
  13. package/dist/admin/connected-apps.d.ts +1 -1
  14. package/dist/admin/connected-apps.js +1 -1
  15. package/dist/admin/credentials.d.ts +3 -3
  16. package/dist/admin/credentials.js +3 -3
  17. package/dist/admin/dashboard.js +2 -2
  18. package/dist/admin/dashboard.js.map +1 -1
  19. package/dist/admin/documents.d.ts +4 -4
  20. package/dist/admin/documents.d.ts.map +1 -1
  21. package/dist/admin/documents.js +150 -144
  22. package/dist/admin/documents.js.map +1 -1
  23. package/dist/admin/editor-actions.d.ts +1 -1
  24. package/dist/admin/editor-actions.js +1 -1
  25. package/dist/admin/federation.d.ts +11 -11
  26. package/dist/admin/federation.d.ts.map +1 -1
  27. package/dist/admin/federation.js +10 -10
  28. package/dist/admin/flash.d.ts +8 -0
  29. package/dist/admin/flash.d.ts.map +1 -1
  30. package/dist/admin/flash.js +11 -0
  31. package/dist/admin/flash.js.map +1 -1
  32. package/dist/admin/indieauth-consent.d.ts +1 -1
  33. package/dist/admin/indieauth-consent.js +1 -1
  34. package/dist/admin/legacy-migrations.d.ts +20 -19
  35. package/dist/admin/legacy-migrations.d.ts.map +1 -1
  36. package/dist/admin/legacy-migrations.js +14 -13
  37. package/dist/admin/legacy-migrations.js.map +1 -1
  38. package/dist/admin/list-indent.d.ts +19 -0
  39. package/dist/admin/list-indent.d.ts.map +1 -0
  40. package/dist/admin/list-indent.js +73 -0
  41. package/dist/admin/list-indent.js.map +1 -0
  42. package/dist/admin/media.js +1 -1
  43. package/dist/admin/menu.d.ts +1 -1
  44. package/dist/admin/menu.js +4 -4
  45. package/dist/admin/menu.js.map +1 -1
  46. package/dist/admin/messages.d.ts +2 -2
  47. package/dist/admin/messages.js +2 -2
  48. package/dist/admin/navigation.d.ts +3 -3
  49. package/dist/admin/navigation.js +3 -3
  50. package/dist/admin/personal-data.d.ts +1 -1
  51. package/dist/admin/personal-data.js +1 -1
  52. package/dist/admin/plugins.d.ts +1 -1
  53. package/dist/admin/plugins.js +1 -1
  54. package/dist/admin/preview.js +3 -3
  55. package/dist/admin/preview.js.map +1 -1
  56. package/dist/admin/recovery.d.ts +1 -1
  57. package/dist/admin/recovery.js +1 -1
  58. package/dist/admin/routes.d.ts +3 -3
  59. package/dist/admin/routes.js +14 -14
  60. package/dist/admin/routes.js.map +1 -1
  61. package/dist/admin/settings-discussion.d.ts +3 -3
  62. package/dist/admin/settings-discussion.js +3 -3
  63. package/dist/admin/settings-federation.d.ts +2 -2
  64. package/dist/admin/settings-federation.js +5 -5
  65. package/dist/admin/settings-federation.js.map +1 -1
  66. package/dist/admin/settings-general.d.ts +1 -1
  67. package/dist/admin/settings-general.js +2 -2
  68. package/dist/admin/settings-general.js.map +1 -1
  69. package/dist/admin/settings-page.d.ts +2 -2
  70. package/dist/admin/settings-page.js +1 -1
  71. package/dist/admin/settings-pages.d.ts +1 -1
  72. package/dist/admin/settings-pages.js +1 -1
  73. package/dist/admin/settings-reading.d.ts +2 -2
  74. package/dist/admin/settings-reading.js +2 -2
  75. package/dist/admin/syndication-targets.d.ts +2 -2
  76. package/dist/admin/syndication-targets.js +2 -2
  77. package/dist/admin/taxonomy.d.ts +4 -4
  78. package/dist/admin/taxonomy.js +4 -4
  79. package/dist/admin/templates.d.ts +2 -2
  80. package/dist/admin/templates.js +2 -2
  81. package/dist/admin/tools.d.ts +1 -1
  82. package/dist/admin/tools.js +1 -1
  83. package/dist/admin/users.d.ts +0 -159
  84. package/dist/admin/users.d.ts.map +1 -1
  85. package/dist/admin/users.js +204 -498
  86. package/dist/admin/users.js.map +1 -1
  87. package/dist/avatars/avatars.d.ts +2 -2
  88. package/dist/avatars/avatars.js +2 -2
  89. package/dist/cache.d.ts +1 -1
  90. package/dist/cache.js +1 -1
  91. package/dist/cli/args.d.ts +20 -0
  92. package/dist/cli/args.d.ts.map +1 -0
  93. package/dist/cli/args.js +138 -0
  94. package/dist/cli/args.js.map +1 -0
  95. package/dist/cli/commands.d.ts +10 -0
  96. package/dist/cli/commands.d.ts.map +1 -0
  97. package/dist/cli/commands.js +261 -0
  98. package/dist/cli/commands.js.map +1 -0
  99. package/dist/cli/database-in-use.d.ts +9 -0
  100. package/dist/cli/database-in-use.d.ts.map +1 -0
  101. package/dist/cli/database-in-use.js +38 -0
  102. package/dist/cli/database-in-use.js.map +1 -0
  103. package/dist/cli/dev-mode.d.ts +3 -0
  104. package/dist/cli/dev-mode.d.ts.map +1 -0
  105. package/dist/cli/dev-mode.js +31 -0
  106. package/dist/cli/dev-mode.js.map +1 -0
  107. package/dist/cli/export.d.ts +3 -0
  108. package/dist/cli/export.d.ts.map +1 -0
  109. package/dist/cli/export.js +53 -0
  110. package/dist/cli/export.js.map +1 -0
  111. package/dist/cli/format.d.ts +3 -0
  112. package/dist/cli/format.d.ts.map +1 -0
  113. package/dist/cli/format.js +10 -0
  114. package/dist/cli/format.js.map +1 -0
  115. package/dist/cli/gemini.d.ts +3 -0
  116. package/dist/cli/gemini.d.ts.map +1 -0
  117. package/dist/cli/gemini.js +34 -0
  118. package/dist/cli/gemini.js.map +1 -0
  119. package/dist/cli/help.d.ts +2 -0
  120. package/dist/cli/help.d.ts.map +1 -0
  121. package/dist/cli/help.js +111 -0
  122. package/dist/cli/help.js.map +1 -0
  123. package/dist/cli/import.d.ts +3 -0
  124. package/dist/cli/import.d.ts.map +1 -0
  125. package/dist/cli/import.js +84 -0
  126. package/dist/cli/import.js.map +1 -0
  127. package/dist/cli/init.d.ts +3 -0
  128. package/dist/cli/init.d.ts.map +1 -0
  129. package/dist/cli/init.js +21 -0
  130. package/dist/cli/init.js.map +1 -0
  131. package/dist/cli/maintenance.d.ts +3 -0
  132. package/dist/cli/maintenance.d.ts.map +1 -0
  133. package/dist/cli/maintenance.js +57 -0
  134. package/dist/cli/maintenance.js.map +1 -0
  135. package/dist/cli/options.d.ts +16 -0
  136. package/dist/cli/options.d.ts.map +1 -0
  137. package/dist/cli/options.js +27 -0
  138. package/dist/cli/options.js.map +1 -0
  139. package/dist/cli/password.d.ts +21 -0
  140. package/dist/cli/password.d.ts.map +1 -0
  141. package/dist/cli/password.js +52 -0
  142. package/dist/cli/password.js.map +1 -0
  143. package/dist/cli/plugin-commands.d.ts +11 -0
  144. package/dist/cli/plugin-commands.d.ts.map +1 -0
  145. package/dist/cli/plugin-commands.js +79 -0
  146. package/dist/cli/plugin-commands.js.map +1 -0
  147. package/dist/cli/plugin-folder.d.ts +3 -0
  148. package/dist/cli/plugin-folder.d.ts.map +1 -0
  149. package/dist/cli/plugin-folder.js +93 -0
  150. package/dist/cli/plugin-folder.js.map +1 -0
  151. package/dist/cli/rebuild.d.ts +5 -0
  152. package/dist/cli/rebuild.d.ts.map +1 -0
  153. package/dist/cli/rebuild.js +44 -0
  154. package/dist/cli/rebuild.js.map +1 -0
  155. package/dist/cli/resend.d.ts +3 -0
  156. package/dist/cli/resend.d.ts.map +1 -0
  157. package/dist/cli/resend.js +36 -0
  158. package/dist/cli/resend.js.map +1 -0
  159. package/dist/cli/run-job.d.ts +5 -0
  160. package/dist/cli/run-job.d.ts.map +1 -0
  161. package/dist/cli/run-job.js +29 -0
  162. package/dist/cli/run-job.js.map +1 -0
  163. package/dist/cli/serve.d.ts +3 -0
  164. package/dist/cli/serve.d.ts.map +1 -0
  165. package/dist/cli/serve.js +65 -0
  166. package/dist/cli/serve.js.map +1 -0
  167. package/dist/cli/settings.d.ts +5 -0
  168. package/dist/cli/settings.d.ts.map +1 -0
  169. package/dist/cli/settings.js +144 -0
  170. package/dist/cli/settings.js.map +1 -0
  171. package/dist/cli/site-plugins.d.ts +5 -0
  172. package/dist/cli/site-plugins.d.ts.map +1 -0
  173. package/dist/cli/site-plugins.js +7 -0
  174. package/dist/cli/site-plugins.js.map +1 -0
  175. package/dist/cli/strip-metadata.d.ts +3 -0
  176. package/dist/cli/strip-metadata.d.ts.map +1 -0
  177. package/dist/cli/strip-metadata.js +20 -0
  178. package/dist/cli/strip-metadata.js.map +1 -0
  179. package/dist/cli/sync.d.ts +3 -0
  180. package/dist/cli/sync.d.ts.map +1 -0
  181. package/dist/cli/sync.js +22 -0
  182. package/dist/cli/sync.js.map +1 -0
  183. package/dist/cli/user.d.ts +3 -0
  184. package/dist/cli/user.d.ts.map +1 -0
  185. package/dist/cli/user.js +54 -0
  186. package/dist/cli/user.js.map +1 -0
  187. package/dist/cli.d.ts +0 -62
  188. package/dist/cli.d.ts.map +1 -1
  189. package/dist/cli.js +6 -1566
  190. package/dist/cli.js.map +1 -1
  191. package/dist/cms/app.js +10 -10
  192. package/dist/cms/app.js.map +1 -1
  193. package/dist/cms/boot.js +5 -5
  194. package/dist/cms/boot.js.map +1 -1
  195. package/dist/cms/create.d.ts +17 -17
  196. package/dist/cms/create.d.ts.map +1 -1
  197. package/dist/cms/create.js +1 -1
  198. package/dist/cms/create.js.map +1 -1
  199. package/dist/cms/server-error.d.ts +1 -1
  200. package/dist/cms/server-error.js +1 -1
  201. package/dist/cms/services.d.ts.map +1 -1
  202. package/dist/cms/services.js +33 -16
  203. package/dist/cms/services.js.map +1 -1
  204. package/dist/comments/akismet.d.ts +4 -4
  205. package/dist/comments/akismet.js +6 -6
  206. package/dist/comments/akismet.js.map +1 -1
  207. package/dist/comments/conversation.d.ts +29 -29
  208. package/dist/comments/conversation.d.ts.map +1 -1
  209. package/dist/comments/conversation.js +2 -2
  210. package/dist/comments/conversation.js.map +1 -1
  211. package/dist/comments/form.d.ts +3 -3
  212. package/dist/comments/form.d.ts.map +1 -1
  213. package/dist/comments/intake.d.ts +4 -4
  214. package/dist/comments/intake.d.ts.map +1 -1
  215. package/dist/comments/intake.js +1 -1
  216. package/dist/comments/migrations.d.ts +3 -3
  217. package/dist/comments/migrations.js +3 -3
  218. package/dist/comments/moderate.d.ts +2 -2
  219. package/dist/comments/moderate.js +2 -2
  220. package/dist/comments/page-form.d.ts +1 -1
  221. package/dist/comments/page-form.js +1 -1
  222. package/dist/comments/records.d.ts +9 -9
  223. package/dist/comments/records.d.ts.map +1 -1
  224. package/dist/comments/records.js +11 -10
  225. package/dist/comments/records.js.map +1 -1
  226. package/dist/comments/reply-notices.d.ts +2 -2
  227. package/dist/comments/reply-post.d.ts +2 -2
  228. package/dist/comments/submission.d.ts +8 -8
  229. package/dist/comments/submission.d.ts.map +1 -1
  230. package/dist/comments/submission.js +9 -9
  231. package/dist/comments/submission.js.map +1 -1
  232. package/dist/config.d.ts +27 -27
  233. package/dist/config.js +3 -3
  234. package/dist/contact/index.d.ts +1 -1
  235. package/dist/contact/index.js +1 -1
  236. package/dist/contact/records.d.ts +7 -7
  237. package/dist/contact/records.js +7 -7
  238. package/dist/content/alt-text.d.ts +2 -2
  239. package/dist/content/alt-text.js +2 -2
  240. package/dist/content/authors.d.ts +6 -6
  241. package/dist/content/authors.d.ts.map +1 -1
  242. package/dist/content/authors.js +6 -6
  243. package/dist/content/authors.js.map +1 -1
  244. package/dist/content/citation.d.ts +1 -1
  245. package/dist/content/content-tree.d.ts +5 -0
  246. package/dist/content/content-tree.d.ts.map +1 -0
  247. package/dist/content/content-tree.js +54 -0
  248. package/dist/content/content-tree.js.map +1 -0
  249. package/dist/content/content-watcher.d.ts +15 -0
  250. package/dist/content/content-watcher.d.ts.map +1 -0
  251. package/dist/content/content-watcher.js +104 -0
  252. package/dist/content/content-watcher.js.map +1 -0
  253. package/dist/content/document-form.d.ts +25 -24
  254. package/dist/content/document-form.d.ts.map +1 -1
  255. package/dist/content/document-form.js +7 -7
  256. package/dist/content/document-form.js.map +1 -1
  257. package/dist/content/document-kind.d.ts +6 -6
  258. package/dist/content/document.d.ts +1 -1
  259. package/dist/content/enclosure-form.js +1 -1
  260. package/dist/content/enclosure.js +1 -1
  261. package/dist/content/event-form.d.ts +2 -2
  262. package/dist/content/event.d.ts +3 -3
  263. package/dist/content/event.js +3 -3
  264. package/dist/content/guids.d.ts +6 -6
  265. package/dist/content/guids.d.ts.map +1 -1
  266. package/dist/content/guids.js +7 -7
  267. package/dist/content/guids.js.map +1 -1
  268. package/dist/content/handles.d.ts +1 -1
  269. package/dist/content/handles.js +1 -1
  270. package/dist/content/html-to-markdown.js +2 -2
  271. package/dist/content/language.d.ts +1 -1
  272. package/dist/content/language.js +1 -1
  273. package/dist/content/locale.d.ts +1 -1
  274. package/dist/content/locale.js +1 -1
  275. package/dist/content/markdown.d.ts +1 -1
  276. package/dist/content/markdown.js +1 -1
  277. package/dist/content/parser.d.ts +1 -1
  278. package/dist/content/parser.d.ts.map +1 -1
  279. package/dist/content/permalinks.d.ts +4 -4
  280. package/dist/content/permalinks.js +4 -4
  281. package/dist/content/photo-form.js +2 -2
  282. package/dist/content/photo.d.ts +2 -2
  283. package/dist/content/photo.js +1 -1
  284. package/dist/content/pinned.d.ts +3 -3
  285. package/dist/content/pinned.js +3 -3
  286. package/dist/content/post-fields.js +2 -2
  287. package/dist/content/post-fields.js.map +1 -1
  288. package/dist/content/post-type.d.ts +4 -4
  289. package/dist/content/post-type.js +1 -1
  290. package/dist/content/reconcile.d.ts +15 -0
  291. package/dist/content/reconcile.d.ts.map +1 -0
  292. package/dist/content/reconcile.js +106 -0
  293. package/dist/content/reconcile.js.map +1 -0
  294. package/dist/content/redirects.d.ts +2 -3
  295. package/dist/content/redirects.d.ts.map +1 -1
  296. package/dist/content/redirects.js +2 -3
  297. package/dist/content/redirects.js.map +1 -1
  298. package/dist/content/rsvp.d.ts +1 -1
  299. package/dist/content/rsvp.js +1 -1
  300. package/dist/content/sanitize.js +1 -1
  301. package/dist/content/save.d.ts +3 -3
  302. package/dist/content/save.js +4 -4
  303. package/dist/content/scan.d.ts +12 -0
  304. package/dist/content/scan.d.ts.map +1 -0
  305. package/dist/content/scan.js +58 -0
  306. package/dist/content/scan.js.map +1 -0
  307. package/dist/content/search.d.ts +3 -3
  308. package/dist/content/search.js +3 -3
  309. package/dist/content/served.d.ts +5 -5
  310. package/dist/content/served.js +4 -4
  311. package/dist/content/site-links.d.ts +3 -4
  312. package/dist/content/site-links.d.ts.map +1 -1
  313. package/dist/content/site-links.js +1 -2
  314. package/dist/content/site-links.js.map +1 -1
  315. package/dist/content/sqlite/clauses.d.ts +1 -1
  316. package/dist/content/sqlite/clauses.js +1 -1
  317. package/dist/content/sqlite/rows.d.ts +1 -1
  318. package/dist/content/sqlite/rows.js +1 -1
  319. package/dist/content/store.d.ts +26 -26
  320. package/dist/content/sync.d.ts +3 -3
  321. package/dist/content/sync.d.ts.map +1 -1
  322. package/dist/content/sync.js +65 -382
  323. package/dist/content/sync.js.map +1 -1
  324. package/dist/content/taxonomy.d.ts +9 -8
  325. package/dist/content/taxonomy.d.ts.map +1 -1
  326. package/dist/content/taxonomy.js +9 -8
  327. package/dist/content/taxonomy.js.map +1 -1
  328. package/dist/content/time.d.ts +1 -1
  329. package/dist/content/time.js +1 -1
  330. package/dist/content/trash.d.ts +4 -5
  331. package/dist/content/trash.d.ts.map +1 -1
  332. package/dist/content/trash.js +4 -5
  333. package/dist/content/trash.js.map +1 -1
  334. package/dist/content/write.d.ts +4 -4
  335. package/dist/content/write.js +19 -19
  336. package/dist/content/write.js.map +1 -1
  337. package/dist/drain.d.ts +1 -1
  338. package/dist/drain.js +1 -1
  339. package/dist/federation/actor.d.ts +9 -9
  340. package/dist/federation/actor.js +10 -10
  341. package/dist/federation/article.d.ts +14 -14
  342. package/dist/federation/article.js +27 -27
  343. package/dist/federation/article.js.map +1 -1
  344. package/dist/federation/backfill.d.ts +2 -2
  345. package/dist/federation/backfill.js +2 -2
  346. package/dist/federation/citations.d.ts +1 -1
  347. package/dist/federation/citations.js +1 -1
  348. package/dist/federation/cited-post.d.ts +1 -1
  349. package/dist/federation/cited-post.js +1 -1
  350. package/dist/federation/delivery-plan.d.ts +1 -1
  351. package/dist/federation/delivery.d.ts +3 -3
  352. package/dist/federation/delivery.d.ts.map +1 -1
  353. package/dist/federation/delivery.js +25 -15
  354. package/dist/federation/delivery.js.map +1 -1
  355. package/dist/federation/federation.d.ts +3 -3
  356. package/dist/federation/federation.d.ts.map +1 -1
  357. package/dist/federation/federation.js +7 -8
  358. package/dist/federation/federation.js.map +1 -1
  359. package/dist/federation/handles.d.ts +1 -1
  360. package/dist/federation/handles.js +1 -1
  361. package/dist/federation/inbox.d.ts +6 -6
  362. package/dist/federation/inbox.js +9 -9
  363. package/dist/federation/keys.d.ts +3 -3
  364. package/dist/federation/keys.js +3 -3
  365. package/dist/federation/object-ids.d.ts +1 -1
  366. package/dist/federation/outbox-observer.d.ts +17 -0
  367. package/dist/federation/outbox-observer.d.ts.map +1 -0
  368. package/dist/federation/outbox-observer.js +98 -0
  369. package/dist/federation/outbox-observer.js.map +1 -0
  370. package/dist/federation/paths.d.ts +8 -8
  371. package/dist/federation/paths.js +8 -8
  372. package/dist/federation/profiles.d.ts +2 -3
  373. package/dist/federation/profiles.d.ts.map +1 -1
  374. package/dist/federation/profiles.js +2 -3
  375. package/dist/federation/profiles.js.map +1 -1
  376. package/dist/federation/quotes.d.ts +1 -1
  377. package/dist/federation/records.d.ts +24 -24
  378. package/dist/federation/records.js +23 -23
  379. package/dist/federation/records.js.map +1 -1
  380. package/dist/federation/refusals.d.ts +1 -1
  381. package/dist/federation/relays.d.ts +1 -1
  382. package/dist/federation/relays.d.ts.map +1 -1
  383. package/dist/federation/relays.js +38 -13
  384. package/dist/federation/relays.js.map +1 -1
  385. package/dist/federation/webfinger.d.ts +2 -2
  386. package/dist/federation/webfinger.js +2 -2
  387. package/dist/files/atomic.d.ts +2 -2
  388. package/dist/files/atomic.js +1 -1
  389. package/dist/forms/checker.d.ts +2 -2
  390. package/dist/forms/checker.d.ts.map +1 -1
  391. package/dist/forms/protection.d.ts +1 -1
  392. package/dist/forms/protection.js +1 -1
  393. package/dist/gemini/certificate.js +1 -1
  394. package/dist/images/markup.d.ts +2 -2
  395. package/dist/images/variants.d.ts +8 -8
  396. package/dist/images/variants.js +1 -1
  397. package/dist/indexnow.d.ts +1 -1
  398. package/dist/indieauth/grants.d.ts +2 -2
  399. package/dist/indieauth/identity.d.ts +3 -5
  400. package/dist/indieauth/identity.d.ts.map +1 -1
  401. package/dist/indieauth/identity.js +3 -5
  402. package/dist/indieauth/identity.js.map +1 -1
  403. package/dist/indieauth/redeem.d.ts +2 -2
  404. package/dist/indieauth/redeem.js +2 -2
  405. package/dist/indieauth/request.d.ts +2 -2
  406. package/dist/indieauth/request.js +2 -2
  407. package/dist/indieauth/tokens.d.ts +3 -5
  408. package/dist/indieauth/tokens.d.ts.map +1 -1
  409. package/dist/indieauth/tokens.js +3 -5
  410. package/dist/indieauth/tokens.js.map +1 -1
  411. package/dist/jobs/file-records.d.ts +1 -1
  412. package/dist/jobs/file-records.js +1 -1
  413. package/dist/jobs/in-process.d.ts +1 -1
  414. package/dist/jobs/in-process.js +1 -1
  415. package/dist/jobs/queue.d.ts +1 -1
  416. package/dist/jobs/queue.js +1 -1
  417. package/dist/mail/provider.d.ts +2 -2
  418. package/dist/mail/provider.js +2 -2
  419. package/dist/media/library.d.ts +2 -2
  420. package/dist/media/uploads.js +2 -2
  421. package/dist/media/uploads.js.map +1 -1
  422. package/dist/micropub/create.d.ts +1 -1
  423. package/dist/micropub/endpoint.d.ts +7 -7
  424. package/dist/micropub/endpoint.js +8 -8
  425. package/dist/micropub/endpoint.js.map +1 -1
  426. package/dist/micropub/media.d.ts +4 -4
  427. package/dist/micropub/media.js +4 -4
  428. package/dist/micropub/update.d.ts +1 -1
  429. package/dist/micropub/update.js +1 -1
  430. package/dist/notifications/comments.d.ts +1 -1
  431. package/dist/notifications/comments.js +2 -2
  432. package/dist/notifications/comments.js.map +1 -1
  433. package/dist/notifications/digest.d.ts +7 -7
  434. package/dist/notifications/digest.js +7 -7
  435. package/dist/notifications/mail-service.d.ts +4 -4
  436. package/dist/notifications/mail-service.d.ts.map +1 -1
  437. package/dist/notifications/mail-service.js +3 -3
  438. package/dist/notifications/mail-templates.d.ts +3 -3
  439. package/dist/notifications/optouts.d.ts +1 -1
  440. package/dist/notifications/optouts.js +1 -1
  441. package/dist/notifications/tokens.d.ts +2 -2
  442. package/dist/plugin.d.ts +5 -5
  443. package/dist/plugin.js +5 -5
  444. package/dist/plugins/changes.js +2 -2
  445. package/dist/plugins/folder.d.ts +2 -2
  446. package/dist/plugins/folder.js +2 -2
  447. package/dist/plugins/install.d.ts +1 -1
  448. package/dist/plugins/install.js +1 -1
  449. package/dist/plugins/registry.d.ts +1 -1
  450. package/dist/plugins/registry.js +1 -1
  451. package/dist/plugins/site.d.ts +1 -1
  452. package/dist/plugins/site.js +1 -1
  453. package/dist/privacy/erase.d.ts +1 -1
  454. package/dist/privacy/erase.js +1 -1
  455. package/dist/privacy/retention.d.ts +2 -2
  456. package/dist/privacy/retention.js +2 -2
  457. package/dist/site/admin-paths.d.ts +2 -2
  458. package/dist/site/admin-paths.js +2 -2
  459. package/dist/site/authors.d.ts +6 -6
  460. package/dist/site/authors.js +5 -5
  461. package/dist/site/dashboard-layout.d.ts +1 -1
  462. package/dist/site/indexnow-key.js +1 -1
  463. package/dist/site/namespace.d.ts +1 -1
  464. package/dist/site/namespace.js +1 -1
  465. package/dist/site/navigation.d.ts +10 -10
  466. package/dist/site/navigation.js +10 -10
  467. package/dist/site/notification-preferences.d.ts +3 -3
  468. package/dist/site/notification-preferences.js +2 -2
  469. package/dist/site/retention-policy.d.ts +1 -1
  470. package/dist/site/retention-policy.js +1 -1
  471. package/dist/site/users.d.ts +23 -24
  472. package/dist/site/users.d.ts.map +1 -1
  473. package/dist/site/users.js +6 -6
  474. package/dist/site/users.js.map +1 -1
  475. package/dist/store/admin-store.d.ts +3 -3
  476. package/dist/store/admin-store.d.ts.map +1 -1
  477. package/dist/store/comments.d.ts +17 -17
  478. package/dist/store/comments.d.ts.map +1 -1
  479. package/dist/store/comments.js +14 -21
  480. package/dist/store/comments.js.map +1 -1
  481. package/dist/store/conversation.d.ts +2 -2
  482. package/dist/store/deliveries.d.ts +13 -5
  483. package/dist/store/deliveries.d.ts.map +1 -1
  484. package/dist/store/deliveries.js +18 -16
  485. package/dist/store/deliveries.js.map +1 -1
  486. package/dist/store/followers.d.ts +5 -5
  487. package/dist/store/followers.d.ts.map +1 -1
  488. package/dist/store/followers.js +7 -10
  489. package/dist/store/followers.js.map +1 -1
  490. package/dist/store/inbox-replies.d.ts +4 -4
  491. package/dist/store/inbox-replies.js +4 -4
  492. package/dist/store/inbox.d.ts +5 -5
  493. package/dist/store/inbox.d.ts.map +1 -1
  494. package/dist/store/inbox.js +21 -34
  495. package/dist/store/inbox.js.map +1 -1
  496. package/dist/store/profiles.d.ts +5 -5
  497. package/dist/store/profiles.d.ts.map +1 -1
  498. package/dist/store/profiles.js +4 -5
  499. package/dist/store/profiles.js.map +1 -1
  500. package/dist/store/relays.d.ts.map +1 -1
  501. package/dist/store/relays.js +7 -9
  502. package/dist/store/relays.js.map +1 -1
  503. package/dist/store/rows.d.ts +6 -20
  504. package/dist/store/rows.d.ts.map +1 -1
  505. package/dist/store/rows.js +10 -15
  506. package/dist/store/rows.js.map +1 -1
  507. package/dist/store/schema.js +35 -35
  508. package/dist/store/schema.js.map +1 -1
  509. package/dist/store/sessions.d.ts +1 -1
  510. package/dist/store/sessions.d.ts.map +1 -1
  511. package/dist/store/sessions.js +10 -10
  512. package/dist/store/sessions.js.map +1 -1
  513. package/dist/store/state.d.ts.map +1 -1
  514. package/dist/store/state.js +2 -2
  515. package/dist/store/state.js.map +1 -1
  516. package/dist/store/tokens.d.ts +1 -1
  517. package/dist/store/tokens.d.ts.map +1 -1
  518. package/dist/store/tokens.js +5 -5
  519. package/dist/store/tokens.js.map +1 -1
  520. package/dist/store/webmentions.d.ts +2 -2
  521. package/dist/store/webmentions.d.ts.map +1 -1
  522. package/dist/store/webmentions.js +11 -11
  523. package/dist/store/webmentions.js.map +1 -1
  524. package/dist/supervisor/plugin-watcher.d.ts +26 -0
  525. package/dist/supervisor/plugin-watcher.d.ts.map +1 -0
  526. package/dist/supervisor/plugin-watcher.js +90 -0
  527. package/dist/supervisor/plugin-watcher.js.map +1 -0
  528. package/dist/supervisor/primary.d.ts +4 -7
  529. package/dist/supervisor/primary.d.ts.map +1 -1
  530. package/dist/supervisor/primary.js +37 -94
  531. package/dist/supervisor/primary.js.map +1 -1
  532. package/dist/supervisor/protocol.d.ts +1 -1
  533. package/dist/supervisor/protocol.js +1 -1
  534. package/dist/supervisor/reload-queue.d.ts +10 -0
  535. package/dist/supervisor/reload-queue.d.ts.map +1 -0
  536. package/dist/supervisor/reload-queue.js +28 -0
  537. package/dist/supervisor/reload-queue.js.map +1 -0
  538. package/dist/supervisor/supervision.d.ts +2 -2
  539. package/dist/supervisor/supervision.js +2 -2
  540. package/dist/supervisor/worker.d.ts +1 -1
  541. package/dist/supervisor/worker.js +1 -1
  542. package/dist/theme/site-data.d.ts +3 -3
  543. package/dist/theme/site-data.js +2 -2
  544. package/dist/theme/templates.d.ts +3 -3
  545. package/dist/theme/templates.js +16 -16
  546. package/dist/theme/templates.js.map +1 -1
  547. package/dist/theme/themes.d.ts +11 -13
  548. package/dist/theme/themes.d.ts.map +1 -1
  549. package/dist/theme/themes.js +8 -9
  550. package/dist/theme/themes.js.map +1 -1
  551. package/dist/web/activity-folding.d.ts +33 -0
  552. package/dist/web/activity-folding.d.ts.map +1 -0
  553. package/dist/web/activity-folding.js +238 -0
  554. package/dist/web/activity-folding.js.map +1 -0
  555. package/dist/web/archive.d.ts +2 -3
  556. package/dist/web/archive.d.ts.map +1 -1
  557. package/dist/web/archive.js +2 -3
  558. package/dist/web/archive.js.map +1 -1
  559. package/dist/web/asset-routes.d.ts +1 -1
  560. package/dist/web/asset-routes.js +1 -1
  561. package/dist/web/comment-routes.js +2 -2
  562. package/dist/web/comment-routes.js.map +1 -1
  563. package/dist/web/compression.d.ts +1 -1
  564. package/dist/web/compression.js +1 -1
  565. package/dist/web/context.d.ts +21 -21
  566. package/dist/web/context.d.ts.map +1 -1
  567. package/dist/web/context.js +7 -7
  568. package/dist/web/conversation-context.d.ts +15 -0
  569. package/dist/web/conversation-context.d.ts.map +1 -0
  570. package/dist/web/conversation-context.js +2 -0
  571. package/dist/web/conversation-context.js.map +1 -0
  572. package/dist/web/conversation-feed.d.ts +18 -0
  573. package/dist/web/conversation-feed.d.ts.map +1 -0
  574. package/dist/web/conversation-feed.js +53 -0
  575. package/dist/web/conversation-feed.js.map +1 -0
  576. package/dist/web/conversation-gather.d.ts +12 -0
  577. package/dist/web/conversation-gather.d.ts.map +1 -0
  578. package/dist/web/conversation-gather.js +189 -0
  579. package/dist/web/conversation-gather.js.map +1 -0
  580. package/dist/web/conversation-lookup.d.ts +15 -0
  581. package/dist/web/conversation-lookup.d.ts.map +1 -0
  582. package/dist/web/conversation-lookup.js +101 -0
  583. package/dist/web/conversation-lookup.js.map +1 -0
  584. package/dist/web/conversation-threads.d.ts +12 -0
  585. package/dist/web/conversation-threads.d.ts.map +1 -0
  586. package/dist/web/conversation-threads.js +144 -0
  587. package/dist/web/conversation-threads.js.map +1 -0
  588. package/dist/web/conversation.d.ts +25 -61
  589. package/dist/web/conversation.d.ts.map +1 -1
  590. package/dist/web/conversation.js +14 -854
  591. package/dist/web/conversation.js.map +1 -1
  592. package/dist/web/document-page.js +4 -4
  593. package/dist/web/document-page.js.map +1 -1
  594. package/dist/web/document-render.d.ts +9 -0
  595. package/dist/web/document-render.d.ts.map +1 -0
  596. package/dist/web/document-render.js +130 -0
  597. package/dist/web/document-render.js.map +1 -0
  598. package/dist/web/document-site.d.ts +1 -1
  599. package/dist/web/document-site.d.ts.map +1 -1
  600. package/dist/web/document-site.js +1 -1
  601. package/dist/web/document-site.js.map +1 -1
  602. package/dist/web/env.d.ts +19 -19
  603. package/dist/web/env.d.ts.map +1 -1
  604. package/dist/web/federation-routes.d.ts +2 -2
  605. package/dist/web/federation-routes.d.ts.map +1 -1
  606. package/dist/web/federation-routes.js +22 -21
  607. package/dist/web/federation-routes.js.map +1 -1
  608. package/dist/web/feed-atom.d.ts +3 -3
  609. package/dist/web/feed-atom.js +3 -3
  610. package/dist/web/feed-item.d.ts +15 -16
  611. package/dist/web/feed-item.d.ts.map +1 -1
  612. package/dist/web/feed-item.js +1 -1
  613. package/dist/web/feed-item.js.map +1 -1
  614. package/dist/web/feed-json.d.ts +4 -4
  615. package/dist/web/feed-json.d.ts.map +1 -1
  616. package/dist/web/feed-json.js +2 -2
  617. package/dist/web/feed-routes.d.ts +3 -3
  618. package/dist/web/feed-routes.js +4 -4
  619. package/dist/web/feed-routes.js.map +1 -1
  620. package/dist/web/feed-rss.d.ts +2 -2
  621. package/dist/web/feed-rss.js +4 -4
  622. package/dist/web/feed-rss.js.map +1 -1
  623. package/dist/web/feed-source.d.ts +5 -5
  624. package/dist/web/feed-source.d.ts.map +1 -1
  625. package/dist/web/feed-source.js +2 -2
  626. package/dist/web/feed-source.js.map +1 -1
  627. package/dist/web/feed-xml.d.ts +4 -4
  628. package/dist/web/feed-xml.d.ts.map +1 -1
  629. package/dist/web/feed-xml.js +4 -4
  630. package/dist/web/feed-xml.js.map +1 -1
  631. package/dist/web/font-routes.d.ts +1 -1
  632. package/dist/web/font-routes.js +1 -1
  633. package/dist/web/health.d.ts +1 -1
  634. package/dist/web/index.d.ts +5 -3
  635. package/dist/web/index.d.ts.map +1 -1
  636. package/dist/web/index.js +4 -2
  637. package/dist/web/index.js.map +1 -1
  638. package/dist/web/indieauth-activity-log.js +1 -1
  639. package/dist/web/indieauth-bearer.d.ts +2 -2
  640. package/dist/web/indieauth-discovery.d.ts +12 -12
  641. package/dist/web/indieauth-discovery.d.ts.map +1 -1
  642. package/dist/web/indieauth-discovery.js +12 -12
  643. package/dist/web/indieauth-discovery.js.map +1 -1
  644. package/dist/web/indieauth-token.d.ts +2 -2
  645. package/dist/web/indieauth-token.js +2 -2
  646. package/dist/web/listing-render.d.ts +11 -0
  647. package/dist/web/listing-render.d.ts.map +1 -0
  648. package/dist/web/listing-render.js +76 -0
  649. package/dist/web/listing-render.js.map +1 -0
  650. package/dist/web/listing-subject.js +1 -1
  651. package/dist/web/listing-subject.js.map +1 -1
  652. package/dist/web/llms.d.ts +1 -1
  653. package/dist/web/llms.js +1 -1
  654. package/dist/web/maintenance.d.ts +1 -1
  655. package/dist/web/maintenance.js +1 -1
  656. package/dist/web/manifest.d.ts +1 -1
  657. package/dist/web/manifest.js +1 -1
  658. package/dist/web/markdown-chrome.d.ts +11 -0
  659. package/dist/web/markdown-chrome.d.ts.map +1 -0
  660. package/dist/web/markdown-chrome.js +178 -0
  661. package/dist/web/markdown-chrome.js.map +1 -0
  662. package/dist/web/markdown-conversation.d.ts +1 -1
  663. package/dist/web/markdown-conversation.d.ts.map +1 -1
  664. package/dist/web/markdown-environment.d.ts +10 -0
  665. package/dist/web/markdown-environment.d.ts.map +1 -0
  666. package/dist/web/markdown-environment.js +56 -0
  667. package/dist/web/markdown-environment.js.map +1 -0
  668. package/dist/web/markdown-representation.d.ts +1 -1
  669. package/dist/web/markdown-representation.d.ts.map +1 -1
  670. package/dist/web/markdown-representation.js +2 -2
  671. package/dist/web/markdown-representation.js.map +1 -1
  672. package/dist/web/negotiate.d.ts +5 -5
  673. package/dist/web/negotiate.d.ts.map +1 -1
  674. package/dist/web/negotiate.js +3 -3
  675. package/dist/web/negotiate.js.map +1 -1
  676. package/dist/web/oembed.d.ts +3 -3
  677. package/dist/web/oembed.js +3 -3
  678. package/dist/web/opensearch.d.ts +1 -1
  679. package/dist/web/opensearch.js +1 -1
  680. package/dist/web/page-context.d.ts +29 -0
  681. package/dist/web/page-context.d.ts.map +1 -0
  682. package/dist/web/page-context.js +126 -0
  683. package/dist/web/page-context.js.map +1 -0
  684. package/dist/web/page-tags.js +1 -1
  685. package/dist/web/page-tags.js.map +1 -1
  686. package/dist/web/paths.d.ts +1 -1
  687. package/dist/web/paths.js +3 -3
  688. package/dist/web/plugin-federation.d.ts +1 -1
  689. package/dist/web/plugin-federation.js +1 -1
  690. package/dist/web/render-scope.d.ts +20 -0
  691. package/dist/web/render-scope.d.ts.map +1 -0
  692. package/dist/web/render-scope.js +36 -0
  693. package/dist/web/render-scope.js.map +1 -0
  694. package/dist/web/render.d.ts +21 -363
  695. package/dist/web/render.d.ts.map +1 -1
  696. package/dist/web/render.js +46 -899
  697. package/dist/web/render.js.map +1 -1
  698. package/dist/web/request.d.ts +1 -1
  699. package/dist/web/request.js +1 -1
  700. package/dist/web/robots.d.ts +1 -1
  701. package/dist/web/robots.js +1 -1
  702. package/dist/web/routes.js +19 -19
  703. package/dist/web/routes.js.map +1 -1
  704. package/dist/web/search.d.ts +1 -1
  705. package/dist/web/search.js +1 -1
  706. package/dist/web/session.d.ts +8 -8
  707. package/dist/web/session.js +8 -8
  708. package/dist/web/share-image.d.ts +2 -3
  709. package/dist/web/share-image.d.ts.map +1 -1
  710. package/dist/web/share-image.js +1 -1
  711. package/dist/web/share-image.js.map +1 -1
  712. package/dist/web/site-view.d.ts +2 -2
  713. package/dist/web/status-pages.d.ts +1 -1
  714. package/dist/web/status-pages.d.ts.map +1 -1
  715. package/dist/web/theme-environment.d.ts +14 -0
  716. package/dist/web/theme-environment.d.ts.map +1 -0
  717. package/dist/web/theme-environment.js +112 -0
  718. package/dist/web/theme-environment.js.map +1 -0
  719. package/dist/web/theme-templates.d.ts +67 -0
  720. package/dist/web/theme-templates.d.ts.map +1 -0
  721. package/dist/web/theme-templates.js +65 -0
  722. package/dist/web/theme-templates.js.map +1 -0
  723. package/dist/webmention/microformats.d.ts +5 -5
  724. package/dist/webmention/microformats.d.ts.map +1 -1
  725. package/dist/webmention/receive.d.ts +7 -7
  726. package/dist/webmention/receive.d.ts.map +1 -1
  727. package/dist/webmention/receive.js +4 -4
  728. package/dist/webmention/receive.js.map +1 -1
  729. package/dist/webmention/reply-context/oembed.js +1 -1
  730. package/dist/webmention/reply-context.d.ts +10 -10
  731. package/dist/webmention/reply-context.d.ts.map +1 -1
  732. package/dist/webmention/reply-context.js +5 -5
  733. package/dist/webmention/reply-contexts.d.ts +6 -6
  734. package/dist/webmention/reply-contexts.d.ts.map +1 -1
  735. package/dist/webmention/reply-contexts.js +2 -2
  736. package/dist/webmention/service.d.ts +13 -13
  737. package/dist/webmention/service.js +9 -9
  738. package/dist/webmention/syndication.d.ts +6 -6
  739. package/dist/webmention/syndication.d.ts.map +1 -1
  740. package/dist/webmention/syndication.js +6 -6
  741. package/dist/webmention/syndication.js.map +1 -1
  742. package/package.json +4 -2
package/dist/cli.js CHANGED
@@ -1,446 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import cluster from 'node:cluster';
3
- import { existsSync, realpathSync } from 'node:fs';
4
- import path from 'node:path';
5
- import { createInterface } from 'node:readline';
6
- import { DatabaseSync } from 'node:sqlite';
7
- import { Writable } from 'node:stream';
2
+ import { realpathSync } from 'node:fs';
8
3
  import { pathToFileURL } from 'node:url';
9
- import { credentialProblem, emailProblem } from './admin/credentials.js';
10
- import { databaseFile, discardDatabase } from './cache.js';
11
- import { CONTENT_SCRATCH_FILES, dataPath } from './files/data-files.js';
12
- import { CONFIG_FILENAMES, loadConfig, loadResolvedConfig, settleConfig } from './config-loader.js';
13
- import { resolveConfig } from './config.js';
14
- import { initSite, ownManifest, seedStarterContent } from './init.js';
15
- import { finishedResult } from './jobs/types.js';
16
- import { importPluginFolders, scanPluginFolders } from './plugins/folder.js';
17
- import { migratePluginSettings } from './plugins/migrate-settings.js';
18
- import { readEnabledPlugins } from './plugins/enabled.js';
19
- import { sitePluginRegistry } from './plugins/site-registry.js';
20
- import { askToReload, isServing } from './supervisor/control.js';
21
- import { DEV_MODE, DEV_MODE_LATCHED } from './settings/dev-mode.js';
22
- import { MAINTENANCE, MAINTENANCE_FILE } from './settings/maintenance.js';
23
- import { overridden, sourceLabel } from './settings/registry.js';
24
- import { readGeminiCertificate, regenerateGeminiCertificate } from './gemini/certificate.js';
25
- import { geminiHost } from './gemini/site-certificate.js';
26
- import { SITE, createSettings } from './site/namespace.js';
4
+ import { configFlag, isCommand, isHelpOrVersion, leadingWords, parseArgs } from './cli/args.js';
5
+ import { COMMANDS } from './cli/commands.js';
6
+ import { usage } from './cli/help.js';
7
+ import { pluginCommand, pluginExtends } from './cli/plugin-commands.js';
8
+ import { ownManifest } from './init.js';
27
9
  import { messageOf } from './util/errors.js';
28
- const COMMANDS = {
29
- serve: {
30
- synopsis: ['[serve] [--config <file>]'],
31
- help: [['serve', ['Start the CMS (the default when no command is given).']]],
32
- run: serveCommand,
33
- },
34
- init: {
35
- synopsis: ['init <directory>'],
36
- help: [['init', ['Create a new site in <directory>.']]],
37
- run: initCommand,
38
- },
39
- sync: {
40
- synopsis: ['sync [--config <file>]'],
41
- help: [['sync', ['Rebuild the content index once and exit.']]],
42
- run: syncCommand,
43
- },
44
- rebuild: {
45
- synopsis: ['rebuild [--config <file>]'],
46
- help: [
47
- [
48
- 'rebuild',
49
- [
50
- 'Delete data/geekity.db and build it again from the files.',
51
- 'Everything in it is derived, so this is always safe with the',
52
- 'site stopped; sessions and delivery outcomes start empty.',
53
- ],
54
- ],
55
- ],
56
- run: rebuildCommand,
57
- },
58
- resend: {
59
- synopsis: ['resend (--all | <slug>...) [--config <file>]'],
60
- help: [
61
- [
62
- 'resend',
63
- [
64
- 'Send announced posts to every follower and relay again, as',
65
- 'they read now: an Update for a post still published, a',
66
- 'Delete for one withdrawn. --all resends every post the site',
67
- 'has announced; this is how posts federated before a new',
68
- 'federation feature (such as quote posts) pick it up.',
69
- ],
70
- ],
71
- ],
72
- run: resendCommand,
73
- },
74
- maintenance: {
75
- synopsis: ['maintenance (on [--until <time>] | off | status) [--config <file>]'],
76
- help: [
77
- [
78
- 'maintenance',
79
- [
80
- 'Take the public site down on purpose, or bring it back.',
81
- 'While on, pages, feeds, sitemaps and inbox deliveries answer',
82
- '503 with Retry-After; the admin, /healthz and signed-in',
83
- 'users are let through. A running site notices within a',
84
- 'second, with no restart.',
85
- ],
86
- ],
87
- ],
88
- run: maintenanceCommand,
89
- },
90
- 'dev-mode': {
91
- synopsis: ['dev-mode (on | off | status) [--config <file>]'],
92
- help: [
93
- [
94
- 'dev-mode',
95
- [
96
- 'Hold everything the site would send to the outside world',
97
- '(ActivityPub deliveries and relay follows, webmentions,',
98
- 'rssCloud and WebSub pings, IndexNow, email) while it is',
99
- 'built or migrated, and record each one in',
100
- 'data/dev-mode.jsonl. off takes the site live: nothing held',
101
- 'is sent then, and the record says when it went live.',
102
- ],
103
- ],
104
- ],
105
- run: devModeCommand,
106
- },
107
- gemini: {
108
- synopsis: ['gemini (cert | new-cert) [--config <file>]'],
109
- help: [
110
- [
111
- 'gemini cert',
112
- [
113
- "Print the Gemini certificate's subject, expiry and SHA-256",
114
- 'fingerprint, and say when it does not name the base URL',
115
- 'host. It makes nothing: the site generates the certificate',
116
- 'when it starts with Gemini on.',
117
- ],
118
- ],
119
- [
120
- 'gemini new-cert',
121
- [
122
- 'Replace the generated certificate with a new one for the',
123
- 'base URL host. Every Gemini client that visited pinned the',
124
- 'old one and warns about the new one. Restart the site to',
125
- 'serve it.',
126
- ],
127
- ],
128
- ],
129
- run: geminiCommand,
130
- },
131
- settings: {
132
- synopsis: [
133
- 'settings list [<namespace>] [--config <file>]',
134
- 'settings get <namespace.key> [--config <file>]',
135
- 'settings set <namespace.key> (<value> | --unset) [--config <file>]',
136
- 'settings migrate-plugins [--config <file>]',
137
- ],
138
- help: [
139
- [
140
- 'settings list',
141
- [
142
- 'Print every runtime setting: its value in effect, where',
143
- 'that value came from (env, config, file or default) and',
144
- 'what it does. A secret prints as (set) or (not set).',
145
- "Each running plugin's settings follow the core ones, as",
146
- '@geekity/plugin-llm.default_model.',
147
- ],
148
- ],
149
- ['settings get', ['Print one value in effect, and what overrides it, if', 'anything.']],
150
- [
151
- 'settings set',
152
- [
153
- 'Store one value, or remove it with --unset so the default',
154
- 'applies. A setting the environment or the config overrides',
155
- 'is refused. A secret set here is left in the shell history.',
156
- ],
157
- ],
158
- [
159
- 'settings migrate-plugins',
160
- [
161
- "Move each plugin's settings out of content/_data/site.json",
162
- 'into data/plugins/<name>/settings.json, keeping enabled',
163
- 'where it is. A server does this when it starts; run it',
164
- 'with the site stopped to do it first. Safe to run twice.',
165
- ],
166
- ],
167
- ],
168
- run: settingsCommand,
169
- },
170
- 'strip-metadata': {
171
- synopsis: ['strip-metadata [--config <file>]'],
172
- help: [
173
- [
174
- 'strip-metadata',
175
- [
176
- 'Remove location and camera metadata (EXIF, XMP, IPTC, a',
177
- "video's location) from files already in content/uploads.",
178
- 'New uploads are stripped as they arrive; this is for the',
179
- 'ones from before. Safe to run again: a clean file is left',
180
- 'as it is.',
181
- ],
182
- ],
183
- ],
184
- run: stripMetadataCommand,
185
- },
186
- export: {
187
- synopsis: [
188
- 'export [--out <file>] [--with-credentials] [--without-content] [--list] [--config <file>]',
189
- ],
190
- help: [
191
- [
192
- 'export',
193
- [
194
- 'Write the site to a .tar.gz: content/ and every file in',
195
- 'data/ the site cannot rebuild, with manifest.json first.',
196
- 'Credentials are left out unless --with-credentials is given.',
197
- 'It only reads, so it runs while the site serves. It prints',
198
- 'the deliveries waiting in the queue, which are never',
199
- 'exported. --list prints what each file in data/ is and',
200
- 'writes nothing.',
201
- ],
202
- ],
203
- ],
204
- run: exportCommand,
205
- },
206
- import: {
207
- synopsis: ['import <file> [--replace] [--dev-mode] [--new-base-url] [--config <file>]'],
208
- help: [
209
- [
210
- 'import',
211
- [
212
- 'Restore a site from an archive geekity export wrote, with the',
213
- 'site stopped. Every file is checked against the manifest and',
214
- 'unpacked beside content/ and data/ before it replaces them.',
215
- 'Folder plugins are installed from the npm registry at the',
216
- 'versions the archive records, and the database is rebuilt.',
217
- 'It exits 1 when a plugin could not be installed, naming it',
218
- 'and the command to retry.',
219
- ],
220
- ],
221
- ],
222
- sharedWithPlugins: true,
223
- run: importCommand,
224
- },
225
- user: {
226
- synopsis: ['user add <username> [--password <pw>] [--email <address>] [--config <file>]'],
227
- help: [
228
- [
229
- 'user add',
230
- ['Create an admin user, so a site can get its first login', 'without the setup screen.'],
231
- ],
232
- ],
233
- run: userCommand,
234
- },
235
- plugin: {
236
- synopsis: [
237
- 'plugin (add <package>[@version] | remove <package>) [--config <file>]',
238
- 'plugin upgrade [<package>...] [--check] [--config <file>]',
239
- ],
240
- help: [
241
- [
242
- 'plugin add',
243
- [
244
- "Install a plugin package's bundle from the npm registry",
245
- '(npm_config_registry, or registry.npmjs.org) into the',
246
- 'plugins folder, GEEKITY_PLUGINS_DIR. It installs only the',
247
- 'package named, and names any plugin it requires that is',
248
- 'missing. Reload on the Plugins screen loads it.',
249
- ],
250
- ],
251
- [
252
- 'plugin remove',
253
- [
254
- "Delete a plugin's folder from the plugins folder. Reload on",
255
- 'the Plugins screen unloads it. It refuses a plugin the site',
256
- 'has enabled: disable it first.',
257
- ],
258
- ],
259
- [
260
- 'plugin upgrade',
261
- [
262
- 'Bring each plugin in the plugins folder, or only the ones',
263
- 'named, up to its newest version that this core and the',
264
- 'other installed plugins can run, installed as plugin add',
265
- 'installs one. Plugins that must move together do. It says,',
266
- 'for each plugin, what it upgraded, or why it held a newer',
267
- 'version back. --check reports and installs nothing.',
268
- ],
269
- ],
270
- ],
271
- run: pluginFolderCommand,
272
- },
273
- };
274
- /**
275
- * The options one command reads out of {@link ParsedArgs.flags}, each of which
276
- * carries a value.
277
- */
278
- const VALUE_FLAGS = ['until', 'out'];
279
- /** The options that are simply on or off. */
280
- const SWITCH_FLAGS = [
281
- 'all',
282
- 'check',
283
- 'unset',
284
- 'with-credentials',
285
- 'without-content',
286
- 'list',
287
- 'replace',
288
- 'dev-mode',
289
- 'new-base-url',
290
- ];
291
- const OPTIONS_HELP = `Options:
292
- --config <file> Config file to load. Defaults to the first of
293
- ${CONFIG_FILENAMES.join(', ')} found in the working directory.
294
- --password <pw> The new user's password. Left off, it is asked for without
295
- echo, or read as one line when standard input is a pipe.
296
- A password on the command line is visible in the process
297
- list and in shell history, so prefer being asked.
298
- --email <addr> The new user's email address. Optional; it is what a
299
- forgotten password is recovered through.
300
- --until <time> With maintenance on: when the site should be back, as an
301
- ISO 8601 time such as 2026-09-28T14:00:00Z. It is the
302
- Retry-After a client is sent, and the maintenance page
303
- says it.
304
- --unset With settings set: remove the stored value.
305
- --all With resend: every announced post rather than named ones.
306
- --check With plugin upgrade: say what would change, install nothing.
307
- --out <file> With export: the archive to write. Defaults to
308
- geekity-<host>-<time>.tar.gz in the working directory.
309
- --with-credentials
310
- With export: include the API keys and logins kept in
311
- data/ (mail.json, akismet.json, tmdb.json, each plugin's
312
- secrets).
313
- --without-content
314
- With export: leave content/ out.
315
- --list With export: print each file data/ may hold, its class
316
- and what is lost without it, and write nothing.
317
- --replace With import: move what content/ and data/ hold into
318
- <dir>/.geekity-before-import-<time> when they hold a site.
319
- --dev-mode With import: turn dev mode on, for a staging copy of a
320
- live site.
321
- --new-base-url With import: accept a base URL in effect that differs
322
- from the one the archive was exported from.
323
- -h, --help Show this help.
324
- -v, --version Show the installed version.
325
-
326
- Environment overrides:
327
- GEEKITY_PORT (or PORT), GEEKITY_CONTENT_DIR, GEEKITY_DATA_DIR,
328
- GEEKITY_THEMES_DIR, GEEKITY_PLUGINS_DIR, GEEKITY_BASE_URL, GEEKITY_WATCH,
329
- GEEKITY_MAINTENANCE (on keeps the site in maintenance until a restart),
330
- GEEKITY_DEV_MODE (on starts the site in dev mode; only dev-mode off ends it),
331
- GEEKITY_GEMINI_CERT and GEEKITY_GEMINI_KEY (the operator's own Gemini
332
- certificate and key instead of the generated pair)
333
- `;
334
- /** Turn `process.argv.slice(2)` into a command, its options and its arguments. */
335
- export function parseArgs(argv) {
336
- let command;
337
- let configPath;
338
- let password;
339
- let email;
340
- const flags = {};
341
- const args = [];
342
- for (let i = 0; i < argv.length; i += 1) {
343
- const arg = argv[i];
344
- if (arg === '--help' || arg === '-h') {
345
- return { command: 'help', configPath, password, email, flags, args };
346
- }
347
- if (arg === '--version' || arg === '-v') {
348
- return { command: 'version', configPath, password, email, flags, args };
349
- }
350
- if (arg === '--config') {
351
- const value = argv[i + 1];
352
- if (value === undefined || value.startsWith('-')) {
353
- throw new Error('--config needs a file path, for example --config geekity.config.ts');
354
- }
355
- configPath = value;
356
- i += 1;
357
- continue;
358
- }
359
- if (arg.startsWith('--config=')) {
360
- const value = arg.slice('--config='.length);
361
- if (value === '') {
362
- throw new Error('--config needs a file path, for example --config geekity.config.ts');
363
- }
364
- configPath = value;
365
- continue;
366
- }
367
- // Unlike --config, the value after --password is taken as given: a
368
- // password may legitimately start with a dash, and `--password=` with
369
- // nothing after it is refused by the password rules, which say why.
370
- if (arg === '--password') {
371
- const value = argv[i + 1];
372
- if (value === undefined) {
373
- throw new Error('--password needs a value, or leave it off to be asked for one.');
374
- }
375
- password = value;
376
- i += 1;
377
- continue;
378
- }
379
- if (arg.startsWith('--password=')) {
380
- password = arg.slice('--password='.length);
381
- continue;
382
- }
383
- // Read like --config rather than like --password: an email address never
384
- // starts with a dash, so a value that does is a missing one.
385
- if (arg === '--email') {
386
- const value = argv[i + 1];
387
- if (value === undefined || value.startsWith('-')) {
388
- throw new Error('--email needs an address, for example --email ada@example.com');
389
- }
390
- email = value;
391
- i += 1;
392
- continue;
393
- }
394
- if (arg.startsWith('--email=')) {
395
- email = arg.slice('--email='.length);
396
- continue;
397
- }
398
- // Everything else spelled as an option goes in the flags map, and an
399
- // option no command has is refused here rather than left to be read as a
400
- // file name by whatever command was running.
401
- if (arg.startsWith('--')) {
402
- const equals = arg.indexOf('=');
403
- const name = equals === -1 ? arg.slice(2) : arg.slice(2, equals);
404
- const inline = equals === -1 ? undefined : arg.slice(equals + 1);
405
- if (SWITCH_FLAGS.includes(name)) {
406
- if (inline !== undefined)
407
- throw new Error(`--${name} takes no value.`);
408
- flags[name] = true;
409
- continue;
410
- }
411
- if (VALUE_FLAGS.includes(name)) {
412
- if (inline !== undefined) {
413
- if (inline === '')
414
- throw new Error(`--${name} needs a value.`);
415
- flags[name] = inline;
416
- continue;
417
- }
418
- const value = argv[i + 1];
419
- if (value === undefined || value.startsWith('-')) {
420
- throw new Error(`--${name} needs a value.`);
421
- }
422
- flags[name] = value;
423
- i += 1;
424
- continue;
425
- }
426
- throw new Error(`Unknown option "--${name}". Run geekity --help to see what is available.`);
427
- }
428
- // The first bare word is the command; everything bare after it belongs to
429
- // that command, so `geekity user add ada` reaches `user` with `add ada`.
430
- if (command === undefined) {
431
- if (!isCommand(arg)) {
432
- throw new Error(`Unknown command "${arg}". Run geekity --help to see what is available.`);
433
- }
434
- command = arg;
435
- continue;
436
- }
437
- args.push(arg);
438
- }
439
- return { command: command ?? 'serve', configPath, password, email, flags, args };
440
- }
441
- function isCommand(value) {
442
- return Object.hasOwn(COMMANDS, value);
443
- }
444
10
  /** Run one command. Resolves with the exit code the process should use. */
445
11
  async function main(argv) {
446
12
  const words = leadingWords(argv);
@@ -461,1132 +27,6 @@ async function main(argv) {
461
27
  }
462
28
  return COMMANDS[parsed.command].run(parsed);
463
29
  }
464
- /** `geekity init <directory>`: scaffold a new site. */
465
- async function initCommand({ args }) {
466
- const directory = args[0];
467
- if (directory === undefined) {
468
- throw new Error('geekity init <directory> needs the directory to create.');
469
- }
470
- const site = await initSite({ directory, cwd: process.cwd() });
471
- const relative = path.relative(process.cwd(), site.directory) || '.';
472
- process.stdout.write([
473
- `Created ${site.directory}`,
474
- '',
475
- 'Next:',
476
- ` cd ${relative}`,
477
- ' pnpm install',
478
- ' pnpm dev',
479
- '',
480
- ].join('\n'));
481
- return 0;
482
- }
483
- async function maintenanceCommand({ args, configPath, flags }) {
484
- const action = args[0];
485
- const config = await loadResolvedConfig(configPath);
486
- const settings = createSettings({ config });
487
- if (action === 'on') {
488
- const until = untilFlag(text(flags, 'until'));
489
- await setOrThrow(settings, 'maintenance', { on: true, until: until?.toISOString() ?? '' });
490
- const file = dataPath(config.dataDir, MAINTENANCE_FILE);
491
- process.stdout.write(`Maintenance mode is on (${file}).${untilLine(until)}\n`);
492
- return 0;
493
- }
494
- if (action === 'off') {
495
- if (overridden((await settings.resolve(MAINTENANCE.on)).source)) {
496
- throw new Error(`Maintenance mode is still on.${forcedLine(true)}`);
497
- }
498
- await setOrThrow(settings, 'maintenance', { on: false });
499
- process.stdout.write('Maintenance mode is off.\n');
500
- return 0;
501
- }
502
- if (action === 'status') {
503
- const on = await settings.resolve(MAINTENANCE.on);
504
- if (!on.value) {
505
- process.stdout.write('Maintenance mode is off.\n');
506
- }
507
- else {
508
- const until = await settings.get(MAINTENANCE.until);
509
- process.stdout.write(`Maintenance mode is on.${untilLine(until === '' ? undefined : new Date(until))}${forcedLine(overridden(on.source))}\n`);
510
- }
511
- return 0;
512
- }
513
- throw new Error('geekity maintenance needs on, off or status.');
514
- }
515
- async function geminiCommand({ args, configPath }) {
516
- const action = args[0];
517
- if (action !== 'cert' && action !== 'new-cert') {
518
- throw new Error('geekity gemini needs cert or new-cert.');
519
- }
520
- const config = await loadResolvedConfig(configPath);
521
- const host = geminiHost(config, await createSettings({ config }).values(SITE));
522
- const result = action === 'cert'
523
- ? await readGeminiCertificate(config, host)
524
- : await regenerateGeminiCertificate(config, host, config.now());
525
- if (!result.ok)
526
- throw new Error(result.problem);
527
- const { certificate } = result;
528
- if (action === 'new-cert') {
529
- process.stdout.write('A new Gemini certificate is written. Every Gemini client that visited before warns that the capsule changed identity. Restart the site to serve it.\n');
530
- }
531
- process.stdout.write([
532
- `Certificate: ${certificate.certFile}${certificate.source === 'operator' ? " (the operator's own)" : ''}`,
533
- `Subject: ${certificate.subject}`,
534
- `Expires: ${certificate.validTo.toISOString()}`,
535
- `SHA-256 fingerprint: ${certificate.fingerprint256}`,
536
- ...(certificate.coversHost
537
- ? []
538
- : [
539
- `It does not name ${host}, the base URL host. Run geekity gemini new-cert to replace it; every client that pinned it will warn.`,
540
- ]),
541
- ].join('\n') + '\n');
542
- return 0;
543
- }
544
- async function devModeCommand({ args, configPath }) {
545
- const action = args[0];
546
- const config = await loadResolvedConfig(configPath);
547
- const settings = createSettings({ config });
548
- if (action === 'on') {
549
- await setOrThrow(settings, 'dev_mode', { on: true });
550
- process.stdout.write('Dev mode is on: nothing the site does is sent until `geekity dev-mode off`.\n');
551
- return 0;
552
- }
553
- if (action === 'off') {
554
- if (config.devMode) {
555
- throw new Error(`${DEV_MODE_LATCHED} Remove it, then run geekity dev-mode off again.`);
556
- }
557
- const wasOn = await settings.get(DEV_MODE.on);
558
- await setOrThrow(settings, 'dev_mode', { on: false });
559
- process.stdout.write(wasOn
560
- ? 'Dev mode is off: the site is live. Nothing held while it was on will be sent.\n'
561
- : 'Dev mode was already off: the site is live.\n');
562
- return 0;
563
- }
564
- if (action === 'status') {
565
- process.stdout.write((await settings.get(DEV_MODE.on)) ? 'Dev mode is on.\n' : 'Dev mode is off.\n');
566
- return 0;
567
- }
568
- throw new Error('geekity dev-mode needs on, off or status.');
569
- }
570
- async function settingsCommand({ args, configPath, flags }) {
571
- const [action, name, value] = args;
572
- const config = await loadResolvedConfig(configPath);
573
- if (action === 'migrate-plugins' && name === undefined) {
574
- const moved = migratePluginSettings({
575
- contentDir: config.contentDir,
576
- dataDir: config.dataDir,
577
- log: (line) => process.stdout.write(`${line}\n`),
578
- });
579
- if (moved.length === 0) {
580
- process.stdout.write('No plugin settings are left in content/_data/site.json.\n');
581
- }
582
- return 0;
583
- }
584
- const request = settingsRequest(action, name, value, flags['unset'] === true);
585
- if (request === undefined) {
586
- throw new Error('geekity settings needs list [<namespace>], get <namespace.key>, set <namespace.key> with a value or --unset, or migrate-plugins.');
587
- }
588
- const settings = await settingsWithRunningPlugins(config);
589
- if (request.action === 'list') {
590
- const refs = settings.list().filter((ref) => name === undefined || ref.namespace === name);
591
- if (refs.length === 0)
592
- throw new Error(`There is no settings namespace ${String(name)}.`);
593
- const rows = await Promise.all(refs.map((ref) => settingRow(settings, ref)));
594
- process.stdout.write(table(rows));
595
- return 0;
596
- }
597
- const ref = settingNamed(settings, request.name);
598
- if (request.action === 'get') {
599
- const resolved = await settings.resolve(ref);
600
- const lines = [shown(ref, resolved.value)];
601
- if (overridden(resolved.source)) {
602
- const held = resolved.stored === undefined ? 'nothing' : shown(ref, resolved.stored);
603
- lines.push(`overridden by ${sourceLabel(resolved.source)}; the file holds ${held}`);
604
- }
605
- process.stdout.write(`${lines.join('\n')}\n`);
606
- return 0;
607
- }
608
- const { type } = ref.declaration;
609
- let stored;
610
- if (request.value !== undefined) {
611
- const parsed = type.fromText(request.value);
612
- if (!parsed.ok)
613
- throw new Error(`${request.name} ${parsed.problem}.`);
614
- stored = type.toJson(parsed.value);
615
- }
616
- await setOrThrow(settings, ref.namespace, { [ref.key]: stored });
617
- process.stdout.write(table([await settingRow(settings, ref)]));
618
- return 0;
619
- }
620
- function settingsRequest(action, name, value, unset) {
621
- if (action === 'list')
622
- return { action };
623
- if (name === undefined)
624
- return undefined;
625
- if (action === 'get')
626
- return { action, name };
627
- if (action === 'set' && (value !== undefined) !== unset)
628
- return { action, name, value };
629
- return undefined;
630
- }
631
- async function settingsWithRunningPlugins(config) {
632
- migratePluginSettings({
633
- contentDir: config.contentDir,
634
- dataDir: config.dataDir,
635
- log: (line) => process.stderr.write(`${line}\n`),
636
- });
637
- const settings = createSettings({ config });
638
- let registry;
639
- try {
640
- registry = await loadSitePlugins(config, settings);
641
- }
642
- catch (error) {
643
- process.stderr.write(`Plugin settings are not listed: ${messageOf(error)}\n`);
644
- return settings;
645
- }
646
- const enabled = readEnabledPlugins(config.contentDir);
647
- const running = registry.active(enabled);
648
- for (const entry of registry.plugins) {
649
- const { name } = entry.plugin;
650
- const declared = entry.settingsNamespace !== undefined;
651
- const unremarkable = !declared && !enabled.has(name) && entry.problem === undefined;
652
- if (running.has(name) || unremarkable)
653
- continue;
654
- const unlisted = declared ? ' Its settings are not listed.' : '';
655
- process.stderr.write(`${name} ${whyNotRunning(entry, enabled)}${unlisted}\n`);
656
- if (declared)
657
- settings.unregister(name);
658
- }
659
- return settings;
660
- }
661
- function whyNotRunning(entry, enabled) {
662
- if (entry.problem !== undefined)
663
- return `did not load: ${entry.problem}`;
664
- if (enabled.has(entry.plugin.name)) {
665
- return 'is enabled but not running, because a plugin it requires is not running.';
666
- }
667
- return 'is installed but not enabled.';
668
- }
669
- function settingNamed(settings, name) {
670
- const dot = name.lastIndexOf('.');
671
- const found = settings
672
- .list()
673
- .find((ref) => ref.namespace === name.slice(0, dot) && ref.key === name.slice(dot + 1));
674
- if (found === undefined) {
675
- throw new Error(`There is no setting ${name}. geekity settings list names them.`);
676
- }
677
- return found;
678
- }
679
- async function setOrThrow(settings, namespace, changes) {
680
- const result = await settings.set(namespace, new Map(Object.entries(changes)), 'cli');
681
- if (!result.ok)
682
- throw new Error(Object.values(result.problems).join(' '));
683
- }
684
- function shown(ref, value) {
685
- if (ref.declaration.secret === true) {
686
- return value === ref.declaration.default ? '(not set)' : '(set)';
687
- }
688
- return ref.declaration.type.toText(value);
689
- }
690
- async function settingRow(settings, ref) {
691
- const resolved = await settings.resolve(ref);
692
- let source = sourceLabel(resolved.source);
693
- if (overridden(resolved.source) && resolved.stored !== undefined) {
694
- source += ` (file: ${shown(ref, resolved.stored)})`;
695
- }
696
- if (ref.declaration.env === false)
697
- source += ', not overridable';
698
- return [
699
- `${ref.namespace}.${ref.key}`,
700
- shown(ref, resolved.value),
701
- source,
702
- ref.declaration.description,
703
- ];
704
- }
705
- function table(rows) {
706
- const widths = rows[0]?.map((_, column) => Math.max(...rows.map((row) => row[column]?.length ?? 0))) ?? [];
707
- return rows
708
- .map((row) => `${row.map((cell, column) => (column === row.length - 1 ? cell : cell.padEnd(widths[column] ?? 0))).join(' ')}\n`)
709
- .join('');
710
- }
711
- function untilFlag(value) {
712
- if (value === undefined)
713
- return undefined;
714
- const until = new Date(value);
715
- if (Number.isNaN(until.getTime())) {
716
- throw new Error(`--until needs a time such as 2026-09-28T14:00:00Z, received ${JSON.stringify(value)}.`);
717
- }
718
- return until;
719
- }
720
- function untilLine(until) {
721
- return until === undefined ? '' : ` Expected back by ${until.toUTCString()}.`;
722
- }
723
- function forcedLine(forced) {
724
- return forced
725
- ? ' GEEKITY_MAINTENANCE or the maintenance setting keeps it on until the site restarts without it.'
726
- : '';
727
- }
728
- /**
729
- * Run one job in this process and return its result, or say on standard
730
- * error why there is none. A job of the same name that is already active
731
- * stops it before it is queued. A queued job counts only while a server is up
732
- * to run it: one a command left queued when it died runs when a server next
733
- * starts, and is no reason to refuse while none is.
734
- */
735
- async function runJobHere(config, job, payload, what, prepare) {
736
- const { createCms } = await import('./index.js');
737
- const cms = createCms(config);
738
- let status;
739
- try {
740
- await prepare?.(cms);
741
- const enqueued = await cms.jobs.enqueueUnlessActive(job, payload, {
742
- countQueued: await isServing(config.dataDir),
743
- });
744
- if (!enqueued.queued) {
745
- process.stderr.write(`A ${job.name} job is already ${enqueued.active.state}, so this one did not start. ` +
746
- `Run the command again once it finishes.\n`);
747
- return undefined;
748
- }
749
- status = await cms.jobs.run(enqueued.id);
750
- }
751
- finally {
752
- await cms.close();
753
- }
754
- const result = finishedResult(job, status);
755
- if (result === undefined) {
756
- const problem = status.state === 'failed' ? status.error : `The job ended ${status.state}.`;
757
- process.stderr.write(`The ${what} did not finish: ${problem}\n`);
758
- }
759
- return result;
760
- }
761
- async function stripMetadataCommand({ configPath }) {
762
- const config = await loadResolvedConfig(configPath, (loaded) => ({ ...loaded, watch: false }));
763
- const { STRIP_METADATA_JOB } = await import('./content/metadata/strip-job.js');
764
- const report = await runJobHere(config, STRIP_METADATA_JOB, null, 'sweep');
765
- if (report === undefined)
766
- return 1;
767
- for (const file of report.stripped) {
768
- process.stdout.write(`${file.path}: removed ${file.removed.join(', ')}\n`);
769
- }
770
- for (const file of report.unreadable) {
771
- process.stderr.write(`${file.path}: ${file.problem} Left as it was.\n`);
772
- }
773
- process.stdout.write(`Checked ${count(report.checked, 'file')}: ${String(report.stripped.length)} stripped, ` +
774
- `${String(report.clean)} already clean, ${String(report.unreadable.length)} unreadable\n`);
775
- return report.unreadable.length === 0 ? 0 : 1;
776
- }
777
- /**
778
- * `geekity sync`: bring the index into line with the files once and stop.
779
- *
780
- * Watching is forced off whatever the config says, because a one-shot scan
781
- * that then sat in a watcher would never exit.
782
- */
783
- async function syncCommand({ configPath }) {
784
- const { createCms } = await import('./index.js');
785
- const cms = createCms(await loadResolvedConfig(configPath, (config) => ({ ...config, watch: false })));
786
- try {
787
- const result = await cms.sync();
788
- process.stdout.write(`Scanned ${String(result.scanned)}: ${String(result.created)} created, ` +
789
- `${String(result.updated)} updated, ${String(result.removed)} removed, ` +
790
- `${String(result.unchanged)} unchanged, ${String(result.failed)} failed\n`);
791
- if (result.failed > 0) {
792
- process.stderr.write(`${String(result.failed)} file${result.failed === 1 ? '' : 's'} could not be parsed and ` +
793
- `${result.failed === 1 ? 'was' : 'were'} left out of the index; the warnings above name ` +
794
- `${result.failed === 1 ? 'it' : 'them'}.\n`);
795
- return 1;
796
- }
797
- return 0;
798
- }
799
- finally {
800
- await cms.close();
801
- }
802
- }
803
- /**
804
- * `geekity resend`: send announced posts to their followers again, as they now
805
- * read.
806
- *
807
- * Mastodon keeps the copy of a post it first fetched, so a property added
808
- * later — the quote policy (TASK-125) is the one that made this a command —
809
- * reaches a post already out only through an `Update`. This is the resend
810
- * button on the federation screen, for every post at once, and it runs the
811
- * same resend job (TASK-393). Delivery runs with no queue, so each activity
812
- * has been posted before the process exits.
813
- */
814
- async function resendCommand({ args, configPath, flags }) {
815
- const all = flags['all'] === true;
816
- if (all === args.length > 0) {
817
- throw new Error('geekity resend needs either --all or the slugs of the posts to resend, and not both.');
818
- }
819
- const config = await loadResolvedConfig(configPath, (loaded) => ({
820
- ...loaded,
821
- watch: false,
822
- federation: { ...loaded.federation, queue: null },
823
- }));
824
- const { RESEND_JOB } = await import('./federation/resend-job.js');
825
- const report = await runJobHere(config, RESEND_JOB, { slugs: all ? 'all' : args, webmentions: false }, 'resend', (cms) => cms.sync());
826
- if (report === undefined)
827
- return 1;
828
- let failed = 0;
829
- for (const post of report.posts) {
830
- const activity = post.resent ? post.activity : null;
831
- if (activity === null) {
832
- process.stderr.write(`${post.slug}: nothing to resend, no announced post has that slug.\n`);
833
- failed += 1;
834
- }
835
- else if (activity.heldByDevMode) {
836
- process.stdout.write(`${post.slug}: ${activity.activityType} held by dev mode, nothing sent\n`);
837
- }
838
- else {
839
- process.stdout.write(`${post.slug}: ${activity.activityType} to ${String(activity.reached)} of ` +
840
- `${String(activity.inboxes)} inboxes\n`);
841
- }
842
- }
843
- return failed === 0 ? 0 : 1;
844
- }
845
- /**
846
- * `geekity rebuild`: throw the database away and read it back out of the files.
847
- *
848
- * Nothing in `data/geekity.db` is anything but a reading of `content/` and
849
- * `data/` (decision-9), so this is a command with no undo and no loss: the
850
- * content index, the followers, the inbox log and the comments come back
851
- * exactly as they were, and what does not — sessions, the cached delivery
852
- * outcomes, the relay handshake — is what a site is told it may lose. It is the
853
- * way past a database this version refuses to open, which is the other reason
854
- * it exists.
855
- *
856
- * The rebuild is the boot: after the file is gone, `createCms` applies the same
857
- * migrations and runs the same rebuilds boot runs, and `sync()`
858
- * is the same scan `serve()` does. Nothing here knows how to build an index,
859
- * which is what keeps a rebuilt database identical to a booted one.
860
- *
861
- * Watching is forced off for the reason `sync` forces it off: a one-shot
862
- * command that sat in a watcher would never exit.
863
- */
864
- async function rebuildCommand({ configPath }) {
865
- const config = await loadResolvedConfig(configPath, (loaded) => ({ ...loaded, watch: false }));
866
- const file = databaseFile(config.dataDir);
867
- if (databaseInUse(config.dataDir)) {
868
- process.stderr.write(`${file} is in use: something else has it open, most likely the site itself. Stop the ` +
869
- 'server and run this again — deleting the database under a running one would leave it ' +
870
- 'writing to a file nothing can find.\n');
871
- return 1;
872
- }
873
- return (await rebuildDatabase(config)) > 0 ? 1 : 0;
874
- }
875
- async function rebuildDatabase(config) {
876
- discardDatabase(config.dataDir);
877
- const { createCms } = await import('./index.js');
878
- const cms = createCms(config);
879
- try {
880
- const result = await cms.sync();
881
- process.stdout.write(`Rebuilt ${databaseFile(config.dataDir)} from the files.\n` +
882
- `Scanned ${String(result.scanned)}: ${String(result.created)} created, ` +
883
- `${String(result.updated)} updated, ${String(result.removed)} removed, ` +
884
- `${String(result.unchanged)} unchanged, ${String(result.failed)} failed\n` +
885
- `Indexed ${count(cms.admin.countFollowers(), 'follower')}, ` +
886
- `${count(cms.admin.countInboxActivities(), 'inbox activity', 'inbox activities')} and ` +
887
- `${count(totalComments(cms.admin), 'comment')}.\n`);
888
- if (result.failed > 0) {
889
- process.stderr.write(`${String(result.failed)} file${result.failed === 1 ? '' : 's'} could not be parsed and ` +
890
- `${result.failed === 1 ? 'was' : 'were'} left out of the index; the warnings above name ` +
891
- `${result.failed === 1 ? 'it' : 'them'}.\n`);
892
- }
893
- return result.failed;
894
- }
895
- finally {
896
- await cms.close();
897
- }
898
- }
899
- async function importCommand({ args, configPath, flags }) {
900
- const [file, ...extra] = args;
901
- if (file === undefined) {
902
- throw new Error('geekity import needs one archive: geekity import <file>.');
903
- }
904
- if (extra.length > 0) {
905
- throw new Error(`geekity import takes one archive, and no plugin on this site adds "import ${file}".`);
906
- }
907
- const unsettled = resolveConfig({
908
- ...(await loadConfig(process.cwd(), configPath)),
909
- watch: false,
910
- });
911
- const { contentDir, dataDir } = unsettled;
912
- if (databaseInUse(dataDir) || (await isServing(dataDir))) {
913
- process.stderr.write(`The site is running: ${dataDir} is in use. Stop it and run geekity import again.\n`);
914
- return 1;
915
- }
916
- const { checkImportTargets, discardStaging, finishSiteImport, importNotes, installArchivedPlugins, placeSiteImport, pluginFailureLine, readSiteManifest, restoreEnabledPlugins, stageSiteImport, } = await import('./export/site-import.js');
917
- const { compactTime } = await import('./export/site-export.js');
918
- const { pluginRegistry } = await import('./plugins/install.js');
919
- const archive = path.resolve(file);
920
- const targets = { contentDir, dataDir };
921
- const settings = createSettings({ config: unsettled });
922
- const archived = await readSiteManifest(archive);
923
- const { manifest } = archived;
924
- const occupied = checkImportTargets(archived, targets, settings).filter((target) => target.state === 'occupied');
925
- if (occupied.length > 0 && flags['replace'] !== true) {
926
- process.stderr.write(`${occupied.map((target) => target.dir).join(' and ')} already ${occupied.length === 1 ? 'holds' : 'hold'} a site. ` +
927
- 'Import into empty folders, or give --replace to move what they hold into <dir>/.geekity-before-import-<time> first.\n');
928
- return 1;
929
- }
930
- const staged = await stageSiteImport({ archive, archived, targets, settings });
931
- const inEffect = await settleConfig(Object.freeze({ ...unsettled, contentDir: staged.content ?? contentDir }));
932
- if (inEffect.baseUrl !== manifest.baseUrl && flags['new-base-url'] !== true) {
933
- await discardStaging(staged);
934
- process.stderr.write(`The base URL in effect is ${inEffect.baseUrl}, and the archive was exported from ${manifest.baseUrl}. ` +
935
- 'Actor ids are built from the base URL, so followers would not follow the site to a new address. ' +
936
- `Set GEEKITY_BASE_URL, or baseUrl in the config, to ${manifest.baseUrl}, ` +
937
- `or give --new-base-url to import it at ${inEffect.baseUrl}.\n`);
938
- return 1;
939
- }
940
- for (const skipped of staged.skipped) {
941
- process.stderr.write(`Left out ${skipped.path}: ${skipped.why}.\n`);
942
- }
943
- for (const aside of await placeSiteImport(staged, { stamp: compactTime(unsettled.now()) })) {
944
- process.stdout.write(`Moved what was there into ${aside}.\n`);
945
- }
946
- process.stdout.write(`Restored ${count(manifest.files.length - staged.skipped.length, 'file')} from ${archive}.\n`);
947
- const config = await settleConfig(unsettled);
948
- if (flags['dev-mode'] === true) {
949
- await setOrThrow(createSettings({ config }), 'dev_mode', { on: true });
950
- process.stdout.write('Dev mode is on: nothing the site does is sent until `geekity dev-mode off`.\n');
951
- }
952
- const failures = await installArchivedPlugins(manifest, {
953
- pluginsDir: config.pluginsDir,
954
- registry: pluginRegistry(process.env),
955
- coreVersion: ownManifest().version,
956
- });
957
- for (const plugin of manifest.plugins) {
958
- if (plugin.source === 'folder' && !failures.some((failed) => failed.name === plugin.name)) {
959
- process.stdout.write(`Installed ${plugin.name} ${plugin.version}.\n`);
960
- }
961
- }
962
- await restoreEnabledPlugins(manifest, config.contentDir);
963
- await rebuildDatabase(config);
964
- await finishSiteImport(targets);
965
- process.stdout.write(importNotes(manifest)
966
- .map((note) => `${note}\n`)
967
- .join(''));
968
- for (const failed of failures)
969
- process.stderr.write(`${pluginFailureLine(failed)}\n`);
970
- return failures.length > 0 ? 1 : 0;
971
- }
972
- /**
973
- * It runs beside a serving site: no migration runs and no database is opened
974
- * but the queue, read-only, to count what waits in it.
975
- */
976
- async function exportCommand({ configPath, flags }) {
977
- const config = await loadResolvedConfig(configPath, (loaded) => ({ ...loaded, watch: false }));
978
- const settings = createSettings({ config });
979
- const plugins = await loadSitePlugins(config, settings);
980
- const { exportFileName, planSiteExport, writeSiteExport } = await import('./export/site-export.js');
981
- const { siteDataFiles } = await import('./plugins/data.js');
982
- if (flags['list'] === true) {
983
- const declarations = siteDataFiles({ dataDir: config.dataDir, settings, plugins });
984
- process.stdout.write(table([
985
- ...declarations.map((each) => [`data/${each.pattern}`, each.dataClass.kind, each.lost]),
986
- ['content/**', 'kept', 'The site: its documents, uploads and _data.'],
987
- ...CONTENT_SCRATCH_FILES.map((each) => [
988
- `content/${each.pattern}`,
989
- each.dataClass.kind,
990
- each.lost,
991
- ]),
992
- ]));
993
- return 0;
994
- }
995
- const plan = await planSiteExport({ config, settings, plugins }, {
996
- withCredentials: flags['with-credentials'] === true,
997
- withContent: flags['without-content'] !== true,
998
- });
999
- const { deliveries } = plan.site.pending;
1000
- process.stdout.write(`${count(deliveries, 'delivery is', 'deliveries are')} waiting in data/queue.sqlite. ` +
1001
- 'They are not exported: before a move, wait until none are.\n' +
1002
- 'The archive holds actor keys, password hashes and personal data. ' +
1003
- 'Store it as carefully as data/.\n');
1004
- const now = config.now();
1005
- const out = path.resolve(text(flags, 'out') ?? exportFileName(config.baseUrl, now));
1006
- const manifest = await writeSiteExport(plan, { out, now });
1007
- for (const file of manifest.undeclared) {
1008
- process.stderr.write(`Left out ${file}: no declaration says what it is.\n`);
1009
- }
1010
- for (const entry of manifest.notCarried) {
1011
- process.stderr.write(`Left out ${entry.path}: it is ${entry.why}, and an export holds only regular files.\n`);
1012
- }
1013
- if (manifest.credentialsLeftOut.length > 0) {
1014
- process.stdout.write(`Credentials left out: ${manifest.credentialsLeftOut.join(', ')}. ` +
1015
- '--with-credentials includes them.\n');
1016
- }
1017
- const bytes = manifest.files.reduce((total, file) => total + file.size, 0);
1018
- process.stdout.write(`Wrote ${out}: ${count(manifest.files.length, 'file')}, ${count(bytes, 'byte')}.\n`);
1019
- return 0;
1020
- }
1021
- /** "1 follower", "2 followers". The plural is the singular plus s unless told. */
1022
- /** How many comments the files hold, whatever a moderator has done with them. */
1023
- function totalComments(admin) {
1024
- const counts = admin.countCommentsByStatus();
1025
- return counts.pending + counts.approved + counts.spam;
1026
- }
1027
- function count(howMany, singular, plural = `${singular}s`) {
1028
- return `${String(howMany)} ${howMany === 1 ? singular : plural}`;
1029
- }
1030
- /**
1031
- * Whether something else has the database open.
1032
- *
1033
- * SQLite in WAL mode keeps a shared-memory file that every connection takes a
1034
- * lock in, and asking for `locking_mode = EXCLUSIVE` means asking to be the
1035
- * only one there — so a write transaction under it comes back
1036
- * {@link SQLITE_BUSY} exactly when somebody else is attached. That is a cheap
1037
- * and honest answer to "is the site running?", where a lock file of our own
1038
- * would have to be cleaned up after a crash and a check of the `-wal` file
1039
- * would say yes to a database nobody has open. The probe's own connection is
1040
- * closed either way, which is what releases the lock it may have taken.
1041
- *
1042
- * Only busy is in use. A database that is not there, and one that will not
1043
- * open or read at all, are both the case this command exists for, so they
1044
- * answer no and let the rebuild get on with it.
1045
- */
1046
- function databaseInUse(dataDir) {
1047
- const file = databaseFile(dataDir);
1048
- if (!existsSync(file))
1049
- return false;
1050
- let db;
1051
- try {
1052
- db = new DatabaseSync(file);
1053
- }
1054
- catch {
1055
- return false;
1056
- }
1057
- try {
1058
- db.exec('PRAGMA locking_mode = EXCLUSIVE');
1059
- db.exec('BEGIN IMMEDIATE');
1060
- db.exec('COMMIT');
1061
- return false;
1062
- }
1063
- catch (error) {
1064
- const code = error?.errcode;
1065
- return code === SQLITE_BUSY || code === SQLITE_LOCKED;
1066
- }
1067
- finally {
1068
- db.close();
1069
- }
1070
- }
1071
- /** SQLite's result codes for "somebody else has it", the only ones that mean in use. */
1072
- const SQLITE_BUSY = 5;
1073
- const SQLITE_LOCKED = 6;
1074
- /**
1075
- * `geekity serve`: the default. Runs until it is signalled.
1076
- *
1077
- * This process is a supervisor (TASK-288): it owns the port and runs the CMS
1078
- * in a `node:cluster` worker that runs this same command, so Reload on the
1079
- * Plugins screen can boot a new worker beside the old one and a worker that
1080
- * crashes is respawned, both without restarting the container.
1081
- *
1082
- * With `seedContent` on, a missing or empty content directory is given the
1083
- * starter site before any worker opens it, so a new box boots into something
1084
- * to show and the setup screen. It happens here rather than in `createCms` so
1085
- * a site that builds its own server never has content written for it.
1086
- */
1087
- async function serveCommand({ configPath }) {
1088
- if (cluster.isWorker)
1089
- return serveWorker(configPath);
1090
- const resolved = await loadResolvedConfig(configPath);
1091
- if (resolved.seedContent &&
1092
- (await seedStarterContent({ contentDir: resolved.contentDir, baseUrl: resolved.baseUrl }))) {
1093
- process.stdout.write(`Seeded ${resolved.contentDir} with the starter site\n`);
1094
- }
1095
- const { superviseCluster } = await import('./supervisor/primary.js');
1096
- superviseCluster({
1097
- dataDir: resolved.dataDir,
1098
- pluginsDir: resolved.pluginsDir,
1099
- pluginWatch: resolved.pluginWatch,
1100
- });
1101
- return 0;
1102
- }
1103
- /**
1104
- * One worker under the supervisor: the site's config and its plugins folder,
1105
- * read afresh, so a reload sees what changed. Signals are the supervisor's to
1106
- * act on; it tells this worker when to close.
1107
- */
1108
- async function serveWorker(configPath) {
1109
- const { processChannel, superviseWorker } = await import('./supervisor/worker.js');
1110
- const { createCms } = await import('./index.js');
1111
- const channel = processChannel();
1112
- for (const signal of ['SIGINT', 'SIGTERM'])
1113
- process.on(signal, () => undefined);
1114
- try {
1115
- // The access log is on here and off in `createCms`: a server that answers
1116
- // the internet should be able to say what it answered, while a CMS embedded
1117
- // in somebody else's app has no business writing to their stdout uninvited.
1118
- // Named as a config value rather than forced, so `GEEKITY_ACCESS_LOG` still
1119
- // wins and a site that wrote `accessLog: false` still gets silence.
1120
- const config = await loadResolvedConfig(configPath, (site) => ({
1121
- ...site,
1122
- accessLog: site.accessLog ?? true,
1123
- }));
1124
- const loaded = scanPluginFolders(config.pluginsDir);
1125
- const worker = superviseWorker({
1126
- channel,
1127
- loaded,
1128
- exit: (code) => process.exit(code),
1129
- log: (line) => process.stderr.write(`${line}\n`),
1130
- });
1131
- const cms = createCms(config, {
1132
- folderPlugins: await importPluginFolders(loaded),
1133
- supervision: worker.supervision,
1134
- });
1135
- const { port, geminiPort } = await cms.serve();
1136
- if (await cms.settings.get(DEV_MODE.on)) {
1137
- process.stdout.write('Dev mode is on: ActivityPub, webmentions, feed pings, IndexNow and email are held ' +
1138
- 'and recorded in data/dev-mode.jsonl. `geekity dev-mode off` takes the site live.\n');
1139
- }
1140
- process.stdout.write(`Geekity CMS is serving ${cms.config.baseUrl} on port ${String(port)}\n`);
1141
- if (geminiPort !== undefined) {
1142
- const host = geminiHost(cms.config, await cms.settings.values(SITE));
1143
- process.stdout.write(`Gemini is on port ${String(geminiPort)} for ${host}\n`);
1144
- }
1145
- worker.serving(cms);
1146
- }
1147
- catch (error) {
1148
- const message = messageOf(error);
1149
- channel.send({ type: 'boot-failed', error: message }, () => process.exit(1));
1150
- }
1151
- return 0;
1152
- }
1153
- async function pluginFolderCommand({ args, configPath, flags }) {
1154
- const [action, ...names] = args;
1155
- const spec = names.length === 1 ? names[0] : undefined;
1156
- if (action !== 'upgrade' && action !== 'add' && action !== 'remove') {
1157
- throw new Error(PLUGIN_USAGE);
1158
- }
1159
- const config = await loadResolvedConfig(configPath);
1160
- const { pluginsDir } = config;
1161
- if (pluginsDir === undefined) {
1162
- throw new Error('geekity plugin needs a plugins folder: set GEEKITY_PLUGINS_DIR, or pluginsDir in the config.');
1163
- }
1164
- const { ADD_WITH_COMMAND, addPlugin, installedFolders, parsePackageSpec, pluginRegistry, removePlugin, requirementNotes, } = await import('./plugins/install.js');
1165
- const registry = pluginRegistry(process.env);
1166
- if (action === 'upgrade') {
1167
- const { upgradePlugins } = await import('./plugins/upgrade.js');
1168
- const report = await upgradePlugins({
1169
- pluginsDir,
1170
- registry,
1171
- coreVersion: ownManifest().version,
1172
- configured: config.plugins.map((plugin) => ({
1173
- name: plugin.name,
1174
- version: plugin.version,
1175
- peerDependencies: plugin.requires ?? {},
1176
- })),
1177
- only: names.length === 0 ? undefined : names,
1178
- check: flags['check'] === true,
1179
- addAdvice: ADD_WITH_COMMAND,
1180
- });
1181
- process.stdout.write(await upgradeReportText(report));
1182
- const reloaded = report.plugins.some((plugin) => plugin.status === 'upgraded')
1183
- ? await reloadRunningSite(config)
1184
- : true;
1185
- return reloaded && report.plugins.every((plugin) => plugin.status !== 'failed') ? 0 : 1;
1186
- }
1187
- if (spec === undefined)
1188
- throw new Error(PLUGIN_USAGE);
1189
- if (action === 'remove') {
1190
- const directory = await removePlugin(spec, { pluginsDir, contentDir: config.contentDir });
1191
- process.stdout.write(`Removed ${spec} (${directory}).\n`);
1192
- return (await reloadRunningSite(config)) ? 0 : 1;
1193
- }
1194
- const { manifest, directory, replaced } = await addPlugin(parsePackageSpec(spec), {
1195
- pluginsDir,
1196
- registry,
1197
- });
1198
- const installed = new Map([
1199
- ...config.plugins.map((plugin) => [plugin.name, plugin.version]),
1200
- ...installedFolders(pluginsDir),
1201
- ]);
1202
- const done = replaced === undefined || replaced === manifest.version
1203
- ? `Added ${manifest.name} ${manifest.version} to ${directory}.`
1204
- : `Replaced ${manifest.name} ${replaced} with ${manifest.version} in ${directory}.`;
1205
- process.stdout.write([
1206
- done,
1207
- ...requirementNotes(manifest, installed, ownManifest().version, ADD_WITH_COMMAND),
1208
- '',
1209
- ].join('\n'));
1210
- const reloaded = await reloadRunningSite(config);
1211
- process.stdout.write('Enable it on the Plugins screen.\n');
1212
- return reloaded ? 0 : 1;
1213
- }
1214
- async function reloadRunningSite(config) {
1215
- const outcome = await askToReload(config.dataDir);
1216
- if (outcome === undefined) {
1217
- process.stdout.write(config.pluginWatch
1218
- ? 'No running geekity serve answered. A running site loads the change by itself within a few seconds.\n'
1219
- : 'No running geekity serve answered. Press Reload on the Plugins screen to load the change.\n');
1220
- return true;
1221
- }
1222
- if (outcome.ok) {
1223
- process.stdout.write('The running site reloaded with the change.\n');
1224
- return true;
1225
- }
1226
- process.stdout.write(`The running site tried to reload, but the new server did not start, so it carried on with the plugins it had: ${outcome.error}\n`);
1227
- return false;
1228
- }
1229
- const PLUGIN_USAGE = 'geekity plugin needs add <package>[@version], remove <package> or upgrade [<package>...].';
1230
- async function upgradeReportText(report) {
1231
- const { describeUpgrade } = await import('./plugins/upgrade.js');
1232
- const lines = report.plugins.map((plugin) => `${plugin.name}: ${describeUpgrade(plugin)}`);
1233
- for (const { name, notes } of report.unmet) {
1234
- lines.push(...notes.map((note) => `${name}: ${note}`));
1235
- }
1236
- const statuses = new Set(report.plugins.map((plugin) => plugin.status));
1237
- if (statuses.has('available')) {
1238
- lines.push('Run geekity plugin upgrade without --check to install them.');
1239
- }
1240
- return lines.map((line) => `${line}\n`).join('');
1241
- }
1242
- /**
1243
- * `geekity user add <username>`: create an admin without the setup screen.
1244
- *
1245
- * The other door into `data/users.json` is the first-run setup form, and this
1246
- * one has to leave the same thing behind it, so both go through
1247
- * {@link credentialProblem} rather than each carrying its own idea of a legal
1248
- * username. The file is written under the config's `dataDir`, which is the
1249
- * same one the server will read.
1250
- *
1251
- * The database is opened for one reason only: this is the one door that can
1252
- * reach the users file before a server ever has, and a site upgrading from the
1253
- * version that kept its accounts in SQLite would otherwise end up with a file
1254
- * holding nobody but the user added here — which, the file winning, is what
1255
- * the next boot would keep. So the same boot migration runs first.
1256
- */
1257
- async function userCommand({ args, configPath, password: flagPassword, email: flagEmail, }) {
1258
- const subcommand = args[0];
1259
- if (subcommand === undefined) {
1260
- throw new Error('geekity user add <username> needs a subcommand. The only one is: add.');
1261
- }
1262
- if (subcommand !== 'add') {
1263
- throw new Error(`Unknown user subcommand "${subcommand}". The only one is: add.`);
1264
- }
1265
- const username = args[1];
1266
- if (username === undefined) {
1267
- throw new Error('geekity user add <username> needs the name of the user to create.');
1268
- }
1269
- const password = flagPassword ?? (await readPassword({ prompt: `Password for ${username}: ` }));
1270
- const email = (flagEmail ?? '').trim();
1271
- const problem = credentialProblem(username, password) ?? emailProblem(email);
1272
- if (problem !== undefined) {
1273
- process.stderr.write(`${problem}\n`);
1274
- return 1;
1275
- }
1276
- const config = await loadResolvedConfig(configPath);
1277
- const { adminStoreOwning, openAdminDatabase } = await import('./store/admin-store.js');
1278
- const { migrateUsersToFile } = await import('./admin/legacy-migrations.js');
1279
- const { createUser, DuplicateUsernameError } = await import('./site/users.js');
1280
- const adminDb = openAdminDatabase(config.dataDir, config.now);
1281
- migrateUsersToFile(adminDb, config.dataDir);
1282
- const admin = adminStoreOwning(adminDb, databaseFile(config.dataDir), config.now);
1283
- try {
1284
- const user = await createUser({
1285
- dataDir: config.dataDir,
1286
- username,
1287
- password,
1288
- email,
1289
- now: config.now(),
1290
- });
1291
- process.stdout.write(`Created admin user ${user.username}${user.email === undefined ? '' : ` (${user.email})`}. Sign in at ${LOGIN_URL}.\n`);
1292
- return 0;
1293
- }
1294
- catch (error) {
1295
- if (error instanceof DuplicateUsernameError) {
1296
- process.stderr.write(`${error.message} Pick another name, or change that user's password from the admin.\n`);
1297
- return 1;
1298
- }
1299
- throw error;
1300
- }
1301
- finally {
1302
- admin.close();
1303
- }
1304
- }
1305
- /** Where the success line points a new admin. Relative, because the host is the site's. */
1306
- const LOGIN_URL = '/admin/login';
1307
- /** One flag as the text it carries, or `undefined` when it was not given. */
1308
- function text(flags, name) {
1309
- const value = flags[name];
1310
- return typeof value === 'string' ? value : undefined;
1311
- }
1312
- function isHelpOrVersion(arg) {
1313
- return arg === '--help' || arg === '-h' || arg === '--version' || arg === '-v';
1314
- }
1315
- /** The bare words before the first option other than `--config`. */
1316
- function leadingWords(argv) {
1317
- const words = [];
1318
- for (let i = 0; i < argv.length; i += 1) {
1319
- const arg = argv[i];
1320
- if (arg === '--config') {
1321
- i += 1;
1322
- continue;
1323
- }
1324
- if (arg.startsWith('--config='))
1325
- continue;
1326
- if (arg.startsWith('-'))
1327
- break;
1328
- words.push(arg);
1329
- }
1330
- return words;
1331
- }
1332
- /** `--config <file>` or `--config=<file>`, wherever it is. */
1333
- function configFlag(argv) {
1334
- for (let i = 0; i < argv.length; i += 1) {
1335
- const arg = argv[i];
1336
- if (arg === '--config')
1337
- return argv[i + 1];
1338
- if (arg.startsWith('--config='))
1339
- return arg.slice('--config='.length);
1340
- }
1341
- return undefined;
1342
- }
1343
- async function loadSitePlugins(config, settings) {
1344
- const folderPlugins = await importPluginFolders(scanPluginFolders(config.pluginsDir));
1345
- return sitePluginRegistry(config, folderPlugins, settings);
1346
- }
1347
- /**
1348
- * Every command the site's available plugins add, from its config and its
1349
- * plugins folder, longest words first.
1350
- */
1351
- async function pluginCommands(config) {
1352
- return (await loadSitePlugins(config, createSettings({ config }))).plugins
1353
- .filter((entry) => entry.problem === undefined)
1354
- .flatMap((entry) => entry.commands.map((command) => ({ plugin: entry.plugin.name, command })))
1355
- .sort((a, b) => b.command.words.length - a.command.words.length);
1356
- }
1357
- async function pluginExtends(first, words, configPath) {
1358
- if (COMMANDS[first].sharedWithPlugins !== true || words.length < 2)
1359
- return false;
1360
- const found = await pluginCommands(await loadResolvedConfig(configPath));
1361
- return found.some(({ command }) => command.words.every((word, index) => words[index] === word));
1362
- }
1363
- /**
1364
- * Run a command a plugin added (decision-33). It needs no enabling: a
1365
- * migration command runs before the plugin it prepares for is turned on.
1366
- *
1367
- * The database is opened for the reason `user add` opens it: a command can
1368
- * reach `data/users.json` before any server has, so a site upgrading from the
1369
- * version that kept its accounts in SQLite is migrated first. The comments
1370
- * are migrated as a boot would migrate them for the same reason: a command
1371
- * writing comments before any server has would otherwise meet ids the site
1372
- * refuses to store. Plugin settings still in `site.json` move to
1373
- * `data/plugins/<name>/` first, so the command reads what a boot would.
1374
- */
1375
- async function pluginCommand(argv) {
1376
- const configPath = configFlag(argv);
1377
- const config = await loadResolvedConfig(configPath);
1378
- const words = leadingWords(argv);
1379
- migratePluginSettings({
1380
- contentDir: config.contentDir,
1381
- dataDir: config.dataDir,
1382
- log: (line) => {
1383
- console.log(line);
1384
- },
1385
- });
1386
- const found = (await pluginCommands(config)).find(({ command }) => command.words.every((word, index) => words[index] === word));
1387
- if (found === undefined) {
1388
- throw new Error(`Unknown command "${words[0] ?? ''}". Run geekity --help to see what is available.`);
1389
- }
1390
- const { args, options } = parseCommandArgs(withoutConfig(argv).slice(found.command.words.length), found.command);
1391
- const { adminStoreOwning, openAdminDatabase } = await import('./store/admin-store.js');
1392
- const { migrateUsersToFile } = await import('./admin/legacy-migrations.js');
1393
- const { migrateCommentEmails, migrateCommentKeys } = await import('./comments/migrations.js');
1394
- const { pluginSite } = await import('./plugins/site.js');
1395
- const adminDb = openAdminDatabase(config.dataDir, config.now);
1396
- migrateUsersToFile(adminDb, config.dataDir);
1397
- const admin = adminStoreOwning(adminDb, databaseFile(config.dataDir), config.now);
1398
- const comments = { contentDir: config.contentDir, dataDir: config.dataDir };
1399
- migrateCommentEmails(comments);
1400
- migrateCommentKeys(comments);
1401
- try {
1402
- return await found.command.run({
1403
- args,
1404
- options,
1405
- cwd: process.cwd(),
1406
- site: pluginSite({ admin, config }),
1407
- write: (output) => process.stdout.write(output),
1408
- });
1409
- }
1410
- finally {
1411
- admin.close();
1412
- }
1413
- }
1414
- function withoutConfig(argv) {
1415
- const kept = [];
1416
- for (let i = 0; i < argv.length; i += 1) {
1417
- const arg = argv[i];
1418
- if (arg === '--config') {
1419
- i += 1;
1420
- continue;
1421
- }
1422
- if (!arg.startsWith('--config='))
1423
- kept.push(arg);
1424
- }
1425
- return kept;
1426
- }
1427
- /** A plugin command's arguments and options, refusing any option it does not take. */
1428
- function parseCommandArgs(argv, command) {
1429
- const args = [];
1430
- const options = {};
1431
- for (let i = 0; i < argv.length; i += 1) {
1432
- const arg = argv[i];
1433
- if (!arg.startsWith('--')) {
1434
- args.push(arg);
1435
- continue;
1436
- }
1437
- const equals = arg.indexOf('=');
1438
- const name = equals === -1 ? arg.slice(2) : arg.slice(2, equals);
1439
- const inline = equals === -1 ? undefined : arg.slice(equals + 1);
1440
- const option = command.options?.find((entry) => entry.name === name);
1441
- if (option === undefined) {
1442
- throw new Error(`Unknown option "--${name}". Run geekity --help to see what is available.`);
1443
- }
1444
- if (option.value === undefined) {
1445
- if (inline !== undefined)
1446
- throw new Error(`--${name} takes no value.`);
1447
- options[name] = true;
1448
- continue;
1449
- }
1450
- if (inline !== undefined) {
1451
- if (inline === '')
1452
- throw new Error(`--${name} needs a value.`);
1453
- options[name] = inline;
1454
- continue;
1455
- }
1456
- const value = argv[i + 1];
1457
- if (value === undefined || value.startsWith('-'))
1458
- throw new Error(`--${name} needs a value.`);
1459
- options[name] = value;
1460
- i += 1;
1461
- }
1462
- return { args, options };
1463
- }
1464
- /**
1465
- * The help, with the commands the site's plugins add. A config that will not
1466
- * load costs the help its plugin section, not the help itself.
1467
- */
1468
- async function usage(configPath) {
1469
- let found;
1470
- try {
1471
- found = await pluginCommands(await loadResolvedConfig(configPath));
1472
- }
1473
- catch (error) {
1474
- process.stderr.write(`Plugin commands are not listed: ${messageOf(error)}\n`);
1475
- return coreUsage();
1476
- }
1477
- if (found.length === 0)
1478
- return coreUsage();
1479
- const lines = ['', 'Plugin commands:'];
1480
- for (const { plugin, command } of found) {
1481
- const synopsis = wrap(`geekity ${[...command.words, command.usage].join(' ').trim()} [--config <file>]`, USAGE_CONTINUATION);
1482
- lines.push(` ${(synopsis[0] ?? '').trimStart()}`, ...synopsis.slice(1));
1483
- lines.push(...wrap(command.summary, HELP_INDENT), `${HELP_INDENT}From ${plugin}.`);
1484
- for (const option of command.options ?? []) {
1485
- const flag = `--${option.name}${option.value === undefined ? '' : ` ${option.value}`}`;
1486
- lines.push(...helpEntry(` ${flag}`, wrap(option.description, HELP_INDENT)));
1487
- }
1488
- }
1489
- return `${coreUsage()}${lines.join('\n')}\n`;
1490
- }
1491
- function coreUsage() {
1492
- const entries = Object.values(COMMANDS);
1493
- return [
1494
- 'geekity — the Geekity CMS command line',
1495
- '',
1496
- 'Usage:',
1497
- ...entries.flatMap((entry) => entry.synopsis.map((line) => ` geekity ${line}`)),
1498
- '',
1499
- 'Commands:',
1500
- ...entries.flatMap((entry) => entry.help.flatMap(([words, summary]) => helpEntry(` ${words}`, summary.map((line) => `${HELP_INDENT}${line}`)))),
1501
- '',
1502
- OPTIONS_HELP,
1503
- ].join('\n');
1504
- }
1505
- function helpEntry(head, described) {
1506
- if (head.length < HELP_INDENT.length - 1 && described[0] !== undefined) {
1507
- described[0] = `${head.padEnd(HELP_INDENT.length)}${described[0].trimStart()}`;
1508
- return described;
1509
- }
1510
- return [head, ...described];
1511
- }
1512
- /** Where the help's descriptions start, as the core commands' do. */
1513
- const HELP_INDENT = ' '.repeat(19);
1514
- /** Where a usage line carries on, as the core commands' do. */
1515
- const USAGE_CONTINUATION = ' '.repeat(10);
1516
- const HELP_WIDTH = 79;
1517
- /** Text wrapped to the help's width, each line indented. */
1518
- function wrap(text, indent) {
1519
- const lines = [];
1520
- let line = '';
1521
- for (const word of text.split(/\s+/).filter((entry) => entry !== '')) {
1522
- if (line !== '' && indent.length + line.length + 1 + word.length > HELP_WIDTH) {
1523
- lines.push(`${indent}${line}`);
1524
- line = word;
1525
- }
1526
- else {
1527
- line = line === '' ? word : `${line} ${word}`;
1528
- }
1529
- }
1530
- if (line !== '')
1531
- lines.push(`${indent}${line}`);
1532
- return lines;
1533
- }
1534
- /**
1535
- * Ask for a password once, without putting it on the screen.
1536
- *
1537
- * Two things would otherwise echo it, and both are turned off: the terminal
1538
- * driver, silenced by putting the input into raw mode, and readline, whose
1539
- * output goes to a writable that keeps nothing. Readline happens to set raw
1540
- * mode itself, but it is set here as well rather than relied on: the day that
1541
- * changes, a password would be printed. Raw mode also means readline sees
1542
- * Ctrl-C as a byte rather than a signal, so it is turned back into a
1543
- * cancellation here.
1544
- *
1545
- * Off a terminal — a pipe, a heredoc, a CI job — nothing is printed and the
1546
- * first line is the password, which is what makes
1547
- * `printf '%s\n' "$PW" | geekity user add ada` work.
1548
- */
1549
- export async function readPassword(options = {}) {
1550
- const input = options.input ?? process.stdin;
1551
- const output = options.output ?? process.stderr;
1552
- const terminal = input.isTTY === true;
1553
- if (terminal && options.prompt !== undefined)
1554
- output.write(options.prompt);
1555
- const wasRaw = input.isRaw === true;
1556
- if (terminal)
1557
- input.setRawMode?.(true);
1558
- const muted = new Writable({
1559
- write(_chunk, _encoding, callback) {
1560
- callback();
1561
- },
1562
- });
1563
- const reader = createInterface({ input, output: muted, terminal });
1564
- let cancelled = false;
1565
- reader.on('SIGINT', () => {
1566
- cancelled = true;
1567
- reader.close();
1568
- });
1569
- try {
1570
- for await (const line of reader) {
1571
- if (!cancelled)
1572
- return line;
1573
- break;
1574
- }
1575
- }
1576
- finally {
1577
- reader.close();
1578
- if (terminal) {
1579
- input.setRawMode?.(wasRaw);
1580
- // The terminal is left on the line the swallowed newline never printed.
1581
- output.write('\n');
1582
- }
1583
- input.pause();
1584
- }
1585
- if (cancelled)
1586
- throw new Error('Cancelled; no user was created.');
1587
- throw new Error('No password was given: standard input ended before a line arrived. Pass --password, or ' +
1588
- 'pipe the password in as a single line.');
1589
- }
1590
30
  /**
1591
31
  * True when this module is the process entry point.
1592
32
  *