@lithia-js/cli 1.0.0-canary.2 → 1.0.0-canary.3
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/CHANGELOG.md +9 -0
- package/package.json +3 -3
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @lithia-js/cli
|
|
2
2
|
|
|
3
|
+
## 1.0.0-canary.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d536a2f: Fixed exports from @lithia-js/native
|
|
8
|
+
- Updated dependencies [d536a2f]
|
|
9
|
+
- @lithia-js/core@1.0.0-canary.3
|
|
10
|
+
- @lithia-js/utils@1.0.0-canary.3
|
|
11
|
+
|
|
3
12
|
## 1.0.0-canary.2
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lithia-js/cli",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
3
|
+
"version": "1.0.0-canary.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"bin": {
|
|
6
6
|
"lithia": "dist/main.js"
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"citty": "^0.2.0",
|
|
20
20
|
"chokidar": "^5.0.0",
|
|
21
|
-
"@lithia-js/core": "1.0.0-canary.
|
|
22
|
-
"@lithia-js/utils": "1.0.0-canary.
|
|
21
|
+
"@lithia-js/core": "1.0.0-canary.3",
|
|
22
|
+
"@lithia-js/utils": "1.0.0-canary.3"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=20"
|
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";
|