@fedify/cli 2.0.0-pr.479.1902 → 2.0.0-pr.479.1913

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cli",
3
- "version": "2.0.0-pr.479.1902+5ac1b5d2",
3
+ "version": "2.0.0-pr.479.1913+736246ec",
4
4
  "license": "MIT",
5
5
  "exports": "./src/mod.ts",
6
6
  "imports": {
package/dist/deno.js CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  //#region deno.json
5
5
  var name = "@fedify/cli";
6
- var version = "2.0.0-pr.479.1902+5ac1b5d2";
6
+ var version = "2.0.0-pr.479.1913+736246ec";
7
7
  var license = "MIT";
8
8
  var exports = "./src/mod.ts";
9
9
  var imports = {
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { debugOption } from "../globals.js";
5
5
  import { KV_STORE, MESSAGE_QUEUE, PACKAGE_MANAGER, WEB_FRAMEWORK } from "./const.js";
6
- import { argument, choice, command, constant, message, multiple, object, option, optionNames, optional } from "@optique/core";
6
+ import { argument, choice, command, constant, merge, message, multiple, object, option, optionNames, optional, or } from "@optique/core";
7
7
  import { path } from "@optique/run";
8
8
 
9
9
  //#region src/init/command.ts
@@ -19,7 +19,7 @@ const initCommand = command("init", object("Initialization options", {
19
19
  packageManager,
20
20
  kvStore,
21
21
  messageQueue,
22
- dryRun: option("-d", "--dry-run", { description: message`Perform a trial run with no changes made.` }),
22
+ dryRun: option("--dry-run", { description: message`Perform a trial run with no changes made.` }),
23
23
  debugOption,
24
24
  testMode
25
25
  }), {
@@ -30,16 +30,16 @@ By default, it initializes the current directory. You can specify a different d
30
30
 
31
31
  Unless you specify all options (${optionNames(["-w", "--web-framework"])}, ${optionNames(["-p", "--package-manager"])}, ${optionNames(["-k", "--kv-store"])}, and ${optionNames(["-m", "--message-queue"])}), it will prompt you to select the options interactively.`
32
32
  });
33
- const testInitCommand = command("test-init", object("Initialization options", {
33
+ const noHydRun = object({ noHydRun: option("--no-hyd-run", { description: message`Log outputs without creating files.` }) });
34
+ const noDryRun = object({ noDryRun: option("--no-dry-run", { description: message`Test with files creations and installations.` }) });
35
+ const testInitCommand = command("test-init", merge(object("Initialization options", {
34
36
  command: constant("test-init"),
35
37
  webFramework: multiple(webFramework),
36
38
  packageManager: multiple(packageManager),
37
39
  kvStore: multiple(kvStore),
38
40
  messageQueue: multiple(messageQueue),
39
- hydRun: option("-h", "--hyd-run", { description: message`Test with files creations and installations.` }),
40
- dryRun: option("-d", "--dry-run", { description: message`Log outputs without creating files.` }),
41
41
  debugOption
42
- }), {
42
+ }), optional(or(noHydRun, noDryRun))), {
43
43
  brief: message`Test an initializing command .`,
44
44
  description: message`Test an initializing command on temporary directories.
45
45
 
@@ -3,12 +3,14 @@
3
3
 
4
4
  import { set } from "../../utils.js";
5
5
  import { fillEmptyOptions } from "./fill.js";
6
- import { isDryRun, isHydRun, runTests } from "./run.js";
6
+ import run_default from "./run.js";
7
7
  import { emptyTestDir, genRunId, genTestDirPrefix, logTestDir } from "./utils.js";
8
8
  import { pipe, tap, when } from "@fxts/core";
9
9
 
10
10
  //#region src/init/test/action.ts
11
- const runTestInit = (options) => pipe(options, set("runId", genRunId), set("testDirPrefix", genTestDirPrefix), tap(emptyTestDir), fillEmptyOptions, tap(when(isHydRun, runTests(false))), tap(when(isDryRun, runTests(true))), tap(logTestDir));
11
+ const runTestInit = (options) => pipe(options, set("runId", genRunId), set("testDirPrefix", genTestDirPrefix), tap(emptyTestDir), fillEmptyOptions, tap(when(isDryRun, run_default(true))), tap(when(isHydRun, run_default(false))), tap(logTestDir));
12
+ const isDryRun = ({ dryRun }) => dryRun;
13
+ const isHydRun = ({ hydRun }) => hydRun;
12
14
  var action_default = runTestInit;
13
15
 
14
16
  //#endregion
@@ -2,7 +2,7 @@
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
 
4
4
  import { KV_STORE, MESSAGE_QUEUE, PACKAGE_MANAGER, WEB_FRAMEWORK } from "../const.js";
5
- import { isEmpty, pipe } from "@fxts/core";
5
+ import { isEmpty, omit, pipe } from "@fxts/core";
6
6
 
7
7
  //#region src/init/test/fill.ts
8
8
  const fillEmptyOptions = (options) => pipe(options, fillWebFramework, fillPackageManager, fillKVStore, fillMessageQueue, fillRunMode);
@@ -14,12 +14,18 @@ const fillWebFramework = fillOption("webFramework", WEB_FRAMEWORK);
14
14
  const fillPackageManager = fillOption("packageManager", PACKAGE_MANAGER);
15
15
  const fillKVStore = fillOption("kvStore", KV_STORE);
16
16
  const fillMessageQueue = fillOption("messageQueue", MESSAGE_QUEUE);
17
- const fillRunMode = (options) => ({
18
- ...options,
19
- ...options.hydRun || options.dryRun ? {} : {
20
- hydRun: true,
21
- dryRun: true
22
- }
17
+ const fillRunMode = (options) => pipe(options, (options$1) => "noHydRun" in options$1 ? {
18
+ ...omit(["noHydRun"], options$1),
19
+ hydRun: !options$1.noHydRun
20
+ } : {
21
+ ...options$1,
22
+ hydRun: true
23
+ }, (options$1) => "noDryRun" in options$1 ? {
24
+ ...omit(["noDryRun"], options$1),
25
+ dryRun: !options$1.noDryRun
26
+ } : {
27
+ ...options$1,
28
+ dryRun: true
23
29
  });
24
30
 
25
31
  //#endregion
@@ -9,6 +9,7 @@ import { values } from "@optique/core";
9
9
  import process from "node:process";
10
10
  import { spawn } from "node:child_process";
11
11
  import { createWriteStream } from "node:fs";
12
+ import { isEmpty } from "@fxts/core/index.js";
12
13
 
13
14
  //#region src/init/test/lookup.ts
14
15
  const HANDLE = "john";
@@ -20,7 +21,7 @@ const BANNED_WFS = ["next"];
20
21
  *
21
22
  * @param dirs - Array of paths to generated app directories
22
23
  */
23
- async function runServerAndReadUser(dirs) {
24
+ async function runServerAndLookupUser(dirs) {
24
25
  const valid = dirs.filter(Boolean);
25
26
  if (valid.length === 0) {
26
27
  printErrorMessage`\nNo directories to lookup test.`;
@@ -39,9 +40,9 @@ async function runServerAndReadUser(dirs) {
39
40
  function filterWebFrameworks(dirs) {
40
41
  const wfs = new Set(dirs.map((dir) => dir.split(sep).slice(-4, -3)[0]));
41
42
  const hasBanned = BANNED_WFS.filter((wf) => wfs.has(wf));
42
- if (!hasBanned) return dirs;
43
+ if (isEmpty(hasBanned)) return dirs;
43
44
  const bannedLabels = hasBanned.map((wf) => webframeworks_default[wf]["label"]);
44
- printErrorMessage`\n${values(bannedLabels)} is not supported in test mode yet.`;
45
+ printErrorMessage`\n${values(bannedLabels)} is not supported in lookup test yet.`;
45
46
  return dirs.filter((dir) => !BANNED_WFS.includes(dir.split(sep).slice(-4, -3)[0]));
46
47
  }
47
48
  /**
@@ -186,4 +187,4 @@ function determinePort(server) {
186
187
  }
187
188
 
188
189
  //#endregion
189
- export { runServerAndReadUser };
190
+ export { runServerAndLookupUser };
@@ -3,17 +3,16 @@
3
3
 
4
4
  import { printMessage } from "../../utils.js";
5
5
  import create_default, { filterOptions, generateTestCases } from "./create.js";
6
- import { runServerAndReadUser } from "./lookup.js";
6
+ import { runServerAndLookupUser } from "./lookup.js";
7
7
  import { join } from "node:path";
8
8
  import { optionNames } from "@optique/core";
9
- import { filter, map as map$1, pipe, tap } from "@fxts/core";
9
+ import { always, filter, map as map$1, pipe, tap, unless } from "@fxts/core";
10
10
 
11
11
  //#region src/init/test/run.ts
12
- const isDryRun = ({ dryRun }) => dryRun;
13
- const isHydRun = ({ hydRun }) => hydRun;
14
- const runTests = (dry) => ({ testDirPrefix, dryRun, hydRun,...options }) => pipe(options, printStartMessage, generateTestCases, filter(filterOptions), map$1(create_default(join(testDirPrefix, getMid(dryRun, hydRun, dry)), dry)), Array.fromAsync, runServerAndReadUser);
15
- const printStartMessage = tap(() => printMessage`\n
16
- Init Test start!
12
+ const runTests = (dry) => ({ testDirPrefix, dryRun, hydRun,...options }) => pipe(options, printStartMessage(dry), generateTestCases, filter(filterOptions), map$1(create_default(join(testDirPrefix, getMid(dryRun, hydRun, dry)), dry)), Array.fromAsync, unless(always(dry), runServerAndLookupUser));
13
+ var run_default = runTests;
14
+ const printStartMessage = (dry) => tap(() => printMessage`\n
15
+ Init ${dry ? "Dry" : "Hyd"} Test start!
17
16
  Options: ${optionNames([
18
17
  "Web Framework",
19
18
  "Package Manager",
@@ -23,4 +22,4 @@ Options: ${optionNames([
23
22
  const getMid = (dryRun, hydRun, dry) => dryRun === hydRun ? dry ? "dry" : "hyd" : "";
24
23
 
25
24
  //#endregion
26
- export { isDryRun, isHydRun, runTests };
25
+ export { run_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cli",
3
- "version": "2.0.0-pr.479.1902+5ac1b5d2",
3
+ "version": "2.0.0-pr.479.1913+736246ec",
4
4
  "description": "CLI toolchain for Fedify and debugging ActivityPub",
5
5
  "keywords": [
6
6
  "fedify",
@@ -71,10 +71,10 @@
71
71
  "ora": "^8.2.0",
72
72
  "shiki": "^1.6.4",
73
73
  "srvx": "^0.8.7",
74
- "@fedify/fedify": "2.0.0-pr.479.1902+5ac1b5d2",
75
- "@fedify/sqlite": "2.0.0-pr.479.1902+5ac1b5d2",
76
- "@fedify/vocab-runtime": "2.0.0-pr.479.1902+5ac1b5d2",
77
- "@fedify/vocab-tools": "2.0.0-pr.479.1902+5ac1b5d2"
74
+ "@fedify/fedify": "2.0.0-pr.479.1913+736246ec",
75
+ "@fedify/sqlite": "2.0.0-pr.479.1913+736246ec",
76
+ "@fedify/vocab-runtime": "2.0.0-pr.479.1913+736246ec",
77
+ "@fedify/vocab-tools": "2.0.0-pr.479.1913+736246ec"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@types/bun": "^1.2.23",
@@ -4,12 +4,14 @@ import {
4
4
  command,
5
5
  constant,
6
6
  type InferValue,
7
+ merge,
7
8
  message,
8
9
  multiple,
9
10
  object,
10
11
  option,
11
12
  optional,
12
13
  optionNames,
14
+ or,
13
15
  } from "@optique/core";
14
16
  import { path } from "@optique/run";
15
17
  import { debugOption } from "../globals.ts";
@@ -73,7 +75,7 @@ export const initCommand = command(
73
75
  packageManager,
74
76
  kvStore,
75
77
  messageQueue,
76
- dryRun: option("-d", "--dry-run", {
78
+ dryRun: option("--dry-run", {
77
79
  description: message`Perform a trial run with no changes made.`,
78
80
  }),
79
81
  debugOption,
@@ -95,22 +97,29 @@ Unless you specify all options (${optionNames(["-w", "--web-framework"])}, ${
95
97
 
96
98
  export type InitCommand = InferValue<typeof initCommand>;
97
99
 
100
+ const noHydRun = object({
101
+ noHydRun: option("--no-hyd-run", {
102
+ description: message`Log outputs without creating files.`,
103
+ }),
104
+ });
105
+ const noDryRun = object({
106
+ noDryRun: option("--no-dry-run", {
107
+ description: message`Test with files creations and installations.`,
108
+ }),
109
+ });
98
110
  export const testInitCommand = command(
99
111
  "test-init",
100
- object("Initialization options", {
101
- command: constant("test-init"),
102
- webFramework: multiple(webFramework),
103
- packageManager: multiple(packageManager),
104
- kvStore: multiple(kvStore),
105
- messageQueue: multiple(messageQueue),
106
- hydRun: option("-h", "--hyd-run", {
107
- description: message`Test with files creations and installations.`,
112
+ merge(
113
+ object("Initialization options", {
114
+ command: constant("test-init"),
115
+ webFramework: multiple(webFramework),
116
+ packageManager: multiple(packageManager),
117
+ kvStore: multiple(kvStore),
118
+ messageQueue: multiple(messageQueue),
119
+ debugOption,
108
120
  }),
109
- dryRun: option("-d", "--dry-run", {
110
- description: message`Log outputs without creating files.`,
111
- }),
112
- debugOption,
113
- }),
121
+ optional(or(noHydRun, noDryRun)),
122
+ ),
114
123
  {
115
124
  brief: message`Test an initializing command .`,
116
125
  description: message`Test an initializing command on temporary directories.
@@ -2,7 +2,7 @@ import { pipe, tap, when } from "@fxts/core";
2
2
  import { set } from "../../utils.ts";
3
3
  import type { TestInitCommand } from "../command.ts";
4
4
  import { fillEmptyOptions } from "./fill.ts";
5
- import { isDryRun, isHydRun, runTests } from "./run.ts";
5
+ import runTests from "./run.ts";
6
6
  import {
7
7
  emptyTestDir,
8
8
  genRunId,
@@ -17,9 +17,12 @@ const runTestInit = (options: TestInitCommand) =>
17
17
  set("testDirPrefix", genTestDirPrefix),
18
18
  tap(emptyTestDir),
19
19
  fillEmptyOptions,
20
- tap(when(isHydRun, runTests(false))),
21
20
  tap(when(isDryRun, runTests(true))),
21
+ tap(when(isHydRun, runTests(false))),
22
22
  tap(logTestDir),
23
23
  );
24
24
 
25
+ const isDryRun = <T extends { dryRun: boolean }>({ dryRun }: T) => dryRun;
26
+ const isHydRun = <T extends { hydRun: boolean }>({ hydRun }: T) => hydRun;
27
+
25
28
  export default runTestInit;
@@ -1,4 +1,4 @@
1
- import { isEmpty, pipe } from "@fxts/core";
1
+ import { isEmpty, omit, pipe } from "@fxts/core";
2
2
  import type { TestInitCommand } from "../command.ts";
3
3
  import {
4
4
  KV_STORE,
@@ -54,8 +54,14 @@ const fillKVStore = fillOption("kvStore", KV_STORE);
54
54
  const fillMessageQueue = fillOption("messageQueue", MESSAGE_QUEUE);
55
55
 
56
56
  const fillRunMode = <T extends TestInitCommand>(
57
- options: DefineAllOptions<T>,
58
- ): DefineAllOptions<T> => ({
59
- ...options,
60
- ...(options.hydRun || options.dryRun ? {} : { hydRun: true, dryRun: true }),
61
- });
57
+ options: T,
58
+ ): DefineAllOptions<T> =>
59
+ pipe(
60
+ options,
61
+ (options) => ("noHydRun" in options
62
+ ? ({ ...omit(["noHydRun"], options), hydRun: !options.noHydRun })
63
+ : ({ ...options, hydRun: true })),
64
+ (options) => ("noDryRun" in options
65
+ ? ({ ...omit(["noDryRun"], options), dryRun: !options.noDryRun })
66
+ : ({ ...options, dryRun: true })),
67
+ ) as DefineAllOptions<T>;
@@ -1,3 +1,4 @@
1
+ import { isEmpty } from "@fxts/core/index.js";
1
2
  import { values } from "@optique/core";
2
3
  import type { ChildProcessByStdio } from "node:child_process";
3
4
  import { spawn } from "node:child_process";
@@ -25,7 +26,7 @@ const BANNED_WFS: WebFramework[] = ["next"];
25
26
  *
26
27
  * @param dirs - Array of paths to generated app directories
27
28
  */
28
- export default async function runServerAndReadUser(
29
+ export default async function runServerAndLookupUser(
29
30
  dirs: string[],
30
31
  ): Promise<void> {
31
32
  const valid = dirs.filter(Boolean);
@@ -55,13 +56,13 @@ function filterWebFrameworks(
55
56
  dirs.map((dir) => dir.split(sep).slice(-4, -3)[0] as WebFramework),
56
57
  );
57
58
  const hasBanned = BANNED_WFS.filter((wf) => wfs.has(wf));
58
- if (!hasBanned) {
59
+ if (isEmpty(hasBanned)) {
59
60
  return dirs;
60
61
  }
61
62
  const bannedLabels = hasBanned.map((wf) => webFrameworks[wf]["label"]);
62
63
  printErrorMessage`\n${
63
64
  values(bannedLabels)
64
- } is not supported in test mode yet.`;
65
+ } is not supported in lookup test yet.`;
65
66
  return dirs.filter((dir) =>
66
67
  !BANNED_WFS.includes(dir.split(sep).slice(-4, -3)[0] as WebFramework)
67
68
  );
@@ -1,42 +1,39 @@
1
- import { filter, map, pipe, tap } from "@fxts/core";
1
+ import { always, filter, map, pipe, tap, unless } from "@fxts/core";
2
2
  import { optionNames } from "@optique/core";
3
3
  import { join } from "node:path";
4
4
  import { printMessage } from "../../utils.ts";
5
5
  import createTestApp, { filterOptions, generateTestCases } from "./create.ts";
6
- import runServerAndReadUser from "./lookup.ts";
6
+ import runServerAndLookupUser from "./lookup.ts";
7
7
  import type { InitTestData } from "./types.ts";
8
8
 
9
- export const isDryRun = <T extends { dryRun: boolean }>({ dryRun }: T) =>
10
- dryRun;
11
- export const isHydRun = <T extends { hydRun: boolean }>({ hydRun }: T) =>
12
- hydRun;
13
-
14
- export const runTests =
9
+ const runTests =
15
10
  (dry: boolean) =>
16
11
  <T extends InitTestData>({ testDirPrefix, dryRun, hydRun, ...options }: T) =>
17
12
  pipe(
18
13
  options,
19
- printStartMessage,
14
+ printStartMessage(dry),
20
15
  generateTestCases,
21
16
  filter(filterOptions),
22
17
  map(createTestApp(join(testDirPrefix, getMid(dryRun, hydRun, dry)), dry)),
23
18
  Array.fromAsync<string>,
24
- runServerAndReadUser,
19
+ unless(always(dry), runServerAndLookupUser),
25
20
  );
21
+ export default runTests;
26
22
 
27
- const printStartMessage: <T>(t: T) => T = tap(
28
- () =>
29
- printMessage`\n
30
- Init Test start!
23
+ const printStartMessage: (dry: boolean) => <T>(t: T) => T = (dry: boolean) =>
24
+ tap(
25
+ () =>
26
+ printMessage`\n
27
+ Init ${dry ? "Dry" : "Hyd"} Test start!
31
28
  Options: ${
32
- optionNames([
33
- "Web Framework",
34
- "Package Manager",
35
- "KV Store",
36
- "Message Queue",
37
- ])
38
- }`,
39
- );
29
+ optionNames([
30
+ "Web Framework",
31
+ "Package Manager",
32
+ "KV Store",
33
+ "Message Queue",
34
+ ])
35
+ }`,
36
+ );
40
37
 
41
38
  const getMid = (dryRun: boolean, hydRun: boolean, dry: boolean) =>
42
39
  dryRun === hydRun ? dry ? "dry" : "hyd" : "";
@@ -1,17 +1,10 @@
1
1
  import type { TestInitCommand } from "../command.ts";
2
2
 
3
- export interface InitTestData extends AllDefinedTestInitCommand {
3
+ export interface InitTestData extends DefineAllOptions<TestInitCommand> {
4
4
  runId: string;
5
5
  testDirPrefix: string;
6
6
  }
7
7
 
8
- export interface AllDefinedTestInitCommand extends TestInitCommand {
9
- webFramework: (TestInitCommand["webFramework"][number] & string)[];
10
- packageManager: (TestInitCommand["packageManager"][number] & string)[];
11
- kvStore: (TestInitCommand["kvStore"][number] & string)[];
12
- messageQueue: (TestInitCommand["messageQueue"][number] & string)[];
13
- }
14
-
15
8
  export type MultipleOption =
16
9
  | "webFramework"
17
10
  | "packageManager"
@@ -21,14 +14,14 @@ export type MultipleOption =
21
14
  export type DefineOption<T extends TestInitCommand, K extends MultipleOption> =
22
15
  & Omit<T, K>
23
16
  & {
24
- [Key in MultipleOption]: Key extends K ? AllDefinedTestInitCommand[Key]
17
+ [Key in MultipleOption]: Key extends K ? TestInitCommand[Key] & string[]
25
18
  : T[Key];
26
19
  };
27
20
 
21
+ type NoRunMode = "noHydRun" | "noDryRun";
22
+ type RunMode = "hydRun" | "dryRun";
23
+
28
24
  export type DefineAllOptions<T extends TestInitCommand> =
29
- & Omit<T, MultipleOption>
30
- & {
31
- [K in MultipleOption]: TestInitCommand[K] extends readonly unknown[]
32
- ? AllDefinedTestInitCommand[K]
33
- : never;
34
- };
25
+ & Omit<T, MultipleOption | NoRunMode>
26
+ & { [K in MultipleOption]: (TestInitCommand[K][number] & string)[] }
27
+ & { [R in RunMode]: boolean };