ecopages 0.2.0-alpha.30 → 0.2.0-alpha.32
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/bin/cli.js +201 -237
- package/bin/launch-plan.js +89 -105
- package/package.json +2 -8
- package/bin/cli.test.ts +0 -136
- package/bin/launch-plan.test.ts +0 -161
- package/dist/CHANGELOG.md +0 -15
- package/dist/README.md +0 -91
- package/dist/bin/cli.js +0 -224
- package/dist/bin/launch-plan.js +0 -96
- package/dist/css/view-transitions.css +0 -217
- package/dist/package.json +0 -42
package/bin/cli.js
CHANGED
|
@@ -1,260 +1,224 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const logger = new Logger('[ecopages:cli]', { debug: process.env.ECOPAGES_LOGGER_DEBUG === 'true' });
|
|
12
|
-
|
|
13
|
-
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
14
|
-
|
|
2
|
+
import { defineCommand, runMain } from "citty";
|
|
3
|
+
import { downloadTemplate } from "giget";
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { Logger } from "@ecopages/logger";
|
|
8
|
+
import { createLaunchPlan, launchPlanRequiresExistingEntryFile } from "./launch-plan.js";
|
|
9
|
+
const logger = new Logger("[ecopages:cli]", { debug: process.env.ECOPAGES_LOGGER_DEBUG === "true" });
|
|
10
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
|
|
15
11
|
function runLaunchPlan(launchPlan) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
logger.error(`Failed to run command: ${error.message}`);
|
|
39
|
-
process.exit(1);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
child.on('exit', (code) => {
|
|
43
|
-
process.exit(code || 0);
|
|
44
|
-
});
|
|
12
|
+
if (Object.keys(launchPlan.envOverrides).length > 0) {
|
|
13
|
+
logger.debug(`Environment overrides: ${JSON.stringify(launchPlan.envOverrides)}`);
|
|
14
|
+
}
|
|
15
|
+
logger.debug(`Runtime: ${launchPlan.runtime}`);
|
|
16
|
+
logger.debug(`Running: ${launchPlan.command} ${launchPlan.commandArgs.join(" ")}`);
|
|
17
|
+
const child = spawn(launchPlan.command, launchPlan.commandArgs, {
|
|
18
|
+
stdio: "inherit",
|
|
19
|
+
env: launchPlan.env
|
|
20
|
+
});
|
|
21
|
+
child.on("error", (error) => {
|
|
22
|
+
if (error && error.code === "ENOENT") {
|
|
23
|
+
const hint = launchPlan.runtime === "bun" ? "Install Bun from https://bun.sh to continue." : "Reinstall ecopages and its dependencies so the packaged tsx runtime is available for Node.js launches.";
|
|
24
|
+
logger.error(`Command not found: ${launchPlan.command}. ${hint}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
logger.error(`Failed to run command: ${error.message}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
|
30
|
+
child.on("exit", (code) => {
|
|
31
|
+
process.exit(code || 0);
|
|
32
|
+
});
|
|
45
33
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
-
logger.error(message);
|
|
62
|
-
process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (launchPlanRequiresExistingEntryFile(launchPlan) && !existsSync(entryFile)) {
|
|
66
|
-
logger.error(`Error: Entry file "${entryFile}" not found in the current directory.`);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
runLaunchPlan(launchPlan);
|
|
34
|
+
async function runEntryCommand(args, options = {}, entryFile = "app.ts") {
|
|
35
|
+
let launchPlan;
|
|
36
|
+
try {
|
|
37
|
+
launchPlan = await createLaunchPlan(args, options, entryFile);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
40
|
+
logger.error(message);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
if (launchPlanRequiresExistingEntryFile(launchPlan) && !existsSync(entryFile)) {
|
|
44
|
+
logger.error(`Error: Entry file "${entryFile}" not found in the current directory.`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
runLaunchPlan(launchPlan);
|
|
71
48
|
}
|
|
72
|
-
|
|
73
|
-
/** Shared server argument definitions for citty commands. */
|
|
74
49
|
const serverArgs = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
50
|
+
entry: {
|
|
51
|
+
type: "positional",
|
|
52
|
+
description: "Entry file",
|
|
53
|
+
default: "app.ts"
|
|
54
|
+
},
|
|
55
|
+
port: {
|
|
56
|
+
type: "string",
|
|
57
|
+
alias: ["p"],
|
|
58
|
+
description: "Override ECOPAGES_PORT"
|
|
59
|
+
},
|
|
60
|
+
hostname: {
|
|
61
|
+
type: "string",
|
|
62
|
+
alias: ["n"],
|
|
63
|
+
description: "Override ECOPAGES_HOSTNAME"
|
|
64
|
+
},
|
|
65
|
+
"base-url": {
|
|
66
|
+
type: "string",
|
|
67
|
+
alias: ["b"],
|
|
68
|
+
description: "Override ECOPAGES_BASE_URL"
|
|
69
|
+
},
|
|
70
|
+
debug: {
|
|
71
|
+
type: "boolean",
|
|
72
|
+
alias: ["d"],
|
|
73
|
+
description: "Enable debug logging (ECOPAGES_LOGGER_DEBUG=true)"
|
|
74
|
+
},
|
|
75
|
+
"react-fast-refresh": {
|
|
76
|
+
type: "boolean",
|
|
77
|
+
alias: ["r"],
|
|
78
|
+
description: "Enable React Fast Refresh for HMR"
|
|
79
|
+
},
|
|
80
|
+
runtime: {
|
|
81
|
+
type: "string",
|
|
82
|
+
description: "Force a specific runtime (bun or node)"
|
|
83
|
+
}
|
|
109
84
|
};
|
|
110
|
-
|
|
111
85
|
const initCommand = defineCommand({
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
} catch (err) {
|
|
159
|
-
logger.error(`Failed to fetch template: ${err.message}`);
|
|
160
|
-
process.exit(1);
|
|
161
|
-
}
|
|
162
|
-
},
|
|
86
|
+
meta: {
|
|
87
|
+
name: "init",
|
|
88
|
+
description: "Initialize a new project from a template"
|
|
89
|
+
},
|
|
90
|
+
args: {
|
|
91
|
+
dir: {
|
|
92
|
+
type: "positional",
|
|
93
|
+
description: "Target directory name",
|
|
94
|
+
required: true
|
|
95
|
+
},
|
|
96
|
+
template: {
|
|
97
|
+
type: "string",
|
|
98
|
+
description: "Template name from ecopages/examples/",
|
|
99
|
+
default: "starter-jsx"
|
|
100
|
+
},
|
|
101
|
+
repo: {
|
|
102
|
+
type: "string",
|
|
103
|
+
description: "GitHub repo (user/repo)",
|
|
104
|
+
default: "ecopages/ecopages"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
async run({ args }) {
|
|
108
|
+
const { dir, template, repo } = args;
|
|
109
|
+
if (existsSync(dir)) {
|
|
110
|
+
logger.error(`Target directory already exists: ${dir}`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
logger.info(`Creating target directory '${dir}'...`);
|
|
114
|
+
try {
|
|
115
|
+
await downloadTemplate(`github:${repo}/examples/${template}`, {
|
|
116
|
+
dir,
|
|
117
|
+
force: true
|
|
118
|
+
});
|
|
119
|
+
const pkgPath = join(dir, "package.json");
|
|
120
|
+
if (existsSync(pkgPath)) {
|
|
121
|
+
const projectPkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
122
|
+
projectPkg.name = dir;
|
|
123
|
+
writeFileSync(pkgPath, JSON.stringify(projectPkg, null, 2) + "\n");
|
|
124
|
+
logger.info(`Renamed project to '${dir}'`);
|
|
125
|
+
}
|
|
126
|
+
logger.info("Project initialized! Run `bun install && bun dev` to start.");
|
|
127
|
+
} catch (err) {
|
|
128
|
+
logger.error(`Failed to fetch template: ${err.message}`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
163
132
|
});
|
|
164
|
-
|
|
165
133
|
const devCommand = defineCommand({
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
134
|
+
meta: {
|
|
135
|
+
name: "dev",
|
|
136
|
+
description: "Start the development server"
|
|
137
|
+
},
|
|
138
|
+
args: serverArgs,
|
|
139
|
+
async run({ args }) {
|
|
140
|
+
await runEntryCommand(["--dev"], { ...args, nodeEnv: "development" }, args.entry);
|
|
141
|
+
}
|
|
174
142
|
});
|
|
175
|
-
|
|
176
143
|
const devWatchCommand = defineCommand({
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
144
|
+
meta: {
|
|
145
|
+
name: "dev:watch",
|
|
146
|
+
description: "Start the development server with watch mode (restarts on file changes)"
|
|
147
|
+
},
|
|
148
|
+
args: serverArgs,
|
|
149
|
+
async run({ args }) {
|
|
150
|
+
await runEntryCommand(["--dev"], { ...args, watch: true, nodeEnv: "development" }, args.entry);
|
|
151
|
+
}
|
|
185
152
|
});
|
|
186
|
-
|
|
187
153
|
const devHotCommand = defineCommand({
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
154
|
+
meta: {
|
|
155
|
+
name: "dev:hot",
|
|
156
|
+
description: "Start the development server with hot reload (HMR without restart)"
|
|
157
|
+
},
|
|
158
|
+
args: serverArgs,
|
|
159
|
+
async run({ args }) {
|
|
160
|
+
await runEntryCommand(["--dev"], { ...args, hot: true, nodeEnv: "development" }, args.entry);
|
|
161
|
+
}
|
|
196
162
|
});
|
|
197
|
-
|
|
198
163
|
const buildCommand = defineCommand({
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
164
|
+
meta: {
|
|
165
|
+
name: "build",
|
|
166
|
+
description: "Build the project for production"
|
|
167
|
+
},
|
|
168
|
+
args: {
|
|
169
|
+
entry: {
|
|
170
|
+
type: "positional",
|
|
171
|
+
description: "Entry file",
|
|
172
|
+
default: "app.ts"
|
|
173
|
+
},
|
|
174
|
+
runtime: {
|
|
175
|
+
type: "string",
|
|
176
|
+
description: "Force a specific runtime (bun or node)"
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
async run({ args }) {
|
|
180
|
+
await runEntryCommand(["--build"], { nodeEnv: "production", ...args }, args.entry);
|
|
181
|
+
}
|
|
217
182
|
});
|
|
218
|
-
|
|
219
183
|
const startCommand = defineCommand({
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
184
|
+
meta: {
|
|
185
|
+
name: "start",
|
|
186
|
+
description: "Start the production server"
|
|
187
|
+
},
|
|
188
|
+
args: serverArgs,
|
|
189
|
+
async run({ args }) {
|
|
190
|
+
await runEntryCommand([], { ...args, nodeEnv: "production" }, args.entry);
|
|
191
|
+
}
|
|
228
192
|
});
|
|
229
|
-
|
|
230
193
|
const previewCommand = defineCommand({
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
194
|
+
meta: {
|
|
195
|
+
name: "preview",
|
|
196
|
+
description: "Preview the production build"
|
|
197
|
+
},
|
|
198
|
+
args: serverArgs,
|
|
199
|
+
async run({ args }) {
|
|
200
|
+
await runEntryCommand(["--preview"], { ...args, nodeEnv: "production" }, args.entry);
|
|
201
|
+
}
|
|
239
202
|
});
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
},
|
|
203
|
+
const mainCommand = defineCommand({
|
|
204
|
+
meta: {
|
|
205
|
+
name: "ecopages",
|
|
206
|
+
version: pkg.version,
|
|
207
|
+
description: "Ecopages CLI utilities"
|
|
208
|
+
},
|
|
209
|
+
subCommands: {
|
|
210
|
+
init: initCommand,
|
|
211
|
+
dev: devCommand,
|
|
212
|
+
"dev:watch": devWatchCommand,
|
|
213
|
+
"dev:hot": devHotCommand,
|
|
214
|
+
build: buildCommand,
|
|
215
|
+
start: startCommand,
|
|
216
|
+
preview: previewCommand
|
|
217
|
+
}
|
|
256
218
|
});
|
|
257
|
-
|
|
258
219
|
if (!process.env.VITEST) {
|
|
259
|
-
|
|
220
|
+
runMain(mainCommand);
|
|
260
221
|
}
|
|
222
|
+
export {
|
|
223
|
+
mainCommand
|
|
224
|
+
};
|