@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.
@@ -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 };
@@ -0,0 +1,6 @@
1
+ import { Command } from "@kidd-cli/core";
2
+
3
+ //#region src/commands/doctor.d.ts
4
+ declare const _default: Command;
5
+ //#endregion
6
+ export { _default as default };