@fedify/cli 1.8.11 → 2.0.0-dev.1757

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 (130) hide show
  1. package/deno.json +72 -0
  2. package/dist/cache.js +17 -0
  3. package/dist/deno.js +72 -0
  4. package/dist/docloader.js +52 -0
  5. package/dist/globals.js +49 -0
  6. package/dist/imagerenderer.js +105 -0
  7. package/dist/inbox/rendercode.js +57 -0
  8. package/dist/inbox/view.js +508 -0
  9. package/dist/inbox.js +315 -0
  10. package/dist/init/action/configs.js +81 -0
  11. package/dist/init/action/deps.js +52 -0
  12. package/dist/init/action/dir.js +16 -0
  13. package/dist/init/action/env.js +13 -0
  14. package/dist/init/action/install.js +22 -0
  15. package/dist/init/action/mod.js +39 -0
  16. package/dist/init/action/notice.js +62 -0
  17. package/dist/init/action/patch.js +141 -0
  18. package/dist/init/action/precommand.js +23 -0
  19. package/dist/init/action/recommend.js +24 -0
  20. package/dist/init/action/set.js +31 -0
  21. package/dist/init/action/templates.js +57 -0
  22. package/dist/init/action/utils.js +50 -0
  23. package/dist/init/ask/dir.js +82 -0
  24. package/dist/init/ask/kv.js +33 -0
  25. package/dist/init/ask/mod.js +16 -0
  26. package/dist/init/ask/mq.js +33 -0
  27. package/dist/init/ask/pm.js +49 -0
  28. package/dist/init/ask/wf.js +29 -0
  29. package/dist/init/command.js +25 -0
  30. package/dist/init/const.js +31 -0
  31. package/dist/init/json/biome.js +24 -0
  32. package/dist/init/json/kv.js +53 -0
  33. package/dist/init/json/mq.js +72 -0
  34. package/dist/init/json/pm.js +44 -0
  35. package/dist/init/json/rt.js +39 -0
  36. package/dist/init/json/vscode-settings-for-deno.js +53 -0
  37. package/dist/init/json/vscode-settings.js +49 -0
  38. package/dist/init/lib.js +129 -0
  39. package/dist/init/mod.js +5 -0
  40. package/dist/init/webframeworks.js +133 -0
  41. package/dist/kv.bun.js +17 -0
  42. package/dist/kv.node.js +17 -0
  43. package/dist/log.js +52 -0
  44. package/dist/lookup.js +287 -0
  45. package/dist/mod.js +34 -0
  46. package/dist/nodeinfo.js +261 -0
  47. package/dist/table.js +24 -0
  48. package/dist/tempserver.js +71 -0
  49. package/dist/tunnel.js +21 -0
  50. package/dist/utils.js +67 -0
  51. package/dist/webfinger/action.js +44 -0
  52. package/dist/webfinger/command.js +20 -0
  53. package/dist/webfinger/error.js +47 -0
  54. package/dist/webfinger/lib.js +45 -0
  55. package/dist/webfinger/mod.js +5 -0
  56. package/package.json +64 -24
  57. package/scripts/pack.ts +64 -0
  58. package/src/cache.ts +17 -0
  59. package/src/docloader.ts +67 -0
  60. package/src/globals.ts +43 -0
  61. package/src/imagerenderer.ts +149 -0
  62. package/src/inbox/entry.ts +10 -0
  63. package/src/inbox/rendercode.ts +68 -0
  64. package/src/inbox/view.tsx +598 -0
  65. package/src/inbox.tsx +535 -0
  66. package/src/init/action/configs.ts +88 -0
  67. package/src/init/action/deps.ts +93 -0
  68. package/src/init/action/dir.ts +11 -0
  69. package/src/init/action/env.ts +14 -0
  70. package/src/init/action/install.ts +59 -0
  71. package/src/init/action/mod.ts +66 -0
  72. package/src/init/action/notice.ts +101 -0
  73. package/src/init/action/patch.ts +212 -0
  74. package/src/init/action/precommand.ts +22 -0
  75. package/src/init/action/recommend.ts +38 -0
  76. package/src/init/action/set.ts +78 -0
  77. package/src/init/action/templates.ts +95 -0
  78. package/src/init/action/utils.ts +64 -0
  79. package/src/init/ask/dir.ts +98 -0
  80. package/src/init/ask/kv.ts +39 -0
  81. package/src/init/ask/mod.ts +23 -0
  82. package/src/init/ask/mq.ts +37 -0
  83. package/src/init/ask/pm.ts +58 -0
  84. package/src/init/ask/wf.ts +27 -0
  85. package/src/init/command.ts +64 -0
  86. package/src/init/const.ts +4 -0
  87. package/src/init/json/biome.json +17 -0
  88. package/src/init/json/kv.json +39 -0
  89. package/src/init/json/mq.json +95 -0
  90. package/src/init/json/pm.json +47 -0
  91. package/src/init/json/rt.json +42 -0
  92. package/src/init/json/vscode-settings-for-deno.json +43 -0
  93. package/src/init/json/vscode-settings.json +41 -0
  94. package/src/init/lib.ts +220 -0
  95. package/src/init/mod.ts +2 -0
  96. package/src/init/templates/defaults/federation.ts.tpl +23 -0
  97. package/src/init/templates/defaults/logging.ts.tpl +23 -0
  98. package/src/init/templates/express/app.ts.tpl +16 -0
  99. package/src/init/templates/express/index.ts.tpl +6 -0
  100. package/src/init/templates/hono/app.tsx.tpl +14 -0
  101. package/src/init/templates/hono/index/bun.ts.tpl +10 -0
  102. package/src/init/templates/hono/index/deno.ts.tpl +13 -0
  103. package/src/init/templates/hono/index/node.ts.tpl +14 -0
  104. package/src/init/templates/next/middleware.ts.tpl +45 -0
  105. package/src/init/templates/nitro/nitro.config.ts.tpl +5 -0
  106. package/src/init/templates/nitro/server/error.ts.tpl +3 -0
  107. package/src/init/templates/nitro/server/middleware/federation.ts.tpl +8 -0
  108. package/src/init/types.ts +88 -0
  109. package/src/init/webframeworks.ts +151 -0
  110. package/src/kv.bun.ts +12 -0
  111. package/src/kv.node.ts +11 -0
  112. package/src/log.ts +64 -0
  113. package/src/lookup.test.ts +182 -0
  114. package/src/lookup.ts +558 -0
  115. package/src/mod.ts +45 -0
  116. package/src/nodeinfo.test.ts +229 -0
  117. package/src/nodeinfo.ts +447 -0
  118. package/src/table.ts +17 -0
  119. package/src/tempserver.ts +87 -0
  120. package/src/tunnel.ts +32 -0
  121. package/src/utils.ts +136 -0
  122. package/src/webfinger/action.ts +50 -0
  123. package/src/webfinger/command.ts +59 -0
  124. package/src/webfinger/error.ts +47 -0
  125. package/src/webfinger/lib.ts +37 -0
  126. package/src/webfinger/mod.test.ts +79 -0
  127. package/src/webfinger/mod.ts +2 -0
  128. package/tsdown.config.ts +24 -0
  129. package/src/install.mjs +0 -189
  130. package/src/run.mjs +0 -22
@@ -0,0 +1,95 @@
1
+ import { entries, join, map, pipe } from "@fxts/core";
2
+ import { toMerged } from "es-toolkit";
3
+ import { replace } from "../../utils.ts";
4
+ import { readTemplate } from "../lib.ts";
5
+ import type { InitCommandData, PackageManager } from "../types.ts";
6
+
7
+ /**
8
+ * Loads the federation configuration file content from template.
9
+ * Reads the default federation template and replaces placeholders with actual configuration values.
10
+ *
11
+ * @param param0 - Configuration object containing imports, project name, KV store, message queue, and package manager
12
+ * @returns The complete federation configuration file content as a string
13
+ */
14
+ export const loadFederation = (
15
+ {
16
+ imports,
17
+ projectName,
18
+ kv,
19
+ mq,
20
+ packageManager,
21
+ }: InitCommandData & { imports: string },
22
+ ) =>
23
+ pipe(
24
+ "defaults/federation.ts",
25
+ readTemplate,
26
+ replace(/\/\* imports \*\//, imports),
27
+ replace(/\/\* logger \*\//, JSON.stringify(projectName)),
28
+ replace(/\/\* kv \*\//, convertEnv(kv.object, packageManager)),
29
+ replace(/\/\* queue \*\//, convertEnv(mq.object, packageManager)),
30
+ );
31
+
32
+ /**
33
+ * Loads the logging configuration file content from template.
34
+ * Reads the default logging template and replaces the project name placeholder.
35
+ *
36
+ * @param param0 - Destructured object containing the project name
37
+ * @returns The complete logging configuration file content as a string
38
+ */
39
+ export const loadLogging = ({ projectName }: InitCommandData) =>
40
+ pipe(
41
+ "defaults/logging.ts",
42
+ readTemplate,
43
+ replace(/\/\* project name \*\//, JSON.stringify(projectName)),
44
+ );
45
+
46
+ /**
47
+ * Generates import statements for KV store and message queue dependencies.
48
+ * Merges imports from both KV and MQ configurations and creates proper ES module import syntax.
49
+ *
50
+ * @param param0 - Destructured object containing kv and mq configurations
51
+ * @returns A multi-line string containing all necessary import statements
52
+ */
53
+ export const getImports = ({ kv, mq }: InitCommandData) =>
54
+ pipe(
55
+ toMerged(kv.imports, mq.imports),
56
+ entries,
57
+ map(([module, { "default": defaultImport = "", ...imports }]) => //
58
+ [module, defaultImport, getAlias(imports)]),
59
+ map(([module, defaultImport, namedImports]) =>
60
+ `import ${
61
+ [defaultImport, namedImports.length > 0 ? `{ ${namedImports} }` : ""]
62
+ .filter((x) => x.length > 0)
63
+ .join(", ")
64
+ } from ${JSON.stringify(module)};`
65
+ ),
66
+ join("\n"),
67
+ );
68
+
69
+ /**
70
+ * Converts import mappings to named import string with aliases.
71
+ * Creates proper ES module named import syntax, using aliases when the import name differs from the local name.
72
+ *
73
+ * @param imports - A record mapping import names to their local aliases
74
+ * @returns A comma-separated string of named imports with aliases where needed
75
+ */
76
+ export const getAlias = (imports: Record<string, string>) =>
77
+ pipe(
78
+ imports,
79
+ entries,
80
+ map(([name, alias]) => name === alias ? name : `${name} as ${alias}`),
81
+ join(", "),
82
+ );
83
+
84
+ /**
85
+ * Converts Node.js environment variable access to Deno-compatible syntax when needed.
86
+ * Transforms `process.env.VAR_NAME` to `Deno.env.get("VAR_NAME")` for Deno projects.
87
+ *
88
+ * @param obj - The object string containing potential environment variable references
89
+ * @param pm - The package manager (runtime) being used
90
+ * @returns The converted object string with appropriate environment variable access syntax
91
+ */
92
+ export const convertEnv = (obj: string, pm: PackageManager) =>
93
+ pm === "deno" && /process\.env\.(\w+)/.test(obj)
94
+ ? obj.replaceAll(/process\.env\.(\w+)/, (_, g1) => `Deno.env.get("${g1}")`)
95
+ : obj;
@@ -0,0 +1,64 @@
1
+ import { join as joinPath } from "node:path";
2
+ import type { InitCommandData } from "../types.ts";
3
+
4
+ export const isDry = ({ dryRun }: InitCommandData) => dryRun;
5
+
6
+ export const hasCommand = (data: InitCommandData) => !!data.initializer.command;
7
+
8
+ export const isDeno = (
9
+ { packageManager }: InitCommandData,
10
+ ) => packageManager === "deno";
11
+
12
+ export const joinDir =
13
+ (dir: string) => ([filename, content]: readonly [string, string | object]) =>
14
+ [joinPath(dir, ...filename.split("/")), content] as [
15
+ string,
16
+ string | object,
17
+ ];
18
+
19
+ /**
20
+ * Stringify an object into a valid `.env` file format.
21
+ * From `@std/dotenv/stringify`.
22
+ *
23
+ * @example Usage
24
+ * ```ts
25
+ * import { stringifyEnvs } from "./utils.ts";
26
+ * import { assertEquals } from "@std/assert";
27
+ *
28
+ * const object = { GREETING: "hello world" };
29
+ * assertEquals(stringifyEnvs(object), "GREETING='hello world'");
30
+ * ```
31
+ *
32
+ * @param object object to be stringified
33
+ * @returns string of object
34
+ */
35
+ export function stringifyEnvs(object: Record<string, string>): string {
36
+ const lines: string[] = [];
37
+ for (const [key, value] of Object.entries(object)) {
38
+ let quote;
39
+
40
+ let escapedValue = value ?? "";
41
+ if (key.startsWith("#")) {
42
+ // deno-lint-ignore no-console
43
+ console.warn(
44
+ `key starts with a '#' indicates a comment and is ignored: '${key}'`,
45
+ );
46
+ continue;
47
+ } else if (escapedValue.includes("\n") || escapedValue.includes("'")) {
48
+ // escape inner new lines
49
+ escapedValue = escapedValue.replaceAll("\n", "\\n");
50
+ quote = `"`;
51
+ } else if (escapedValue.match(/\W/)) {
52
+ quote = "'";
53
+ }
54
+
55
+ if (quote) {
56
+ // escape inner quotes
57
+ escapedValue = escapedValue.replaceAll(quote, `\\${quote}`);
58
+ escapedValue = `${quote}${escapedValue}${quote}`;
59
+ }
60
+ const line = `${key}=${escapedValue}`;
61
+ lines.push(line);
62
+ }
63
+ return lines.join("\n");
64
+ }
@@ -0,0 +1,98 @@
1
+ import { identity, pipe, when } from "@fxts/core";
2
+ import { input } from "@inquirer/prompts";
3
+ import { message } from "@optique/core/message";
4
+ import { printError } from "@optique/run";
5
+ import toggle from "inquirer-toggle";
6
+ import { getCwd, getOsType, runSubCommand } from "../../utils.ts";
7
+ import { isDirectoryEmpty, logger } from "../lib.ts";
8
+
9
+ /**
10
+ * Fills in the project directory by prompting the user if not provided.
11
+ * If the directory is not empty, asks the user whether to use it anyway.
12
+ * If the user agrees, offers to move existing contents to trash.
13
+ * Else, recursively prompts for a new directory until a valid one is provided.
14
+ *
15
+ * @param options - Initialization options possibly containing a directory
16
+ * @returns A promise resolving to options with a guaranteed directory
17
+ */
18
+ const fillDir: <T extends { dir?: string }>(
19
+ options: T,
20
+ ) => Promise<T & { dir: string }> = async (options) => {
21
+ const dir = options.dir ?? await askDir(getCwd());
22
+ return await askIfNonEmpty(dir)
23
+ ? { ...options, dir }
24
+ : await fillDir(options);
25
+ };
26
+
27
+ export default fillDir;
28
+
29
+ const askDir = (cwd: string) =>
30
+ input({ message: "Project directory:", default: cwd });
31
+
32
+ const askIfNonEmpty = async (dir: string) => {
33
+ if (await isDirectoryEmpty(dir)) return true;
34
+ if (await askNonEmpty(dir)) return await moveDirToTrash(dir);
35
+ return false;
36
+ };
37
+
38
+ const askNonEmpty = (dir: string) =>
39
+ toggle.default({
40
+ message: `Directory "${dir}" is not empty.
41
+ Do you want to use it anyway?`,
42
+ default: false,
43
+ });
44
+
45
+ const moveDirToTrash = (dir: string) =>
46
+ pipe(dir, askMoveToTrash, when(identity, moveToTrash(dir)));
47
+
48
+ const askMoveToTrash = (dir: string) =>
49
+ toggle.default({
50
+ message: `Do you want to move the contents of "${dir}" to the trash?
51
+ If you choose "No", you should choose another directory.`,
52
+ default: false,
53
+ });
54
+
55
+ const moveToTrash = (dir: string) => () =>
56
+ pipe(
57
+ getOsType(),
58
+ getTrashCommand,
59
+ (fn) => fn(dir),
60
+ (cmd) => runSubCommand(cmd, { stdio: "ignore" }),
61
+ () => true,
62
+ ).catch((e) => {
63
+ logger.error(e);
64
+ printError(message`Failed to move ${dir} to trash.
65
+ Please move it manually.`);
66
+ return false;
67
+ });
68
+
69
+ const getTrashCommand = (os: NodeJS.Platform) =>
70
+ trashCommands[os as keyof typeof trashCommands] ?? trashCommands.linux;
71
+
72
+ const trashCommands: Record<
73
+ Extract<NodeJS.Platform, "darwin" | "win32" | "linux">,
74
+ (dir: string) => string[]
75
+ > = {
76
+ // mac
77
+ darwin: (dir: string) => ["trash", dir],
78
+ // windows
79
+ win32: (dir: string) => [
80
+ "powershell",
81
+ "-Command",
82
+ getPowershellTrashCommand(dir),
83
+ ],
84
+ // other unix
85
+ linux: (dir: string) => ["rm", "-rf", dir],
86
+ };
87
+
88
+ const getPowershellTrashCommand = (dir: string) =>
89
+ [
90
+ "Add-Type",
91
+ "-AssemblyName",
92
+ "Microsoft.VisualBasic;",
93
+ "[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteDirectory('",
94
+ dir,
95
+ "',",
96
+ "'OnlyErrorDialogs',",
97
+ "'SendToRecycleBin')",
98
+ ].join(" ");
@@ -0,0 +1,39 @@
1
+ import { select } from "@inquirer/prompts";
2
+ import { KV_STORE } from "../const.ts";
3
+ import { kvStores } from "../lib.ts";
4
+ import type { KvStore, PackageManager } from "../types.ts";
5
+
6
+ /**
7
+ * Fills in the key-value store by prompting the user if not provided.
8
+ * Ensures the selected KV store is compatible with the chosen package manager.
9
+ *
10
+ * @param options - Initialization options possibly containing a kvStore and packageManager
11
+ * @returns A promise resolving to options with a guaranteed kvStore
12
+ */
13
+ const fillKvStore: //
14
+ <T extends { kvStore?: KvStore; packageManager: PackageManager }>(
15
+ options: T,
16
+ ) => Promise<T & { kvStore: KvStore }> = async (options) => //
17
+ ({
18
+ ...options,
19
+ kvStore: options.kvStore ?? await askKvStore(options.packageManager),
20
+ });
21
+
22
+ export default fillKvStore;
23
+
24
+ const askKvStore = (pm: PackageManager) =>
25
+ select<KvStore>({
26
+ message: "Choose the key-value store to use",
27
+ choices: KV_STORE.map(choiceKvStore(pm)),
28
+ });
29
+
30
+ const choiceKvStore = (pm: PackageManager) => (value: KvStore) => ({
31
+ name: isKvSupportsPm(value, pm)
32
+ ? value
33
+ : `${value} (not supported with ${pm})`,
34
+ value,
35
+ disabled: !isKvSupportsPm(value, pm),
36
+ });
37
+
38
+ const isKvSupportsPm = (kv: KvStore, pm: PackageManager) =>
39
+ kvStores[kv].packageManagers.includes(pm);
@@ -0,0 +1,23 @@
1
+ import { pipe } from "@fxts/core";
2
+ import type { RequiredNotNull } from "../../utils.ts";
3
+ import type { InitCommand } from "../command.ts";
4
+ import fillDir from "./dir.ts";
5
+ import fillKvStore from "./kv.ts";
6
+ import fillMessageQueue from "./mq.ts";
7
+ import fillPackageManager from "./pm.ts";
8
+ import fillWebFramework from "./wf.ts";
9
+
10
+ const askOptions: (
11
+ options: InitCommand,
12
+ ) => Promise<RequiredNotNull<InitCommand>> = //
13
+ (options) =>
14
+ pipe(
15
+ options,
16
+ fillDir,
17
+ fillWebFramework,
18
+ fillPackageManager,
19
+ fillMessageQueue,
20
+ fillKvStore,
21
+ );
22
+
23
+ export default askOptions;
@@ -0,0 +1,37 @@
1
+ import { select } from "@inquirer/prompts";
2
+ import { MESSAGE_QUEUE } from "../const.ts";
3
+ import { messageQueues } from "../lib.ts";
4
+ import type { MessageQueue, PackageManager } from "../types.ts";
5
+
6
+ /**
7
+ * Fills in the message queue by prompting the user if not provided.
8
+ * Ensures the selected message queue is compatible with the chosen package manager.
9
+ *
10
+ * @param options - Initialization options possibly containing a messageQueue and packageManager
11
+ * @returns A promise resolving to options with a guaranteed messageQueue
12
+ */
13
+ const fillMessageQueue: //
14
+ <T extends { messageQueue?: MessageQueue; packageManager: PackageManager }> //
15
+ (options: T) => Promise<T & { messageQueue: MessageQueue }> = //
16
+ async (options) => ({
17
+ ...options,
18
+ messageQueue: options.messageQueue ??
19
+ await askMessageQueue(options.packageManager),
20
+ });
21
+
22
+ export default fillMessageQueue;
23
+
24
+ const askMessageQueue = (pm: PackageManager) =>
25
+ select<MessageQueue>({
26
+ message: "Choose the message queue to use",
27
+ choices: MESSAGE_QUEUE.map(choiceMessageQueue(pm)),
28
+ });
29
+ const choiceMessageQueue = (pm: PackageManager) => (value: MessageQueue) => ({
30
+ name: isMqSupportsPm(value, pm)
31
+ ? value
32
+ : `${value} (not supported with ${pm})`,
33
+ value,
34
+ disabled: !isMqSupportsPm(value, pm),
35
+ });
36
+ const isMqSupportsPm = (mq: MessageQueue, pm: PackageManager) =>
37
+ messageQueues[mq].packageManagers.includes(pm);
@@ -0,0 +1,58 @@
1
+ import { select } from "@inquirer/prompts";
2
+ import { message } from "@optique/core/message";
3
+ import { print } from "@optique/run";
4
+ import { PACKAGE_MANAGER } from "../const.ts";
5
+ import { getInstallUrl, getLabel, isPackageManagerAvailable } from "../lib.ts";
6
+ import type { PackageManager, WebFramework } from "../types.ts";
7
+ import webFrameworks from "../webframeworks.ts";
8
+
9
+ /**
10
+ * Fills in the package manager by prompting the user if not provided.
11
+ * Ensures the selected package manager is compatible with the chosen web framework.
12
+ * If the selected package manager is not installed, informs the user and prompts again.
13
+ *
14
+ * @param options - Initialization options possibly containing a packageManager and webFramework
15
+ * @returns A promise resolving to options with a guaranteed packageManager
16
+ */
17
+ const fillPackageManager: //
18
+ <T extends { packageManager?: PackageManager; webFramework: WebFramework }> //
19
+ (options: T) => //
20
+ Promise<Omit<T, "packageManager"> & { packageManager: PackageManager }> = //
21
+ async ({ packageManager, ...options }) => {
22
+ const pm = packageManager ?? await askPackageManager(options.webFramework);
23
+ if (await isPackageManagerAvailable(pm)) {
24
+ return ({ ...options, packageManager: pm });
25
+ }
26
+ noticeInstallUrl(pm);
27
+ return await fillPackageManager(options) as //
28
+ typeof options & { packageManager: PackageManager };
29
+ };
30
+
31
+ export default fillPackageManager;
32
+
33
+ const askPackageManager = (wf: WebFramework) =>
34
+ select<PackageManager>({
35
+ message: "Choose the package manager to use",
36
+ choices: PACKAGE_MANAGER.map(choicePackageManager(wf)),
37
+ });
38
+
39
+ const choicePackageManager = (wf: WebFramework) => (value: PackageManager) => ({
40
+ name: isWfSupportsPm(wf, value)
41
+ ? value
42
+ : `${value} (not supported with ${webFrameworks[wf].label})`,
43
+ value,
44
+ disabled: !isWfSupportsPm(wf, value),
45
+ });
46
+
47
+ const isWfSupportsPm = (
48
+ wf: WebFramework,
49
+ pm: PackageManager,
50
+ ) => webFrameworks[wf].packageManagers.includes(pm);
51
+
52
+ const noticeInstallUrl = (pm: PackageManager) => {
53
+ const label = getLabel(pm);
54
+ const url = getInstallUrl(pm);
55
+ print(message` Package manager ${label} is not installed.`);
56
+ print(message` You can install it from following link: ${url}`);
57
+ print(message` or choose another package manager:`);
58
+ };
@@ -0,0 +1,27 @@
1
+ import { select } from "@inquirer/prompts";
2
+ import { WEB_FRAMEWORK } from "../const.ts";
3
+ import type { WebFramework } from "../types.ts";
4
+ import webFrameworks from "../webframeworks.ts";
5
+
6
+ /**
7
+ * Fills in the web framework by prompting the user if not provided.
8
+ *
9
+ * @param options - Initialization options possibly containing a webFramework
10
+ * @returns A promise resolving to options with a guaranteed webFramework
11
+ */
12
+ const fillWebFramework: //
13
+ <T extends { webFramework?: WebFramework }>(options: T) => //
14
+ Promise<T & { webFramework: WebFramework }> = async (options) => //
15
+ ({
16
+ ...options,
17
+ webFramework: options.webFramework ?? await askWebFramework(),
18
+ });
19
+
20
+ export default fillWebFramework;
21
+
22
+ const askWebFramework = () =>
23
+ select<WebFramework>({
24
+ message: "Choose the web framework to use",
25
+ choices: WEB_FRAMEWORK.map((value) => //
26
+ ({ name: webFrameworks[value].label, value })),
27
+ });
@@ -0,0 +1,64 @@
1
+ import {
2
+ argument,
3
+ choice,
4
+ command,
5
+ constant,
6
+ type InferValue,
7
+ message,
8
+ object,
9
+ option,
10
+ optional,
11
+ } from "@optique/core";
12
+ import { path } from "@optique/run";
13
+ import {
14
+ KV_STORE,
15
+ MESSAGE_QUEUE,
16
+ PACKAGE_MANAGER,
17
+ WEB_FRAMEWORK,
18
+ } from "./const.ts";
19
+
20
+ const joinSep = (str: readonly string[]) => str.join(" | ");
21
+ const webFramework = optional(option(
22
+ "-w",
23
+ "--web-framework",
24
+ choice(WEB_FRAMEWORK, {
25
+ metavar: `WEB_FRAMEWORK: ${joinSep(WEB_FRAMEWORK)}`,
26
+ }),
27
+ ));
28
+ const packageManager = optional(option(
29
+ "-p",
30
+ "--package-manager",
31
+ choice(PACKAGE_MANAGER, {
32
+ metavar: `PACKAGE_MANAGER: ${joinSep(PACKAGE_MANAGER)}`,
33
+ }),
34
+ ));
35
+ const kvStore = optional(option(
36
+ "-k",
37
+ "--kv-store",
38
+ choice(KV_STORE, { metavar: `KV_STORE: ${joinSep(KV_STORE)}` }),
39
+ ));
40
+ const messageQueue = optional(option(
41
+ "-m",
42
+ "--message-queue",
43
+ choice(MESSAGE_QUEUE, {
44
+ metavar: `MESSAGE_QUEUE: ${joinSep(MESSAGE_QUEUE)}`,
45
+ }),
46
+ ));
47
+
48
+ export const initCommand = command(
49
+ "init",
50
+ object({
51
+ command: constant("init"),
52
+ dir: optional(argument(path({ metavar: "DIRECTORY" }))),
53
+ webFramework,
54
+ packageManager,
55
+ kvStore,
56
+ messageQueue,
57
+ dryRun: option("-d", "--dry-run"),
58
+ }),
59
+ {
60
+ description: message`Initialize a new Fedify project directory.`,
61
+ },
62
+ );
63
+
64
+ export type InitCommand = InferValue<typeof initCommand>;
@@ -0,0 +1,4 @@
1
+ export const PACKAGE_MANAGER = ["deno", "pnpm", "bun", "yarn", "npm"] as const;
2
+ export const WEB_FRAMEWORK = ["hono", "nitro", "next", "express"] as const;
3
+ export const MESSAGE_QUEUE = ["denokv", "redis", "postgres", "amqp"] as const;
4
+ export const KV_STORE = ["denokv", "redis", "postgres"] as const;
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
3
+ "organizeImports": {
4
+ "enabled": true
5
+ },
6
+ "formatter": {
7
+ "enabled": true,
8
+ "indentStyle": "space",
9
+ "indentWidth": 2
10
+ },
11
+ "linter": {
12
+ "enabled": true,
13
+ "rules": {
14
+ "recommended": true
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "redis": {
3
+ "label": "Redis",
4
+ "packageManagers": ["deno", "bun", "npm", "yarn", "pnpm"],
5
+ "dependencies": {
6
+ "npm:ioredis": "^5.4.1"
7
+ },
8
+ "imports": {
9
+ "@fedify/redis": { "RedisKvStore": "RedisKvStore" },
10
+ "ioredis": { "Redis": "Redis" }
11
+ },
12
+ "object": "new RedisKvStore(new Redis(process.env.REDIS_URL))",
13
+ "env": {
14
+ "REDIS_URL": "redis://localhost:6379"
15
+ }
16
+ },
17
+ "postgres": {
18
+ "label": "PostgreSQL",
19
+ "packageManagers": ["deno", "bun", "npm", "yarn", "pnpm"],
20
+ "dependencies": {
21
+ "npm:postgres": "^3.4.5"
22
+ },
23
+ "imports": {
24
+ "@fedify/postgres": { "PostgresKvStore": "PostgresKvStore" },
25
+ "postgres": { "default": "postgres" }
26
+ },
27
+ "object": "new PostgresKvStore(postgres(process.env.DATABASE_URL))",
28
+ "env": {
29
+ "DATABASE_URL": "postgres://postgres@localhost:5432/postgres"
30
+ }
31
+ },
32
+ "denokv": {
33
+ "label": "Deno KV",
34
+ "packageManagers": ["deno"],
35
+ "imports": { "@fedify/denokv": { "DenoKvStore": "DenoKvStore" } },
36
+ "object": "new DenoKvStore(await Deno.openKv())",
37
+ "denoUnstable": ["kv"]
38
+ }
39
+ }
@@ -0,0 +1,95 @@
1
+ {
2
+ "redis": {
3
+ "label": "Redis",
4
+ "packageManagers": [
5
+ "deno",
6
+ "bun",
7
+ "npm",
8
+ "yarn",
9
+ "pnpm"
10
+ ],
11
+ "dependencies": {
12
+ "npm:ioredis": "^5.4.1"
13
+ },
14
+ "imports": {
15
+ "@fedify/redis": {
16
+ "RedisMessageQueue": "RedisMessageQueue"
17
+ },
18
+ "ioredis": {
19
+ "Redis": "Redis"
20
+ }
21
+ },
22
+ "object": "new RedisMessageQueue(() => new Redis(process.env.REDIS_URL))",
23
+ "env": {
24
+ "REDIS_URL": "redis://localhost:6379"
25
+ }
26
+ },
27
+ "postgres": {
28
+ "label": "PostgreSQL",
29
+ "packageManagers": [
30
+ "deno",
31
+ "bun",
32
+ "npm",
33
+ "yarn",
34
+ "pnpm"
35
+ ],
36
+ "dependencies": {
37
+ "npm:postgres": "^3.4.5"
38
+ },
39
+ "imports": {
40
+ "@fedify/postgres": {
41
+ "PostgresMessageQueue": "PostgresMessageQueue"
42
+ },
43
+ "postgres": {
44
+ "default": "postgres"
45
+ }
46
+ },
47
+ "object": "new PostgresMessageQueue(postgres(process.env.DATABASE_URL))",
48
+ "env": {
49
+ "DATABASE_URL": "postgres://postgres@localhost:5432/postgres"
50
+ }
51
+ },
52
+ "amqp": {
53
+ "label": "AMQP (e.g., RabbitMQ)",
54
+ "packageManagers": [
55
+ "deno",
56
+ "bun",
57
+ "npm",
58
+ "yarn",
59
+ "pnpm"
60
+ ],
61
+ "dependencies": {
62
+ "npm:amqplib": "^0.10.4"
63
+ },
64
+ "devDependencies": {
65
+ "npm:@types/amqplib": "^0.10.5"
66
+ },
67
+ "imports": {
68
+ "@fedify/amqp": {
69
+ "AmqpMessageQueue": "AmqpMessageQueue"
70
+ },
71
+ "amqplib": {
72
+ "connect": "connect"
73
+ }
74
+ },
75
+ "object": "new AmqpMessageQueue(await connect(process.env.AMQP_URL))",
76
+ "env": {
77
+ "AMQP_URL": "amqp://localhost"
78
+ }
79
+ },
80
+ "denokv": {
81
+ "label": "Deno KV",
82
+ "packageManagers": [
83
+ "deno"
84
+ ],
85
+ "imports": {
86
+ "@fedify/denokv": {
87
+ "DenoKvMessageQueue": "DenoKvMessageQueue"
88
+ }
89
+ },
90
+ "object": "new DenoKvMessageQueue(await Deno.openKv())",
91
+ "denoUnstable": [
92
+ "kv"
93
+ ]
94
+ }
95
+ }