@antelopejs/dms-frontend 0.3.8 → 0.3.10

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 (80) hide show
  1. package/README.md +87 -23
  2. package/dist/cancellation.d.ts +8 -0
  3. package/dist/cancellation.js +23 -0
  4. package/dist/child-output.d.ts +45 -0
  5. package/dist/child-output.js +183 -0
  6. package/dist/commands/build-action.d.ts +21 -0
  7. package/dist/commands/build-action.js +144 -0
  8. package/dist/commands/build.js +54 -62
  9. package/dist/commands/clean-action.d.ts +8 -0
  10. package/dist/commands/clean-action.js +97 -0
  11. package/dist/commands/clean.js +52 -39
  12. package/dist/commands/dev-action.d.ts +8 -0
  13. package/dist/commands/dev-action.js +120 -0
  14. package/dist/commands/dev.js +55 -115
  15. package/dist/commands/prepare-action.d.ts +8 -0
  16. package/dist/commands/prepare-action.js +73 -0
  17. package/dist/commands/prepare.js +55 -54
  18. package/dist/commands/start-action.d.ts +5 -0
  19. package/dist/commands/start-action.js +77 -0
  20. package/dist/commands/start.js +48 -48
  21. package/dist/commands/verify-source-action.d.ts +10 -0
  22. package/dist/commands/verify-source-action.js +104 -0
  23. package/dist/commands/verify-source.d.ts +0 -1
  24. package/dist/commands/verify-source.js +53 -31
  25. package/dist/commands/workspace-task.d.ts +2 -0
  26. package/dist/commands/workspace-task.js +26 -0
  27. package/dist/commands/workspaces-action.d.ts +25 -0
  28. package/dist/commands/workspaces-action.js +71 -0
  29. package/dist/commands/workspaces.d.ts +2 -0
  30. package/dist/commands/workspaces.js +60 -0
  31. package/dist/common.d.ts +1 -0
  32. package/dist/common.js +1 -0
  33. package/dist/config.d.ts +13 -4
  34. package/dist/config.js +115 -18
  35. package/dist/derived-outputs.d.ts +6 -1
  36. package/dist/derived-outputs.js +12 -3
  37. package/dist/discovery.d.ts +2 -1
  38. package/dist/discovery.js +28 -11
  39. package/dist/env-file.js +5 -2
  40. package/dist/help.d.ts +5 -0
  41. package/dist/help.js +71 -0
  42. package/dist/index.js +129 -38
  43. package/dist/layer-watch.d.ts +2 -1
  44. package/dist/layer-watch.js +129 -26
  45. package/dist/layers.d.ts +9 -2
  46. package/dist/layers.js +82 -23
  47. package/dist/manifest-secrets.d.ts +3 -2
  48. package/dist/manifest-secrets.js +25 -21
  49. package/dist/manifest.d.ts +22 -5
  50. package/dist/manifest.js +184 -28
  51. package/dist/materialize.js +2 -1
  52. package/dist/output.d.ts +43 -0
  53. package/dist/output.js +214 -0
  54. package/dist/ports.d.ts +2 -0
  55. package/dist/ports.js +23 -13
  56. package/dist/renderer-range.d.ts +3 -1
  57. package/dist/renderer-range.js +49 -17
  58. package/dist/server-process.d.ts +39 -0
  59. package/dist/server-process.js +226 -0
  60. package/dist/typecheck-output.d.ts +13 -0
  61. package/dist/typecheck-output.js +87 -0
  62. package/dist/update-check.d.ts +14 -2
  63. package/dist/update-check.js +97 -29
  64. package/dist/verify-source-result.d.ts +11 -0
  65. package/dist/verify-source-result.js +17 -0
  66. package/dist/verify-source-runner.js +266 -131
  67. package/dist/vite-output.d.ts +14 -0
  68. package/dist/vite-output.js +99 -0
  69. package/dist/workspace-setup.d.ts +17 -3
  70. package/dist/workspace-setup.js +122 -35
  71. package/dist/workspace.d.ts +8 -2
  72. package/dist/workspace.js +47 -12
  73. package/package.json +4 -12
  74. package/templates/vue/package.json +4 -0
  75. package/templates/vue/server/cli-report.mjs +91 -0
  76. package/templates/vue/server.mjs +18 -15
  77. package/templates/vue/vite.config.ts +8 -1
  78. package/templates/vue/vite.email.config.ts +5 -1
  79. package/dist/utils/cli-ui.d.ts +0 -27
  80. package/dist/utils/cli-ui.js +0 -178
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runPrepare = runPrepare;
4
+ const cli_1 = require("@antelopejs/core/cli");
5
+ const common_1 = require("../common");
6
+ const output_1 = require("../output");
7
+ const workspace_task_1 = require("./workspace-task");
8
+ const NOT_GENERATED = "The types and the module registry were not generated.";
9
+ const STRICT_HINT = "prepare never fails an install; add --strict to make this an error.";
10
+ function isSkip(error) {
11
+ return (error instanceof common_1.BackendUnreachableError ||
12
+ error instanceof common_1.NoCachedManifestError);
13
+ }
14
+ async function runPrepare(options) {
15
+ const startedAt = Date.now();
16
+ const offline = (0, common_1.flagOrEnv)(options.offline, "DMS_OFFLINE");
17
+ const strict = (0, common_1.flagOrEnv)(options.strict, "DMS_PREPARE_STRICT");
18
+ const ui = (0, cli_1.getProcessUi)();
19
+ const hint = ui.symbols.levels.hint;
20
+ if (!options.backendUrl) {
21
+ if (strict)
22
+ (0, common_1.requireBackendUrl)(options.backendUrl);
23
+ ui.message("warn", "Skipped prepare: no backend URL", {
24
+ details: [
25
+ `${hint} Pass -b <url> or set DMS_API_BASE_URL to generate the types`,
26
+ STRICT_HINT,
27
+ ],
28
+ });
29
+ return;
30
+ }
31
+ let result;
32
+ try {
33
+ const backendUrl = (0, common_1.parseBackendUrl)(options.backendUrl);
34
+ const bootstrapSecret = (0, common_1.resolveBootstrapSecret)(options.bootstrapSecret, options.backendUrl);
35
+ (0, output_1.writeHeader)("prepare", [backendUrl]);
36
+ result = await (0, workspace_task_1.setUpWorkspace)({
37
+ backendUrl,
38
+ force: !!options.force,
39
+ mode: "dev",
40
+ offline,
41
+ bootstrapSecret,
42
+ });
43
+ }
44
+ catch (err) {
45
+ if (err instanceof common_1.CancelledError || strict)
46
+ throw err;
47
+ const [title, ...details] = (0, output_1.failureDetails)(err, ui);
48
+ const outcome = isSkip(err) ? "Skipped prepare" : "Prepare failed";
49
+ ui.message("warn", `${outcome}: ${title}`, {
50
+ details: [...details, NOT_GENERATED, STRICT_HINT],
51
+ });
52
+ return;
53
+ }
54
+ const { workspaceDir, layers, manifestFromCache, manifestFetchedAt } = result;
55
+ if (manifestFromCache) {
56
+ const manifest = `the frontend-module manifest${(0, output_1.cachedAge)(manifestFetchedAt)}`;
57
+ if (offline) {
58
+ ui.message("info", `Offline: using ${manifest}`);
59
+ }
60
+ else {
61
+ ui.message("warn", `Backend unreachable: using ${manifest}`);
62
+ }
63
+ }
64
+ const summary = [
65
+ "Prepared the workspace",
66
+ (0, cli_1.pluralize)(layers.length, "module"),
67
+ "types and registry written",
68
+ (0, cli_1.formatDuration)(Date.now() - startedAt),
69
+ ];
70
+ ui.message("success", summary.join(ui.symbols.separator), {
71
+ detail: (0, output_1.showWorkspace)(workspaceDir),
72
+ });
73
+ }
@@ -1,60 +1,61 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
5
35
  Object.defineProperty(exports, "__esModule", { value: true });
6
36
  exports.cmdPrepare = cmdPrepare;
7
- const chalk_1 = __importDefault(require("chalk"));
8
37
  const commander_1 = require("commander");
9
- const common_1 = require("../common");
10
- const cli_ui_1 = require("../utils/cli-ui");
38
+ const config_1 = require("../config");
39
+ const cli_1 = require("@antelopejs/core/cli");
40
+ const PREPARE_EXAMPLES = [
41
+ {
42
+ description: "From a frontend module's postinstall hook",
43
+ command: "ajs dms prepare",
44
+ },
45
+ {
46
+ description: "Before a CI type check, which needs the types",
47
+ command: "ajs dms prepare -b http://localhost:5010 --strict",
48
+ },
49
+ ];
11
50
  function cmdPrepare() {
12
- return new commander_1.Command("prepare")
13
- .description("Prepare the generated Vite workspace and frontend-module registry")
14
- .addOption(common_1.Options.backendUrl)
15
- .addOption(common_1.Options.force)
16
- .addOption(common_1.Options.offline)
17
- .addOption(common_1.Options.bootstrapSecret)
18
- .action(async (options) => {
19
- if (!options.backendUrl) {
20
- (0, cli_ui_1.warning)("Backend URL not set; skipping prepare. Pass -b <url> or set DMS_API_BASE_URL to generate types.");
21
- process.exit(0);
22
- }
23
- const spinner = new cli_ui_1.Spinner("Setting up workspace...");
24
- await spinner.start();
25
- let workspaceDir;
26
- let manifestFromCache;
27
- let manifestFetchedAt;
28
- try {
29
- const result = await (0, common_1.setupWorkspace)({
30
- backendUrl: options.backendUrl,
31
- force: !!options.force,
32
- mode: "dev",
33
- offline: options.offline,
34
- bootstrapSecret: (0, common_1.resolveBootstrapSecret)(options.bootstrapSecret, options.backendUrl),
35
- });
36
- workspaceDir = result.workspaceDir;
37
- manifestFromCache = result.manifestFromCache;
38
- manifestFetchedAt = result.manifestFetchedAt;
39
- }
40
- catch (err) {
41
- await spinner.warn(`Skipping prepare: ${err.message}`);
42
- process.exit(0);
43
- }
44
- await spinner.succeed("Workspace ready");
45
- if (manifestFromCache) {
46
- const cachedOn = manifestFetchedAt
47
- ? ` (cached on ${manifestFetchedAt})`
48
- : "";
49
- if (options.offline) {
50
- (0, cli_ui_1.info)(`Offline mode — using cached frontend-module manifest${cachedOn}`);
51
- }
52
- else {
53
- (0, cli_ui_1.warning)(`Backend unreachable — using cached frontend-module manifest${cachedOn}`);
54
- }
55
- }
56
- console.log("");
57
- (0, cli_ui_1.success)(`Vite workspace prepared ${chalk_1.default.dim(`(${workspaceDir})`)}`);
58
- process.exit(0);
59
- });
51
+ const command = new commander_1.Command("prepare")
52
+ .summary("Generate the workspace and module types (postinstall-safe)")
53
+ .description("Generate the workspace, the frontend-module registry and the module types. Without --strict, prepare never fails: when it cannot prepare the workspace it warns and exits 0, so a postinstall hook never breaks an install.")
54
+ .addOption(config_1.Options.backendUrl("Backend URL; without one, prepare is skipped with a warning"))
55
+ .addOption(config_1.Options.force("Reinstall the workspace dependencies"))
56
+ .addOption(config_1.Options.offline("Reuse the last cached manifest instead of fetching it"))
57
+ .addOption(config_1.Options.strict)
58
+ .addOption(config_1.Options.bootstrapSecret("Discovered from .antelope/dms-dev.json for the enclosing project's backend"))
59
+ .action(async (options) => (await Promise.resolve().then(() => __importStar(require("./prepare-action")))).runPrepare(options));
60
+ return (0, cli_1.withExamples)(command, PREPARE_EXAMPLES);
60
61
  }
@@ -0,0 +1,5 @@
1
+ export interface StartOptions {
2
+ backendUrl?: string;
3
+ port: string;
4
+ }
5
+ export declare function runStart(options: StartOptions): Promise<void>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runStart = runStart;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const cli_1 = require("@antelopejs/core/cli");
7
+ const common_1 = require("../common");
8
+ const output_1 = require("../output");
9
+ const ports_1 = require("../ports");
10
+ const server_process_1 = require("../server-process");
11
+ const update_check_1 = require("../update-check");
12
+ const BUILD_TIME_MANIFEST = "the build-time manifest";
13
+ async function runStart(options) {
14
+ const startedAt = Date.now();
15
+ const backendUrl = (0, common_1.requireBackendUrl)(options.backendUrl);
16
+ const requestedPort = (0, common_1.parsePort)(options.port);
17
+ const sessionSecret = (0, common_1.resolveSessionSecret)("start");
18
+ const workspaceDir = (0, common_1.getWorkspaceDir)(backendUrl);
19
+ const serverPath = (0, node_path_1.join)(workspaceDir, "server.mjs");
20
+ const clientPath = (0, node_path_1.join)(workspaceDir, "dist", "client", "index.html");
21
+ if (!(0, node_fs_1.existsSync)(serverPath) || !(0, node_fs_1.existsSync)(clientPath)) {
22
+ throw new cli_1.CliError({
23
+ title: `No production build for ${backendUrl}`,
24
+ reason: `${(0, output_1.showWorkspace)(workspaceDir)} has no built server or client.`,
25
+ fixes: [`Build it first: ajs dms build -b ${backendUrl}`],
26
+ });
27
+ }
28
+ (0, common_1.writeWorkspaceMeta)(workspaceDir, backendUrl, (0, common_1.canonicalizeBackendUrl)(backendUrl));
29
+ const builtAt = (0, node_fs_1.statSync)(clientPath).mtime.toISOString();
30
+ (0, output_1.writeHeader)("start", [
31
+ backendUrl,
32
+ "production",
33
+ `built ${(0, output_1.formatAge)(builtAt)}`,
34
+ ]);
35
+ const reserved = await (0, ports_1.reservePort)(requestedPort);
36
+ if (!reserved) {
37
+ throw new cli_1.CliError({
38
+ title: `Port ${requestedPort} is already in use`,
39
+ fixes: [
40
+ "Stop the process listening on it, or pass another port: -p <port>",
41
+ ],
42
+ });
43
+ }
44
+ const port = reserved.port;
45
+ const secrets = (0, common_1.resolveManifestSecrets)((0, common_1.collectManifestSecrets)((0, common_1.readCachedManifest)(workspaceDir)?.manifest.modules ?? []));
46
+ (0, common_1.reportManifestSecrets)(secrets, (count) => `Set ${count === 1 ? "it" : "them"}, or rebuild with DMS_BOOTSTRAP_SECRET so the manifest carries ${count === 1 ? "it" : "them"}`);
47
+ const secretSources = (0, common_1.describeSecretSources)(secrets.sources, BUILD_TIME_MANIFEST);
48
+ await reserved.release();
49
+ const code = await (0, server_process_1.runServer)({
50
+ name: "production server",
51
+ script: serverPath,
52
+ cwd: workspaceDir,
53
+ env: {
54
+ ...process.env,
55
+ PORT: String(port),
56
+ DMS_API_BASE_URL: backendUrl,
57
+ DMS_SESSION_SECRET: sessionSecret,
58
+ ...secrets.env,
59
+ DMS_COOKIE_SECURE: process.env.DMS_COOKIE_SECURE ?? "true",
60
+ },
61
+ onReady: (address) => {
62
+ (0, output_1.writeReadyBlock)({
63
+ title: `Production server ready in ${(0, cli_1.formatDuration)(Date.now() - startedAt)}`,
64
+ lines: (0, server_process_1.readyLines)(address, [
65
+ { label: "Backend", value: backendUrl },
66
+ { label: "Workspace", value: (0, output_1.showWorkspace)(workspaceDir) },
67
+ ...(secretSources
68
+ ? [{ label: "Secrets", value: secretSources }]
69
+ : []),
70
+ ]),
71
+ footer: "Ctrl+C to stop",
72
+ });
73
+ void (0, update_check_1.reportAvailableUpdate)({ isFollowed: true });
74
+ },
75
+ });
76
+ process.exitCode = code;
77
+ }
@@ -1,54 +1,54 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
5
35
  Object.defineProperty(exports, "__esModule", { value: true });
6
36
  exports.cmdStart = cmdStart;
7
- const node_fs_1 = require("node:fs");
8
- const node_path_1 = require("node:path");
9
- const chalk_1 = __importDefault(require("chalk"));
10
37
  const commander_1 = require("commander");
11
- const common_1 = require("../common");
12
- const cli_ui_1 = require("../utils/cli-ui");
38
+ const config_1 = require("../config");
39
+ const cli_1 = require("@antelopejs/core/cli");
40
+ const START_EXAMPLES = [
41
+ {
42
+ description: "After ajs dms build -b https://dms.example.com",
43
+ command: "ajs dms start -b https://dms.example.com -p 3001",
44
+ },
45
+ ];
13
46
  function cmdStart() {
14
- return new commander_1.Command("start")
15
- .description("Start the production server from a built workspace")
16
- .addOption(common_1.Options.backendUrl)
17
- .addOption(common_1.Options.port)
18
- .action(async (options) => {
19
- if (!options.backendUrl) {
20
- (0, cli_ui_1.error)("Backend URL is required. Use -b <url> or set DMS_API_BASE_URL.");
21
- process.exit(1);
22
- }
23
- const sessionSecret = (0, common_1.resolveSessionSecret)("start");
24
- const workspaceDir = (0, common_1.getWorkspaceDir)(options.backendUrl);
25
- const serverPath = (0, node_path_1.join)(workspaceDir, "server.mjs");
26
- const clientPath = (0, node_path_1.join)(workspaceDir, "dist", "client", "index.html");
27
- if (!(0, node_fs_1.existsSync)(serverPath) || !(0, node_fs_1.existsSync)(clientPath)) {
28
- console.log("");
29
- (0, cli_ui_1.error)("Production build not found!");
30
- console.log(chalk_1.default.dim(" Run 'ajs dms build -b " +
31
- options.backendUrl +
32
- "' first to create a production build"));
33
- process.exit(1);
34
- }
35
- console.log("");
36
- (0, cli_ui_1.info)(`Starting production server on port ${chalk_1.default.cyan(options.port)}...`);
37
- console.log(chalk_1.default.dim(` Workspace: ${workspaceDir}`));
38
- const secrets = (0, common_1.resolveManifestSecrets)((0, common_1.collectManifestSecrets)((0, common_1.readCachedManifest)(workspaceDir)?.manifest.modules ?? []));
39
- (0, common_1.reportManifestSecrets)(secrets, "build-time manifest");
40
- console.log("");
41
- const code = await (0, common_1.runCommand)("node", [serverPath], {
42
- cwd: workspaceDir,
43
- env: {
44
- ...process.env,
45
- PORT: options.port,
46
- DMS_API_BASE_URL: options.backendUrl,
47
- DMS_SESSION_SECRET: sessionSecret,
48
- ...secrets.env,
49
- DMS_COOKIE_SECURE: process.env.DMS_COOKIE_SECURE ?? "true",
50
- },
51
- });
52
- process.exit(code);
53
- });
47
+ const command = new commander_1.Command("start")
48
+ .summary("Serve the production build")
49
+ .description("Serve the production frontend ajs dms build made for the same backend URL. Needs the DMS_SESSION_SECRET the build used.")
50
+ .addOption(config_1.Options.backendUrl("Backend URL the build was made for; required, as -b or the variable"))
51
+ .addOption(config_1.Options.port)
52
+ .action(async (options) => (await Promise.resolve().then(() => __importStar(require("./start-action")))).runStart(options));
53
+ return (0, cli_1.withExamples)(command, START_EXAMPLES);
54
54
  }
@@ -0,0 +1,10 @@
1
+ import { type CliProblem, type Ui } from "@antelopejs/core/cli";
2
+ export interface VerifySourceOptions {
3
+ layer?: string;
4
+ localPackage?: string[];
5
+ module?: string[];
6
+ }
7
+ export declare function parseLocalPackages(values: string[]): Record<string, string>;
8
+ export declare function usageProblems(options: VerifySourceOptions): CliProblem[];
9
+ export declare function assertValidUsage(problems: CliProblem[], ui?: Ui): void;
10
+ export declare function runVerifySource(options: VerifySourceOptions): Promise<void>;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseLocalPackages = parseLocalPackages;
4
+ exports.usageProblems = usageProblems;
5
+ exports.assertValidUsage = assertValidUsage;
6
+ exports.runVerifySource = runVerifySource;
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = require("node:path");
9
+ const cli_1 = require("@antelopejs/core/cli");
10
+ const common_1 = require("../common");
11
+ const verify_source_result_1 = require("../verify-source-result");
12
+ const COMMAND_PATH = "ajs dms verify-source";
13
+ const LAYER_OPTION = "-l, --layer <path>";
14
+ function localPackageSeparator(value) {
15
+ const separator = value.indexOf("=");
16
+ return separator <= 0 || separator === value.length - 1 ? -1 : separator;
17
+ }
18
+ function localPackageProblem(value) {
19
+ if (localPackageSeparator(value) >= 0)
20
+ return undefined;
21
+ return {
22
+ title: `Invalid local package '${value}'`,
23
+ fixes: ["Pass it as name=path: --local-package @scope/package=../package"],
24
+ };
25
+ }
26
+ function parseLocalPackages(values) {
27
+ return Object.fromEntries(values.map((value) => {
28
+ const problem = localPackageProblem(value);
29
+ if (problem)
30
+ throw new common_1.UsageError(problem);
31
+ const separator = localPackageSeparator(value);
32
+ return [value.slice(0, separator), (0, node_path_1.resolve)(value.slice(separator + 1))];
33
+ }));
34
+ }
35
+ function directoryProblem(path, label) {
36
+ if ((0, node_fs_1.statSync)(path, { throwIfNoEntry: false })?.isDirectory())
37
+ return undefined;
38
+ return { title: `${label} not found: ${path}`, fixes: [verify_source_result_1.LAYER_PATH_FIX] };
39
+ }
40
+ const MISSING_LAYER = {
41
+ title: `Required option '${LAYER_OPTION}' not specified`,
42
+ reason: `Usage: ${COMMAND_PATH} [options]`,
43
+ fixes: [`Run ${COMMAND_PATH} --help for usage`],
44
+ };
45
+ function usageProblems(options) {
46
+ const problems = [
47
+ options.layer === undefined
48
+ ? MISSING_LAYER
49
+ : directoryProblem(options.layer, "Layer path"),
50
+ ...(options.module ?? []).map((path) => directoryProblem(path, "Module path")),
51
+ ...(options.localPackage ?? []).map(localPackageProblem),
52
+ ];
53
+ return problems.filter((problem) => problem !== undefined);
54
+ }
55
+ function assertValidUsage(problems, ui = (0, cli_1.getProcessUi)()) {
56
+ if (problems.length === 0)
57
+ return;
58
+ const last = problems[problems.length - 1];
59
+ for (const problem of problems.slice(0, -1))
60
+ ui.problem(problem);
61
+ throw new common_1.UsageError(last);
62
+ }
63
+ const FORWARDED_FLAGS = ["--no-color", "--verbose"];
64
+ const RESULT_TIMEOUT_MS = 2000;
65
+ function channelClosed(child) {
66
+ return new Promise((settle) => {
67
+ child.once("disconnect", settle);
68
+ child.once("exit", () => setTimeout(settle, RESULT_TIMEOUT_MS).unref());
69
+ });
70
+ }
71
+ async function runVerifySource(options) {
72
+ const startedAt = Date.now();
73
+ assertValidUsage(usageProblems(options));
74
+ const layer = options.layer ?? "";
75
+ const modules = options.module ?? [];
76
+ const localPackages = parseLocalPackages(options.localPackage ?? []);
77
+ const runner = (0, node_path_1.join)(__dirname, "..", `verify-source-runner${(0, node_path_1.extname)(__filename)}`);
78
+ const flags = FORWARDED_FLAGS.filter((flag) => process.argv.includes(flag));
79
+ let result;
80
+ let closed = Promise.resolve();
81
+ const code = await (0, common_1.runCommand)(process.execPath, [...process.execArgv, runner, ...flags], {
82
+ shell: false,
83
+ stdio: ["inherit", "inherit", "inherit", "ipc"],
84
+ env: {
85
+ ...process.env,
86
+ DMS_LAYER_SOURCE: (0, node_path_1.resolve)(layer),
87
+ DMS_MODULE_SOURCES: JSON.stringify(modules.map((path) => (0, node_path_1.resolve)(path))),
88
+ DMS_LOCAL_PACKAGES: JSON.stringify(localPackages),
89
+ },
90
+ }, (child) => {
91
+ child.on("message", (message) => {
92
+ result = message;
93
+ });
94
+ closed = channelClosed(child);
95
+ });
96
+ await closed;
97
+ (0, verify_source_result_1.reportVerification)(result ?? {
98
+ ok: false,
99
+ problem: {
100
+ title: "Source verification failed",
101
+ reason: `The verification exited with code ${code} before reporting a result; its output is above.`,
102
+ },
103
+ }, Date.now() - startedAt);
104
+ }
@@ -1,3 +1,2 @@
1
1
  import { Command } from "commander";
2
- export declare function parseLocalPackages(values: string[]): Record<string, string>;
3
2
  export declare function cmdVerifySource(): Command;
@@ -1,39 +1,61 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseLocalPackages = parseLocalPackages;
4
36
  exports.cmdVerifySource = cmdVerifySource;
5
- const node_path_1 = require("node:path");
6
37
  const commander_1 = require("commander");
7
- const common_1 = require("../common");
8
- function collectOption(value, values) {
38
+ const cli_1 = require("@antelopejs/core/cli");
39
+ function collectOption(value, values = []) {
9
40
  return [...values, value];
10
41
  }
11
- function parseLocalPackages(values) {
12
- return Object.fromEntries(values.map((value) => {
13
- const separator = value.indexOf("=");
14
- if (separator <= 0 || separator === value.length - 1)
15
- throw new Error(`Invalid local package "${value}"; expected name=path`);
16
- return [value.slice(0, separator), (0, node_path_1.resolve)(value.slice(separator + 1))];
17
- }));
18
- }
19
- async function verifySource(options) {
20
- const runner = (0, node_path_1.join)((0, common_1.getPackageRoot)(), "dist", "verify-source-runner.js");
21
- const code = await (0, common_1.runCommand)(process.execPath, [runner], {
22
- env: {
23
- ...process.env,
24
- DMS_LAYER_SOURCE: (0, node_path_1.resolve)(options.layer),
25
- DMS_MODULE_SOURCES: JSON.stringify(options.module.map((path) => (0, node_path_1.resolve)(path))),
26
- DMS_LOCAL_PACKAGES: JSON.stringify(parseLocalPackages(options.localPackage)),
27
- },
28
- });
29
- if (code !== 0)
30
- throw new Error("Source verification failed");
31
- }
42
+ const VERIFY_SOURCE_EXAMPLES = [
43
+ {
44
+ description: "A frontend package and a module that uses it",
45
+ command: "ajs dms verify-source -l ../dms/frontend-vue -m ./frontend-vue",
46
+ },
47
+ {
48
+ description: "With a local build of a package it depends on",
49
+ command: "ajs dms verify-source -l . --local-package @antelopejs/dms=../dms",
50
+ },
51
+ ];
32
52
  function cmdVerifySource() {
33
- return new commander_1.Command("verify-source")
34
- .description("Build and typecheck unpublished DMS frontend sources")
35
- .requiredOption("-l, --layer <path>", "DMS frontend package root")
36
- .option("-m, --module <path>", "Additional frontend package root (repeatable)", collectOption, [])
37
- .option("--local-package <name=path>", "Bind a local package into the generated workspace (repeatable)", collectOption, [])
38
- .action(verifySource);
53
+ const command = new commander_1.Command("verify-source")
54
+ .summary("Build and type-check unpublished frontend sources")
55
+ .description("Build and type-check unpublished DMS frontend sources against this loader version, in a temporary workspace removed when the run ends. Starts no backend.")
56
+ .option("-l, --layer <path>", "Root of the DMS frontend package to verify (required)")
57
+ .option("-m, --module <path>", "Root of another frontend package to verify with it (repeatable)", collectOption)
58
+ .option("--local-package <name=path>", "Bind a local package into the generated workspace (repeatable)", collectOption)
59
+ .action(async (options) => (await Promise.resolve().then(() => __importStar(require("./verify-source-action")))).runVerifySource(options));
60
+ return (0, cli_1.withExamples)(command, VERIFY_SOURCE_EXAMPLES);
39
61
  }
@@ -0,0 +1,2 @@
1
+ import { type SetupWorkspaceOptions, type SetupWorkspaceResult } from "../common";
2
+ export declare function setUpWorkspace(options: Omit<SetupWorkspaceOptions, "beforeInstall">): Promise<SetupWorkspaceResult>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setUpWorkspace = setUpWorkspace;
4
+ const cli_1 = require("@antelopejs/core/cli");
5
+ const common_1 = require("../common");
6
+ const output_1 = require("../output");
7
+ async function setUpWorkspace(options) {
8
+ const task = (0, cli_1.getProcessTasks)().start("Setting up the workspace");
9
+ let isInstalling = false;
10
+ try {
11
+ const result = await (0, common_1.setupWorkspace)({
12
+ ...options,
13
+ beforeInstall: async () => {
14
+ task.succeed("Workspace generated");
15
+ isInstalling = true;
16
+ },
17
+ });
18
+ if (!isInstalling)
19
+ task.succeed("Workspace ready");
20
+ return result;
21
+ }
22
+ catch (error) {
23
+ (0, output_1.endInterruptedTask)(task, error, "Workspace setup stopped");
24
+ throw error;
25
+ }
26
+ }
@@ -0,0 +1,25 @@
1
+ import { type Ui } from "@antelopejs/core/cli";
2
+ export interface WorkspacesOptions {
3
+ json?: boolean;
4
+ }
5
+ export interface WorkspaceRecord {
6
+ id: string;
7
+ dir: string;
8
+ backendUrl: string;
9
+ key: {
10
+ type: "url";
11
+ } | {
12
+ type: "project";
13
+ path: string;
14
+ };
15
+ sizeBytes: number;
16
+ lastUsedAt: string;
17
+ }
18
+ export declare function readWorkspaceRecords(): {
19
+ records: WorkspaceRecord[];
20
+ skipped: string[];
21
+ };
22
+ export declare function describeKey(record: WorkspaceRecord): string;
23
+ export declare function renderWorkspaces(ui: Ui, records: WorkspaceRecord[], isTerminal: boolean): void;
24
+ export declare function reportSkipped(ui: Ui, skipped: string[]): void;
25
+ export declare function runWorkspaces(options: WorkspacesOptions): void;