@fluojs/cli 1.0.0-beta.4 → 1.0.0-beta.6
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/README.ko.md +97 -3
- package/README.md +97 -3
- package/dist/cli.d.ts +8 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +201 -4
- package/dist/commands/diagnostics.d.ts +15 -0
- package/dist/commands/diagnostics.d.ts.map +1 -0
- package/dist/commands/diagnostics.js +163 -0
- package/dist/commands/new.js +2 -2
- package/dist/commands/package-manager.d.ts +9 -0
- package/dist/commands/package-manager.d.ts.map +1 -0
- package/dist/commands/package-manager.js +63 -0
- package/dist/commands/package-workflow.d.ts +20 -0
- package/dist/commands/package-workflow.d.ts.map +1 -0
- package/dist/commands/package-workflow.js +137 -0
- package/dist/commands/scripts.d.ts +38 -0
- package/dist/commands/scripts.d.ts.map +1 -0
- package/dist/commands/scripts.js +570 -0
- package/dist/dev-runner/node-restart-runner.d.ts +55 -0
- package/dist/dev-runner/node-restart-runner.d.ts.map +1 -0
- package/dist/dev-runner/node-restart-runner.js +317 -0
- package/dist/dev-runner/preserve-color-tty.d.ts +2 -0
- package/dist/dev-runner/preserve-color-tty.d.ts.map +1 -0
- package/dist/dev-runner/preserve-color-tty.js +12 -0
- package/dist/generators/manifest.d.ts +24 -0
- package/dist/generators/manifest.d.ts.map +1 -1
- package/dist/generators/manifest.js +9 -0
- package/dist/generators/resource.d.ts +10 -0
- package/dist/generators/resource.d.ts.map +1 -0
- package/dist/generators/resource.js +23 -0
- package/dist/generators/templates/controller.ts.ejs +5 -1
- package/dist/generators/templates/request-dto.ts.ejs +3 -0
- package/dist/new/scaffold.d.ts.map +1 -1
- package/dist/new/scaffold.js +193 -148
- package/dist/new/starter-profiles.d.ts.map +1 -1
- package/dist/new/starter-profiles.js +13 -13
- package/dist/update-check.d.ts +1 -0
- package/dist/update-check.d.ts.map +1 -1
- package/dist/update-check.js +7 -5
- package/package.json +2 -2
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { detectPackageManager, SUPPORTED_PACKAGE_MANAGERS } from './package-manager.js';
|
|
3
|
+
const DEFAULT_PACKAGE_NAME = '@fluojs/cli';
|
|
4
|
+
const DEFAULT_REGISTRY_TIMEOUT_MS = 5_000;
|
|
5
|
+
const EMPTY_ENV = {};
|
|
6
|
+
function normalizeFluoPackage(packageName) {
|
|
7
|
+
if (packageName.startsWith('@fluojs/')) {
|
|
8
|
+
return packageName;
|
|
9
|
+
}
|
|
10
|
+
return `@fluojs/${packageName}`;
|
|
11
|
+
}
|
|
12
|
+
function buildAddArgs(packageManager, packages, dev) {
|
|
13
|
+
if (packageManager === 'npm') {
|
|
14
|
+
return ['install', dev ? '--save-dev' : '--save', ...packages];
|
|
15
|
+
}
|
|
16
|
+
if (packageManager === 'yarn') {
|
|
17
|
+
return ['add', ...(dev ? ['--dev'] : []), ...packages];
|
|
18
|
+
}
|
|
19
|
+
return ['add', ...(dev ? ['-D'] : []), ...packages];
|
|
20
|
+
}
|
|
21
|
+
function defaultSpawnCommand(command, args, options) {
|
|
22
|
+
return new Promise((resolveExitCode, reject) => {
|
|
23
|
+
const child = spawn(command, args, options);
|
|
24
|
+
child.on('error', reject);
|
|
25
|
+
child.on('exit', code => resolveExitCode(code ?? 1));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async function fetchNpmDistTags(packageName) {
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
const timeout = setTimeout(() => controller.abort(), DEFAULT_REGISTRY_TIMEOUT_MS);
|
|
31
|
+
try {
|
|
32
|
+
const response = await fetch(`https://registry.npmjs.org/-/package/${encodeURIComponent(packageName)}/dist-tags`, {
|
|
33
|
+
headers: {
|
|
34
|
+
accept: 'application/json'
|
|
35
|
+
},
|
|
36
|
+
signal: controller.signal
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const payload = await response.json();
|
|
42
|
+
if (typeof payload !== 'object' || payload === null) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const distTags = {};
|
|
46
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
distTags[key] = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return distTags;
|
|
52
|
+
} catch (_error) {
|
|
53
|
+
return undefined;
|
|
54
|
+
} finally {
|
|
55
|
+
clearTimeout(timeout);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function parsePackageManager(value) {
|
|
59
|
+
if (!value || value.startsWith('-')) {
|
|
60
|
+
throw new Error('Expected --package-manager to have a value.');
|
|
61
|
+
}
|
|
62
|
+
if (!SUPPORTED_PACKAGE_MANAGERS.has(value)) {
|
|
63
|
+
throw new Error(`Invalid --package-manager value "${value}". Use one of: pnpm, npm, yarn, bun.`);
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
export function addUsage() {
|
|
68
|
+
return ['Usage: fluo add <package...> [options]', '', 'Install one or more @fluojs packages with the detected package manager.', '', 'Options', ' --dev Install as a development dependency.', ' --package-manager <pnpm|npm|yarn|bun> Override package-manager detection.', ' --dry-run Print the command without running it.', ' --help Show help for the add command.'].join('\n');
|
|
69
|
+
}
|
|
70
|
+
export function upgradeUsage() {
|
|
71
|
+
return ['Usage: fluo upgrade [options]', '', 'Report the latest CLI package state and point to migration workflows.', '', 'Options', ' --help Show help for the upgrade command.'].join('\n');
|
|
72
|
+
}
|
|
73
|
+
export async function runAddCommand(argv, runtime = {}) {
|
|
74
|
+
if (argv.includes('--help') || argv.includes('-h')) {
|
|
75
|
+
(runtime.stdout ?? process.stdout).write(`${addUsage()}\n`);
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
let dev = false;
|
|
79
|
+
let dryRun = false;
|
|
80
|
+
let packageManager;
|
|
81
|
+
const packages = [];
|
|
82
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
83
|
+
const arg = argv[index];
|
|
84
|
+
if (arg === '--dev' || arg === '-D') {
|
|
85
|
+
dev = true;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (arg === '--dry-run') {
|
|
89
|
+
dryRun = true;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (arg === '--package-manager') {
|
|
93
|
+
packageManager = parsePackageManager(argv[index + 1]);
|
|
94
|
+
index += 1;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (arg.startsWith('-')) {
|
|
98
|
+
throw new Error(`Unknown add option: ${arg}`);
|
|
99
|
+
}
|
|
100
|
+
packages.push(normalizeFluoPackage(arg));
|
|
101
|
+
}
|
|
102
|
+
if (packages.length === 0) {
|
|
103
|
+
throw new Error('Expected at least one package for fluo add.');
|
|
104
|
+
}
|
|
105
|
+
const env = runtime.env ?? EMPTY_ENV;
|
|
106
|
+
const manager = packageManager ?? detectPackageManager({
|
|
107
|
+
cwd: runtime.cwd ?? process.cwd(),
|
|
108
|
+
env
|
|
109
|
+
});
|
|
110
|
+
const args = buildAddArgs(manager, packages, dev);
|
|
111
|
+
if (dryRun) {
|
|
112
|
+
(runtime.stdout ?? process.stdout).write(`Would run: ${manager} ${args.join(' ')}\n`);
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
return (runtime.spawnCommand ?? defaultSpawnCommand)(manager, args, {
|
|
116
|
+
cwd: runtime.cwd ?? process.cwd(),
|
|
117
|
+
env,
|
|
118
|
+
stdio: 'inherit'
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
export async function runUpgradeCommand(argv, runtime = {}) {
|
|
122
|
+
if (argv.includes('--help') || argv.includes('-h')) {
|
|
123
|
+
(runtime.stdout ?? process.stdout).write(`${upgradeUsage()}\n`);
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
if (argv.length > 0) {
|
|
127
|
+
throw new Error(`Unknown upgrade option: ${argv[0]}`);
|
|
128
|
+
}
|
|
129
|
+
const distTags = await (runtime.fetchDistTags ?? fetchNpmDistTags)(DEFAULT_PACKAGE_NAME);
|
|
130
|
+
const stdout = runtime.stdout ?? process.stdout;
|
|
131
|
+
stdout.write('fluo upgrade\n');
|
|
132
|
+
stdout.write(` Latest CLI: ${distTags?.latest ?? 'unavailable'}\n`);
|
|
133
|
+
stdout.write(' To update the global CLI, run your package manager global install command for @fluojs/cli@latest.\n');
|
|
134
|
+
stdout.write(' To preview NestJS migration codemods, run `fluo migrate <path> --json`.\n');
|
|
135
|
+
stdout.write(' To inspect generated starter drift, run `fluo doctor`.\n');
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type CliStream = {
|
|
2
|
+
isTTY?: boolean;
|
|
3
|
+
write(message: string): unknown;
|
|
4
|
+
};
|
|
5
|
+
type SpawnCommandOptions = {
|
|
6
|
+
cwd: string;
|
|
7
|
+
env: NodeJS.ProcessEnv;
|
|
8
|
+
stderr?: CliStream;
|
|
9
|
+
stdio: 'inherit' | 'pipe';
|
|
10
|
+
stdout?: CliStream;
|
|
11
|
+
};
|
|
12
|
+
type ScriptRuntimeOptions = {
|
|
13
|
+
ci?: boolean;
|
|
14
|
+
cwd?: string;
|
|
15
|
+
env?: NodeJS.ProcessEnv;
|
|
16
|
+
spawnCommand?: (command: string, args: string[], options: SpawnCommandOptions) => Promise<number>;
|
|
17
|
+
stderr?: CliStream;
|
|
18
|
+
stdout?: CliStream;
|
|
19
|
+
};
|
|
20
|
+
type ScriptCommand = 'build' | 'dev' | 'start';
|
|
21
|
+
/**
|
|
22
|
+
* Renders lifecycle command help text.
|
|
23
|
+
*
|
|
24
|
+
* @param command Lifecycle command whose help text should be rendered.
|
|
25
|
+
* @returns Human-readable lifecycle command usage text.
|
|
26
|
+
*/
|
|
27
|
+
export declare function scriptUsage(command: ScriptCommand): string;
|
|
28
|
+
/**
|
|
29
|
+
* Runs one generated-project lifecycle command through the CLI-owned runtime command matrix.
|
|
30
|
+
*
|
|
31
|
+
* @param command Lifecycle command to run.
|
|
32
|
+
* @param argv Command-specific arguments after the lifecycle command name.
|
|
33
|
+
* @param runtime Runtime dependencies used by tests, sandboxes, and embedders.
|
|
34
|
+
* @returns Process-style exit code from the lifecycle command.
|
|
35
|
+
*/
|
|
36
|
+
export declare function runScriptCommand(command: ScriptCommand, argv: string[], runtime?: ScriptRuntimeOptions): Promise<number>;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=scripts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../src/commands/scripts.ts"],"names":[],"mappings":"AAMA,KAAK,SAAS,GAAG;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC,CAAC;AAMF,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAClG,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB,CAAC;AAGF,KAAK,aAAa,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;AA4c/C;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAmB1D;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyElI"}
|