@vercube/cli 1.2.1 → 1.3.1
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/dist/index.mjs +103 -7
- package/dist/toolkit.d.mts +5 -5
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -4,12 +4,12 @@ import { createRequire } from "node:module";
|
|
|
4
4
|
import { defineCommand, runMain } from "citty";
|
|
5
5
|
import { Container } from "@vercube/di";
|
|
6
6
|
import { BaseLogger, Logger } from "@vercube/logger";
|
|
7
|
-
import { dirname, resolve } from "node:path";
|
|
7
|
+
import { dirname, join, resolve } from "node:path";
|
|
8
8
|
import { loadVercubeConfig } from "@vercube/core";
|
|
9
9
|
import { createJiti } from "jiti";
|
|
10
10
|
import { build, createDevServer, createVercube, watch } from "@vercube/devkit";
|
|
11
11
|
import { cliFetch } from "srvx/cli";
|
|
12
|
-
import { existsSync } from "node:fs";
|
|
12
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
13
13
|
import { consola } from "consola";
|
|
14
14
|
import { colors } from "consola/utils";
|
|
15
15
|
import { downloadTemplate, startShell } from "giget";
|
|
@@ -17,8 +17,10 @@ import { installDependencies } from "nypm";
|
|
|
17
17
|
import { relative, resolve as resolve$1 } from "pathe";
|
|
18
18
|
import { hasTTY } from "std-env";
|
|
19
19
|
import { x } from "tinyexec";
|
|
20
|
+
import { spawn } from "node:child_process";
|
|
21
|
+
import { tmpdir } from "node:os";
|
|
20
22
|
//#region package.json
|
|
21
|
-
var version = "1.
|
|
23
|
+
var version = "1.3.1";
|
|
22
24
|
//#endregion
|
|
23
25
|
//#region src/Utils/CommandUtils.ts
|
|
24
26
|
/**
|
|
@@ -212,7 +214,7 @@ async function loadUserCommands(cwd) {
|
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
216
|
//#endregion
|
|
215
|
-
//#region \0@oxc-project+runtime@0.
|
|
217
|
+
//#region \0@oxc-project+runtime@0.150.0/helpers/esm/decorate.js
|
|
216
218
|
function __decorate(decorators, target, key, desc) {
|
|
217
219
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
218
220
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -228,7 +230,8 @@ let BuildCommand = class BuildCommand extends BaseCommand {
|
|
|
228
230
|
* @returns resolves when the build is done
|
|
229
231
|
*/
|
|
230
232
|
async run() {
|
|
231
|
-
|
|
233
|
+
const app = await createVercube({ build: { entry: this.entry } });
|
|
234
|
+
await build(app);
|
|
232
235
|
}
|
|
233
236
|
};
|
|
234
237
|
__decorate([Flag({
|
|
@@ -511,6 +514,97 @@ InitCommand = __decorate([Command({
|
|
|
511
514
|
description: "Initialize a new Vercube app"
|
|
512
515
|
})], InitCommand);
|
|
513
516
|
//#endregion
|
|
517
|
+
//#region src/Commands/Inspect.ts
|
|
518
|
+
let InspectCommand = class InspectCommand extends BaseCommand {
|
|
519
|
+
/** Entry file relative to the output directory. */
|
|
520
|
+
entry;
|
|
521
|
+
/** Comma-separated section ids. Every section when omitted. */
|
|
522
|
+
section;
|
|
523
|
+
/**
|
|
524
|
+
* @returns Resolves once the JSON has been printed
|
|
525
|
+
*/
|
|
526
|
+
async run() {
|
|
527
|
+
const app = await onlyStderr(async () => {
|
|
528
|
+
const instance = await createVercube({ build: { dts: false } });
|
|
529
|
+
await build(instance);
|
|
530
|
+
return instance;
|
|
531
|
+
});
|
|
532
|
+
const entry = resolve(app.config.build?.output?.dir ?? "dist", this.entry);
|
|
533
|
+
const directory = mkdtempSync(join(tmpdir(), "vercube-inspect-"));
|
|
534
|
+
const output = join(directory, "introspection.json");
|
|
535
|
+
try {
|
|
536
|
+
await this.runEntry(entry, output);
|
|
537
|
+
process.stdout.write(readFileSync(output, "utf8"));
|
|
538
|
+
} finally {
|
|
539
|
+
rmSync(directory, {
|
|
540
|
+
recursive: true,
|
|
541
|
+
force: true
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Runs the built entry with introspection enabled.
|
|
547
|
+
*
|
|
548
|
+
* The child's stdout is pointed at this process's stderr: an application is
|
|
549
|
+
* free to log while it boots, and none of that belongs in the payload.
|
|
550
|
+
*
|
|
551
|
+
* @param entry - Absolute path of the built entry file
|
|
552
|
+
* @param output - File the child writes the JSON to
|
|
553
|
+
* @returns Resolves when the child exits successfully
|
|
554
|
+
*/
|
|
555
|
+
runEntry(entry, output) {
|
|
556
|
+
return new Promise((done, fail) => {
|
|
557
|
+
const child = spawn(process.execPath, [entry], {
|
|
558
|
+
env: {
|
|
559
|
+
...process.env,
|
|
560
|
+
VERCUBE_INSPECT: this.section ?? "*",
|
|
561
|
+
VERCUBE_INSPECT_OUT: output
|
|
562
|
+
},
|
|
563
|
+
stdio: [
|
|
564
|
+
"ignore",
|
|
565
|
+
process.stderr,
|
|
566
|
+
"inherit"
|
|
567
|
+
]
|
|
568
|
+
});
|
|
569
|
+
child.on("error", fail);
|
|
570
|
+
child.on("exit", (code) => code === 0 ? done() : fail(/* @__PURE__ */ new Error(`Inspect exited with code ${code}`)));
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
__decorate([Flag({
|
|
575
|
+
name: "entry",
|
|
576
|
+
description: "Entry point for the application",
|
|
577
|
+
default: "index.mjs"
|
|
578
|
+
})], InspectCommand.prototype, "entry", void 0);
|
|
579
|
+
__decorate([Flag({
|
|
580
|
+
name: "section",
|
|
581
|
+
description: "Only print these sections (comma-separated)",
|
|
582
|
+
type: "string"
|
|
583
|
+
})], InspectCommand.prototype, "section", void 0);
|
|
584
|
+
InspectCommand = __decorate([Command({
|
|
585
|
+
name: "inspect",
|
|
586
|
+
description: "Print the application structure as JSON"
|
|
587
|
+
})], InspectCommand);
|
|
588
|
+
/**
|
|
589
|
+
* Runs `fn` with everything written to stdout diverted to stderr.
|
|
590
|
+
*
|
|
591
|
+
* The build pipeline logs progress through several loggers, and reaching into
|
|
592
|
+
* each of them to reconfigure it would be both fragile and incomplete.
|
|
593
|
+
* Diverting the stream catches all of them.
|
|
594
|
+
*
|
|
595
|
+
* @param fn - The work to run
|
|
596
|
+
* @returns Whatever `fn` returned
|
|
597
|
+
*/
|
|
598
|
+
async function onlyStderr(fn) {
|
|
599
|
+
const write = process.stdout.write.bind(process.stdout);
|
|
600
|
+
process.stdout.write = process.stderr.write.bind(process.stderr);
|
|
601
|
+
try {
|
|
602
|
+
return await fn();
|
|
603
|
+
} finally {
|
|
604
|
+
process.stdout.write = write;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
//#endregion
|
|
514
608
|
//#region src/index.ts
|
|
515
609
|
const container = createCliContainer();
|
|
516
610
|
const registry = container.resolve(CommandRegistry);
|
|
@@ -518,15 +612,17 @@ registry.register(BuildCommand);
|
|
|
518
612
|
registry.register(DevCommand);
|
|
519
613
|
registry.register(InitCommand);
|
|
520
614
|
registry.register(FetchCommand);
|
|
615
|
+
registry.register(InspectCommand);
|
|
521
616
|
const userCommands = await loadUserCommands(process.cwd());
|
|
522
617
|
for (const UserCommand of userCommands) registry.register(UserCommand);
|
|
523
|
-
|
|
618
|
+
const main = defineCommand({
|
|
524
619
|
meta: {
|
|
525
620
|
name: "vercube",
|
|
526
621
|
version,
|
|
527
622
|
description: "Vercube CLI"
|
|
528
623
|
},
|
|
529
624
|
subCommands: registry.buildCittyTree(container)
|
|
530
|
-
})
|
|
625
|
+
});
|
|
626
|
+
runMain(main);
|
|
531
627
|
//#endregion
|
|
532
628
|
export {};
|
package/dist/toolkit.d.mts
CHANGED
|
@@ -19,7 +19,7 @@ import { Container } from "@vercube/di";
|
|
|
19
19
|
* }
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
declare abstract class BaseCommand {
|
|
22
|
+
export declare abstract class BaseCommand {
|
|
23
23
|
/**
|
|
24
24
|
* CLI DI container, injected by CommandRegistry before `run()`.
|
|
25
25
|
* Prefer `@Inject` decorators over accessing this directly.
|
|
@@ -80,7 +80,7 @@ declare namespace CliTypes {
|
|
|
80
80
|
* export class BuildCommand extends BaseCommand { ... }
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
declare function Command(meta: CliTypes.CommandMeta): Function;
|
|
83
|
+
export declare function Command(meta: CliTypes.CommandMeta): Function;
|
|
84
84
|
//#endregion
|
|
85
85
|
//#region src/Decorators/Arg.d.ts
|
|
86
86
|
interface ArgOptions {
|
|
@@ -101,7 +101,7 @@ interface ArgOptions {
|
|
|
101
101
|
* public query: string;
|
|
102
102
|
* ```
|
|
103
103
|
*/
|
|
104
|
-
declare function Arg(options: ArgOptions): Function;
|
|
104
|
+
export declare function Arg(options: ArgOptions): Function;
|
|
105
105
|
//#endregion
|
|
106
106
|
//#region src/Decorators/Flag.d.ts
|
|
107
107
|
interface FlagOptions {
|
|
@@ -129,6 +129,6 @@ interface FlagOptions {
|
|
|
129
129
|
* public json: boolean;
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
|
-
declare function Flag(options: FlagOptions): Function;
|
|
132
|
+
export declare function Flag(options: FlagOptions): Function;
|
|
133
133
|
//#endregion
|
|
134
|
-
export {
|
|
134
|
+
export type { CliTypes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercube/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "CLI module for Vercube framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,20 +26,20 @@
|
|
|
26
26
|
"vercube": "./dist/index.mjs"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"
|
|
29
|
+
"@vercube/core": "1.3.1",
|
|
30
|
+
"@vercube/devkit": "1.3.1",
|
|
31
|
+
"@vercube/di": "1.3.1",
|
|
32
|
+
"@vercube/logger": "1.3.1",
|
|
33
|
+
"c12": "4.0.0-rc.2",
|
|
30
34
|
"citty": "0.2.2",
|
|
31
35
|
"consola": "3.4.2",
|
|
32
36
|
"giget": "3.3.1",
|
|
33
37
|
"jiti": "2.7.0",
|
|
34
|
-
"nypm": "0.6.
|
|
38
|
+
"nypm": "0.6.10",
|
|
35
39
|
"pathe": "2.0.3",
|
|
36
|
-
"srvx": "0.
|
|
37
|
-
"std-env": "4.
|
|
38
|
-
"tinyexec": "1.3.
|
|
39
|
-
"@vercube/core": "1.2.1",
|
|
40
|
-
"@vercube/devkit": "1.2.1",
|
|
41
|
-
"@vercube/di": "1.2.1",
|
|
42
|
-
"@vercube/logger": "1.2.1"
|
|
40
|
+
"srvx": "1.0.5",
|
|
41
|
+
"std-env": "4.3.0",
|
|
42
|
+
"tinyexec": "1.3.1"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|