@antelopejs/dms-frontend 0.3.8 → 0.3.9

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 +82 -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 +70 -0
  42. package/dist/index.js +98 -38
  43. package/dist/layer-watch.d.ts +2 -1
  44. package/dist/layer-watch.js +129 -26
  45. package/dist/layers.d.ts +2 -2
  46. package/dist/layers.js +71 -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 +41 -0
  53. package/dist/output.js +197 -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 +221 -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 +95 -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 +119 -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
@@ -1,68 +1,60 @@
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.cmdBuild = cmdBuild;
7
- const node_path_1 = require("node:path");
8
- const chalk_1 = __importDefault(require("chalk"));
9
37
  const commander_1 = require("commander");
10
- const common_1 = require("../common");
11
- const cli_ui_1 = require("../utils/cli-ui");
38
+ const config_1 = require("../config");
39
+ const cli_1 = require("@antelopejs/core/cli");
40
+ const BUILD_EXAMPLES = [
41
+ {
42
+ description: "With DMS_SESSION_SECRET set in the environment or ./.env",
43
+ command: "ajs dms build -b https://dms.example.com",
44
+ },
45
+ {
46
+ description: "Rebuild from the cache while the backend is down",
47
+ command: "ajs dms build -b https://dms.example.com --offline",
48
+ },
49
+ ];
12
50
  function cmdBuild() {
13
- return new commander_1.Command("build")
14
- .description("Build for production (downloads layers via ZIP from backend)")
15
- .addOption(common_1.Options.backendUrl)
16
- .addOption(common_1.Options.force)
17
- .addOption(common_1.Options.offline)
18
- .addOption(common_1.Options.bootstrapSecret)
19
- .action(async (options) => {
20
- if (!options.backendUrl) {
21
- (0, cli_ui_1.error)("Backend URL is required. Use -b <url> or set DMS_API_BASE_URL.");
22
- process.exit(1);
23
- }
24
- const sessionSecret = (0, common_1.resolveSessionSecret)("build");
25
- const spinner = new cli_ui_1.Spinner("Setting up workspace...");
26
- await spinner.start();
27
- try {
28
- const { workspaceDir, manifestFromCache, manifestFetchedAt } = await (0, common_1.setupWorkspace)({
29
- backendUrl: options.backendUrl,
30
- force: !!options.force,
31
- mode: "build",
32
- offline: options.offline,
33
- bootstrapSecret: (0, common_1.normalizeBootstrapSecret)(options.bootstrapSecret),
34
- });
35
- await spinner.succeed("Workspace ready");
36
- if (manifestFromCache) {
37
- (0, cli_ui_1.warning)(`Building from cached manifest and layers archive${manifestFetchedAt ? ` (cached on ${manifestFetchedAt})` : ""} — output may not match the current backend`);
38
- }
39
- console.log("");
40
- (0, cli_ui_1.info)("Building for production...");
41
- console.log(chalk_1.default.dim(` Workspace: ${workspaceDir}`));
42
- console.log("");
43
- const nodeModulesDir = (0, node_path_1.join)(workspaceDir, "node_modules");
44
- const code = await (0, common_1.runCommand)("pnpm", ["run", "build"], {
45
- cwd: workspaceDir,
46
- env: {
47
- ...process.env,
48
- DMS_SESSION_SECRET: sessionSecret,
49
- NODE_OPTIONS: "--max-old-space-size=4096",
50
- NODE_PATH: nodeModulesDir,
51
- },
52
- });
53
- if (code === 0) {
54
- console.log("");
55
- (0, cli_ui_1.success)("Build completed successfully!");
56
- console.log(chalk_1.default.dim(" Run 'ajs dms start' to start the production server"));
57
- }
58
- else {
59
- (0, cli_ui_1.error)("Build failed");
60
- }
61
- process.exit(code);
62
- }
63
- catch (err) {
64
- await spinner.fail(`Setup failed: ${err.message}`);
65
- process.exit(1);
66
- }
67
- });
51
+ const command = new commander_1.Command("build")
52
+ .summary("Build the production frontend")
53
+ .description("Build the production frontend from the manifest and layers archive the backend serves, into the workspace's dist directory. Needs a DMS_SESSION_SECRET of 32 characters or more.")
54
+ .addOption(config_1.Options.backendUrl("Backend URL to build for; required, as -b or the variable"))
55
+ .addOption(config_1.Options.force("Extract the layers archive from scratch and reinstall the workspace dependencies"))
56
+ .addOption(config_1.Options.offline("Build from the last cached manifest and layers archive, without the backend"))
57
+ .addOption(config_1.Options.bootstrapSecret())
58
+ .action(async (options) => (await Promise.resolve().then(() => __importStar(require("./build-action")))).runBuild(options));
59
+ return (0, cli_1.withExamples)(command, BUILD_EXAMPLES);
68
60
  }
@@ -0,0 +1,8 @@
1
+ import { type WorkspaceRecord } from "./workspaces-action";
2
+ export interface CleanOptions {
3
+ backendUrl?: string;
4
+ all?: boolean;
5
+ yes?: boolean;
6
+ }
7
+ export declare function describeWorkspaces(records: WorkspaceRecord[], isTerminal: boolean): string[];
8
+ export declare function runClean(options: CleanOptions): Promise<void>;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.describeWorkspaces = describeWorkspaces;
4
+ exports.runClean = runClean;
5
+ const node_fs_1 = require("node:fs");
6
+ const cli_1 = require("@antelopejs/core/cli");
7
+ const common_1 = require("../common");
8
+ const output_1 = require("../output");
9
+ const workspaces_action_1 = require("./workspaces-action");
10
+ const CLEAN_ALL_COMMAND = "ajs dms clean --all";
11
+ const YES_FLAG = "--yes";
12
+ const COLUMN_GAP = " ";
13
+ const ROW_INDENT = " ";
14
+ function describeWorkspaces(records, isTerminal) {
15
+ const rows = records.map((record) => [
16
+ (0, output_1.workspaceId)(record.dir, isTerminal),
17
+ record.backendUrl,
18
+ (0, workspaces_action_1.describeKey)(record),
19
+ ]);
20
+ const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
21
+ return rows.map((row) => row
22
+ .map((cell, column) => cell.padEnd(widths[column]))
23
+ .join(COLUMN_GAP)
24
+ .trimEnd());
25
+ }
26
+ async function confirmCleanAll(records, totalBytes, options) {
27
+ const prompter = (0, cli_1.createPrompter)({ command: CLEAN_ALL_COMMAND });
28
+ if (!options.yes && prompter.isInteractive) {
29
+ (0, output_1.writeFeedback)(`Remove ${(0, cli_1.pluralize)(records.length, "workspace")} (${(0, output_1.formatSize)(totalBytes)})?`);
30
+ for (const line of describeWorkspaces(records, true)) {
31
+ (0, output_1.writeFeedback)(`${ROW_INDENT}${line}`);
32
+ }
33
+ }
34
+ return prompter.confirm({
35
+ message: "Continue?",
36
+ flag: YES_FLAG,
37
+ answer: options.yes || undefined,
38
+ defaultAnswer: false,
39
+ });
40
+ }
41
+ async function cleanAll(options) {
42
+ const ui = (0, cli_1.getProcessUi)();
43
+ const { records, skipped } = (0, workspaces_action_1.readWorkspaceRecords)();
44
+ if (records.length === 0) {
45
+ ui.message("info", "No workspaces found");
46
+ (0, workspaces_action_1.reportSkipped)(ui, skipped);
47
+ return;
48
+ }
49
+ const totalBytes = records.reduce((sum, record) => sum + record.sizeBytes, 0);
50
+ if (!(await confirmCleanAll(records, totalBytes, options))) {
51
+ ui.message("skip", "Nothing removed");
52
+ return;
53
+ }
54
+ for (const record of records) {
55
+ (0, node_fs_1.rmSync)(record.dir, { recursive: true, force: true });
56
+ }
57
+ ui.message("success", [
58
+ `Removed ${(0, cli_1.pluralize)(records.length, "workspace")}`,
59
+ `freed ${(0, output_1.formatSize)(totalBytes)}`,
60
+ ].join(ui.symbols.separator), {
61
+ details: options.yes
62
+ ? describeWorkspaces(records, (0, output_1.isTerminalFeedback)())
63
+ : [],
64
+ });
65
+ (0, workspaces_action_1.reportSkipped)(ui, skipped);
66
+ }
67
+ async function runClean(options) {
68
+ const ui = (0, cli_1.getProcessUi)();
69
+ if (options.all) {
70
+ await cleanAll(options);
71
+ return;
72
+ }
73
+ if (!options.backendUrl) {
74
+ throw new common_1.UsageError({
75
+ title: "Nothing to clean: pass -b <url> or --all",
76
+ reason: "clean never uses DMS_API_BASE_URL from the environment or ./.env.",
77
+ fixes: [
78
+ "Remove the workspace build, start and dev -b share for a URL: ajs dms clean -b <url>",
79
+ "Remove every workspace, including those dev created without -b: ajs dms clean --all",
80
+ "List the workspaces: ajs dms workspaces",
81
+ ],
82
+ });
83
+ }
84
+ const backendUrl = (0, common_1.parseBackendUrl)(options.backendUrl);
85
+ const workspaceDir = (0, common_1.getWorkspaceDir)(backendUrl);
86
+ if (!(0, node_fs_1.existsSync)(workspaceDir)) {
87
+ ui.message("info", `No workspace for ${backendUrl}: nothing to clean`);
88
+ return;
89
+ }
90
+ const freedBytes = (0, common_1.directorySize)(workspaceDir);
91
+ (0, node_fs_1.rmSync)(workspaceDir, { recursive: true, force: true });
92
+ ui.message("success", [
93
+ `Removed workspace ${(0, output_1.showWorkspace)(workspaceDir)}`,
94
+ backendUrl,
95
+ `freed ${(0, output_1.formatSize)(freedBytes)}`,
96
+ ].join(ui.symbols.separator));
97
+ }
@@ -1,45 +1,58 @@
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
36
  exports.cmdClean = cmdClean;
4
- const node_fs_1 = require("node:fs");
5
37
  const commander_1 = require("commander");
6
- const common_1 = require("../common");
7
- const cli_ui_1 = require("../utils/cli-ui");
38
+ const cli_1 = require("@antelopejs/core/cli");
39
+ const CLEAN_EXAMPLES = [
40
+ {
41
+ description: "The workspace build, start and dev -b share for a backend",
42
+ command: "ajs dms clean -b https://dms.example.com",
43
+ },
44
+ {
45
+ description: "Every workspace, without asking (scripts, CI)",
46
+ command: "ajs dms clean --all --yes",
47
+ },
48
+ ];
8
49
  function cmdClean() {
9
- return new commander_1.Command("clean")
10
- .description("Remove workspace build artifacts")
11
- .addOption(common_1.Options.backendUrl)
12
- .option("-a, --all", "Clean all workspaces")
13
- .action(async (options) => {
14
- console.log("");
15
- if (options.all) {
16
- (0, cli_ui_1.info)("Cleaning all workspaces...");
17
- const workspaces = (0, common_1.listWorkspaces)();
18
- if (workspaces.length === 0) {
19
- (0, cli_ui_1.info)("No workspaces found.");
20
- return;
21
- }
22
- for (const ws of workspaces) {
23
- (0, node_fs_1.rmSync)(ws.dir, { recursive: true, force: true });
24
- (0, cli_ui_1.success)(`Removed ${ws.dir} (${(0, common_1.describeWorkspace)(ws)})`);
25
- }
26
- console.log("");
27
- (0, cli_ui_1.success)(`Cleaned ${workspaces.length} workspace(s).`);
28
- return;
29
- }
30
- if (!options.backendUrl) {
31
- (0, cli_ui_1.warning)("Specify -b <url> to clean a specific workspace, or --all to clean everything.\n" +
32
- " -b only reaches the workspace 'build', 'start' and 'dev -b' share for that URL;\n" +
33
- " a workspace 'dev' created without -b is keyed on the project directory and is\n" +
34
- " only removable with --all.");
35
- process.exit(1);
36
- }
37
- const workspaceDir = (0, common_1.getWorkspaceDir)(options.backendUrl);
38
- if (!(0, node_fs_1.existsSync)(workspaceDir)) {
39
- (0, cli_ui_1.info)("Workspace not found — nothing to clean.");
40
- return;
41
- }
42
- (0, node_fs_1.rmSync)(workspaceDir, { recursive: true, force: true });
43
- (0, cli_ui_1.success)(`Removed workspace: ${workspaceDir}`);
44
- });
50
+ const command = new commander_1.Command("clean")
51
+ .summary("Remove generated workspaces")
52
+ .description("Remove generated workspaces: their node_modules, manifest cache, downloaded layers and build output.")
53
+ .option("-b, --backend-url <url>", "Backend URL whose workspace to remove; DMS_API_BASE_URL is never read")
54
+ .option("-a, --all", "Remove every workspace, after a confirmation")
55
+ .option("-y, --yes", "Skip the confirmation of --all")
56
+ .action(async (options) => (await Promise.resolve().then(() => __importStar(require("./clean-action")))).runClean(options));
57
+ return (0, cli_1.withExamples)(command, CLEAN_EXAMPLES);
45
58
  }
@@ -0,0 +1,8 @@
1
+ export interface DevOptions {
2
+ backendUrl?: string;
3
+ port: string;
4
+ force?: boolean;
5
+ offline?: boolean;
6
+ bootstrapSecret?: string;
7
+ }
8
+ export declare function runDev(options: DevOptions): Promise<void>;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runDev = runDev;
4
+ const node_path_1 = require("node:path");
5
+ const cli_1 = require("@antelopejs/core/cli");
6
+ const common_1 = require("../common");
7
+ const child_output_1 = require("../child-output");
8
+ const discovery_1 = require("../discovery");
9
+ const output_1 = require("../output");
10
+ const ports_1 = require("../ports");
11
+ const server_process_1 = require("../server-process");
12
+ const update_check_1 = require("../update-check");
13
+ const workspace_task_1 = require("./workspace-task");
14
+ function clientHost() {
15
+ const host = process.env.HOST?.trim();
16
+ if (!host || host === "0.0.0.0" || host === "::" || host === "[::]") {
17
+ return "localhost";
18
+ }
19
+ return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
20
+ }
21
+ function resolveBackend(options) {
22
+ if (options.backendUrl) {
23
+ return { backendUrl: (0, common_1.parseBackendUrl)(options.backendUrl) };
24
+ }
25
+ const result = (0, discovery_1.discoverBackend)(process.cwd());
26
+ if (result.status !== "found") {
27
+ throw new cli_1.CliError((0, discovery_1.describeDiscoveryFailure)(result));
28
+ }
29
+ return {
30
+ backendUrl: result.backend.backendUrl,
31
+ workspaceKey: (0, common_1.projectWorkspaceKey)(result.backend.projectDir),
32
+ projectDir: result.backend.projectDir,
33
+ };
34
+ }
35
+ async function runDev(options) {
36
+ const startedAt = Date.now();
37
+ const requestedPort = (0, common_1.parsePort)(options.port);
38
+ const offline = (0, common_1.flagOrEnv)(options.offline, "DMS_OFFLINE");
39
+ const sessionSecret = (0, common_1.resolveSessionSecret)("dev");
40
+ const { backendUrl, workspaceKey, projectDir } = resolveBackend(options);
41
+ const bootstrapSecret = (0, common_1.resolveBootstrapSecret)(options.bootstrapSecret, backendUrl);
42
+ const ui = (0, cli_1.getProcessUi)();
43
+ (0, output_1.writeHeader)("dev", [backendUrl, "development"]);
44
+ if (projectDir) {
45
+ ui.message("info", `Backend discovered from ${(0, output_1.showPath)(projectDir)}`);
46
+ }
47
+ const reserved = await (0, ports_1.reserveFreePort)(requestedPort);
48
+ const port = reserved.port;
49
+ const clientUrl = `http://${clientHost()}:${port}`;
50
+ const { workspaceDir, layers, manifestFromCache, manifestFetchedAt, manifestSecrets, } = await (0, workspace_task_1.setUpWorkspace)({
51
+ backendUrl,
52
+ force: !!options.force,
53
+ mode: "dev",
54
+ offline,
55
+ clientUrl,
56
+ workspaceKey,
57
+ bootstrapSecret,
58
+ });
59
+ if (port !== requestedPort) {
60
+ ui.message("warn", `Port ${requestedPort} is busy, using ${port}`);
61
+ }
62
+ if (manifestFromCache) {
63
+ const manifest = `the layers manifest${(0, output_1.cachedAge)(manifestFetchedAt)}`;
64
+ if (offline) {
65
+ ui.message("info", `Offline: using ${manifest}`);
66
+ }
67
+ else {
68
+ ui.message("warn", `Backend unreachable: using ${manifest}`, {
69
+ detail: "API calls fail until the backend is up.",
70
+ });
71
+ }
72
+ }
73
+ const secrets = (0, common_1.resolveManifestSecrets)(manifestSecrets);
74
+ (0, common_1.reportManifestSecrets)(secrets, (count) => `Set ${count === 1 ? "it" : "them"} in the environment or the project's .env`);
75
+ const stopWatchers = (0, common_1.startLayerWatchers)(workspaceDir, layers);
76
+ const handleShutdown = async () => {
77
+ await stopWatchers();
78
+ };
79
+ process.once("SIGINT", handleShutdown);
80
+ process.once("SIGTERM", handleShutdown);
81
+ const nodeModulesDir = (0, node_path_1.join)(workspaceDir, "node_modules");
82
+ await reserved.release();
83
+ const secretSources = (0, common_1.describeSecretSources)(secrets.sources);
84
+ const code = await (0, server_process_1.runServer)({
85
+ name: "dev server",
86
+ script: "server.mjs",
87
+ cwd: workspaceDir,
88
+ mapPath: (0, child_output_1.createPathMapper)(workspaceDir, layers),
89
+ env: {
90
+ ...process.env,
91
+ PORT: String(port),
92
+ DMS_DEV: "true",
93
+ DMS_COOKIE_SECURE: process.env.DMS_COOKIE_SECURE ?? "false",
94
+ DMS_API_BASE_URL: backendUrl,
95
+ DMS_BOOTSTRAP_SECRET: bootstrapSecret,
96
+ DMS_SESSION_SECRET: sessionSecret,
97
+ ...secrets.env,
98
+ NODE_OPTIONS: "--max-old-space-size=4096",
99
+ NODE_PATH: nodeModulesDir,
100
+ },
101
+ onReady: (address) => {
102
+ (0, output_1.writeReadyBlock)({
103
+ title: `Dev server ready in ${(0, cli_1.formatDuration)(Date.now() - startedAt)}`,
104
+ lines: (0, server_process_1.readyLines)(address, [
105
+ { label: "Backend", value: backendUrl },
106
+ { label: "Workspace", value: (0, output_1.showWorkspace)(workspaceDir) },
107
+ ...(secretSources
108
+ ? [{ label: "Secrets", value: secretSources }]
109
+ : []),
110
+ ]),
111
+ footer: [
112
+ `Watching ${(0, cli_1.pluralize)(layers.length, "layer source")}`,
113
+ "Ctrl+C to stop",
114
+ ].join(ui.symbols.separator),
115
+ });
116
+ void (0, update_check_1.reportAvailableUpdate)({ isFollowed: true });
117
+ },
118
+ }).finally(stopWatchers);
119
+ process.exitCode = code;
120
+ }
@@ -1,121 +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.cmdDev = cmdDev;
7
- const node_path_1 = require("node:path");
8
- const chalk_1 = __importDefault(require("chalk"));
9
37
  const commander_1 = require("commander");
10
- const common_1 = require("../common");
11
- const discovery_1 = require("../discovery");
12
- const ports_1 = require("../ports");
13
- const cli_ui_1 = require("../utils/cli-ui");
14
- function clientHost() {
15
- const host = process.env.HOST?.trim();
16
- if (!host || host === "0.0.0.0" || host === "::" || host === "[::]") {
17
- return "localhost";
18
- }
19
- return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
20
- }
21
- function resolveBackend(options) {
22
- if (options.backendUrl) {
23
- return { backendUrl: options.backendUrl };
24
- }
25
- const result = (0, discovery_1.discoverBackend)(process.cwd());
26
- if (result.status !== "found") {
27
- (0, cli_ui_1.error)((0, discovery_1.describeDiscoveryFailure)(result));
28
- process.exit(1);
29
- }
30
- (0, cli_ui_1.info)(`Backend discovered from ${chalk_1.default.cyan(result.backend.projectDir)}: ${chalk_1.default.cyan(result.backend.backendUrl)}`);
31
- return {
32
- backendUrl: result.backend.backendUrl,
33
- workspaceKey: (0, common_1.projectWorkspaceKey)(result.backend.projectDir),
34
- };
35
- }
38
+ const config_1 = require("../config");
39
+ const cli_1 = require("@antelopejs/core/cli");
40
+ const DEV_EXAMPLES = [
41
+ {
42
+ description: "Inside a project started with ajs project dev",
43
+ command: "ajs dms dev",
44
+ },
45
+ {
46
+ description: "Share one workspace with build and start",
47
+ command: "ajs dms dev -b http://localhost:5010 -p 3001",
48
+ },
49
+ ];
36
50
  function cmdDev() {
37
- return new commander_1.Command("dev")
38
- .description("Start development server with hot reload (direct paths, same machine)")
39
- .addOption(common_1.Options.backendUrl)
40
- .addOption(common_1.Options.port)
41
- .addOption(common_1.Options.force)
42
- .addOption(common_1.Options.offline)
43
- .addOption(common_1.Options.bootstrapSecret)
44
- .action(async (options) => {
45
- const { backendUrl, workspaceKey } = resolveBackend(options);
46
- const bootstrapSecret = (0, common_1.resolveBootstrapSecret)(options.bootstrapSecret, backendUrl);
47
- const sessionSecret = (0, common_1.resolveSessionSecret)("dev");
48
- const requestedPort = Number.parseInt(options.port, 10);
49
- if (Number.isNaN(requestedPort)) {
50
- (0, cli_ui_1.error)(`Invalid port: ${options.port}`);
51
- process.exit(1);
52
- }
53
- let reserved;
54
- try {
55
- reserved = await (0, ports_1.reserveFreePort)(requestedPort);
56
- }
57
- catch (err) {
58
- (0, cli_ui_1.error)(err.message);
59
- process.exit(1);
60
- }
61
- const port = reserved.port;
62
- if (port !== requestedPort) {
63
- (0, cli_ui_1.warning)(`Port ${requestedPort} in use, using ${port} instead`);
64
- }
65
- const clientUrl = `http://${clientHost()}:${port}`;
66
- const spinner = new cli_ui_1.Spinner("Setting up workspace...");
67
- await spinner.start();
68
- try {
69
- const { workspaceDir, layers, manifestFromCache, manifestFetchedAt, manifestSecrets, } = await (0, common_1.setupWorkspace)({
70
- backendUrl,
71
- force: !!options.force,
72
- mode: "dev",
73
- offline: options.offline,
74
- clientUrl,
75
- workspaceKey,
76
- bootstrapSecret,
77
- });
78
- await spinner.succeed("Workspace ready");
79
- if (manifestFromCache) {
80
- (0, cli_ui_1.warning)(`Using cached layers manifest${manifestFetchedAt ? ` (cached on ${manifestFetchedAt})` : ""} — API calls will fail until the backend is up`);
81
- }
82
- const stopWatchers = (0, common_1.startLayerWatchers)(workspaceDir, layers);
83
- const handleShutdown = async () => {
84
- await stopWatchers();
85
- };
86
- process.once("SIGINT", handleShutdown);
87
- process.once("SIGTERM", handleShutdown);
88
- console.log("");
89
- (0, cli_ui_1.info)(`Starting dev server on port ${chalk_1.default.cyan(String(port))}...`);
90
- console.log(chalk_1.default.dim(` Workspace: ${workspaceDir}`));
91
- console.log(chalk_1.default.dim(` Backend: ${backendUrl}`));
92
- console.log(chalk_1.default.dim(` Watching: ${layers.length} layer source tree(s)`));
93
- const secrets = (0, common_1.resolveManifestSecrets)(manifestSecrets);
94
- (0, common_1.reportManifestSecrets)(secrets);
95
- console.log("");
96
- const nodeModulesDir = (0, node_path_1.join)(workspaceDir, "node_modules");
97
- await reserved.release();
98
- const code = await (0, common_1.runCommand)("node", ["server.mjs"], {
99
- cwd: workspaceDir,
100
- env: {
101
- ...process.env,
102
- PORT: String(port),
103
- DMS_DEV: "true",
104
- DMS_COOKIE_SECURE: process.env.DMS_COOKIE_SECURE ?? "false",
105
- DMS_API_BASE_URL: backendUrl,
106
- DMS_BOOTSTRAP_SECRET: bootstrapSecret,
107
- DMS_SESSION_SECRET: sessionSecret,
108
- ...secrets.env,
109
- NODE_OPTIONS: "--max-old-space-size=4096",
110
- NODE_PATH: nodeModulesDir,
111
- },
112
- });
113
- await stopWatchers();
114
- process.exit(code);
115
- }
116
- catch (err) {
117
- await spinner.fail(`Setup failed: ${err.message}`);
118
- process.exit(1);
119
- }
120
- });
51
+ const command = new commander_1.Command("dev")
52
+ .summary("Run the dev server against a local backend, with hot reload")
53
+ .description("Run the dev server with hot reload. It reads the frontend modules in place, from the backend's own directories, so the backend runs on this machine.")
54
+ .addOption(config_1.Options.backendUrl("Backend URL; when omitted, discovered from the enclosing antelope project's .antelope/dev.json"))
55
+ .addOption(config_1.Options.port)
56
+ .addOption(config_1.Options.force("Reinstall the workspace dependencies"))
57
+ .addOption(config_1.Options.offline("Reuse the last cached manifest instead of fetching it"))
58
+ .addOption(config_1.Options.bootstrapSecret("Discovered from .antelope/dms-dev.json for the project's own backend"))
59
+ .action(async (options) => (await Promise.resolve().then(() => __importStar(require("./dev-action")))).runDev(options));
60
+ return (0, cli_1.withExamples)(command, DEV_EXAMPLES);
121
61
  }
@@ -0,0 +1,8 @@
1
+ export interface PrepareOptions {
2
+ backendUrl?: string;
3
+ force?: boolean;
4
+ offline?: boolean;
5
+ strict?: boolean;
6
+ bootstrapSecret?: string;
7
+ }
8
+ export declare function runPrepare(options: PrepareOptions): Promise<void>;