@evjs/cli 0.1.0 → 0.1.2
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 +9 -10
- package/dist/index.d.ts +3 -20
- package/dist/index.js +13 -232
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @evjs/cli
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Thin command-line wrapper for the **evjs** fullstack framework.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ npm install -g @evjs/cli
|
|
|
10
10
|
|
|
11
11
|
## Convention over Configuration
|
|
12
12
|
|
|
13
|
-
No configuration file is needed. `ev dev` and `ev build`
|
|
13
|
+
No configuration file is needed. `ev dev` and `ev build` delegate to `@evjs/ev` and inject the default utoopack adapter:
|
|
14
14
|
|
|
15
15
|
- Entry: `./src/main.tsx`
|
|
16
16
|
- HTML: `./index.html`
|
|
@@ -29,13 +29,13 @@ No configuration file is needed. `ev dev` and `ev build` work out of the box wit
|
|
|
29
29
|
|
|
30
30
|
### `ev dev`
|
|
31
31
|
|
|
32
|
-
Uses bundler
|
|
32
|
+
Uses the default bundler adapter directly (no temp config files):
|
|
33
33
|
1. **dev server** (port 3000) — client bundle with HMR.
|
|
34
34
|
2. **Node API Server** (port 3001) — auto-starts when server bundle is emitted, uses `node --watch`.
|
|
35
35
|
|
|
36
36
|
### `ev build`
|
|
37
37
|
|
|
38
|
-
Runs
|
|
38
|
+
Runs the production build through `@evjs/ev` with `NODE_ENV=production`:
|
|
39
39
|
- `dist/client/` — optimized client assets with content hashes.
|
|
40
40
|
- `dist/server/main.[hash].js` — server bundle (entry discovered via `dist/server/manifest.json`).
|
|
41
41
|
|
|
@@ -51,7 +51,6 @@ export default defineConfig({
|
|
|
51
51
|
html: "./index.html",
|
|
52
52
|
dev: { port: 3000 },
|
|
53
53
|
server: {
|
|
54
|
-
endpoint: "/api/fn",
|
|
55
54
|
dev: { port: 3001 },
|
|
56
55
|
},
|
|
57
56
|
});
|
|
@@ -80,13 +79,13 @@ my-app/
|
|
|
80
79
|
## Common Mistakes
|
|
81
80
|
|
|
82
81
|
1. **Don't create `custom bundler config file`** — use `ev.config.ts` instead
|
|
83
|
-
2. **Don't install
|
|
82
|
+
2. **Don't install bundler internals manually** — the default adapter is provided by `@evjs/cli`
|
|
84
83
|
3. **Config file must be `ev.config.ts`** — not `evjs.config.ts`
|
|
85
84
|
4. **Import `defineConfig` from `@evjs/ev`** — not from `@evjs/server`
|
|
86
85
|
|
|
87
86
|
## Bundled Dependencies
|
|
88
87
|
|
|
89
|
-
Users do NOT need to install these — they're included
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
-
|
|
88
|
+
Users do NOT need to install these — they're included through `@evjs/cli`:
|
|
89
|
+
- `@evjs/bundler-utoopack`
|
|
90
|
+
- `@evjs/build-tools`
|
|
91
|
+
- the bundler's underlying compiler dependencies
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { CONFIG_DEFAULTS, type
|
|
3
|
-
export
|
|
4
|
-
cwd?: string;
|
|
5
|
-
}
|
|
6
|
-
export interface BuildOptions {
|
|
7
|
-
cwd?: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Start the development server programmatically.
|
|
11
|
-
*
|
|
12
|
-
* @param config - evjs configuration object (from `defineConfig`)
|
|
13
|
-
* @param options - additional options like `cwd`
|
|
14
|
-
*/
|
|
1
|
+
import { type BuildOptions, type DevOptions, type EvConfig } from "@evjs/ev";
|
|
2
|
+
export { type BuildOptions, type BundlerAdapter, CONFIG_DEFAULTS, type DevOptions, defineConfig, type EvBuildResult, type EvBundlerCtx, type EvConfig, type EvPlugin, type EvPluginContext, type EvPluginHooks, type ResolvedEvConfig, resolveConfig, } from "@evjs/ev";
|
|
3
|
+
export { loadConfig } from "./load-config.js";
|
|
15
4
|
export declare function dev(userConfig?: EvConfig, options?: DevOptions): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Run a production build programmatically.
|
|
18
|
-
*
|
|
19
|
-
* @param config - evjs configuration object (from `defineConfig`)
|
|
20
|
-
* @param options - additional options like `cwd`
|
|
21
|
-
*/
|
|
22
5
|
export declare function build(userConfig?: EvConfig, options?: BuildOptions): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,236 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { CONFIG_DEFAULTS, resolveConfig, defineConfig, };
|
|
7
|
-
const logger = getLogger(["evjs", "cli"]);
|
|
8
|
-
/**
|
|
9
|
-
* Resolve the bundler adapter specified in the configuration.
|
|
10
|
-
* Falls back to utoopack when no bundler is explicitly provided.
|
|
11
|
-
*/
|
|
12
|
-
async function getBundlerAdapter(config) {
|
|
13
|
-
if (config?.bundler) {
|
|
14
|
-
return config.bundler;
|
|
15
|
-
}
|
|
16
|
-
// Default: dynamically import utoopack so it's not a hard dependency
|
|
17
|
-
const { utoopackAdapter } = await import("@evjs/bundler-utoopack");
|
|
18
|
-
return utoopackAdapter;
|
|
19
|
-
}
|
|
20
|
-
function withActiveBundler(config, bundler) {
|
|
21
|
-
if (config.bundler === bundler) {
|
|
22
|
-
return config;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
...config,
|
|
26
|
-
bundler,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Run plugin setup() hooks and collect lifecycle hooks.
|
|
31
|
-
*/
|
|
32
|
-
async function collectPluginHooks(plugins, ctx) {
|
|
33
|
-
const allHooks = [];
|
|
34
|
-
for (const plugin of plugins) {
|
|
35
|
-
if (plugin.setup) {
|
|
36
|
-
const hooks = await plugin.setup(ctx);
|
|
37
|
-
if (hooks) {
|
|
38
|
-
allHooks.push(hooks);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return allHooks;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Run all buildStart hooks sequentially.
|
|
46
|
-
*/
|
|
47
|
-
async function runBuildStartHooks(hooks) {
|
|
48
|
-
for (const h of hooks) {
|
|
49
|
-
if (h.buildStart) {
|
|
50
|
-
await h.buildStart();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Run all buildEnd hooks sequentially.
|
|
56
|
-
*/
|
|
57
|
-
async function runBuildEndHooks(hooks, result) {
|
|
58
|
-
for (const h of hooks) {
|
|
59
|
-
if (h.buildEnd) {
|
|
60
|
-
await h.buildEnd(result);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Read build manifests from disk.
|
|
66
|
-
*/
|
|
67
|
-
function readBuildResult(cwd, serverEnabled, isRebuild) {
|
|
68
|
-
const clientManifestPath = serverEnabled
|
|
69
|
-
? path.resolve(cwd, "dist/client/manifest.json")
|
|
70
|
-
: path.resolve(cwd, "dist/manifest.json");
|
|
71
|
-
if (!fs.existsSync(clientManifestPath))
|
|
72
|
-
return null;
|
|
73
|
-
let clientManifest;
|
|
74
|
-
try {
|
|
75
|
-
clientManifest = JSON.parse(fs.readFileSync(clientManifestPath, "utf-8"));
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
logger.warn `Failed to parse client manifest: ${err}`;
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
let serverManifest;
|
|
82
|
-
if (serverEnabled) {
|
|
83
|
-
const serverManifestPath = path.resolve(cwd, "dist/server/manifest.json");
|
|
84
|
-
if (fs.existsSync(serverManifestPath)) {
|
|
85
|
-
try {
|
|
86
|
-
serverManifest = JSON.parse(fs.readFileSync(serverManifestPath, "utf-8"));
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
logger.warn `Failed to parse server manifest: ${err}`;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return { clientManifest, serverManifest, isRebuild };
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Start the development server programmatically.
|
|
97
|
-
*
|
|
98
|
-
* @param config - evjs configuration object (from `defineConfig`)
|
|
99
|
-
* @param options - additional options like `cwd`
|
|
100
|
-
*/
|
|
1
|
+
import { utoopackAdapter } from "@evjs/bundler-utoopack";
|
|
2
|
+
import { build as frameworkBuild, dev as frameworkDev, } from "@evjs/ev";
|
|
3
|
+
export { CONFIG_DEFAULTS, defineConfig, resolveConfig, } from "@evjs/ev";
|
|
4
|
+
export { loadConfig } from "./load-config.js";
|
|
5
|
+
const defaultBundler = utoopackAdapter;
|
|
101
6
|
export async function dev(userConfig, options) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const config = withActiveBundler(resolvedConfig, bundler);
|
|
107
|
-
// Collect plugin hooks
|
|
108
|
-
const pluginCtx = { mode: "development", cwd, config };
|
|
109
|
-
const hooks = await collectPluginHooks(config.plugins, pluginCtx);
|
|
110
|
-
// Run buildStart hooks
|
|
111
|
-
await runBuildStartHooks(hooks);
|
|
112
|
-
// Validate HTML files exist
|
|
113
|
-
if (config.pages) {
|
|
114
|
-
for (const [name, page] of Object.entries(config.pages)) {
|
|
115
|
-
if (!fs.existsSync(path.resolve(cwd, page.html))) {
|
|
116
|
-
throw new Error(`[evjs] MPA page "${name}" html template not found: ${page.html}`);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else if (!fs.existsSync(path.resolve(cwd, config.html))) {
|
|
121
|
-
throw new Error(`[evjs] HTML template not found: ${config.html}`);
|
|
122
|
-
}
|
|
123
|
-
// Track the running API server process for lifecycle management.
|
|
124
|
-
let apiProcess = null;
|
|
125
|
-
let isFirstBuild = true;
|
|
126
|
-
const handleServerBundleReady = async () => {
|
|
127
|
-
if (!config.serverEnabled)
|
|
128
|
-
return;
|
|
129
|
-
const manifestPath = path.resolve(cwd, "dist/server/manifest.json");
|
|
130
|
-
if (!fs.existsSync(manifestPath))
|
|
131
|
-
return;
|
|
132
|
-
let manifest;
|
|
133
|
-
try {
|
|
134
|
-
manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
135
|
-
}
|
|
136
|
-
catch (err) {
|
|
137
|
-
logger.warn `Failed to parse server manifest: ${err}`;
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (manifest.version !== 1) {
|
|
141
|
-
logger.warn `Unexpected server manifest version: ${manifest.version}. Expected 1.`;
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (!manifest.entry)
|
|
145
|
-
return;
|
|
146
|
-
// Run buildEnd hooks with manifests
|
|
147
|
-
const buildResult = readBuildResult(cwd, config.serverEnabled, !isFirstBuild);
|
|
148
|
-
if (buildResult) {
|
|
149
|
-
runBuildEndHooks(hooks, buildResult).catch((err) => {
|
|
150
|
-
logger.error `Plugin buildEnd hook failed: ${err}`;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
isFirstBuild = false;
|
|
154
|
-
// Kill previous process before restarting (handles both first start and restarts)
|
|
155
|
-
if (apiProcess) {
|
|
156
|
-
logger.info `Restarting API server...`;
|
|
157
|
-
const oldProcess = apiProcess;
|
|
158
|
-
apiProcess = null;
|
|
159
|
-
oldProcess.kill();
|
|
160
|
-
try {
|
|
161
|
-
await Promise.race([
|
|
162
|
-
oldProcess.catch(() => { }),
|
|
163
|
-
new Promise((resolve) => setTimeout(resolve, 3000)),
|
|
164
|
-
]);
|
|
165
|
-
}
|
|
166
|
-
catch { }
|
|
167
|
-
}
|
|
168
|
-
const serverPort = config?.server?.dev?.port ?? CONFIG_DEFAULTS.serverPort;
|
|
169
|
-
logger.info `Server bundle detected, starting API...`;
|
|
170
|
-
const bootstrapPath = path.resolve(cwd, "dist/server/_dev_start.cjs");
|
|
171
|
-
try {
|
|
172
|
-
const serverBundlePath = path.resolve(cwd, "dist/server", manifest.entry);
|
|
173
|
-
if (!fs.existsSync(path.dirname(bootstrapPath))) {
|
|
174
|
-
fs.mkdirSync(path.dirname(bootstrapPath), { recursive: true });
|
|
175
|
-
}
|
|
176
|
-
fs.writeFileSync(bootstrapPath, [
|
|
177
|
-
`const handler = require(${JSON.stringify(serverBundlePath)}).default;`,
|
|
178
|
-
`const { serve } = require("@evjs/server/node");`,
|
|
179
|
-
`serve({ fetch: handler.fetch }, { port: ${serverPort}, https: ${JSON.stringify(config.server.dev.https)} });`,
|
|
180
|
-
].join("\n"));
|
|
181
|
-
const runtimeArgs = [bootstrapPath];
|
|
182
|
-
// Don't await execa here since it's a long-running watch process
|
|
183
|
-
const child = execa("node", runtimeArgs, {
|
|
184
|
-
stdio: "inherit",
|
|
185
|
-
env: { ...process.env, NODE_ENV: "development" },
|
|
186
|
-
});
|
|
187
|
-
apiProcess = child;
|
|
188
|
-
child.catch(() => {
|
|
189
|
-
// Clear reference so the next compilation can restart
|
|
190
|
-
if (apiProcess === child) {
|
|
191
|
-
apiProcess = null;
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
catch (err) {
|
|
196
|
-
logger.error `Server runtime failed: ${err}`;
|
|
197
|
-
apiProcess = null;
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
await bundler.dev(config, cwd, { onServerBundleReady: handleServerBundleReady }, hooks);
|
|
7
|
+
await frameworkDev(userConfig, {
|
|
8
|
+
...options,
|
|
9
|
+
bundler: options?.bundler ?? userConfig?.bundler ?? defaultBundler,
|
|
10
|
+
});
|
|
201
11
|
}
|
|
202
|
-
/**
|
|
203
|
-
* Run a production build programmatically.
|
|
204
|
-
*
|
|
205
|
-
* @param config - evjs configuration object (from `defineConfig`)
|
|
206
|
-
* @param options - additional options like `cwd`
|
|
207
|
-
*/
|
|
208
12
|
export async function build(userConfig, options) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const config = withActiveBundler(resolvedConfig, bundler);
|
|
214
|
-
// Collect plugin hooks
|
|
215
|
-
const pluginCtx = { mode: "production", cwd, config };
|
|
216
|
-
const hooks = await collectPluginHooks(config.plugins, pluginCtx);
|
|
217
|
-
// Run buildStart hooks
|
|
218
|
-
await runBuildStartHooks(hooks);
|
|
219
|
-
// Validate HTML files exist
|
|
220
|
-
if (config.pages) {
|
|
221
|
-
for (const [name, page] of Object.entries(config.pages)) {
|
|
222
|
-
if (!fs.existsSync(path.resolve(cwd, page.html))) {
|
|
223
|
-
throw new Error(`[evjs] MPA page "${name}" html template not found: ${page.html}`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
else if (!fs.existsSync(path.resolve(cwd, config.html))) {
|
|
228
|
-
throw new Error(`[evjs] HTML template not found: ${config.html}`);
|
|
229
|
-
}
|
|
230
|
-
await bundler.build(config, cwd, hooks);
|
|
231
|
-
// Run buildEnd hooks with manifests
|
|
232
|
-
const buildResult = readBuildResult(cwd, config.serverEnabled, false);
|
|
233
|
-
if (buildResult) {
|
|
234
|
-
await runBuildEndHooks(hooks, buildResult);
|
|
235
|
-
}
|
|
13
|
+
await frameworkBuild(userConfig, {
|
|
14
|
+
...options,
|
|
15
|
+
bundler: options?.bundler ?? userConfig?.bundler ?? defaultBundler,
|
|
16
|
+
});
|
|
236
17
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evjs/cli",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Command-line wrapper for the evjs framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -31,8 +31,7 @@
|
|
|
31
31
|
"@evjs/bundler-utoopack": "*",
|
|
32
32
|
"@evjs/ev": "*",
|
|
33
33
|
"@logtape/logtape": "^2.0.4",
|
|
34
|
-
"commander": "^12.1.0"
|
|
35
|
-
"execa": "^9.6.1"
|
|
34
|
+
"commander": "^12.1.0"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
37
|
"@types/node": "^22.19.15",
|