@lite-fsm/cli 0.1.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 (94) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bin/lite-fsm.d.cts +2 -0
  3. package/dist/bin/lite-fsm.d.ts +2 -0
  4. package/dist/bin/lite-fsm.js +12 -0
  5. package/dist/cli/context.d.cts +21 -0
  6. package/dist/cli/context.d.ts +21 -0
  7. package/dist/cli/context.js +0 -0
  8. package/dist/cli/create-program.d.cts +6 -0
  9. package/dist/cli/create-program.d.ts +6 -0
  10. package/dist/cli/create-program.js +48 -0
  11. package/dist/cli/diagnostics.d.cts +15 -0
  12. package/dist/cli/diagnostics.d.ts +15 -0
  13. package/dist/cli/diagnostics.js +13 -0
  14. package/dist/cli/node-fs.d.cts +2 -0
  15. package/dist/cli/node-fs.d.ts +2 -0
  16. package/dist/cli/node-fs.js +33 -0
  17. package/dist/cli/result.d.cts +6 -0
  18. package/dist/cli/result.d.ts +6 -0
  19. package/dist/cli/result.js +8 -0
  20. package/dist/export-graph/command.d.cts +8 -0
  21. package/dist/export-graph/command.d.ts +8 -0
  22. package/dist/export-graph/command.js +30 -0
  23. package/dist/export-graph/export-document.d.cts +38 -0
  24. package/dist/export-graph/export-document.d.ts +38 -0
  25. package/dist/export-graph/export-document.js +35 -0
  26. package/dist/export-graph/options.d.cts +21 -0
  27. package/dist/export-graph/options.d.ts +21 -0
  28. package/dist/export-graph/options.js +40 -0
  29. package/dist/export-graph/run-export-graph.d.cts +10 -0
  30. package/dist/export-graph/run-export-graph.d.ts +10 -0
  31. package/dist/export-graph/run-export-graph.js +53 -0
  32. package/dist/export-graph/source-bundle.d.cts +12 -0
  33. package/dist/export-graph/source-bundle.d.ts +12 -0
  34. package/dist/export-graph/source-bundle.js +48 -0
  35. package/dist/export-graph/write-output.d.cts +10 -0
  36. package/dist/export-graph/write-output.d.ts +10 -0
  37. package/dist/export-graph/write-output.js +24 -0
  38. package/dist/output/format-diagnostics.d.cts +6 -0
  39. package/dist/output/format-diagnostics.d.ts +6 -0
  40. package/dist/output/format-diagnostics.js +33 -0
  41. package/dist/output/stable-json.d.cts +1 -0
  42. package/dist/output/stable-json.d.ts +1 -0
  43. package/dist/output/stable-json.js +72 -0
  44. package/dist/project/build-project-graph.d.cts +19 -0
  45. package/dist/project/build-project-graph.d.ts +19 -0
  46. package/dist/project/build-project-graph.js +64 -0
  47. package/dist/project/create-project-host.d.cts +4 -0
  48. package/dist/project/create-project-host.d.ts +4 -0
  49. package/dist/project/create-project-host.js +11 -0
  50. package/dist/project/module-resolver.d.cts +15 -0
  51. package/dist/project/module-resolver.d.ts +15 -0
  52. package/dist/project/module-resolver.js +111 -0
  53. package/dist/project/source-cache.d.cts +11 -0
  54. package/dist/project/source-cache.d.ts +11 -0
  55. package/dist/project/source-cache.js +55 -0
  56. package/dist/project/tsconfig.d.cts +15 -0
  57. package/dist/project/tsconfig.d.ts +15 -0
  58. package/dist/project/tsconfig.js +116 -0
  59. package/dist/visualize/command.d.cts +9 -0
  60. package/dist/visualize/command.d.ts +9 -0
  61. package/dist/visualize/command.js +35 -0
  62. package/dist/visualize/http.d.cts +11 -0
  63. package/dist/visualize/http.d.ts +11 -0
  64. package/dist/visualize/http.js +65 -0
  65. package/dist/visualize/open-browser.d.cts +22 -0
  66. package/dist/visualize/open-browser.d.ts +22 -0
  67. package/dist/visualize/open-browser.js +45 -0
  68. package/dist/visualize/options.d.cts +16 -0
  69. package/dist/visualize/options.d.ts +16 -0
  70. package/dist/visualize/options.js +51 -0
  71. package/dist/visualize/routes.d.cts +2 -0
  72. package/dist/visualize/routes.d.ts +2 -0
  73. package/dist/visualize/routes.js +24 -0
  74. package/dist/visualize/run-visualize.d.cts +32 -0
  75. package/dist/visualize/run-visualize.d.ts +32 -0
  76. package/dist/visualize/run-visualize.js +81 -0
  77. package/dist/visualize/server.d.cts +40 -0
  78. package/dist/visualize/server.d.ts +40 -0
  79. package/dist/visualize/server.js +90 -0
  80. package/dist/visualize/session.d.cts +34 -0
  81. package/dist/visualize/session.d.ts +34 -0
  82. package/dist/visualize/session.js +137 -0
  83. package/dist/visualize/static-assets.d.cts +17 -0
  84. package/dist/visualize/static-assets.d.ts +17 -0
  85. package/dist/visualize/static-assets.js +87 -0
  86. package/dist/visualize/types.d.cts +65 -0
  87. package/dist/visualize/types.d.ts +65 -0
  88. package/dist/visualize/types.js +0 -0
  89. package/dist/visualizer/assets/MachineCanvasGraph-CHpVij2M.css +1 -0
  90. package/dist/visualizer/assets/MachineCanvasGraph-DuWIhVsu.js +30 -0
  91. package/dist/visualizer/assets/index-CZYnsrxd.js +42381 -0
  92. package/dist/visualizer/assets/index-DMdcz3e2.css +2 -0
  93. package/dist/visualizer/index.html +13 -0
  94. package/package.json +57 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 AlexanderGureev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { createProgram } from "../cli/create-program.js";
3
+ import { createNodeFileSystem } from "../cli/node-fs.js";
4
+ const context = {
5
+ cwd: process.cwd(),
6
+ stdout: process.stdout,
7
+ stderr: process.stderr,
8
+ env: process.env,
9
+ fs: createNodeFileSystem()
10
+ };
11
+ const result = await createProgram(context).parse(process.argv);
12
+ process.exitCode = result.exitCode;
@@ -0,0 +1,21 @@
1
+ import type { Writable } from "node:stream";
2
+ export type CliFileSystem = {
3
+ readFile(path: string): string;
4
+ readFileBuffer?(path: string): Uint8Array;
5
+ writeFile(path: string, contents: string): void;
6
+ mkdir(path: string, options: {
7
+ recursive: true;
8
+ }): void;
9
+ rename(from: string, to: string): void;
10
+ unlink(path: string): void;
11
+ fileExists(path: string): boolean;
12
+ directoryExists(path: string): boolean;
13
+ realpath?(path: string): string;
14
+ };
15
+ export type CliContext = {
16
+ cwd: string;
17
+ stdout: Writable;
18
+ stderr: Writable;
19
+ env: Readonly<Record<string, string | undefined>>;
20
+ fs: CliFileSystem;
21
+ };
@@ -0,0 +1,21 @@
1
+ import type { Writable } from "node:stream";
2
+ export type CliFileSystem = {
3
+ readFile(path: string): string;
4
+ readFileBuffer?(path: string): Uint8Array;
5
+ writeFile(path: string, contents: string): void;
6
+ mkdir(path: string, options: {
7
+ recursive: true;
8
+ }): void;
9
+ rename(from: string, to: string): void;
10
+ unlink(path: string): void;
11
+ fileExists(path: string): boolean;
12
+ directoryExists(path: string): boolean;
13
+ realpath?(path: string): string;
14
+ };
15
+ export type CliContext = {
16
+ cwd: string;
17
+ stdout: Writable;
18
+ stderr: Writable;
19
+ env: Readonly<Record<string, string | undefined>>;
20
+ fs: CliFileSystem;
21
+ };
File without changes
@@ -0,0 +1,6 @@
1
+ import type { CliContext } from "./context.js";
2
+ import type { CommandResult } from "./result.js";
3
+ export type CliProgram = {
4
+ parse(argv: readonly string[]): Promise<CommandResult>;
5
+ };
6
+ export declare const createProgram: (context: CliContext) => CliProgram;
@@ -0,0 +1,6 @@
1
+ import type { CliContext } from "./context.js";
2
+ import type { CommandResult } from "./result.js";
3
+ export type CliProgram = {
4
+ parse(argv: readonly string[]): Promise<CommandResult>;
5
+ };
6
+ export declare const createProgram: (context: CliContext) => CliProgram;
@@ -0,0 +1,48 @@
1
+ import { Command, CommanderError } from "commander";
2
+ import { cliDiagnostic } from "./diagnostics.js";
3
+ import { createCommandResult } from "./result.js";
4
+ import { registerExportGraphCommand } from "../export-graph/command.js";
5
+ import { formatDiagnostics } from "../output/format-diagnostics.js";
6
+ import { registerVisualizeCommand } from "../visualize/command.js";
7
+ const invalidOptionsResult = (context, message) => {
8
+ const diagnostic = cliDiagnostic("LFC_INVALID_OPTIONS", "error", message);
9
+ context.stderr.write(formatDiagnostics([diagnostic]));
10
+ return createCommandResult([diagnostic]);
11
+ };
12
+ const isHelpDisplayed = (error) => {
13
+ return error instanceof CommanderError && error.code === "commander.helpDisplayed";
14
+ };
15
+ const isCommanderError = (error) => {
16
+ return error instanceof CommanderError;
17
+ };
18
+ const createProgram = (context) => {
19
+ let commandResult = { exitCode: 0, diagnostics: [] };
20
+ const program = new Command();
21
+ program.name("lite-fsm").description("lite-fsm command line tools").exitOverride().configureOutput({
22
+ writeOut: (value) => context.stdout.write(value),
23
+ /* v8 ignore next -- commander calls this only for its own formatted stderr, which CLI suppresses in favor of CliDiagnostic output. */
24
+ writeErr: () => void 0,
25
+ outputError: () => void 0
26
+ });
27
+ registerExportGraphCommand(program, context, (result) => {
28
+ commandResult = result;
29
+ });
30
+ registerVisualizeCommand(program, context, (result) => {
31
+ commandResult = result;
32
+ });
33
+ return {
34
+ async parse(argv) {
35
+ commandResult = { exitCode: 0, diagnostics: [] };
36
+ try {
37
+ await program.parseAsync([...argv], { from: "node" });
38
+ } catch (error) {
39
+ if (isHelpDisplayed(error)) return { exitCode: 0, diagnostics: [] };
40
+ return invalidOptionsResult(context, isCommanderError(error) ? error.message : String(error));
41
+ }
42
+ return commandResult;
43
+ }
44
+ };
45
+ };
46
+ export {
47
+ createProgram
48
+ };
@@ -0,0 +1,15 @@
1
+ export type CliDiagnosticSeverity = "info" | "warning" | "error";
2
+ export type CliDiagnosticCode = "LFC_INVALID_OPTIONS" | "LFC_TSCONFIG_NOT_FOUND" | "LFC_TSCONFIG_INVALID" | "LFC_GRAPH_PROJECT_FAILED" | "LFC_NO_MACHINES_EXPORTED" | "LFC_SOURCE_BUNDLE_FILE_UNREADABLE" | "LFC_VISUALIZER_STATIC_MISSING" | "LFC_VISUALIZER_PORT_UNAVAILABLE" | "LFC_VISUALIZER_SERVER_FAILED" | "LFC_VISUALIZER_OPEN_FAILED" | "LFC_WRITE_FAILED";
3
+ export type CliDiagnostic = {
4
+ code: CliDiagnosticCode;
5
+ severity: CliDiagnosticSeverity;
6
+ message: string;
7
+ file?: string;
8
+ loc?: {
9
+ line: number;
10
+ column: number;
11
+ };
12
+ hint?: string;
13
+ };
14
+ export declare const cliDiagnostic: (code: CliDiagnosticCode, severity: CliDiagnosticSeverity, message: string, details?: Omit<CliDiagnostic, "code" | "severity" | "message">) => CliDiagnostic;
15
+ export declare const hasBlockingCliDiagnostics: (diagnostics: readonly CliDiagnostic[]) => boolean;
@@ -0,0 +1,15 @@
1
+ export type CliDiagnosticSeverity = "info" | "warning" | "error";
2
+ export type CliDiagnosticCode = "LFC_INVALID_OPTIONS" | "LFC_TSCONFIG_NOT_FOUND" | "LFC_TSCONFIG_INVALID" | "LFC_GRAPH_PROJECT_FAILED" | "LFC_NO_MACHINES_EXPORTED" | "LFC_SOURCE_BUNDLE_FILE_UNREADABLE" | "LFC_VISUALIZER_STATIC_MISSING" | "LFC_VISUALIZER_PORT_UNAVAILABLE" | "LFC_VISUALIZER_SERVER_FAILED" | "LFC_VISUALIZER_OPEN_FAILED" | "LFC_WRITE_FAILED";
3
+ export type CliDiagnostic = {
4
+ code: CliDiagnosticCode;
5
+ severity: CliDiagnosticSeverity;
6
+ message: string;
7
+ file?: string;
8
+ loc?: {
9
+ line: number;
10
+ column: number;
11
+ };
12
+ hint?: string;
13
+ };
14
+ export declare const cliDiagnostic: (code: CliDiagnosticCode, severity: CliDiagnosticSeverity, message: string, details?: Omit<CliDiagnostic, "code" | "severity" | "message">) => CliDiagnostic;
15
+ export declare const hasBlockingCliDiagnostics: (diagnostics: readonly CliDiagnostic[]) => boolean;
@@ -0,0 +1,13 @@
1
+ const cliDiagnostic = (code, severity, message, details = {}) => ({
2
+ code,
3
+ severity,
4
+ message,
5
+ ...details
6
+ });
7
+ const hasBlockingCliDiagnostics = (diagnostics) => {
8
+ return diagnostics.some((diagnostic) => diagnostic.severity === "error");
9
+ };
10
+ export {
11
+ cliDiagnostic,
12
+ hasBlockingCliDiagnostics
13
+ };
@@ -0,0 +1,2 @@
1
+ import type { CliFileSystem } from "./context.js";
2
+ export declare const createNodeFileSystem: () => CliFileSystem;
@@ -0,0 +1,2 @@
1
+ import type { CliFileSystem } from "./context.js";
2
+ export declare const createNodeFileSystem: () => CliFileSystem;
@@ -0,0 +1,33 @@
1
+ import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
2
+ const createNodeFileSystem = () => ({
3
+ readFile(path) {
4
+ return readFileSync(path, "utf8");
5
+ },
6
+ readFileBuffer(path) {
7
+ return readFileSync(path);
8
+ },
9
+ writeFile(path, contents) {
10
+ writeFileSync(path, contents, "utf8");
11
+ },
12
+ mkdir(path, options) {
13
+ mkdirSync(path, options);
14
+ },
15
+ rename(from, to) {
16
+ renameSync(from, to);
17
+ },
18
+ unlink(path) {
19
+ unlinkSync(path);
20
+ },
21
+ fileExists(path) {
22
+ return existsSync(path) && statSync(path).isFile();
23
+ },
24
+ directoryExists(path) {
25
+ return existsSync(path) && statSync(path).isDirectory();
26
+ },
27
+ realpath(path) {
28
+ return realpathSync(path);
29
+ }
30
+ });
31
+ export {
32
+ createNodeFileSystem
33
+ };
@@ -0,0 +1,6 @@
1
+ import type { CliDiagnostic } from "./diagnostics.js";
2
+ export type CommandResult = {
3
+ exitCode: 0 | 1;
4
+ diagnostics: CliDiagnostic[];
5
+ };
6
+ export declare const createCommandResult: (diagnostics: readonly CliDiagnostic[]) => CommandResult;
@@ -0,0 +1,6 @@
1
+ import type { CliDiagnostic } from "./diagnostics.js";
2
+ export type CommandResult = {
3
+ exitCode: 0 | 1;
4
+ diagnostics: CliDiagnostic[];
5
+ };
6
+ export declare const createCommandResult: (diagnostics: readonly CliDiagnostic[]) => CommandResult;
@@ -0,0 +1,8 @@
1
+ import { hasBlockingCliDiagnostics } from "./diagnostics.js";
2
+ const createCommandResult = (diagnostics) => ({
3
+ exitCode: hasBlockingCliDiagnostics(diagnostics) ? 1 : 0,
4
+ diagnostics: [...diagnostics]
5
+ });
6
+ export {
7
+ createCommandResult
8
+ };
@@ -0,0 +1,8 @@
1
+ import type { Command } from "commander";
2
+ import type { CliContext } from "../cli/context.js";
3
+ import type { CommandResult } from "../cli/result.js";
4
+ import { type RawExportGraphOptions } from "./options.js";
5
+ type SetCommandResult = (result: CommandResult) => void;
6
+ export declare const runExportGraphCommand: (context: CliContext, rawOptions: RawExportGraphOptions) => Promise<CommandResult>;
7
+ export declare const registerExportGraphCommand: (program: Command, context: CliContext, setResult: SetCommandResult) => void;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { Command } from "commander";
2
+ import type { CliContext } from "../cli/context.js";
3
+ import type { CommandResult } from "../cli/result.js";
4
+ import { type RawExportGraphOptions } from "./options.js";
5
+ type SetCommandResult = (result: CommandResult) => void;
6
+ export declare const runExportGraphCommand: (context: CliContext, rawOptions: RawExportGraphOptions) => Promise<CommandResult>;
7
+ export declare const registerExportGraphCommand: (program: Command, context: CliContext, setResult: SetCommandResult) => void;
8
+ export {};
@@ -0,0 +1,30 @@
1
+ import { createCommandResult } from "../cli/result.js";
2
+ import { formatDiagnostics } from "../output/format-diagnostics.js";
3
+ import { normalizeExportGraphOptions } from "./options.js";
4
+ const writeDiagnostics = (context, diagnostics) => {
5
+ const formatted = formatDiagnostics(diagnostics);
6
+ if (formatted) context.stderr.write(formatted);
7
+ };
8
+ const runExportGraphCommand = async (context, rawOptions) => {
9
+ const normalized = normalizeExportGraphOptions(rawOptions);
10
+ if (!normalized.ok) {
11
+ writeDiagnostics(context, normalized.diagnostics);
12
+ return createCommandResult(normalized.diagnostics);
13
+ }
14
+ const { runExportGraph } = await import("./run-export-graph.js");
15
+ const result = runExportGraph(context, normalized.options);
16
+ writeDiagnostics(context, [...result.diagnostics, ...result.graphDiagnostics]);
17
+ return {
18
+ exitCode: result.exitCode,
19
+ diagnostics: result.diagnostics
20
+ };
21
+ };
22
+ const registerExportGraphCommand = (program, context, setResult) => {
23
+ program.command("export-graph").description("Export a lite-fsm project graph document as JSON").option("--entry <path>", "entrypoint TypeScript file").option("--out <path>", "output JSON file").option("--tsconfig <path>", "explicit tsconfig for TypeScript module resolution").option("--include-source", "embed project source text in JSON export").action(async (options) => {
24
+ setResult(await runExportGraphCommand(context, options));
25
+ });
26
+ };
27
+ export {
28
+ registerExportGraphCommand,
29
+ runExportGraphCommand
30
+ };
@@ -0,0 +1,38 @@
1
+ import type { LiteFsmGraphDocument, LiteFsmGraphProjectFile, LiteFsmGraphProjectResult } from "@lite-fsm/graph";
2
+ import type { CliDiagnostic } from "../cli/diagnostics.js";
3
+ export declare const PROJECT_GRAPH_EXPORT_VERSION = "lite-fsm.project-graph-export/v1";
4
+ export declare const CLI_PACKAGE_NAME = "@lite-fsm/cli";
5
+ export declare const CLI_PACKAGE_VERSION = "0.1.0";
6
+ export type LiteFsmProjectGraphExportDocument = {
7
+ version: typeof PROJECT_GRAPH_EXPORT_VERSION;
8
+ createdBy: {
9
+ package: typeof CLI_PACKAGE_NAME;
10
+ version: string;
11
+ };
12
+ entry: {
13
+ path: string;
14
+ tsconfigPath?: string;
15
+ };
16
+ graph: LiteFsmGraphDocument;
17
+ files: readonly LiteFsmGraphProjectFile[];
18
+ diagnostics: readonly CliDiagnostic[];
19
+ sources?: LiteFsmProjectGraphSourceBundle;
20
+ };
21
+ export type LiteFsmProjectGraphSourceFile = {
22
+ fileName: string;
23
+ language: "ts";
24
+ hash: string;
25
+ text: string;
26
+ };
27
+ export type LiteFsmProjectGraphSourceBundle = {
28
+ files: readonly LiteFsmProjectGraphSourceFile[];
29
+ };
30
+ export type CreateProjectGraphExportDocumentOptions = {
31
+ entryPath: string;
32
+ tsconfigPath?: string;
33
+ graphResult: LiteFsmGraphProjectResult;
34
+ diagnostics: readonly CliDiagnostic[];
35
+ sources?: LiteFsmProjectGraphSourceBundle;
36
+ };
37
+ export declare const createProjectGraphExportDocument: ({ entryPath, tsconfigPath, graphResult, diagnostics, sources, }: CreateProjectGraphExportDocumentOptions) => LiteFsmProjectGraphExportDocument;
38
+ export declare const stringifyProjectGraphExportDocument: (document: LiteFsmProjectGraphExportDocument) => string;
@@ -0,0 +1,38 @@
1
+ import type { LiteFsmGraphDocument, LiteFsmGraphProjectFile, LiteFsmGraphProjectResult } from "@lite-fsm/graph";
2
+ import type { CliDiagnostic } from "../cli/diagnostics.js";
3
+ export declare const PROJECT_GRAPH_EXPORT_VERSION = "lite-fsm.project-graph-export/v1";
4
+ export declare const CLI_PACKAGE_NAME = "@lite-fsm/cli";
5
+ export declare const CLI_PACKAGE_VERSION = "0.1.0";
6
+ export type LiteFsmProjectGraphExportDocument = {
7
+ version: typeof PROJECT_GRAPH_EXPORT_VERSION;
8
+ createdBy: {
9
+ package: typeof CLI_PACKAGE_NAME;
10
+ version: string;
11
+ };
12
+ entry: {
13
+ path: string;
14
+ tsconfigPath?: string;
15
+ };
16
+ graph: LiteFsmGraphDocument;
17
+ files: readonly LiteFsmGraphProjectFile[];
18
+ diagnostics: readonly CliDiagnostic[];
19
+ sources?: LiteFsmProjectGraphSourceBundle;
20
+ };
21
+ export type LiteFsmProjectGraphSourceFile = {
22
+ fileName: string;
23
+ language: "ts";
24
+ hash: string;
25
+ text: string;
26
+ };
27
+ export type LiteFsmProjectGraphSourceBundle = {
28
+ files: readonly LiteFsmProjectGraphSourceFile[];
29
+ };
30
+ export type CreateProjectGraphExportDocumentOptions = {
31
+ entryPath: string;
32
+ tsconfigPath?: string;
33
+ graphResult: LiteFsmGraphProjectResult;
34
+ diagnostics: readonly CliDiagnostic[];
35
+ sources?: LiteFsmProjectGraphSourceBundle;
36
+ };
37
+ export declare const createProjectGraphExportDocument: ({ entryPath, tsconfigPath, graphResult, diagnostics, sources, }: CreateProjectGraphExportDocumentOptions) => LiteFsmProjectGraphExportDocument;
38
+ export declare const stringifyProjectGraphExportDocument: (document: LiteFsmProjectGraphExportDocument) => string;
@@ -0,0 +1,35 @@
1
+ import { stringifyStableJson } from "../output/stable-json.js";
2
+ const PROJECT_GRAPH_EXPORT_VERSION = "lite-fsm.project-graph-export/v1";
3
+ const CLI_PACKAGE_NAME = "@lite-fsm/cli";
4
+ const CLI_PACKAGE_VERSION = "0.1.0";
5
+ const createProjectGraphExportDocument = ({
6
+ entryPath,
7
+ tsconfigPath,
8
+ graphResult,
9
+ diagnostics,
10
+ sources
11
+ }) => ({
12
+ version: PROJECT_GRAPH_EXPORT_VERSION,
13
+ createdBy: {
14
+ package: CLI_PACKAGE_NAME,
15
+ version: CLI_PACKAGE_VERSION
16
+ },
17
+ entry: {
18
+ path: entryPath,
19
+ ...tsconfigPath ? { tsconfigPath } : {}
20
+ },
21
+ graph: graphResult.document,
22
+ files: graphResult.files,
23
+ diagnostics,
24
+ ...sources ? { sources } : {}
25
+ });
26
+ const stringifyProjectGraphExportDocument = (document) => {
27
+ return stringifyStableJson(document);
28
+ };
29
+ export {
30
+ CLI_PACKAGE_NAME,
31
+ CLI_PACKAGE_VERSION,
32
+ PROJECT_GRAPH_EXPORT_VERSION,
33
+ createProjectGraphExportDocument,
34
+ stringifyProjectGraphExportDocument
35
+ };
@@ -0,0 +1,21 @@
1
+ import type { CliDiagnostic } from "../cli/diagnostics.js";
2
+ export type ExportGraphOptions = {
3
+ entry: string;
4
+ out: string;
5
+ tsconfig?: string;
6
+ includeSource: boolean;
7
+ };
8
+ export type RawExportGraphOptions = {
9
+ entry?: unknown;
10
+ out?: unknown;
11
+ tsconfig?: unknown;
12
+ includeSource?: unknown;
13
+ };
14
+ export type NormalizeExportGraphOptionsResult = {
15
+ ok: true;
16
+ options: ExportGraphOptions;
17
+ } | {
18
+ ok: false;
19
+ diagnostics: CliDiagnostic[];
20
+ };
21
+ export declare const normalizeExportGraphOptions: (rawOptions: RawExportGraphOptions) => NormalizeExportGraphOptionsResult;
@@ -0,0 +1,21 @@
1
+ import type { CliDiagnostic } from "../cli/diagnostics.js";
2
+ export type ExportGraphOptions = {
3
+ entry: string;
4
+ out: string;
5
+ tsconfig?: string;
6
+ includeSource: boolean;
7
+ };
8
+ export type RawExportGraphOptions = {
9
+ entry?: unknown;
10
+ out?: unknown;
11
+ tsconfig?: unknown;
12
+ includeSource?: unknown;
13
+ };
14
+ export type NormalizeExportGraphOptionsResult = {
15
+ ok: true;
16
+ options: ExportGraphOptions;
17
+ } | {
18
+ ok: false;
19
+ diagnostics: CliDiagnostic[];
20
+ };
21
+ export declare const normalizeExportGraphOptions: (rawOptions: RawExportGraphOptions) => NormalizeExportGraphOptionsResult;
@@ -0,0 +1,40 @@
1
+ import { cliDiagnostic } from "../cli/diagnostics.js";
2
+ const stringOption = (value) => {
3
+ return typeof value === "string" && value.trim() !== "" ? value : void 0;
4
+ };
5
+ const normalizeExportGraphOptions = (rawOptions) => {
6
+ const entry = stringOption(rawOptions.entry);
7
+ const out = stringOption(rawOptions.out);
8
+ const tsconfig = stringOption(rawOptions.tsconfig);
9
+ const includeSource = rawOptions.includeSource === true;
10
+ const diagnostics = [];
11
+ if (!entry) {
12
+ diagnostics.push(
13
+ cliDiagnostic("LFC_INVALID_OPTIONS", "error", "Option --entry is required.", {
14
+ hint: "Pass --entry path/to/store/index.ts."
15
+ })
16
+ );
17
+ }
18
+ if (!out) {
19
+ diagnostics.push(
20
+ cliDiagnostic("LFC_INVALID_OPTIONS", "error", "Option --out is required.", {
21
+ hint: "Pass --out lite-fsm.graph.json."
22
+ })
23
+ );
24
+ } else if (out === "-") {
25
+ diagnostics.push(cliDiagnostic("LFC_INVALID_OPTIONS", "error", "JSON stdout output is not supported. Pass a file path to --out."));
26
+ }
27
+ if (diagnostics.length > 0) return { ok: false, diagnostics };
28
+ return {
29
+ ok: true,
30
+ options: {
31
+ entry,
32
+ out,
33
+ includeSource,
34
+ ...tsconfig ? { tsconfig } : {}
35
+ }
36
+ };
37
+ };
38
+ export {
39
+ normalizeExportGraphOptions
40
+ };
@@ -0,0 +1,10 @@
1
+ import type { GraphDiagnostic } from "@lite-fsm/graph";
2
+ import type { CliContext } from "../cli/context.js";
3
+ import type { CommandResult } from "../cli/result.js";
4
+ import { type ProjectGraphBuildResult } from "../project/build-project-graph.js";
5
+ import type { ExportGraphOptions } from "./options.js";
6
+ export type ExportGraphRunResult = CommandResult & {
7
+ graphDiagnostics: GraphDiagnostic[];
8
+ };
9
+ export declare const createExportGraphRunResult: (context: CliContext, options: ExportGraphOptions, buildResult: ProjectGraphBuildResult) => ExportGraphRunResult;
10
+ export declare const runExportGraph: (context: CliContext, options: ExportGraphOptions) => ExportGraphRunResult;
@@ -0,0 +1,10 @@
1
+ import type { GraphDiagnostic } from "@lite-fsm/graph";
2
+ import type { CliContext } from "../cli/context.js";
3
+ import type { CommandResult } from "../cli/result.js";
4
+ import { type ProjectGraphBuildResult } from "../project/build-project-graph.js";
5
+ import type { ExportGraphOptions } from "./options.js";
6
+ export type ExportGraphRunResult = CommandResult & {
7
+ graphDiagnostics: GraphDiagnostic[];
8
+ };
9
+ export declare const createExportGraphRunResult: (context: CliContext, options: ExportGraphOptions, buildResult: ProjectGraphBuildResult) => ExportGraphRunResult;
10
+ export declare const runExportGraph: (context: CliContext, options: ExportGraphOptions) => ExportGraphRunResult;
@@ -0,0 +1,53 @@
1
+ import { cliDiagnostic, hasBlockingCliDiagnostics } from "../cli/diagnostics.js";
2
+ import { buildProjectGraph } from "../project/build-project-graph.js";
3
+ import { createProjectGraphExportDocument, stringifyProjectGraphExportDocument } from "./export-document.js";
4
+ import { createProjectGraphSourceBundle } from "./source-bundle.js";
5
+ import { writeOutput } from "./write-output.js";
6
+ const graphHasBlockingDiagnostics = (diagnostics) => {
7
+ return diagnostics.some((diagnostic) => diagnostic.severity === "error");
8
+ };
9
+ const hasExportedMachines = (graphResult) => {
10
+ return graphResult.document.managers.some((manager) => manager.machineRefs.length > 0);
11
+ };
12
+ const result = (diagnostics, graphDiagnostics = []) => ({
13
+ exitCode: hasBlockingCliDiagnostics(diagnostics) ? 1 : 0,
14
+ diagnostics: [...diagnostics],
15
+ graphDiagnostics: [...graphDiagnostics]
16
+ });
17
+ const createExportGraphRunResult = (context, options, buildResult) => {
18
+ const graphDiagnostics = buildResult.graphResult?.diagnostics ?? [];
19
+ const diagnostics = [...buildResult.diagnostics];
20
+ if (buildResult.blocking) return result(diagnostics, graphDiagnostics);
21
+ if (!buildResult.graphResult) {
22
+ diagnostics.push(cliDiagnostic("LFC_GRAPH_PROJECT_FAILED", "error", "Project graph build did not return a graph result."));
23
+ return result(diagnostics, graphDiagnostics);
24
+ }
25
+ if (graphHasBlockingDiagnostics(graphDiagnostics)) {
26
+ diagnostics.push(cliDiagnostic("LFC_GRAPH_PROJECT_FAILED", "error", "Project graph compile finished with blocking diagnostics."));
27
+ return result(diagnostics, graphDiagnostics);
28
+ }
29
+ if (!hasExportedMachines(buildResult.graphResult)) {
30
+ diagnostics.push(cliDiagnostic("LFC_NO_MACHINES_EXPORTED", "error", "Project graph export has no manager machine refs."));
31
+ return result(diagnostics, graphDiagnostics);
32
+ }
33
+ const sources = options.includeSource ? createProjectGraphSourceBundle(context, buildResult.project.projectRoot, buildResult.graphResult.files) : void 0;
34
+ if (sources && !sources.ok) return result([...diagnostics, ...sources.diagnostics], graphDiagnostics);
35
+ const document = createProjectGraphExportDocument({
36
+ entryPath: buildResult.project.entryPath,
37
+ tsconfigPath: buildResult.project.tsconfigPath,
38
+ graphResult: buildResult.graphResult,
39
+ diagnostics,
40
+ ...sources ? { sources: sources.sources } : {}
41
+ });
42
+ const written = writeOutput(context, options.out, stringifyProjectGraphExportDocument(document));
43
+ if (!written.ok) return result([...diagnostics, ...written.diagnostics], graphDiagnostics);
44
+ return result(diagnostics, graphDiagnostics);
45
+ };
46
+ const runExportGraph = (context, options) => {
47
+ const buildResult = buildProjectGraph(context, { entry: options.entry, tsconfig: options.tsconfig });
48
+ return createExportGraphRunResult(context, options, buildResult);
49
+ };
50
+ export {
51
+ createExportGraphRunResult,
52
+ runExportGraph
53
+ };
@@ -0,0 +1,12 @@
1
+ import type { LiteFsmGraphProjectFile } from "@lite-fsm/graph";
2
+ import type { CliContext } from "../cli/context.js";
3
+ import type { CliDiagnostic } from "../cli/diagnostics.js";
4
+ import type { LiteFsmProjectGraphSourceBundle } from "./export-document.js";
5
+ export type CreateProjectGraphSourceBundleResult = {
6
+ ok: true;
7
+ sources: LiteFsmProjectGraphSourceBundle;
8
+ } | {
9
+ ok: false;
10
+ diagnostics: CliDiagnostic[];
11
+ };
12
+ export declare const createProjectGraphSourceBundle: (context: CliContext, projectRoot: string, files: readonly LiteFsmGraphProjectFile[]) => CreateProjectGraphSourceBundleResult;
@@ -0,0 +1,12 @@
1
+ import type { LiteFsmGraphProjectFile } from "@lite-fsm/graph";
2
+ import type { CliContext } from "../cli/context.js";
3
+ import type { CliDiagnostic } from "../cli/diagnostics.js";
4
+ import type { LiteFsmProjectGraphSourceBundle } from "./export-document.js";
5
+ export type CreateProjectGraphSourceBundleResult = {
6
+ ok: true;
7
+ sources: LiteFsmProjectGraphSourceBundle;
8
+ } | {
9
+ ok: false;
10
+ diagnostics: CliDiagnostic[];
11
+ };
12
+ export declare const createProjectGraphSourceBundle: (context: CliContext, projectRoot: string, files: readonly LiteFsmGraphProjectFile[]) => CreateProjectGraphSourceBundleResult;