@codemation/cli 0.0.22 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/{CliBin-PdQvm7od.js → CliBin-CWXW_92Y.js} +99 -12
- package/dist/bin.js +1 -1
- package/dist/index.d.ts +6616 -203
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/CliProgramFactory.ts +3 -0
- package/src/commands/DevCommand.ts +20 -20
- package/src/dev/DevCliBannerRenderer.ts +39 -0
- package/src/dev/DevNextChildProcessOutputFilter.ts +30 -0
- package/src/dev/DevNextStartupBannerLineFilter.ts +25 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @codemation/cli
|
|
2
2
|
|
|
3
|
+
## 0.0.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`a72444e`](https://github.com/MadeRelevant/codemation/commit/a72444e25c4e744a9a90e231a59c93f8d90346e5), [`a72444e`](https://github.com/MadeRelevant/codemation/commit/a72444e25c4e744a9a90e231a59c93f8d90346e5)]:
|
|
8
|
+
- @codemation/host@0.1.2
|
|
9
|
+
- @codemation/next-host@0.1.2
|
|
10
|
+
|
|
11
|
+
## 0.0.23
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`cbfe843`](https://github.com/MadeRelevant/codemation/commit/cbfe843ef2363e400a219f4d0bcd05b091ab83b4)]:
|
|
16
|
+
- @codemation/host@0.1.1
|
|
17
|
+
- @codemation/next-host@0.1.1
|
|
18
|
+
|
|
3
19
|
## 0.0.22
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -16,6 +16,7 @@ import { PrismaMigrationDeployer } from "@codemation/host/persistence";
|
|
|
16
16
|
import boxen from "boxen";
|
|
17
17
|
import chalk from "chalk";
|
|
18
18
|
import figlet from "figlet";
|
|
19
|
+
import { createInterface } from "node:readline";
|
|
19
20
|
import { createServer } from "node:http";
|
|
20
21
|
import httpProxy from "http-proxy";
|
|
21
22
|
import { WebSocket, WebSocketServer } from "ws";
|
|
@@ -128,7 +129,7 @@ var DbMigrateCommand = class {
|
|
|
128
129
|
//#region src/commands/DevCommand.ts
|
|
129
130
|
var DevCommand = class {
|
|
130
131
|
require = createRequire(import.meta.url);
|
|
131
|
-
constructor(pathResolver, tsRuntime, devLockFactory, devSourceWatcherFactory, cliLogger, session, databaseMigrationsApplyService, consumerOutputBuilderFactory, pluginDiscovery, consumerBuildArtifactsPublisher, devBootstrapSummaryFetcher, devCliBannerRenderer, consumerEnvDotenvFilePredicate, devTrackedProcessTreeKiller, nextHostConsumerServerCommandFactory, devApiRuntimeFactory, cliDevProxyServerFactory, devRebuildQueueFactory) {
|
|
132
|
+
constructor(pathResolver, tsRuntime, devLockFactory, devSourceWatcherFactory, cliLogger, session, databaseMigrationsApplyService, consumerOutputBuilderFactory, pluginDiscovery, consumerBuildArtifactsPublisher, devBootstrapSummaryFetcher, devCliBannerRenderer, consumerEnvDotenvFilePredicate, devTrackedProcessTreeKiller, nextHostConsumerServerCommandFactory, devApiRuntimeFactory, cliDevProxyServerFactory, devRebuildQueueFactory, devNextChildProcessOutputFilter) {
|
|
132
133
|
this.pathResolver = pathResolver;
|
|
133
134
|
this.tsRuntime = tsRuntime;
|
|
134
135
|
this.devLockFactory = devLockFactory;
|
|
@@ -147,6 +148,7 @@ var DevCommand = class {
|
|
|
147
148
|
this.devApiRuntimeFactory = devApiRuntimeFactory;
|
|
148
149
|
this.cliDevProxyServerFactory = cliDevProxyServerFactory;
|
|
149
150
|
this.devRebuildQueueFactory = devRebuildQueueFactory;
|
|
151
|
+
this.devNextChildProcessOutputFilter = devNextChildProcessOutputFilter;
|
|
150
152
|
}
|
|
151
153
|
async execute(args) {
|
|
152
154
|
const paths = await this.pathResolver.resolve(args.consumerRoot);
|
|
@@ -185,11 +187,11 @@ var DevCommand = class {
|
|
|
185
187
|
await this.startPackagedUiWhenNeeded(prepared, processState, uiProxyBase);
|
|
186
188
|
this.bindShutdownSignalsToChildProcesses(processState, proxyServer);
|
|
187
189
|
await this.spawnDevUiWhenNeeded(prepared, processState, gatewayBaseUrl);
|
|
190
|
+
this.devCliBannerRenderer.renderGatewayListeningHint(prepared.devMode === "watch-framework" ? prepared.nextPort : prepared.gatewayPort, commandName, prepared.devMode, prepared.devMode === "watch-framework" ? prepared.gatewayPort : void 0);
|
|
188
191
|
await this.startWatcherForSourceRestart(prepared, processState, watcher, devMode, gatewayBaseUrl, proxyServer, {
|
|
189
192
|
commandName,
|
|
190
193
|
configPathOverride: args.configPathOverride
|
|
191
194
|
});
|
|
192
|
-
this.logPackagedUiDevHintWhenNeeded(devMode, gatewayPort, commandName);
|
|
193
195
|
await stopPromise;
|
|
194
196
|
} finally {
|
|
195
197
|
if (previousDevelopmentServerToken === void 0) delete process$1.env.CODEMATION_DEV_SERVER_TOKEN;
|
|
@@ -265,9 +267,10 @@ var DevCommand = class {
|
|
|
265
267
|
});
|
|
266
268
|
state.currentPackagedUi = spawn(nextHostCommand.command, nextHostCommand.args, {
|
|
267
269
|
cwd: nextHostCommand.cwd,
|
|
268
|
-
...this.
|
|
270
|
+
...this.devDetachedChildSpawnPipeOptions(),
|
|
269
271
|
env: nextHostEnvironment
|
|
270
272
|
});
|
|
273
|
+
this.devNextChildProcessOutputFilter.attach(state.currentPackagedUi);
|
|
271
274
|
state.currentPackagedUi.on("error", (error) => {
|
|
272
275
|
if (state.stopRequested || state.isRestartingUi) return;
|
|
273
276
|
state.stopRequested = true;
|
|
@@ -296,13 +299,25 @@ var DevCommand = class {
|
|
|
296
299
|
});
|
|
297
300
|
proxyServer.setBuildStatus("idle");
|
|
298
301
|
}
|
|
299
|
-
|
|
302
|
+
/**
|
|
303
|
+
* Next startup lines are filtered (see {@link DevNextChildProcessOutputFilter}) so the CLI can
|
|
304
|
+
* own the primary “open this URL” message without the internal loopback port dominating stdout.
|
|
305
|
+
*/
|
|
306
|
+
devDetachedChildSpawnPipeOptions() {
|
|
300
307
|
return process$1.platform === "win32" ? {
|
|
301
|
-
stdio:
|
|
308
|
+
stdio: [
|
|
309
|
+
"ignore",
|
|
310
|
+
"pipe",
|
|
311
|
+
"pipe"
|
|
312
|
+
],
|
|
302
313
|
detached: true,
|
|
303
314
|
windowsHide: true
|
|
304
315
|
} : {
|
|
305
|
-
stdio:
|
|
316
|
+
stdio: [
|
|
317
|
+
"ignore",
|
|
318
|
+
"pipe",
|
|
319
|
+
"pipe"
|
|
320
|
+
],
|
|
306
321
|
detached: true
|
|
307
322
|
};
|
|
308
323
|
}
|
|
@@ -349,9 +364,10 @@ var DevCommand = class {
|
|
|
349
364
|
"dev"
|
|
350
365
|
], {
|
|
351
366
|
cwd: nextHostRoot,
|
|
352
|
-
...this.
|
|
367
|
+
...this.devDetachedChildSpawnPipeOptions(),
|
|
353
368
|
env: nextHostEnvironment
|
|
354
369
|
});
|
|
370
|
+
this.devNextChildProcessOutputFilter.attach(state.currentDevUi);
|
|
355
371
|
state.currentDevUi.on("exit", (code) => {
|
|
356
372
|
const normalizedCode = code ?? 0;
|
|
357
373
|
if (state.stopRequested || state.isRestartingUi) return;
|
|
@@ -496,10 +512,6 @@ var DevCommand = class {
|
|
|
496
512
|
await this.consumerBuildArtifactsPublisher.publish(snapshot, discoveredPlugins);
|
|
497
513
|
this.cliLogger.debug(`Dev: consumer output published (${snapshot.buildVersion}).`);
|
|
498
514
|
}
|
|
499
|
-
logPackagedUiDevHintWhenNeeded(devMode, gatewayPort, commandName) {
|
|
500
|
-
if (devMode !== "packaged-ui") return;
|
|
501
|
-
this.cliLogger.info(`codemation ${commandName}: open http://127.0.0.1:${gatewayPort} — this uses the packaged @codemation/next-host UI. Use \`codemation ${commandName} --watch-framework\` only when working on the framework UI itself.`);
|
|
502
|
-
}
|
|
503
515
|
};
|
|
504
516
|
|
|
505
517
|
//#endregion
|
|
@@ -1505,6 +1517,37 @@ var DevCliBannerRenderer = class {
|
|
|
1505
1517
|
this.renderRuntimeSummary(summary);
|
|
1506
1518
|
}
|
|
1507
1519
|
/**
|
|
1520
|
+
* URL to open in the browser: packaged UI uses the CLI gateway port; watch-framework uses the
|
|
1521
|
+
* Next.js dev port (PORT). When they differ, {@link devGatewayPort} is shown in the footer.
|
|
1522
|
+
*/
|
|
1523
|
+
renderGatewayListeningHint(browserPort, commandName, devMode, devGatewayPort) {
|
|
1524
|
+
const url = `http://127.0.0.1:${browserPort}`;
|
|
1525
|
+
const footer = devMode === "watch-framework" ? chalk.dim(devGatewayPort !== void 0 && devGatewayPort !== browserPort ? `The dev gateway (API + runtime) is at http://127.0.0.1:${devGatewayPort}. Open the URL above for the Next.js UI (HMR).` : "Open the URL above for the Next.js UI.") : chalk.dim(`The UI is served through this URL (not the internal Next port). Framework UI work in the monorepo: \`codemation ${commandName} --watch-framework\`.`);
|
|
1526
|
+
const box = boxen([
|
|
1527
|
+
chalk.whiteBright.bold("Codemation is running"),
|
|
1528
|
+
"",
|
|
1529
|
+
`${chalk.hex("#9ca3af")("Open in your browser:")} ${chalk.greenBright.underline(url)}`,
|
|
1530
|
+
"",
|
|
1531
|
+
footer
|
|
1532
|
+
].join("\n"), {
|
|
1533
|
+
padding: {
|
|
1534
|
+
top: 0,
|
|
1535
|
+
bottom: 0,
|
|
1536
|
+
left: 1,
|
|
1537
|
+
right: 1
|
|
1538
|
+
},
|
|
1539
|
+
margin: {
|
|
1540
|
+
top: 1,
|
|
1541
|
+
bottom: 0
|
|
1542
|
+
},
|
|
1543
|
+
borderStyle: "double",
|
|
1544
|
+
borderColor: "green",
|
|
1545
|
+
title: chalk.bold("Codemation dev"),
|
|
1546
|
+
titleAlignment: "center"
|
|
1547
|
+
});
|
|
1548
|
+
process.stdout.write(`${box}\n`);
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1508
1551
|
* Shown after hot reload / watcher restarts (no figlet).
|
|
1509
1552
|
*/
|
|
1510
1553
|
renderCompact(summary) {
|
|
@@ -1586,6 +1629,50 @@ var DevCliBannerRenderer = class {
|
|
|
1586
1629
|
}
|
|
1587
1630
|
};
|
|
1588
1631
|
|
|
1632
|
+
//#endregion
|
|
1633
|
+
//#region src/dev/DevNextChildProcessOutputFilter.ts
|
|
1634
|
+
/**
|
|
1635
|
+
* Attaches to a spawned Next child process and forwards streams while dropping
|
|
1636
|
+
* {@link DevNextStartupBannerLineFilter} matches (startup banner only).
|
|
1637
|
+
*/
|
|
1638
|
+
var DevNextChildProcessOutputFilter = class {
|
|
1639
|
+
constructor(lineFilter) {
|
|
1640
|
+
this.lineFilter = lineFilter;
|
|
1641
|
+
}
|
|
1642
|
+
attach(child) {
|
|
1643
|
+
this.pipeFilteredStream(child.stdout, process.stdout);
|
|
1644
|
+
this.pipeFilteredStream(child.stderr, process.stderr);
|
|
1645
|
+
}
|
|
1646
|
+
pipeFilteredStream(source, sink) {
|
|
1647
|
+
if (!source) return;
|
|
1648
|
+
createInterface({
|
|
1649
|
+
input: source,
|
|
1650
|
+
crlfDelay: Infinity
|
|
1651
|
+
}).on("line", (line) => {
|
|
1652
|
+
if (this.lineFilter.shouldSuppress(line)) return;
|
|
1653
|
+
sink.write(`${line}\n`);
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
//#endregion
|
|
1659
|
+
//#region src/dev/DevNextStartupBannerLineFilter.ts
|
|
1660
|
+
/**
|
|
1661
|
+
* Filters noisy Next.js `next start` / `next dev` startup lines so the CLI can
|
|
1662
|
+
* surface the Codemation gateway URL as the primary “where to browse” signal.
|
|
1663
|
+
*/
|
|
1664
|
+
var DevNextStartupBannerLineFilter = class {
|
|
1665
|
+
shouldSuppress(line) {
|
|
1666
|
+
const t = line.replace(/\r$/, "").trimEnd();
|
|
1667
|
+
if (t.length === 0) return false;
|
|
1668
|
+
if (/^\s*▲\s+Next\.js/.test(t)) return true;
|
|
1669
|
+
if (/^\s*-\s+Local:\s+/.test(t)) return true;
|
|
1670
|
+
if (/^\s*-\s+Network:\s+/.test(t)) return true;
|
|
1671
|
+
if (/^\s*✓\s+Ready\b/.test(t)) return true;
|
|
1672
|
+
return false;
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
|
|
1589
1676
|
//#endregion
|
|
1590
1677
|
//#region src/dev/CliDevProxyServer.ts
|
|
1591
1678
|
var CliDevProxyServer = class {
|
|
@@ -3331,7 +3418,7 @@ var CliProgramFactory = class {
|
|
|
3331
3418
|
const buildOptionsParser = new ConsumerBuildOptionsParser();
|
|
3332
3419
|
const consumerOutputBuilderFactory = new ConsumerOutputBuilderFactory();
|
|
3333
3420
|
const consumerBuildArtifactsPublisher = new ConsumerBuildArtifactsPublisher();
|
|
3334
|
-
const devCommand = new DevCommand(pathResolver, tsRuntime, new DevLockFactory(), new DevSourceWatcherFactory(), cliLogger, devSessionServices, databaseMigrationsApplyService, consumerOutputBuilderFactory, pluginDiscovery, consumerBuildArtifactsPublisher, new DevBootstrapSummaryFetcher(), new DevCliBannerRenderer(), new ConsumerEnvDotenvFilePredicate(), new DevTrackedProcessTreeKiller(), nextHostConsumerServerCommandFactory, new DevApiRuntimeFactory(devSessionServices.loopbackPortAllocator, appConfigLoader, pluginDiscovery), new CliDevProxyServerFactory(), new DevRebuildQueueFactory());
|
|
3421
|
+
const devCommand = new DevCommand(pathResolver, tsRuntime, new DevLockFactory(), new DevSourceWatcherFactory(), cliLogger, devSessionServices, databaseMigrationsApplyService, consumerOutputBuilderFactory, pluginDiscovery, consumerBuildArtifactsPublisher, new DevBootstrapSummaryFetcher(), new DevCliBannerRenderer(), new ConsumerEnvDotenvFilePredicate(), new DevTrackedProcessTreeKiller(), nextHostConsumerServerCommandFactory, new DevApiRuntimeFactory(devSessionServices.loopbackPortAllocator, appConfigLoader, pluginDiscovery), new CliDevProxyServerFactory(), new DevRebuildQueueFactory(), new DevNextChildProcessOutputFilter(new DevNextStartupBannerLineFilter()));
|
|
3335
3422
|
return new CliProgram(buildOptionsParser, new BuildCommand(cliLogger, pathResolver, consumerOutputBuilderFactory, pluginDiscovery, consumerBuildArtifactsPublisher, tsRuntime), devCommand, new DevPluginCommand(new PluginDevConfigFactory(), devCommand), new ServeWebCommand(pathResolver, new CodemationConsumerConfigLoader(), tsRuntime, sourceMapNodeOptions, new ConsumerEnvLoader(), new ListenPortResolver(), nextHostConsumerServerCommandFactory), new ServeWorkerCommand(pathResolver, appConfigLoader, new AppContainerFactory()), new DbMigrateCommand(databaseMigrationsApplyService), new UserCreateCommand(new LocalUserCreator(userAdminBootstrap), userAdminCliOptionsParser), new UserListCommand(cliLogger, userAdminBootstrap, new CliDatabaseUrlDescriptor(), userAdminCliOptionsParser));
|
|
3336
3423
|
}
|
|
3337
3424
|
};
|
package/dist/bin.js
CHANGED