@lithia-js/cli 1.0.0-canary.2 → 1.0.0-canary.20
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.md +18 -45
- package/dist/_entrypoint.mjs +25 -0
- package/dist/_entrypoint.mjs.map +1 -0
- package/dist/index.mjs +263 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -13
- package/CHANGELOG.md +0 -31
- package/dist/cmd/build.d.ts +0 -2
- package/dist/cmd/build.js +0 -28
- package/dist/cmd/build.js.map +0 -1
- package/dist/cmd/dev.d.ts +0 -2
- package/dist/cmd/dev.js +0 -116
- package/dist/cmd/dev.js.map +0 -1
- package/dist/cmd/start.d.ts +0 -2
- package/dist/cmd/start.js +0 -46
- package/dist/cmd/start.js.map +0 -1
- package/dist/main.d.ts +0 -2
- package/dist/main.js +0 -25
- package/dist/main.js.map +0 -1
- package/dist/meta.d.ts +0 -1
- package/dist/meta.js +0 -6
- package/dist/meta.js.map +0 -1
- package/src/cmd/build.ts +0 -26
- package/src/cmd/dev.ts +0 -126
- package/src/cmd/start.ts +0 -47
- package/src/main.ts +0 -22
- package/src/meta.ts +0 -1
- package/tsconfig.json +0 -8
package/README.md
CHANGED
|
@@ -2,59 +2,32 @@
|
|
|
2
2
|
<a href="https://github.com/lithia-framework/lithia">
|
|
3
3
|
<img alt="Lithia logo" src="https://raw.githubusercontent.com/lithia-framework/lithia/canary/.github/assets/logo.svg" height="128">
|
|
4
4
|
</a>
|
|
5
|
-
<h1
|
|
6
|
-
<p><strong>The
|
|
5
|
+
<h1>@lithia-js/cli</h1>
|
|
6
|
+
<p><strong>The `lithia` command-line interface.</strong></p>
|
|
7
7
|
|
|
8
|
-
<
|
|
9
|
-
|
|
8
|
+
<p>Development server, production build flow, and host orchestration for Lithia apps.</p>
|
|
9
|
+
|
|
10
|
+
<a href="https://www.npmjs.com/package/@lithia-js/cli"><img alt="NPM version" src="https://img.shields.io/npm/v/@lithia-js/cli.svg?style=for-the-badge&labelColor=000000"></a>
|
|
11
|
+
<a href="https://github.com/lithia-framework/lithia/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@lithia-js/cli.svg?style=for-the-badge&labelColor=000000"></a>
|
|
10
12
|
<a href="https://opencollective.com/lithiajs"><img alt="Support Lithia" src="https://img.shields.io/badge/Support%20Lithia-blueviolet.svg?style=for-the-badge&logo=OpenCollective&labelColor=000000&logoWidth=20"></a>
|
|
11
13
|
|
|
12
14
|
</div>
|
|
13
15
|
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
Lithia is a next-generation Node.js framework that enables you to build powerful APIs with file-based routing, built-in WebSocket support, and a beautiful development interface.
|
|
17
|
-
|
|
18
|
-
- Visit our [Learn Lithia](https://lithiajs.com/docs) guide to get started.
|
|
19
|
-
- Check out the [Examples](https://github.com/lithia-framework/lithia/tree/main/examples) to see Lithia in action.
|
|
20
|
-
|
|
21
|
-
## Documentation
|
|
22
|
-
|
|
23
|
-
Visit [https://lithiajs.com/docs](https://lithiajs.com/docs) to view the full documentation.
|
|
24
|
-
|
|
25
|
-
## Community
|
|
26
|
-
|
|
27
|
-
The Lithia community can be found on [GitHub Discussions](https://github.com/lithia-framework/lithia/discussions) where you can ask questions, voice ideas, and share your projects with other people.
|
|
16
|
+
## Commands
|
|
28
17
|
|
|
29
|
-
|
|
18
|
+
### `lithia dev`
|
|
30
19
|
|
|
31
|
-
|
|
20
|
+
Starts the development server, watches source/config/env changes, rebuilds the
|
|
21
|
+
app, and swaps the app worker when reloads succeed.
|
|
32
22
|
|
|
33
|
-
|
|
23
|
+
### `lithia build`
|
|
34
24
|
|
|
35
|
-
|
|
25
|
+
Builds the application into the configured `outDir`, generates manifests, and
|
|
26
|
+
prints the discovered routes, events, and async tasks.
|
|
36
27
|
|
|
37
|
-
|
|
28
|
+
## Notes
|
|
38
29
|
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## License
|
|
47
|
-
|
|
48
|
-
Lithia is [MIT licensed](LICENSE). Free for personal and commercial use.
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
<div align="center">
|
|
53
|
-
<p><strong>Built with ❤️ by the Lithia community</strong></p>
|
|
54
|
-
<p>
|
|
55
|
-
<a href="https://github.com/lithia-framework/lithia">GitHub</a> •
|
|
56
|
-
<a href="https://lithiajs.com">Documentation</a> •
|
|
57
|
-
<a href="https://opencollective.com/lithiajs">OpenCollective</a> •
|
|
58
|
-
<a href="https://github.com/lithia-framework/lithia/discussions">Discussions</a>
|
|
59
|
-
</p>
|
|
60
|
-
</div>
|
|
30
|
+
- The CLI is designed around the worker-based Lithia runtime.
|
|
31
|
+
- It uses `@lithia-js/core/_` internally for host orchestration.
|
|
32
|
+
- Templates are scaffolded by `create-lithia`, while repo-local examples live
|
|
33
|
+
under `examples/`.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import { CFG_GLOBAL_KEY, HostSupervisor } from '@lithia-js/core/_';
|
|
3
|
+
|
|
4
|
+
async function bootstrap() {
|
|
5
|
+
globalThis[CFG_GLOBAL_KEY] = __CONFIG__;
|
|
6
|
+
const lithia = new HostSupervisor({ environment: "production" });
|
|
7
|
+
await lithia.setup();
|
|
8
|
+
try {
|
|
9
|
+
await lithia.start();
|
|
10
|
+
} catch {
|
|
11
|
+
}
|
|
12
|
+
const shutdown = async () => {
|
|
13
|
+
try {
|
|
14
|
+
await lithia.stop();
|
|
15
|
+
} catch {
|
|
16
|
+
} finally {
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
process.once("SIGINT", shutdown);
|
|
21
|
+
process.once("SIGTERM", shutdown);
|
|
22
|
+
}
|
|
23
|
+
await bootstrap().catch(() => process.exit(1));
|
|
24
|
+
//# sourceMappingURL=_entrypoint.mjs.map
|
|
25
|
+
//# sourceMappingURL=_entrypoint.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/_entrypoint.ts"],"names":[],"mappings":";;;AA8BA,eAAe,SAAA,GAA2B;AAEzC,EAAA,UAAA,CAAW,cAAc,CAAA,GAAI,UAAA;AAE7B,EAAA,MAAM,SAAS,IAAI,cAAA,CAAe,EAAE,WAAA,EAAa,cAAc,CAAA;AAE/D,EAAA,MAAM,OAAO,KAAA,EAAM;AAEnB,EAAA,IAAI;AACH,IAAA,MAAM,OAAO,KAAA,EAAM;AAAA,EACpB,CAAA,CAAA,MAAQ;AAAA,EAER;AAMA,EAAA,MAAM,WAAW,YAA2B;AAC3C,IAAA,IAAI;AACH,MAAA,MAAM,OAAO,IAAA,EAAK;AAAA,IACnB,CAAA,CAAA,MAAQ;AAAA,IAER,CAAA,SAAE;AACD,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IACf;AAAA,EACD,CAAA;AAGA,EAAA,OAAA,CAAQ,IAAA,CAAK,UAAU,QAAQ,CAAA;AAC/B,EAAA,OAAA,CAAQ,IAAA,CAAK,WAAW,QAAQ,CAAA;AACjC;AAGA,MAAM,WAAU,CAAE,KAAA,CAAM,MAAM,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAC,CAAA","file":"_entrypoint.mjs","sourcesContent":["#! /usr/bin/env node\n/**\n * -----------------------------------------------------------------------------\n * LITHIA FRAMEWORK - PRODUCTION ENTRY POINT\n * -----------------------------------------------------------------------------\n * * WARNING: THIS IS A GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n * * This file is automatically generated by the Lithia CLI during the build\n * process. Any manual modifications will be lost when the project is rebuilt.\n * * For configuration changes, please modify your 'lithia.config' file or\n * environment variables.\n * * @generated\n * -----------------------------------------------------------------------------\n */\n\nimport type { LithiaConfig } from \"@lithia-js/core\";\nimport { CFG_GLOBAL_KEY, HostSupervisor } from \"@lithia-js/core/_\";\n\ndeclare global {\n\tvar __lithia_host_config_v1: LithiaConfig;\n}\n\n/**\n * The __CONFIG__ constant is a placeholder injected during the build step.\n * It contains the resolved application configuration for production.\n */\ndeclare const __CONFIG__: LithiaConfig;\n\n/**\n * Bootstraps the production environment and manages the host lifecycle.\n */\nasync function bootstrap(): Promise<void> {\n\t// Initialize the global configuration context\n\tglobalThis[CFG_GLOBAL_KEY] = __CONFIG__;\n\n\tconst lithia = new HostSupervisor({ environment: \"production\" });\n\n\tawait lithia.setup();\n\n\ttry {\n\t\tawait lithia.start();\n\t} catch {\n\t\t// Initialization failure handled by the host internally\n\t}\n\n\t/**\n\t * Orchestrates a graceful shutdown by stopping the host\n\t * and releasing process resources.\n\t */\n\tconst shutdown = async (): Promise<void> => {\n\t\ttry {\n\t\t\tawait lithia.stop();\n\t\t} catch {\n\t\t\t// Ensure the process exits even if the stop sequence encounters an error\n\t\t} finally {\n\t\t\tprocess.exit(0);\n\t\t}\n\t};\n\n\t// Register process signal listeners for clean termination\n\tprocess.once(\"SIGINT\", shutdown);\n\tprocess.once(\"SIGTERM\", shutdown);\n}\n\n// Execute the bootstrap sequence and handle unhandled rejections\nawait bootstrap().catch(() => process.exit(1));\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import { defineCommand, runMain } from 'citty';
|
|
3
|
+
import { readFile, writeFile, chmod } from 'fs/promises';
|
|
4
|
+
import { join, resolve } from 'path';
|
|
5
|
+
import { HostSupervisor } from '@lithia-js/core/_';
|
|
6
|
+
import { logger } from '@lithia-js/utils';
|
|
7
|
+
import chokidar from 'chokidar';
|
|
8
|
+
|
|
9
|
+
var build = defineCommand({
|
|
10
|
+
meta: {
|
|
11
|
+
name: "build",
|
|
12
|
+
description: "Compile the project for production deployment"
|
|
13
|
+
},
|
|
14
|
+
/**
|
|
15
|
+
* Primary execution logic for the build command.
|
|
16
|
+
* @throws {Error} If build processes or file operations fail.
|
|
17
|
+
*/
|
|
18
|
+
async run() {
|
|
19
|
+
const lithia = new HostSupervisor({ environment: "build" });
|
|
20
|
+
await lithia.setup();
|
|
21
|
+
logger.info("Initializing production build sequence...");
|
|
22
|
+
try {
|
|
23
|
+
await lithia.build();
|
|
24
|
+
} catch {
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
const { config } = lithia;
|
|
28
|
+
const workingDirectory = process.cwd();
|
|
29
|
+
const entryPath = join(workingDirectory, config.outDir, "server.js");
|
|
30
|
+
const templatePath = resolve(import.meta.dirname, "_entrypoint.mjs");
|
|
31
|
+
try {
|
|
32
|
+
const rawTemplate = await readFile(templatePath, "utf-8");
|
|
33
|
+
const processedContent = rawTemplate.replace(
|
|
34
|
+
"__CONFIG__",
|
|
35
|
+
JSON.stringify(config)
|
|
36
|
+
);
|
|
37
|
+
await writeFile(entryPath, processedContent, "utf-8");
|
|
38
|
+
await lithia.loadRoutes();
|
|
39
|
+
await lithia.loadEvents();
|
|
40
|
+
await lithia.loadTasks();
|
|
41
|
+
await chmod(entryPath, 493);
|
|
42
|
+
logger.success("Production build completed successfully.");
|
|
43
|
+
} catch (error) {
|
|
44
|
+
logger.error("Failed to finalize the build entry point.");
|
|
45
|
+
logger.debug(error);
|
|
46
|
+
}
|
|
47
|
+
lithia.printRouteTree();
|
|
48
|
+
lithia.printEventTree();
|
|
49
|
+
lithia.printTaskTree();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
var build_default = build;
|
|
53
|
+
|
|
54
|
+
// src/cmd/dev-scheduler.ts
|
|
55
|
+
var DevLifecycleScheduler = class {
|
|
56
|
+
constructor(onBatch, debounceMs = 180, onError = () => {
|
|
57
|
+
}) {
|
|
58
|
+
this.onBatch = onBatch;
|
|
59
|
+
this.debounceMs = debounceMs;
|
|
60
|
+
this.onError = onError;
|
|
61
|
+
}
|
|
62
|
+
pending = {
|
|
63
|
+
source: false,
|
|
64
|
+
config: false,
|
|
65
|
+
env: false
|
|
66
|
+
};
|
|
67
|
+
timer = null;
|
|
68
|
+
running = false;
|
|
69
|
+
enqueue(kind) {
|
|
70
|
+
this.pending[kind] = true;
|
|
71
|
+
if (this.running) return;
|
|
72
|
+
if (this.timer) clearTimeout(this.timer);
|
|
73
|
+
this.timer = setTimeout(() => {
|
|
74
|
+
this.timer = null;
|
|
75
|
+
void this.flush();
|
|
76
|
+
}, this.debounceMs);
|
|
77
|
+
}
|
|
78
|
+
async flush() {
|
|
79
|
+
if (this.running) return;
|
|
80
|
+
this.running = true;
|
|
81
|
+
try {
|
|
82
|
+
while (this.hasPendingChanges()) {
|
|
83
|
+
await this.onBatch(this.consumePending());
|
|
84
|
+
}
|
|
85
|
+
} catch (error) {
|
|
86
|
+
this.onError(error);
|
|
87
|
+
} finally {
|
|
88
|
+
this.running = false;
|
|
89
|
+
if (this.hasPendingChanges() && !this.timer) {
|
|
90
|
+
this.timer = setTimeout(() => {
|
|
91
|
+
this.timer = null;
|
|
92
|
+
void this.flush();
|
|
93
|
+
}, this.debounceMs);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
hasPendingChanges() {
|
|
98
|
+
return this.pending.source || this.pending.config || this.pending.env;
|
|
99
|
+
}
|
|
100
|
+
consumePending() {
|
|
101
|
+
const batch = { ...this.pending };
|
|
102
|
+
this.pending.source = false;
|
|
103
|
+
this.pending.config = false;
|
|
104
|
+
this.pending.env = false;
|
|
105
|
+
return batch;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/cmd/dev.ts
|
|
110
|
+
var dev = defineCommand({
|
|
111
|
+
meta: {
|
|
112
|
+
name: "dev",
|
|
113
|
+
description: "Start the development server with hot-reload capabilities"
|
|
114
|
+
},
|
|
115
|
+
async run() {
|
|
116
|
+
const cwd = process.cwd();
|
|
117
|
+
const lithia = new HostSupervisor({ environment: "development" });
|
|
118
|
+
await lithia.setup();
|
|
119
|
+
const initialBuildSucceeded = await lithia.build();
|
|
120
|
+
const lifecycleState = {
|
|
121
|
+
hasReloadableArtifacts: initialBuildSucceeded
|
|
122
|
+
};
|
|
123
|
+
if (initialBuildSucceeded) {
|
|
124
|
+
try {
|
|
125
|
+
await lithia.start();
|
|
126
|
+
} catch {
|
|
127
|
+
logger.error("Failed to start the development server.");
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
logger.warn(
|
|
131
|
+
"Initial build failed. Waiting for file changes while continuing to serve nothing."
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const scheduler = new DevLifecycleScheduler(
|
|
135
|
+
async (batch) => {
|
|
136
|
+
await processDevBatch(lithia, batch, lifecycleState);
|
|
137
|
+
},
|
|
138
|
+
180,
|
|
139
|
+
(error) => {
|
|
140
|
+
logger.error("Dev lifecycle failed:", error);
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
const srcWatcher = chokidar.watch(join(cwd, "src"), {
|
|
144
|
+
ignored: [/(^|[/\\])\../, "**/node_modules/**"],
|
|
145
|
+
persistent: true,
|
|
146
|
+
ignoreInitial: true
|
|
147
|
+
});
|
|
148
|
+
srcWatcher.on("all", (event) => {
|
|
149
|
+
if (["add", "change", "unlink"].includes(event)) {
|
|
150
|
+
scheduler.enqueue("source");
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
const extensions = [".js", ".mjs", ".ts", ".mts", ".json"];
|
|
154
|
+
const configFiles = [
|
|
155
|
+
...lithia.config.envFiles,
|
|
156
|
+
...extensions.map((ext) => join(cwd, `lithia.config${ext}`))
|
|
157
|
+
];
|
|
158
|
+
const configWatcher = chokidar.watch(configFiles, {
|
|
159
|
+
cwd,
|
|
160
|
+
ignoreInitial: true
|
|
161
|
+
});
|
|
162
|
+
configWatcher.on("all", (event, filePath) => {
|
|
163
|
+
if (["change", "add"].includes(event)) {
|
|
164
|
+
if (filePath.includes("lithia.config")) {
|
|
165
|
+
scheduler.enqueue("config");
|
|
166
|
+
} else {
|
|
167
|
+
scheduler.enqueue("env");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const shutdown = async () => {
|
|
172
|
+
logger.info("Shutting down development server...");
|
|
173
|
+
await Promise.allSettled([
|
|
174
|
+
srcWatcher.close(),
|
|
175
|
+
configWatcher.close(),
|
|
176
|
+
lithia.stop()
|
|
177
|
+
]);
|
|
178
|
+
process.exit(0);
|
|
179
|
+
};
|
|
180
|
+
process.once("SIGINT", shutdown);
|
|
181
|
+
process.once("SIGTERM", shutdown);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
var dev_default = dev;
|
|
185
|
+
async function processDevBatch(lithia, batch, state) {
|
|
186
|
+
if (batch.config) {
|
|
187
|
+
logger.info("Configuration updated. Rebuilding and reloading host...");
|
|
188
|
+
const previousConfig = structuredClone(lithia.config);
|
|
189
|
+
const previousEnv = lithia.getEnvSnapshot();
|
|
190
|
+
try {
|
|
191
|
+
await lithia.loadConfig();
|
|
192
|
+
await lithia.loadEnv();
|
|
193
|
+
const buildSucceeded = await lithia.build();
|
|
194
|
+
if (!buildSucceeded) {
|
|
195
|
+
state.hasReloadableArtifacts = state.hasReloadableArtifacts || lithia.isAppReady;
|
|
196
|
+
lithia.replaceConfig(previousConfig);
|
|
197
|
+
lithia.replaceEnv(previousEnv);
|
|
198
|
+
logger.warn(
|
|
199
|
+
"Reload skipped due to build failure. Rolled back config/env and kept serving the previous app."
|
|
200
|
+
);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
await lithia.reload();
|
|
204
|
+
state.hasReloadableArtifacts = true;
|
|
205
|
+
logger.success("Reload complete.");
|
|
206
|
+
return;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
lithia.replaceConfig(previousConfig);
|
|
209
|
+
lithia.replaceEnv(previousEnv);
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (batch.source) {
|
|
214
|
+
logger.info("Source updated. Building host...");
|
|
215
|
+
const buildSucceeded = await lithia.build();
|
|
216
|
+
if (!buildSucceeded) {
|
|
217
|
+
state.hasReloadableArtifacts = state.hasReloadableArtifacts || lithia.isAppReady;
|
|
218
|
+
logger.warn(
|
|
219
|
+
"Reload skipped due to build failure. Continuing to serve previous app."
|
|
220
|
+
);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
state.hasReloadableArtifacts = true;
|
|
224
|
+
}
|
|
225
|
+
if (batch.env) {
|
|
226
|
+
if (!state.hasReloadableArtifacts) {
|
|
227
|
+
logger.warn(
|
|
228
|
+
"Reload skipped because the latest build artifacts are unavailable. Fix the build and save again."
|
|
229
|
+
);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
logger.info("Environment updated. Reloading host...");
|
|
233
|
+
await lithia.loadEnv();
|
|
234
|
+
}
|
|
235
|
+
if (batch.source || batch.env) {
|
|
236
|
+
await lithia.reload();
|
|
237
|
+
state.hasReloadableArtifacts = true;
|
|
238
|
+
logger.success("Reload complete.");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// package.json
|
|
243
|
+
var package_default = {
|
|
244
|
+
version: "1.0.0-canary.20"};
|
|
245
|
+
|
|
246
|
+
// src/meta.ts
|
|
247
|
+
var version = package_default.version;
|
|
248
|
+
|
|
249
|
+
// src/index.ts
|
|
250
|
+
var main = defineCommand({
|
|
251
|
+
meta: {
|
|
252
|
+
name: "lithia",
|
|
253
|
+
description: "Lithia CLI",
|
|
254
|
+
version
|
|
255
|
+
},
|
|
256
|
+
subCommands: {
|
|
257
|
+
dev: dev_default,
|
|
258
|
+
build: build_default
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
runMain(main).then();
|
|
262
|
+
//# sourceMappingURL=index.mjs.map
|
|
263
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cmd/build.ts","../src/cmd/dev-scheduler.ts","../src/cmd/dev.ts","../package.json","../src/meta.ts","../src/index.ts"],"names":["defineCommand","H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AAA,KAAA,CAAM,sBAAA,GACL,KAAA,CAAM,sBAAA,IAA0B,MAAA,CAAO,UAAA;AACxC,MAAAA,MAAAA,CAAO,IAAA;AAAA,QACN;AAAA,OACD;AACA,MAAA;AAAA,IACD;AAEA,IAAA,KAAA,CAAM,sBAAA,GAAyB,IAAA;AAAA,EAChC;AAEA,EAAA,IAAI,MAAM,GAAA,EAAK;AACd,IAAA,IAAI,CAAC,MAAM,sBAAA,EAAwB;AAClC,MAAAA,MAAAA,CAAO,IAAA;AAAA,QACN;AAAA,OACD;AACA,MAAA;AAAA,IACD;AACA,IAAAA,MAAAA,CAAO,KAAK,wCAAwC,CAAA;AACpD,IAAA,MAAM,OAAO,OAAA,EAAQ;AAAA,EACtB;AAEA,EAAA,IAAI,KAAA,CAAM,MAAA,IAAU,KAAA,CAAM,GAAA,EAAK;AAC9B,IAAA,MAAM,OAAO,MAAA,EAAO;AACpB,IAAA,KAAA,CAAM,sBAAA,GAAyB,IAAA;AAC/B,IAAAA,MAAAA,CAAO,QAAQ,kBAAkB,CAAA;AAAA,EAClC;AACD;;;ACjLA,IAAA,eAAA,GAAA;AAAA,EAEC,OAAA,EAAW,iBAkDZ,CAAA;;;ACnDO,IAAM,UAAU,eAAA,CAAM,OAAA;;;ACM7B,IAAM,OAAOF,aAAAA,CAAc;AAAA,EAC1B,IAAA,EAAM;AAAA,IACL,IAAA,EAAM,QAAA;AAAA,IACN,WAAA,EAAa,YAAA;AAAA,IACb;AAAA,GACD;AAAA,EACA,WAAA,EAAa;AAAA,IACZ,GAAA,EAAA,WAAA;AAAA,IACA,KAAA,EAAA;AAAA;AAEF,CAAC,CAAA;AAED,OAAA,CAAQ,IAAI,EAAE,IAAA,EAAK","file":"index.mjs","sourcesContent":["/**\n * @fileoverview Build command implementation for the Lithia CLI.\n * Handles project compilation, entry point generation, and environment preparation.\n */\n\nimport { chmod, readFile, writeFile } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { HostSupervisor } from \"@lithia-js/core/_\";\nimport { logger } from \"@lithia-js/utils\";\nimport { defineCommand } from \"citty\";\n\n/**\n * The 'build' command compiles the application for production environments.\n * It initializes the Lithia host, generates the server entry point,\n * and configures file permissions.\n */\nconst build = defineCommand({\n\tmeta: {\n\t\tname: \"build\",\n\t\tdescription: \"Compile the project for production deployment\",\n\t},\n\n\t/**\n\t * Primary execution logic for the build command.\n\t * @throws {Error} If build processes or file operations fail.\n\t */\n\tasync run() {\n\t\tconst lithia = new HostSupervisor({ environment: \"build\" });\n\n\t\t// Initialize the host environment\n\t\tawait lithia.setup();\n\n\t\tlogger.info(\"Initializing production build sequence...\");\n\n\t\t// Trigger the core build process\n\t\ttry {\n\t\t\tawait lithia.build();\n\t\t} catch {\n\t\t\tprocess.exit(1);\n\t\t}\n\n\t\tconst { config } = lithia;\n\t\tconst workingDirectory = process.cwd();\n\n\t\t// Path resolution for entry point generation\n\t\tconst entryPath = join(workingDirectory, config.outDir, \"server.js\");\n\t\tconst templatePath = resolve(import.meta.dirname, \"_entrypoint.mjs\");\n\n\t\t// Generate production entry point by injecting runtime configuration\n\t\ttry {\n\t\t\tconst rawTemplate = await readFile(templatePath, \"utf-8\");\n\t\t\tconst processedContent = rawTemplate.replace(\n\t\t\t\t\"__CONFIG__\",\n\t\t\t\tJSON.stringify(config),\n\t\t\t);\n\n\t\t\tawait writeFile(entryPath, processedContent, \"utf-8\");\n\n\t\t\t// Post-write operations: Loading metadata and setting permissions\n\t\t\tawait lithia.loadRoutes();\n\t\t\tawait lithia.loadEvents();\n\t\t\tawait lithia.loadTasks();\n\n\t\t\t// Ensure the entry point is executable (0o755: rwxr-xr-x)\n\t\t\tawait chmod(entryPath, 0o755);\n\n\t\t\tlogger.success(\"Production build completed successfully.\");\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Failed to finalize the build entry point.\");\n\t\t\tlogger.debug(error);\n\t\t\t// Silent catch maintained as per original implementation,\n\t\t\t// but logged for visibility.\n\t\t}\n\n\t\t// Output visual representation of the application structure\n\t\tlithia.printRouteTree();\n\t\tlithia.printEventTree();\n\t\tlithia.printTaskTree();\n\t},\n});\n\nexport default build;\n","export type DevChangeKind = \"source\" | \"config\" | \"env\";\n\nexport interface DevChangeBatch {\n\tsource: boolean;\n\tconfig: boolean;\n\tenv: boolean;\n}\n\nexport class DevLifecycleScheduler {\n\tprivate readonly pending: DevChangeBatch = {\n\t\tsource: false,\n\t\tconfig: false,\n\t\tenv: false,\n\t};\n\n\tprivate timer: NodeJS.Timeout | null = null;\n\tprivate running = false;\n\n\tconstructor(\n\t\tprivate readonly onBatch: (batch: DevChangeBatch) => Promise<void>,\n\t\tprivate readonly debounceMs: number = 180,\n\t\tprivate readonly onError: (error: unknown) => void = () => {},\n\t) {}\n\n\tpublic enqueue(kind: DevChangeKind): void {\n\t\tthis.pending[kind] = true;\n\t\tif (this.running) return;\n\n\t\tif (this.timer) clearTimeout(this.timer);\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.timer = null;\n\t\t\tvoid this.flush();\n\t\t}, this.debounceMs);\n\t}\n\n\tprivate async flush(): Promise<void> {\n\t\tif (this.running) return;\n\t\tthis.running = true;\n\n\t\ttry {\n\t\t\twhile (this.hasPendingChanges()) {\n\t\t\t\tawait this.onBatch(this.consumePending());\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis.onError(error);\n\t\t} finally {\n\t\t\tthis.running = false;\n\t\t\tif (this.hasPendingChanges() && !this.timer) {\n\t\t\t\tthis.timer = setTimeout(() => {\n\t\t\t\t\tthis.timer = null;\n\t\t\t\t\tvoid this.flush();\n\t\t\t\t}, this.debounceMs);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate hasPendingChanges(): boolean {\n\t\treturn this.pending.source || this.pending.config || this.pending.env;\n\t}\n\n\tprivate consumePending(): DevChangeBatch {\n\t\tconst batch = { ...this.pending };\n\t\tthis.pending.source = false;\n\t\tthis.pending.config = false;\n\t\tthis.pending.env = false;\n\t\treturn batch;\n\t}\n}\n","/**\n * @fileoverview Development command for the Lithia CLI.\n * Provides Hot Module Replacement (HMR) capabilities via file system watchers,\n * automatic configuration reloading, and environment synchronization.\n */\n\nimport { join } from \"node:path\";\nimport { HostSupervisor } from \"@lithia-js/core/_\";\nimport { logger } from \"@lithia-js/utils\";\nimport chokidar from \"chokidar\";\nimport { defineCommand } from \"citty\";\nimport { type DevChangeBatch, DevLifecycleScheduler } from \"./dev-scheduler\";\n\nconst dev = defineCommand({\n\tmeta: {\n\t\tname: \"dev\",\n\t\tdescription: \"Start the development server with hot-reload capabilities\",\n\t},\n\n\tasync run() {\n\t\tconst cwd = process.cwd();\n\t\tconst lithia = new HostSupervisor({ environment: \"development\" });\n\n\t\t// 1. Initial Host Setup\n\t\tawait lithia.setup();\n\t\tconst initialBuildSucceeded = await lithia.build();\n\t\tconst lifecycleState = {\n\t\t\thasReloadableArtifacts: initialBuildSucceeded,\n\t\t};\n\n\t\tif (initialBuildSucceeded) {\n\t\t\ttry {\n\t\t\t\tawait lithia.start();\n\t\t\t} catch {\n\t\t\t\tlogger.error(\"Failed to start the development server.\");\n\t\t\t}\n\t\t} else {\n\t\t\tlogger.warn(\n\t\t\t\t\"Initial build failed. Waiting for file changes while continuing to serve nothing.\",\n\t\t\t);\n\t\t}\n\n\t\t// 2. Define the serialized dev lifecycle\n\t\tconst scheduler = new DevLifecycleScheduler(\n\t\t\tasync (batch) => {\n\t\t\t\tawait processDevBatch(lithia, batch, lifecycleState);\n\t\t\t},\n\t\t\t180,\n\t\t\t(error) => {\n\t\t\t\tlogger.error(\"Dev lifecycle failed:\", error);\n\t\t\t},\n\t\t);\n\n\t\t// 3. Source Code Watcher\n\t\tconst srcWatcher = chokidar.watch(join(cwd, \"src\"), {\n\t\t\tignored: [/(^|[/\\\\])\\../, \"**/node_modules/**\"],\n\t\t\tpersistent: true,\n\t\t\tignoreInitial: true,\n\t\t});\n\n\t\tsrcWatcher.on(\"all\", (event) => {\n\t\t\tif ([\"add\", \"change\", \"unlink\"].includes(event)) {\n\t\t\t\tscheduler.enqueue(\"source\");\n\t\t\t}\n\t\t});\n\n\t\t// 4. Configuration and Environment Watcher\n\t\tconst extensions = [\".js\", \".mjs\", \".ts\", \".mts\", \".json\"];\n\t\tconst configFiles = [\n\t\t\t...lithia.config.envFiles,\n\t\t\t...extensions.map((ext) => join(cwd, `lithia.config${ext}`)),\n\t\t];\n\n\t\tconst configWatcher = chokidar.watch(configFiles, {\n\t\t\tcwd,\n\t\t\tignoreInitial: true,\n\t\t});\n\n\t\tconfigWatcher.on(\"all\", (event, filePath) => {\n\t\t\tif ([\"change\", \"add\"].includes(event)) {\n\t\t\t\tif (filePath.includes(\"lithia.config\")) {\n\t\t\t\t\tscheduler.enqueue(\"config\");\n\t\t\t\t} else {\n\t\t\t\t\tscheduler.enqueue(\"env\");\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// 5. Graceful Shutdown Orchestration\n\t\tconst shutdown = async () => {\n\t\t\tlogger.info(\"Shutting down development server...\");\n\t\t\tawait Promise.allSettled([\n\t\t\t\tsrcWatcher.close(),\n\t\t\t\tconfigWatcher.close(),\n\t\t\t\tlithia.stop(),\n\t\t\t]);\n\t\t\tprocess.exit(0);\n\t\t};\n\n\t\t// Correctly bind signal handlers to the shutdown sequence\n\t\tprocess.once(\"SIGINT\", shutdown);\n\t\tprocess.once(\"SIGTERM\", shutdown);\n\t},\n});\n\nexport default dev;\n\nexport async function processDevBatch(\n\tlithia: HostSupervisor,\n\tbatch: DevChangeBatch,\n\tstate: { hasReloadableArtifacts: boolean },\n): Promise<void> {\n\tif (batch.config) {\n\t\tlogger.info(\"Configuration updated. Rebuilding and reloading host...\");\n\n\t\tconst previousConfig = structuredClone(lithia.config);\n\t\tconst previousEnv = lithia.getEnvSnapshot();\n\n\t\ttry {\n\t\t\tawait lithia.loadConfig();\n\t\t\tawait lithia.loadEnv();\n\n\t\t\tconst buildSucceeded = await lithia.build();\n\t\t\tif (!buildSucceeded) {\n\t\t\t\tstate.hasReloadableArtifacts =\n\t\t\t\t\tstate.hasReloadableArtifacts || lithia.isAppReady;\n\t\t\t\tlithia.replaceConfig(previousConfig);\n\t\t\t\tlithia.replaceEnv(previousEnv);\n\t\t\t\tlogger.warn(\n\t\t\t\t\t\"Reload skipped due to build failure. Rolled back config/env and kept serving the previous app.\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tawait lithia.reload();\n\t\t\tstate.hasReloadableArtifacts = true;\n\t\t\tlogger.success(\"Reload complete.\");\n\t\t\treturn;\n\t\t} catch (error) {\n\t\t\tlithia.replaceConfig(previousConfig);\n\t\t\tlithia.replaceEnv(previousEnv);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tif (batch.source) {\n\t\tlogger.info(\"Source updated. Building host...\");\n\t\tconst buildSucceeded = await lithia.build();\n\n\t\tif (!buildSucceeded) {\n\t\t\tstate.hasReloadableArtifacts =\n\t\t\t\tstate.hasReloadableArtifacts || lithia.isAppReady;\n\t\t\tlogger.warn(\n\t\t\t\t\"Reload skipped due to build failure. Continuing to serve previous app.\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tstate.hasReloadableArtifacts = true;\n\t}\n\n\tif (batch.env) {\n\t\tif (!state.hasReloadableArtifacts) {\n\t\t\tlogger.warn(\n\t\t\t\t\"Reload skipped because the latest build artifacts are unavailable. Fix the build and save again.\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tlogger.info(\"Environment updated. Reloading host...\");\n\t\tawait lithia.loadEnv();\n\t}\n\n\tif (batch.source || batch.env) {\n\t\tawait lithia.reload();\n\t\tstate.hasReloadableArtifacts = true;\n\t\tlogger.success(\"Reload complete.\");\n\t}\n}\n","{\n\t\"name\": \"@lithia-js/cli\",\n\t\"version\": \"1.0.0-canary.20\",\n\t\"description\": \"Command-line interface for developing and building Lithia.js applications.\",\n\t\"keywords\": [\n\t\t\"lithia\",\n\t\t\"lithia-js\",\n\t\t\"cli\",\n\t\t\"framework\",\n\t\t\"backend\",\n\t\t\"create-app\",\n\t\t\"build-tool\",\n\t\t\"dev-server\"\n\t],\n\t\"author\": \"Lucas Arch <luketsx@icloud.com>\",\n\t\"license\": \"MIT\",\n\t\"homepage\": \"https://lithiajs.org\",\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"git+https://github.com/lithia-framework/lithia.git\",\n\t\t\"directory\": \"packages/cli\"\n\t},\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/lithia-framework/lithia/issues\"\n\t},\n\t\"type\": \"module\",\n\t\"bin\": {\n\t\t\"lithia\": \"./dist/index.mjs\"\n\t},\n\t\"main\": \"./dist/index.mjs\",\n\t\"files\": [\n\t\t\"dist\",\n\t\t\"templates\"\n\t],\n\t\"engines\": {\n\t\t\"node\": \">=20\"\n\t},\n\t\"scripts\": {\n\t\t\"build\": \"tsup --config tsup.config.ts\",\n\t\t\"test\": \"vitest --run\"\n\t},\n\t\"dependencies\": {\n\t\t\"@lithia-js/core\": \"workspace:1.0.0-canary.20\",\n\t\t\"@lithia-js/utils\": \"workspace:1.0.0-canary.20\",\n\t\t\"citty\": \"^0.2.0\",\n\t\t\"chokidar\": \"^5.0.0\"\n\t},\n\t\"publishConfig\": {\n\t\t\"registry\": \"https://registry.npmjs.org/\",\n\t\t\"access\": \"public\",\n\t\t\"provenance\": true\n\t}\n}\n","import pJson from \"../package.json\" with { type: \"json\" };\nexport const version = pJson.version;\n","#! /usr/bin/env node\n\nimport { defineCommand, runMain } from \"citty\";\nimport build from \"./cmd/build\";\nimport dev from \"./cmd/dev\";\nimport { version } from \"./meta\";\n\nconst main = defineCommand({\n\tmeta: {\n\t\tname: \"lithia\",\n\t\tdescription: \"Lithia CLI\",\n\t\tversion,\n\t},\n\tsubCommands: {\n\t\tdev,\n\t\tbuild,\n\t},\n});\n\nrunMain(main).then();\n"]}
|
package/package.json
CHANGED
|
@@ -1,35 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lithia-js/cli",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"lithia"
|
|
7
|
-
|
|
3
|
+
"version": "1.0.0-canary.20",
|
|
4
|
+
"description": "Command-line interface for developing and building Lithia.js applications.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"lithia",
|
|
7
|
+
"lithia-js",
|
|
8
|
+
"cli",
|
|
9
|
+
"framework",
|
|
10
|
+
"backend",
|
|
11
|
+
"create-app",
|
|
12
|
+
"build-tool",
|
|
13
|
+
"dev-server"
|
|
14
|
+
],
|
|
8
15
|
"author": "Lucas Arch <luketsx@icloud.com>",
|
|
9
|
-
"homepage": "https://lithiajs.com",
|
|
10
16
|
"license": "MIT",
|
|
17
|
+
"homepage": "https://lithiajs.org",
|
|
11
18
|
"repository": {
|
|
12
19
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/lithia-framework/lithia.git"
|
|
20
|
+
"url": "git+https://github.com/lithia-framework/lithia.git",
|
|
21
|
+
"directory": "packages/cli"
|
|
14
22
|
},
|
|
15
23
|
"bugs": {
|
|
16
24
|
"url": "https://github.com/lithia-framework/lithia/issues"
|
|
17
25
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"@lithia-js/core": "1.0.0-canary.2",
|
|
22
|
-
"@lithia-js/utils": "1.0.0-canary.2"
|
|
26
|
+
"type": "module",
|
|
27
|
+
"bin": {
|
|
28
|
+
"lithia": "./dist/index.mjs"
|
|
23
29
|
},
|
|
30
|
+
"main": "./dist/index.mjs",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"templates"
|
|
34
|
+
],
|
|
24
35
|
"engines": {
|
|
25
36
|
"node": ">=20"
|
|
26
37
|
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@lithia-js/core": "1.0.0-canary.20",
|
|
40
|
+
"@lithia-js/utils": "1.0.0-canary.20",
|
|
41
|
+
"citty": "^0.2.0",
|
|
42
|
+
"chokidar": "^5.0.0"
|
|
43
|
+
},
|
|
27
44
|
"publishConfig": {
|
|
28
45
|
"registry": "https://registry.npmjs.org/",
|
|
29
46
|
"access": "public",
|
|
30
47
|
"provenance": true
|
|
31
48
|
},
|
|
32
49
|
"scripts": {
|
|
33
|
-
"build": "
|
|
50
|
+
"build": "tsup --config tsup.config.ts",
|
|
51
|
+
"test": "vitest --run"
|
|
34
52
|
}
|
|
35
53
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# @lithia-js/cli
|
|
2
|
-
|
|
3
|
-
## 1.0.0-canary.2
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- .npmignore update
|
|
8
|
-
- Updated dependencies
|
|
9
|
-
- @lithia-js/core@1.0.0-canary.2
|
|
10
|
-
- @lithia-js/utils@1.0.0-canary.2
|
|
11
|
-
|
|
12
|
-
## 1.0.0-canary.1
|
|
13
|
-
|
|
14
|
-
### Patch Changes
|
|
15
|
-
|
|
16
|
-
- 2992e91: Manifest update for workflow compatibility
|
|
17
|
-
- Updated dependencies [2992e91]
|
|
18
|
-
- @lithia-js/utils@1.0.0-canary.1
|
|
19
|
-
- @lithia-js/core@1.0.0-canary.1
|
|
20
|
-
|
|
21
|
-
## 1.0.0-canary.0
|
|
22
|
-
|
|
23
|
-
### Major Changes
|
|
24
|
-
|
|
25
|
-
- e9a0904: Lithia v1 canary release. Now with separated modules and napi bindings for build performance
|
|
26
|
-
|
|
27
|
-
### Patch Changes
|
|
28
|
-
|
|
29
|
-
- Updated dependencies [e9a0904]
|
|
30
|
-
- @lithia-js/core@1.0.0-canary.0
|
|
31
|
-
- @lithia-js/utils@1.0.0-canary.0
|
package/dist/cmd/build.d.ts
DELETED
package/dist/cmd/build.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
-
const core_1 = require("@lithia-js/core");
|
|
8
|
-
const utils_1 = require("@lithia-js/utils");
|
|
9
|
-
const citty_1 = require("citty");
|
|
10
|
-
const build = (0, citty_1.defineCommand)({
|
|
11
|
-
meta: {
|
|
12
|
-
name: "build",
|
|
13
|
-
description: "Start the build process",
|
|
14
|
-
},
|
|
15
|
-
async run() {
|
|
16
|
-
const tsConfig = (0, utils_1.parseTsConfig)();
|
|
17
|
-
const sourceRoot = node_path_1.default.join(process.cwd(), "src");
|
|
18
|
-
const outRoot = node_path_1.default.join(process.cwd(), tsConfig.outDir);
|
|
19
|
-
const lithia = await core_1.Lithia.create({
|
|
20
|
-
environment: "production",
|
|
21
|
-
sourceRoot,
|
|
22
|
-
outRoot,
|
|
23
|
-
});
|
|
24
|
-
lithia.build();
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
exports.default = build;
|
|
28
|
-
//# sourceMappingURL=build.js.map
|
package/dist/cmd/build.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/cmd/build.ts"],"names":[],"mappings":";;;;;AAAA,0DAA6B;AAC7B,0CAAyC;AACzC,4CAAiD;AACjD,iCAAsC;AAEtC,MAAM,KAAK,GAAG,IAAA,qBAAa,EAAC;IAC3B,IAAI,EAAE;QACL,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,yBAAyB;KACtC;IACD,KAAK,CAAC,GAAG;QACR,MAAM,QAAQ,GAAG,IAAA,qBAAa,GAAE,CAAC;QACjC,MAAM,UAAU,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;QACnD,MAAM,OAAO,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAE1D,MAAM,MAAM,GAAG,MAAM,aAAM,CAAC,MAAM,CAAC;YAClC,WAAW,EAAE,YAAY;YACzB,UAAU;YACV,OAAO;SACP,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;CACD,CAAC,CAAC;AAEH,kBAAe,KAAK,CAAC"}
|
package/dist/cmd/dev.d.ts
DELETED
package/dist/cmd/dev.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
-
const core_1 = require("@lithia-js/core");
|
|
8
|
-
const utils_1 = require("@lithia-js/utils");
|
|
9
|
-
const chokidar_1 = __importDefault(require("chokidar"));
|
|
10
|
-
const citty_1 = require("citty");
|
|
11
|
-
const dev = (0, citty_1.defineCommand)({
|
|
12
|
-
meta: {
|
|
13
|
-
name: "dev",
|
|
14
|
-
description: "Start the development server",
|
|
15
|
-
},
|
|
16
|
-
async run() {
|
|
17
|
-
const cwd = process.cwd();
|
|
18
|
-
// Load environment variables initially
|
|
19
|
-
(0, core_1.loadEnv)(cwd);
|
|
20
|
-
const tsConfig = (0, utils_1.parseTsConfig)();
|
|
21
|
-
const sourceRoot = node_path_1.default.join(cwd, "src");
|
|
22
|
-
const outRoot = node_path_1.default.join(cwd, tsConfig.outDir);
|
|
23
|
-
const lithia = await core_1.Lithia.create({
|
|
24
|
-
environment: "development",
|
|
25
|
-
sourceRoot,
|
|
26
|
-
outRoot,
|
|
27
|
-
});
|
|
28
|
-
// Initial build
|
|
29
|
-
lithia.build();
|
|
30
|
-
// Start the HTTP server after initial build
|
|
31
|
-
try {
|
|
32
|
-
await lithia.start();
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// let Lithia's emitter handle the error
|
|
36
|
-
}
|
|
37
|
-
// Debounced rebuild helper
|
|
38
|
-
let timer = null;
|
|
39
|
-
const debounce = (fn, ms = 150) => {
|
|
40
|
-
if (timer)
|
|
41
|
-
clearTimeout(timer);
|
|
42
|
-
timer = setTimeout(() => {
|
|
43
|
-
timer = null;
|
|
44
|
-
fn();
|
|
45
|
-
}, ms);
|
|
46
|
-
};
|
|
47
|
-
// Watch source files
|
|
48
|
-
const watchPath = sourceRoot;
|
|
49
|
-
const sourceWatcher = chokidar_1.default.watch(watchPath, {
|
|
50
|
-
ignored: /(^|[/\\])\../, // ignore dotfiles
|
|
51
|
-
persistent: true,
|
|
52
|
-
ignoreInitial: true,
|
|
53
|
-
});
|
|
54
|
-
sourceWatcher.on("all", (event, changedPath) => {
|
|
55
|
-
// only trigger on relevant events
|
|
56
|
-
if (event === "add" || event === "change" || event === "unlink") {
|
|
57
|
-
const filename = node_path_1.default.basename(changedPath);
|
|
58
|
-
if (filename === "_server.ts") {
|
|
59
|
-
core_1.logger.warn(`Detected change in ${(0, utils_1.green)(filename)} file. Please restart the dev server to apply changes.`);
|
|
60
|
-
}
|
|
61
|
-
// notify Lithia about the changed file so core can react
|
|
62
|
-
try {
|
|
63
|
-
lithia.emit("file:changed", { event, path: changedPath });
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
// ignore if emitter not available for some reason
|
|
67
|
-
}
|
|
68
|
-
debounce(() => {
|
|
69
|
-
lithia.build();
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
// Watch env files for changes
|
|
74
|
-
const envWatcher = chokidar_1.default.watch([".env", ".env.local"], {
|
|
75
|
-
cwd: cwd,
|
|
76
|
-
ignoreInitial: true,
|
|
77
|
-
});
|
|
78
|
-
envWatcher.on("all", (event, path) => {
|
|
79
|
-
if (event === "change" || event === "add") {
|
|
80
|
-
// Reload env vars
|
|
81
|
-
(0, core_1.loadEnv)(cwd);
|
|
82
|
-
// Restart server to pick up new env vars if needed
|
|
83
|
-
// For now we just reload, but some configs might depend on env vars
|
|
84
|
-
// so a full restart might be safer, but let's stick to hot reloading what we can
|
|
85
|
-
// Usually env var changes require process restart in Node, but
|
|
86
|
-
// since we are just setting process.env, subsequent accesses will see new values.
|
|
87
|
-
// However, if code read process.env at startup, it won't suffice.
|
|
88
|
-
// For a dev server, maybe logging that env changed is enough?
|
|
89
|
-
// Or fully restarting the Lithia instance?
|
|
90
|
-
// Given the request "recarregamento automático de .env", we should try to support it.
|
|
91
|
-
// But Node.js process.env changes don't affect already started modules if they cached it.
|
|
92
|
-
// Let's at least reload the env vars.
|
|
93
|
-
// A full restart would require tearing down Lithia and recreating it.
|
|
94
|
-
core_1.logger.event(`Environment file changed (${path}). Reloading...`);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
// Graceful shutdown: stop watchers and server
|
|
98
|
-
const shutdown = async () => {
|
|
99
|
-
try {
|
|
100
|
-
await sourceWatcher.close();
|
|
101
|
-
await envWatcher.close();
|
|
102
|
-
}
|
|
103
|
-
catch (_) { }
|
|
104
|
-
try {
|
|
105
|
-
await lithia.stop();
|
|
106
|
-
}
|
|
107
|
-
catch (_) { }
|
|
108
|
-
process.exit(0);
|
|
109
|
-
};
|
|
110
|
-
process.on("SIGINT", shutdown);
|
|
111
|
-
process.on("SIGTERM", shutdown);
|
|
112
|
-
// Process remains alive while the HTTP server and watcher run
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
exports.default = dev;
|
|
116
|
-
//# sourceMappingURL=dev.js.map
|
package/dist/cmd/dev.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/cmd/dev.ts"],"names":[],"mappings":";;;;;AAAA,0DAA6B;AAC7B,0CAA0D;AAC1D,4CAAwD;AACxD,wDAAgC;AAChC,iCAAsC;AAEtC,MAAM,GAAG,G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DAA+D;gBAC/D,kFAAkF;gBAClF,kEAAkE;gBAClE,8DAA8D;gBAC9D,2CAA2C;gBAC3C,sFAAsF;gBACtF,0FAA0F;gBAE1F,sCAAsC;gBACtC,sEAAsE;gBAEtE,aAAM,CAAC,KAAK,CAAC,6BAA6B,IAAI,iBAAiB,CAAC,CAAC;YAClE,CAAC;QACF,CAAC,CAAC,CAAC;QAEH,8CAA8C;QAC9C,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;YAC3B,IAAI,CAAC;gBACJ,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC5B,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;YAC1B,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;YACd,IAAI,CAAC;gBACJ,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACrB,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEhC,8DAA8D;IAC/D,CAAC;CACD,CAAC,CAAC;AAEH,kBAAe,GAAG,CAAC"}
|
package/dist/cmd/start.d.ts
DELETED
package/dist/cmd/start.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
-
const core_1 = require("@lithia-js/core");
|
|
8
|
-
const utils_1 = require("@lithia-js/utils");
|
|
9
|
-
const citty_1 = require("citty");
|
|
10
|
-
const start = (0, citty_1.defineCommand)({
|
|
11
|
-
meta: {
|
|
12
|
-
name: "start",
|
|
13
|
-
description: "Start the production server",
|
|
14
|
-
},
|
|
15
|
-
async run() {
|
|
16
|
-
const cwd = process.cwd();
|
|
17
|
-
// Load environment variables
|
|
18
|
-
(0, core_1.loadEnv)(cwd);
|
|
19
|
-
const tsConfig = (0, utils_1.parseTsConfig)();
|
|
20
|
-
const sourceRoot = node_path_1.default.join(cwd, "src");
|
|
21
|
-
const outRoot = node_path_1.default.join(cwd, tsConfig.outDir);
|
|
22
|
-
const lithia = await core_1.Lithia.create({
|
|
23
|
-
environment: "production",
|
|
24
|
-
sourceRoot,
|
|
25
|
-
outRoot,
|
|
26
|
-
});
|
|
27
|
-
lithia.loadRoutes();
|
|
28
|
-
try {
|
|
29
|
-
await lithia.start();
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
// let Lithia's emitter handle the error
|
|
33
|
-
}
|
|
34
|
-
const shutdown = async () => {
|
|
35
|
-
try {
|
|
36
|
-
await lithia.stop();
|
|
37
|
-
}
|
|
38
|
-
catch { }
|
|
39
|
-
process.exit(0);
|
|
40
|
-
};
|
|
41
|
-
process.on("SIGINT", shutdown);
|
|
42
|
-
process.on("SIGTERM", shutdown);
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
exports.default = start;
|
|
46
|
-
//# sourceMappingURL=start.js.map
|
package/dist/cmd/start.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/cmd/start.ts"],"names":[],"mappings":";;;;;AAAA,0DAA6B;AAC7B,0CAAkD;AAClD,4CAAiD;AACjD,iCAAsC;AAEtC,MAAM,KAAK,GAAG,IAAA,qBAAa,EAAC;IAC3B,IAAI,EAAE;QACL,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,6BAA6B;KAC1C;IACD,KAAK,CAAC,GAAG;QACR,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAE1B,6BAA6B;QAC7B,IAAA,cAAO,EAAC,GAAG,CAAC,CAAC;QAEb,MAAM,QAAQ,GAAG,IAAA,qBAAa,GAAE,CAAC;QACjC,MAAM,UAAU,GAAG,mBAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,mBAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAEhD,MAAM,MAAM,GAAG,MAAM,aAAM,CAAC,MAAM,CAAC;YAClC,WAAW,EAAE,YAAY;YACzB,UAAU;YACV,OAAO;SACP,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,EAAE,CAAC;QAEpB,IAAI,CAAC;YACJ,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;QAAC,MAAM,CAAC;YACR,wCAAwC;QACzC,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;YAC3B,IAAI,CAAC;gBACJ,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACrB,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YACV,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC;CACD,CAAC,CAAC;AAEH,kBAAe,KAAK,CAAC"}
|
package/dist/main.d.ts
DELETED
package/dist/main.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const citty_1 = require("citty");
|
|
8
|
-
const build_1 = __importDefault(require("./cmd/build"));
|
|
9
|
-
const dev_1 = __importDefault(require("./cmd/dev"));
|
|
10
|
-
const start_1 = __importDefault(require("./cmd/start"));
|
|
11
|
-
const meta_1 = require("./meta");
|
|
12
|
-
const main = (0, citty_1.defineCommand)({
|
|
13
|
-
meta: {
|
|
14
|
-
name: "lithia",
|
|
15
|
-
description: "Lithia CLI",
|
|
16
|
-
version: meta_1.version,
|
|
17
|
-
},
|
|
18
|
-
subCommands: {
|
|
19
|
-
dev: dev_1.default,
|
|
20
|
-
build: build_1.default,
|
|
21
|
-
start: start_1.default,
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
(0, citty_1.runMain)(main).then();
|
|
25
|
-
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;AAEA,iCAA+C;AAC/C,wDAAgC;AAChC,oDAA4B;AAC5B,wDAAgC;AAChC,iCAAiC;AAEjC,MAAM,IAAI,GAAG,IAAA,qBAAa,EAAC;IAC1B,IAAI,EAAE;QACL,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,YAAY;QACzB,OAAO,EAAP,cAAO;KACP;IACD,WAAW,EAAE;QACZ,GAAG,EAAH,aAAG;QACH,KAAK,EAAL,eAAK;QACL,KAAK,EAAL,eAAK;KACL;CACD,CAAC,CAAC;AAEH,IAAA,eAAO,EAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC"}
|
package/dist/meta.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { version } from "../package.json";
|
package/dist/meta.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.version = void 0;
|
|
4
|
-
var package_json_1 = require("../package.json");
|
|
5
|
-
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return package_json_1.version; } });
|
|
6
|
-
//# sourceMappingURL=meta.js.map
|
package/dist/meta.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":";;;AAAA,gDAA0C;AAAjC,uGAAA,OAAO,OAAA"}
|
package/src/cmd/build.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { Lithia } from "@lithia-js/core";
|
|
3
|
-
import { parseTsConfig } from "@lithia-js/utils";
|
|
4
|
-
import { defineCommand } from "citty";
|
|
5
|
-
|
|
6
|
-
const build = defineCommand({
|
|
7
|
-
meta: {
|
|
8
|
-
name: "build",
|
|
9
|
-
description: "Start the build process",
|
|
10
|
-
},
|
|
11
|
-
async run() {
|
|
12
|
-
const tsConfig = parseTsConfig();
|
|
13
|
-
const sourceRoot = path.join(process.cwd(), "src");
|
|
14
|
-
const outRoot = path.join(process.cwd(), tsConfig.outDir);
|
|
15
|
-
|
|
16
|
-
const lithia = await Lithia.create({
|
|
17
|
-
environment: "production",
|
|
18
|
-
sourceRoot,
|
|
19
|
-
outRoot,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
lithia.build();
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export default build;
|
package/src/cmd/dev.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { Lithia, loadEnv, logger } from "@lithia-js/core";
|
|
3
|
-
import { green, parseTsConfig } from "@lithia-js/utils";
|
|
4
|
-
import chokidar from "chokidar";
|
|
5
|
-
import { defineCommand } from "citty";
|
|
6
|
-
|
|
7
|
-
const dev = defineCommand({
|
|
8
|
-
meta: {
|
|
9
|
-
name: "dev",
|
|
10
|
-
description: "Start the development server",
|
|
11
|
-
},
|
|
12
|
-
async run() {
|
|
13
|
-
const cwd = process.cwd();
|
|
14
|
-
|
|
15
|
-
// Load environment variables initially
|
|
16
|
-
loadEnv(cwd);
|
|
17
|
-
|
|
18
|
-
const tsConfig = parseTsConfig();
|
|
19
|
-
const sourceRoot = path.join(cwd, "src");
|
|
20
|
-
const outRoot = path.join(cwd, tsConfig.outDir);
|
|
21
|
-
const lithia = await Lithia.create({
|
|
22
|
-
environment: "development",
|
|
23
|
-
sourceRoot,
|
|
24
|
-
outRoot,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Initial build
|
|
28
|
-
lithia.build();
|
|
29
|
-
|
|
30
|
-
// Start the HTTP server after initial build
|
|
31
|
-
try {
|
|
32
|
-
await lithia.start();
|
|
33
|
-
} catch {
|
|
34
|
-
// let Lithia's emitter handle the error
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Debounced rebuild helper
|
|
38
|
-
let timer: NodeJS.Timeout | null = null;
|
|
39
|
-
const debounce = (fn: () => void, ms = 150) => {
|
|
40
|
-
if (timer) clearTimeout(timer);
|
|
41
|
-
timer = setTimeout(() => {
|
|
42
|
-
timer = null;
|
|
43
|
-
fn();
|
|
44
|
-
}, ms);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// Watch source files
|
|
48
|
-
const watchPath = sourceRoot;
|
|
49
|
-
const sourceWatcher = chokidar.watch(watchPath, {
|
|
50
|
-
ignored: /(^|[/\\])\../, // ignore dotfiles
|
|
51
|
-
persistent: true,
|
|
52
|
-
ignoreInitial: true,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
sourceWatcher.on("all", (event, changedPath) => {
|
|
56
|
-
// only trigger on relevant events
|
|
57
|
-
if (event === "add" || event === "change" || event === "unlink") {
|
|
58
|
-
const filename = path.basename(changedPath);
|
|
59
|
-
if (filename === "_server.ts") {
|
|
60
|
-
logger.warn(
|
|
61
|
-
`Detected change in ${green(filename)} file. Please restart the dev server to apply changes.`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// notify Lithia about the changed file so core can react
|
|
66
|
-
try {
|
|
67
|
-
lithia.emit("file:changed", { event, path: changedPath });
|
|
68
|
-
} catch {
|
|
69
|
-
// ignore if emitter not available for some reason
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
debounce(() => {
|
|
73
|
-
lithia.build();
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// Watch env files for changes
|
|
79
|
-
const envWatcher = chokidar.watch([".env", ".env.local"], {
|
|
80
|
-
cwd: cwd,
|
|
81
|
-
ignoreInitial: true,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
envWatcher.on("all", (event, path) => {
|
|
85
|
-
if (event === "change" || event === "add") {
|
|
86
|
-
// Reload env vars
|
|
87
|
-
loadEnv(cwd);
|
|
88
|
-
|
|
89
|
-
// Restart server to pick up new env vars if needed
|
|
90
|
-
// For now we just reload, but some configs might depend on env vars
|
|
91
|
-
// so a full restart might be safer, but let's stick to hot reloading what we can
|
|
92
|
-
// Usually env var changes require process restart in Node, but
|
|
93
|
-
// since we are just setting process.env, subsequent accesses will see new values.
|
|
94
|
-
// However, if code read process.env at startup, it won't suffice.
|
|
95
|
-
// For a dev server, maybe logging that env changed is enough?
|
|
96
|
-
// Or fully restarting the Lithia instance?
|
|
97
|
-
// Given the request "recarregamento automático de .env", we should try to support it.
|
|
98
|
-
// But Node.js process.env changes don't affect already started modules if they cached it.
|
|
99
|
-
|
|
100
|
-
// Let's at least reload the env vars.
|
|
101
|
-
// A full restart would require tearing down Lithia and recreating it.
|
|
102
|
-
|
|
103
|
-
logger.event(`Environment file changed (${path}). Reloading...`);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Graceful shutdown: stop watchers and server
|
|
108
|
-
const shutdown = async () => {
|
|
109
|
-
try {
|
|
110
|
-
await sourceWatcher.close();
|
|
111
|
-
await envWatcher.close();
|
|
112
|
-
} catch (_) {}
|
|
113
|
-
try {
|
|
114
|
-
await lithia.stop();
|
|
115
|
-
} catch (_) {}
|
|
116
|
-
process.exit(0);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
process.on("SIGINT", shutdown);
|
|
120
|
-
process.on("SIGTERM", shutdown);
|
|
121
|
-
|
|
122
|
-
// Process remains alive while the HTTP server and watcher run
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
export default dev;
|
package/src/cmd/start.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { Lithia, loadEnv } from "@lithia-js/core";
|
|
3
|
-
import { parseTsConfig } from "@lithia-js/utils";
|
|
4
|
-
import { defineCommand } from "citty";
|
|
5
|
-
|
|
6
|
-
const start = defineCommand({
|
|
7
|
-
meta: {
|
|
8
|
-
name: "start",
|
|
9
|
-
description: "Start the production server",
|
|
10
|
-
},
|
|
11
|
-
async run() {
|
|
12
|
-
const cwd = process.cwd();
|
|
13
|
-
|
|
14
|
-
// Load environment variables
|
|
15
|
-
loadEnv(cwd);
|
|
16
|
-
|
|
17
|
-
const tsConfig = parseTsConfig();
|
|
18
|
-
const sourceRoot = path.join(cwd, "src");
|
|
19
|
-
const outRoot = path.join(cwd, tsConfig.outDir);
|
|
20
|
-
|
|
21
|
-
const lithia = await Lithia.create({
|
|
22
|
-
environment: "production",
|
|
23
|
-
sourceRoot,
|
|
24
|
-
outRoot,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
lithia.loadRoutes();
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
await lithia.start();
|
|
31
|
-
} catch {
|
|
32
|
-
// let Lithia's emitter handle the error
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const shutdown = async () => {
|
|
36
|
-
try {
|
|
37
|
-
await lithia.stop();
|
|
38
|
-
} catch {}
|
|
39
|
-
process.exit(0);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
process.on("SIGINT", shutdown);
|
|
43
|
-
process.on("SIGTERM", shutdown);
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export default start;
|
package/src/main.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { defineCommand, runMain } from "citty";
|
|
4
|
-
import build from "./cmd/build";
|
|
5
|
-
import dev from "./cmd/dev";
|
|
6
|
-
import start from "./cmd/start";
|
|
7
|
-
import { version } from "./meta";
|
|
8
|
-
|
|
9
|
-
const main = defineCommand({
|
|
10
|
-
meta: {
|
|
11
|
-
name: "lithia",
|
|
12
|
-
description: "Lithia CLI",
|
|
13
|
-
version,
|
|
14
|
-
},
|
|
15
|
-
subCommands: {
|
|
16
|
-
dev,
|
|
17
|
-
build,
|
|
18
|
-
start,
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
runMain(main).then();
|
package/src/meta.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { version } from "../package.json";
|