@fedify/cli 2.0.0-pr.479.1922 → 2.0.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 (160) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -3
  3. package/dist/cache.js +17 -3
  4. package/dist/config.js +105 -0
  5. package/dist/deno.js +18 -8
  6. package/dist/generate-vocab/action.js +1 -1
  7. package/dist/imagerenderer.js +1 -1
  8. package/dist/inbox/rendercode.js +11 -21
  9. package/dist/inbox.js +162 -132
  10. package/dist/init/mod.js +3 -3
  11. package/dist/log.js +35 -1
  12. package/dist/lookup.js +55 -23
  13. package/dist/mod.js +95 -18
  14. package/dist/nodeinfo.js +39 -22
  15. package/dist/options.js +84 -0
  16. package/dist/relay.js +136 -0
  17. package/dist/tempserver.js +15 -8
  18. package/dist/tunnel.js +6 -10
  19. package/dist/utils.js +19 -108
  20. package/dist/webfinger/action.js +1 -1
  21. package/dist/webfinger/command.js +17 -9
  22. package/dist/webfinger/lib.js +3 -3
  23. package/package.json +50 -28
  24. package/deno.json +0 -71
  25. package/dist/globals.js +0 -49
  26. package/dist/init/action/configs.js +0 -91
  27. package/dist/init/action/const.js +0 -10
  28. package/dist/init/action/deps.js +0 -50
  29. package/dist/init/action/dir.js +0 -16
  30. package/dist/init/action/env.js +0 -13
  31. package/dist/init/action/install.js +0 -20
  32. package/dist/init/action/mod.js +0 -39
  33. package/dist/init/action/notice.js +0 -55
  34. package/dist/init/action/patch.js +0 -147
  35. package/dist/init/action/precommand.js +0 -28
  36. package/dist/init/action/recommend.js +0 -24
  37. package/dist/init/action/set.js +0 -31
  38. package/dist/init/action/templates.js +0 -58
  39. package/dist/init/action/utils.js +0 -50
  40. package/dist/init/ask/dir.js +0 -82
  41. package/dist/init/ask/kv.js +0 -44
  42. package/dist/init/ask/mod.js +0 -16
  43. package/dist/init/ask/mq.js +0 -46
  44. package/dist/init/ask/pm.js +0 -49
  45. package/dist/init/ask/wf.js +0 -29
  46. package/dist/init/command.js +0 -50
  47. package/dist/init/const.js +0 -31
  48. package/dist/init/json/biome.js +0 -24
  49. package/dist/init/json/kv.js +0 -53
  50. package/dist/init/json/mq.js +0 -72
  51. package/dist/init/json/pm.js +0 -44
  52. package/dist/init/json/rt.js +0 -39
  53. package/dist/init/json/vscode-settings-for-deno.js +0 -53
  54. package/dist/init/json/vscode-settings.js +0 -49
  55. package/dist/init/lib.js +0 -136
  56. package/dist/init/templates/defaults/federation.ts.tpl +0 -23
  57. package/dist/init/templates/defaults/logging.ts.tpl +0 -23
  58. package/dist/init/templates/express/app.ts.tpl +0 -16
  59. package/dist/init/templates/express/index.ts.tpl +0 -6
  60. package/dist/init/templates/hono/app.tsx.tpl +0 -14
  61. package/dist/init/templates/hono/index/bun.ts.tpl +0 -10
  62. package/dist/init/templates/hono/index/deno.ts.tpl +0 -13
  63. package/dist/init/templates/hono/index/node.ts.tpl +0 -14
  64. package/dist/init/templates/next/middleware.ts.tpl +0 -45
  65. package/dist/init/templates/nitro/.env.test.tpl +0 -1
  66. package/dist/init/templates/nitro/nitro.config.ts.tpl +0 -14
  67. package/dist/init/templates/nitro/server/error.ts.tpl +0 -3
  68. package/dist/init/templates/nitro/server/middleware/federation.ts.tpl +0 -8
  69. package/dist/init/test/action.js +0 -17
  70. package/dist/init/test/create.js +0 -100
  71. package/dist/init/test/fill.js +0 -32
  72. package/dist/init/test/lookup.js +0 -190
  73. package/dist/init/test/run.js +0 -25
  74. package/dist/init/test/utils.js +0 -17
  75. package/dist/init/webframeworks.js +0 -136
  76. package/scripts/pack.ts +0 -71
  77. package/src/cache.ts +0 -17
  78. package/src/docloader.ts +0 -67
  79. package/src/generate-vocab/action.ts +0 -17
  80. package/src/generate-vocab/command.ts +0 -44
  81. package/src/generate-vocab/mod.ts +0 -2
  82. package/src/globals.ts +0 -43
  83. package/src/imagerenderer.ts +0 -149
  84. package/src/inbox/entry.ts +0 -10
  85. package/src/inbox/rendercode.ts +0 -68
  86. package/src/inbox/view.tsx +0 -598
  87. package/src/inbox.tsx +0 -536
  88. package/src/init/action/configs.ts +0 -133
  89. package/src/init/action/const.ts +0 -9
  90. package/src/init/action/deps.ts +0 -161
  91. package/src/init/action/dir.ts +0 -11
  92. package/src/init/action/env.ts +0 -14
  93. package/src/init/action/install.ts +0 -24
  94. package/src/init/action/mod.ts +0 -66
  95. package/src/init/action/notice.ts +0 -103
  96. package/src/init/action/patch.ts +0 -233
  97. package/src/init/action/precommand.ts +0 -29
  98. package/src/init/action/recommend.ts +0 -38
  99. package/src/init/action/set.ts +0 -65
  100. package/src/init/action/templates.ts +0 -96
  101. package/src/init/action/utils.ts +0 -64
  102. package/src/init/ask/dir.ts +0 -98
  103. package/src/init/ask/kv.ts +0 -82
  104. package/src/init/ask/mod.ts +0 -23
  105. package/src/init/ask/mq.ts +0 -86
  106. package/src/init/ask/pm.ts +0 -58
  107. package/src/init/ask/wf.ts +0 -27
  108. package/src/init/command.ts +0 -135
  109. package/src/init/const.ts +0 -4
  110. package/src/init/json/biome.json +0 -17
  111. package/src/init/json/kv.json +0 -39
  112. package/src/init/json/mq.json +0 -95
  113. package/src/init/json/pm.json +0 -47
  114. package/src/init/json/rt.json +0 -42
  115. package/src/init/json/vscode-settings-for-deno.json +0 -43
  116. package/src/init/json/vscode-settings.json +0 -41
  117. package/src/init/lib.ts +0 -223
  118. package/src/init/mod.ts +0 -3
  119. package/src/init/templates/defaults/federation.ts.tpl +0 -23
  120. package/src/init/templates/defaults/logging.ts.tpl +0 -23
  121. package/src/init/templates/express/app.ts.tpl +0 -16
  122. package/src/init/templates/express/index.ts.tpl +0 -6
  123. package/src/init/templates/hono/app.tsx.tpl +0 -14
  124. package/src/init/templates/hono/index/bun.ts.tpl +0 -10
  125. package/src/init/templates/hono/index/deno.ts.tpl +0 -13
  126. package/src/init/templates/hono/index/node.ts.tpl +0 -14
  127. package/src/init/templates/next/middleware.ts.tpl +0 -45
  128. package/src/init/templates/nitro/.env.test.tpl +0 -1
  129. package/src/init/templates/nitro/nitro.config.ts.tpl +0 -14
  130. package/src/init/templates/nitro/server/error.ts.tpl +0 -3
  131. package/src/init/templates/nitro/server/middleware/federation.ts.tpl +0 -8
  132. package/src/init/test/action.ts +0 -28
  133. package/src/init/test/create.ts +0 -137
  134. package/src/init/test/fill.ts +0 -67
  135. package/src/init/test/lookup.ts +0 -254
  136. package/src/init/test/run.ts +0 -39
  137. package/src/init/test/types.ts +0 -27
  138. package/src/init/test/utils.ts +0 -21
  139. package/src/init/types.ts +0 -89
  140. package/src/init/webframeworks.ts +0 -168
  141. package/src/kv.bun.ts +0 -12
  142. package/src/kv.node.ts +0 -11
  143. package/src/log.ts +0 -64
  144. package/src/lookup.test.ts +0 -182
  145. package/src/lookup.ts +0 -563
  146. package/src/mod.ts +0 -62
  147. package/src/nodeinfo.test.ts +0 -229
  148. package/src/nodeinfo.ts +0 -454
  149. package/src/table.ts +0 -17
  150. package/src/tempserver.ts +0 -87
  151. package/src/tunnel.test.ts +0 -157
  152. package/src/tunnel.ts +0 -94
  153. package/src/utils.ts +0 -254
  154. package/src/webfinger/action.ts +0 -50
  155. package/src/webfinger/command.ts +0 -64
  156. package/src/webfinger/error.ts +0 -47
  157. package/src/webfinger/lib.ts +0 -37
  158. package/src/webfinger/mod.test.ts +0 -79
  159. package/src/webfinger/mod.ts +0 -2
  160. package/tsdown.config.ts +0 -35
@@ -1,65 +0,0 @@
1
- import { pipe } from "@fxts/core";
2
- import { existsSync } from "node:fs";
3
- import { realpath } from "node:fs/promises";
4
- import { basename, normalize } from "node:path";
5
- import { merge, set } from "../../utils.ts";
6
- import { kvStores, messageQueues } from "../lib.ts";
7
- import type {
8
- InitCommandData,
9
- InitCommandOptions,
10
- KvStore,
11
- KvStoreDescription,
12
- MessageQueue,
13
- MessageQueueDescription,
14
- } from "../types.ts";
15
- import webFrameworks from "../webframeworks.ts";
16
-
17
- /**
18
- * Set all necessary data for initializing the project.
19
- * This function orchestrates the setting of project name, initializer,
20
- * key-value store, message queue, and environment variables by calling
21
- * individual setter functions for each piece of data.
22
- *
23
- * @param data - The initial command options provided by the user
24
- * @returns A promise resolving to a complete InitCommandData object
25
- */
26
- const setData = (data: InitCommandOptions): Promise<InitCommandData> =>
27
- pipe(
28
- data,
29
- setProjectName,
30
- setInitializer,
31
- setKv,
32
- setMq,
33
- setEnv,
34
- );
35
-
36
- export default setData;
37
-
38
- const setProjectName = set(
39
- "projectName",
40
- async <
41
- T extends { dir: string },
42
- >({ dir }: T) =>
43
- basename(existsSync(dir) ? await realpath(dir) : normalize(dir)),
44
- );
45
-
46
- const setInitializer = set("initializer", <
47
- T extends InitCommandOptions & { projectName: string },
48
- >(data: T) => webFrameworks[data.webFramework].init(data));
49
-
50
- const setKv = set("kv", <
51
- T extends { kvStore: KvStore },
52
- >({ kvStore }: T) => kvStores[kvStore]);
53
-
54
- const setMq = set(
55
- "mq",
56
- <
57
- T extends { messageQueue: MessageQueue },
58
- >({ messageQueue }: T) => messageQueues[messageQueue],
59
- );
60
- const setEnv = set(
61
- "env",
62
- <
63
- T extends { kv: KvStoreDescription; mq: MessageQueueDescription },
64
- >({ kv, mq }: T) => merge(kv.env)(mq.env),
65
- );
@@ -1,96 +0,0 @@
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
- const ENV_REG_EXP = /process\.env\.(\w+)/g;
85
- /**
86
- * Converts Node.js environment variable access to Deno-compatible syntax when needed.
87
- * Transforms `process.env.VAR_NAME` to `Deno.env.get("VAR_NAME")` for Deno projects.
88
- *
89
- * @param obj - The object string containing potential environment variable references
90
- * @param pm - The package manager (runtime) being used
91
- * @returns The converted object string with appropriate environment variable access syntax
92
- */
93
- export const convertEnv = (obj: string, pm: PackageManager) =>
94
- pm === "deno" && ENV_REG_EXP.test(obj)
95
- ? obj.replaceAll(ENV_REG_EXP, (_, g1) => `Deno.env.get("${g1}")`)
96
- : obj;
@@ -1,64 +0,0 @@
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 }: Pick<InitCommandData, "packageManager">,
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
- }
@@ -1,98 +0,0 @@
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(" ");
@@ -1,82 +0,0 @@
1
- import { pipe, tap, throwError, unless, when } from "@fxts/core/index.js";
2
- import { select } from "@inquirer/prompts";
3
- import { printErrorMessage } from "../../utils.ts";
4
- import { KV_STORE } from "../const.ts";
5
- import { isTest, kvStores } from "../lib.ts";
6
- import type { KvStore, PackageManager } from "../types.ts";
7
-
8
- /**
9
- * Fills in the key-value store by prompting the user if not provided.
10
- * Ensures the selected KV store is compatible with the chosen package manager.
11
- *
12
- * @param options - Initialization options possibly containing a kvStore and packageManager
13
- * @returns A promise resolving to options with a guaranteed kvStore
14
- */
15
- const fillKvStore: //
16
- <
17
- T extends {
18
- kvStore?: KvStore;
19
- packageManager: PackageManager;
20
- testMode: boolean;
21
- },
22
- >(options: T) => Promise<KvDefined<T>> //
23
- = (options) =>
24
- pipe(
25
- options,
26
- when(isKvStoreEmpty, askKvStore) as <
27
- T extends { kvStore?: KvStore; packageManager: PackageManager },
28
- >(options: T) => KvDefined<T>,
29
- unless(
30
- isKvSupportsPm,
31
- (opt: KvDefined<typeof options>) =>
32
- pipe(
33
- opt,
34
- when(isTest, throwError(unmatchedWhileTesting)),
35
- tap(noticeUnmatched),
36
- fillKvStore,
37
- ),
38
- ),
39
- ) as Promise<KvDefined<typeof options>>;
40
-
41
- export default fillKvStore;
42
-
43
- type KvDefined<T> = Omit<T, "kvStore"> & { kvStore: KvStore };
44
-
45
- const isKvStoreEmpty = <T extends { kvStore?: KvStore }>(
46
- options: T,
47
- ): options is T & { kvStore: undefined } => !options.kvStore;
48
-
49
- const askKvStore = async <
50
- T extends { packageManager: PackageManager },
51
- >(data: T): Promise<Omit<T, "kvStore"> & { kvStore: KvStore }> => ({
52
- ...data,
53
- kvStore: await select<KvStore>({
54
- message: "Choose the key-value store to use",
55
- choices: KV_STORE.map(choiceKvStore(data.packageManager)),
56
- }),
57
- });
58
-
59
- const unmatchedWhileTesting = <
60
- T extends { kvStore: KvStore; packageManager: PackageManager },
61
- >({ kvStore: kv, packageManager: pm }: T) =>
62
- new Error(
63
- `Key-value store '${kv}' is not compatible with package manager '${pm}'`,
64
- );
65
-
66
- const noticeUnmatched = <
67
- T extends { kvStore: KvStore; packageManager: PackageManager },
68
- >({ kvStore: kv, packageManager: pm }: T) =>
69
- printErrorMessage`Error: Key-value store '${kv}' is not compatible with package manager '${pm}'`;
70
-
71
- const choiceKvStore = (pm: PackageManager) => (kv: KvStore) => ({
72
- name: isKvSupportsPm({ kvStore: kv, packageManager: pm })
73
- ? kv
74
- : `${kv} (not supported with ${pm})`,
75
- value: kv,
76
- disabled: !isKvSupportsPm({ kvStore: kv, packageManager: pm }),
77
- });
78
-
79
- const isKvSupportsPm = <
80
- T extends { kvStore: KvStore; packageManager: PackageManager },
81
- >({ kvStore, packageManager }: T) =>
82
- kvStores[kvStore].packageManagers.includes(packageManager);
@@ -1,23 +0,0 @@
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;
@@ -1,86 +0,0 @@
1
- import { pipe, tap, throwError, unless, when } from "@fxts/core/index.js";
2
- import { select } from "@inquirer/prompts";
3
- import { printErrorMessage } from "../../utils.ts";
4
- import { MESSAGE_QUEUE } from "../const.ts";
5
- import { isTest, messageQueues } from "../lib.ts";
6
- import type { MessageQueue, PackageManager } from "../types.ts";
7
-
8
- /**
9
- * Fills in the message queue by prompting the user if not provided.
10
- * Ensures the selected message queue is compatible with the chosen package manager.
11
- *
12
- * @param options - Initialization options possibly containing a messageQueue and packageManager
13
- * @returns A promise resolving to options with a guaranteed messageQueue
14
- */
15
- const fillMessageQueue: //
16
- <
17
- T extends {
18
- messageQueue?: MessageQueue;
19
- packageManager: PackageManager;
20
- testMode: boolean;
21
- },
22
- >(options: T) => Promise<MqDefined<T>> //
23
- = (options) =>
24
- pipe(
25
- options,
26
- when(isMessageQueueEmpty, askMessageQueue) as <
27
- T extends { messageQueue?: MessageQueue; packageManager: PackageManager },
28
- >(options: T) => MqDefined<T>,
29
- unless(
30
- isMqSupportsPm,
31
- (opt: MqDefined<typeof options>) =>
32
- pipe(
33
- opt,
34
- when(isTest, throwError(unmatchedWhileTesting)),
35
- tap(noticeUnmatched),
36
- fillMessageQueue,
37
- ),
38
- ),
39
- ) as Promise<MqDefined<typeof options>>;
40
-
41
- export default fillMessageQueue;
42
-
43
- type MqDefined<T> = Omit<T, "messageQueue"> & { messageQueue: MessageQueue };
44
-
45
- const isMessageQueueEmpty = <T extends { messageQueue?: MessageQueue }>(
46
- options: T,
47
- ): options is T & { messageQueue: undefined } => !options.messageQueue;
48
-
49
- const askMessageQueue = async <
50
- T extends { packageManager: PackageManager },
51
- >(
52
- data: T,
53
- ): Promise<Omit<T, "messageQueue"> & { messageQueue: MessageQueue }> => ({
54
- ...data,
55
- messageQueue: await select<MessageQueue>({
56
- message: "Choose the message queue to use",
57
- choices: MESSAGE_QUEUE.map(choiceMessageQueue(data.packageManager)),
58
- }),
59
- });
60
-
61
- const unmatchedWhileTesting = <
62
- T extends { messageQueue: MessageQueue; packageManager: PackageManager },
63
- >({ messageQueue: mq, packageManager: pm }: T) =>
64
- new Error(
65
- `Message queue '${mq}' is not compatible with package manager '${pm}'`,
66
- );
67
-
68
- const noticeUnmatched = <
69
- T extends { messageQueue: MessageQueue; packageManager: PackageManager },
70
- >({ messageQueue: mq, packageManager: pm }: T) => {
71
- printErrorMessage`Error: Message queue '${mq}' is not compatible with package manager '${pm}'`;
72
- };
73
-
74
- const choiceMessageQueue =
75
- (packageManager: PackageManager) => (messageQueue: MessageQueue) => ({
76
- name: isMqSupportsPm({ messageQueue, packageManager })
77
- ? messageQueue
78
- : `${messageQueue} (not supported with ${packageManager})`,
79
- value: messageQueue,
80
- disabled: !isMqSupportsPm({ messageQueue, packageManager }),
81
- });
82
-
83
- const isMqSupportsPm = <
84
- T extends { messageQueue: MessageQueue; packageManager: PackageManager },
85
- >({ messageQueue, packageManager }: T) =>
86
- messageQueues[messageQueue].packageManagers.includes(packageManager);
@@ -1,58 +0,0 @@
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
- };
@@ -1,27 +0,0 @@
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
- });