@kidd-cli/cli 0.1.0
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/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/commands/add/command.d.mts +6 -0
- package/dist/commands/add/command.mjs +137 -0
- package/dist/commands/add/index.d.mts +6 -0
- package/dist/commands/add/index.mjs +7 -0
- package/dist/commands/add/middleware.d.mts +6 -0
- package/dist/commands/add/middleware.mjs +101 -0
- package/dist/commands/build.d.mts +6 -0
- package/dist/commands/build.mjs +163 -0
- package/dist/commands/commands.d.mts +13 -0
- package/dist/commands/commands.mjs +135 -0
- package/dist/commands/dev.d.mts +12 -0
- package/dist/commands/dev.mjs +68 -0
- package/dist/commands/doctor.d.mts +6 -0
- package/dist/commands/doctor.mjs +680 -0
- package/dist/commands/init.d.mts +6 -0
- package/dist/commands/init.mjs +167 -0
- package/dist/detect-DDE1hlQ8.mjs +73 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +41 -0
- package/dist/lib/templates/command/command.ts.liquid +12 -0
- package/dist/lib/templates/middleware/middleware.ts.liquid +9 -0
- package/dist/lib/templates/project/gitignore.liquid +3 -0
- package/dist/lib/templates/project/package.json.liquid +29 -0
- package/dist/lib/templates/project/src/commands/hello.ts.liquid +12 -0
- package/dist/lib/templates/project/src/index.ts.liquid +8 -0
- package/dist/lib/templates/project/tsconfig.json.liquid +19 -0
- package/dist/lib/templates/project/tsdown.config.ts.liquid +9 -0
- package/dist/lib/templates/project/vitest.config.ts.liquid +8 -0
- package/dist/write-DDGnajpV.mjs +166 -0
- package/package.json +43 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { command } from "@kidd-cli/core";
|
|
2
|
+
import { watch } from "@kidd-cli/bundler";
|
|
3
|
+
import { loadConfig } from "@kidd-cli/config/loader";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/dev.ts
|
|
6
|
+
/**
|
|
7
|
+
* Start a kidd CLI project in development mode with file watching.
|
|
8
|
+
*
|
|
9
|
+
* Loads the project's `kidd.config.ts`, starts tsdown in watch mode, and
|
|
10
|
+
* logs rebuild status on each successful build.
|
|
11
|
+
*/
|
|
12
|
+
const devCommand = command({
|
|
13
|
+
description: "Start a kidd CLI project in development mode",
|
|
14
|
+
handler: async (ctx) => {
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
const [configError, configResult] = await loadConfig({ cwd });
|
|
17
|
+
const config = extractConfig(configResult);
|
|
18
|
+
if (configError) {}
|
|
19
|
+
ctx.spinner.start("Starting dev server...");
|
|
20
|
+
const [watchError] = await watch({
|
|
21
|
+
config,
|
|
22
|
+
cwd,
|
|
23
|
+
onSuccess: createOnSuccess(ctx)
|
|
24
|
+
});
|
|
25
|
+
if (watchError) {
|
|
26
|
+
ctx.spinner.stop("Watch failed");
|
|
27
|
+
ctx.fail(watchError.message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Extract a KiddConfig from a load result, falling back to empty defaults.
|
|
33
|
+
*
|
|
34
|
+
* @private
|
|
35
|
+
* @param result - The result from loadConfig, or null when loading failed.
|
|
36
|
+
* @returns The loaded config or an empty object (all KiddConfig fields are optional).
|
|
37
|
+
*/
|
|
38
|
+
function extractConfig(result) {
|
|
39
|
+
if (result) return result.config;
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create an onSuccess callback that tracks first-build state.
|
|
44
|
+
*
|
|
45
|
+
* On the first invocation the spinner is stopped and a "watching" message is
|
|
46
|
+
* logged. Subsequent invocations log a "rebuilt" message instead.
|
|
47
|
+
*
|
|
48
|
+
* Uses a mutable container object inside the closure to track build count
|
|
49
|
+
* without `let` reassignment.
|
|
50
|
+
*
|
|
51
|
+
* @private
|
|
52
|
+
* @param ctx - The command context for spinner and logger access.
|
|
53
|
+
* @returns A callback suitable for the watch `onSuccess` parameter.
|
|
54
|
+
*/
|
|
55
|
+
function createOnSuccess(ctx) {
|
|
56
|
+
const state = { buildCount: 0 };
|
|
57
|
+
return () => {
|
|
58
|
+
if (state.buildCount === 0) {
|
|
59
|
+
state.buildCount = 1;
|
|
60
|
+
ctx.spinner.stop("Watching for changes...");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
ctx.logger.success("Rebuilt successfully");
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { devCommand as default };
|