ecopages 0.2.1-beta.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,84 +1,208 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { parseEnv } from "node:util";
3
- const nodeRequirePreload = import.meta.resolve("./node-require-preload.js");
4
- const tsxLoader = import.meta.resolve("tsx/esm");
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parseEnv } from 'node:util';
4
+ import {
5
+ resolveEcoConfigPath,
6
+ resolveEmittedEcoConfigPath,
7
+ resolveProductionServerEntry,
8
+ resolveProductionDistDir,
9
+ assertProductionConfigIdentity,
10
+ } from '@ecopages/core/config';
11
+ import { ECOPAGES_ENTRY_WATCH_ENV, getDevEnvFileNames, getEcopagesEnv } from '@ecopages/core/build';
12
+
13
+ const nodeRequirePreload = import.meta.resolve('./node-require-preload.js');
14
+ const tsxLoader = import.meta.resolve('tsx/esm');
15
+
5
16
  function getEnvFilePaths(nodeEnv) {
6
- const envFiles = [".env", ".env.local"];
7
- if (nodeEnv) {
8
- envFiles.push(`.env.${nodeEnv}`, `.env.${nodeEnv}.local`);
9
- }
10
- return envFiles.filter((envFile) => existsSync(envFile));
17
+ return getDevEnvFileNames(nodeEnv).filter((envFile) => existsSync(envFile));
11
18
  }
12
- function buildEnvOverrides(options) {
13
- const env = {};
14
- if (options.port) env.ECOPAGES_PORT = String(options.port);
15
- if (options.hostname) env.ECOPAGES_HOSTNAME = options.hostname;
16
- if (options.baseUrl) env.ECOPAGES_BASE_URL = options.baseUrl;
17
- if (options.debug) env.ECOPAGES_LOGGER_DEBUG = "true";
18
- if (options.nodeEnv) env.NODE_ENV = options.nodeEnv;
19
- return env;
19
+
20
+ export function buildEnvOverrides(options) {
21
+ const env = options.nodeEnv ? { NODE_ENV: options.nodeEnv } : {};
22
+ if (options.port) env.ECOPAGES_PORT = String(options.port);
23
+ if (options.hostname) env.ECOPAGES_HOSTNAME = options.hostname;
24
+ if (options.baseUrl) env.ECOPAGES_BASE_URL = options.baseUrl;
25
+ if (options.debug) env.ECOPAGES_LOGGER_DEBUG = 'true';
26
+ if (options.entryFile) env.ECOPAGES_ENTRY_FILE = options.entryFile;
27
+ if (options.configFile) {
28
+ env.ECOPAGES_CONFIG_FILE = path.isAbsolute(options.configFile)
29
+ ? options.configFile
30
+ : path.resolve(process.cwd(), options.configFile);
31
+ }
32
+ if (options.watch) {
33
+ env[ECOPAGES_ENTRY_WATCH_ENV] = '1';
34
+ }
35
+ return env;
20
36
  }
21
- function buildLaunchEnv(options) {
22
- const envOverrides = buildEnvOverrides(options);
23
- const envFileValues = getEnvFilePaths(options.nodeEnv).reduce((env, envFile) => {
24
- return { ...env, ...parseEnv(readFileSync(envFile, "utf8")) };
25
- }, {});
26
- return {
27
- envOverrides,
28
- env: { ...envFileValues, ...process.env, ...envOverrides }
29
- };
37
+
38
+ export function resolveEcoConfigFilePath(options = {}, cwd = process.cwd(), resolverOptions = {}) {
39
+ return resolveEcoConfigPath({
40
+ configFile: options.configFile,
41
+ cwd,
42
+ required: false,
43
+ preferEmitted: resolverOptions.preferEmitted,
44
+ distDir: resolverOptions.distDir,
45
+ });
30
46
  }
31
- function detectRuntime(options = {}) {
32
- if (options.runtime === "bun" || options.runtime === "node") {
33
- return options.runtime;
34
- }
35
- const userAgent = process.env.npm_config_user_agent || "";
36
- if (userAgent.startsWith("bun/")) {
37
- return "bun";
38
- }
39
- if (typeof Bun !== "undefined") {
40
- return "bun";
41
- }
42
- return "node";
47
+
48
+ export function buildLaunchEnv(options) {
49
+ const envOverrides = buildEnvOverrides(options);
50
+ const envFileValues = getEnvFilePaths(options.nodeEnv).reduce((env, envFile) => {
51
+ return { ...env, ...parseEnv(readFileSync(envFile, 'utf8')) };
52
+ }, {});
53
+
54
+ return {
55
+ envOverrides,
56
+ env: { ...envFileValues, ...process.env, ...envOverrides },
57
+ };
43
58
  }
44
- function buildBunArgs(args, options, entryFile, hasConfig) {
45
- const bunArgs = [];
46
- if (options.watch) bunArgs.push("--watch");
47
- if (options.hot) bunArgs.push("--hot");
48
- bunArgs.push("run");
49
- if (hasConfig) {
50
- bunArgs.push("--preload", `./eco.config.${"ts"}`);
51
- }
52
- bunArgs.push(entryFile, ...args);
53
- if (options.reactFastRefresh) {
54
- bunArgs.push("--react-fast-refresh");
55
- }
56
- return bunArgs;
59
+
60
+ /**
61
+ * Picks the runtime for the app process.
62
+ *
63
+ * @remarks
64
+ * Bun runs the app when the command was launched through Bun (`bun dev`,
65
+ * `bun run dev`, `bunx ecopages`), when the CLI itself runs on Bun, or with
66
+ * `--runtime bun`. Every other launcher gets Node. The user-agent check is
67
+ * needed because Bun honours the CLI's `node` shebang, so the CLI process is
68
+ * Node even when Bun launched it.
69
+ */
70
+ export function detectRuntime(options = {}) {
71
+ if (options.runtime === 'bun' || options.runtime === 'node') {
72
+ return options.runtime;
73
+ }
74
+
75
+ const userAgent = process.env.npm_config_user_agent || '';
76
+
77
+ if (userAgent.startsWith('bun/') || process.versions.bun) {
78
+ return 'bun';
79
+ }
80
+
81
+ return 'node';
57
82
  }
58
- function createLaunchPlan(args, options = {}, entryFile = "app.ts") {
59
- const { envOverrides, env } = buildLaunchEnv(options);
60
- const runtime = detectRuntime(options);
61
- if (runtime === "node") {
62
- return {
63
- runtime,
64
- command: process.execPath,
65
- commandArgs: ["--import", nodeRequirePreload, "--import", tsxLoader, entryFile, ...args],
66
- envOverrides,
67
- env
68
- };
69
- }
70
- return {
71
- runtime,
72
- command: "bun",
73
- commandArgs: buildBunArgs(args, options, entryFile, existsSync("eco.config.ts")),
74
- envOverrides,
75
- env
76
- };
83
+
84
+ function usesProductionBundle(launchMode) {
85
+ return launchMode === 'start';
86
+ }
87
+
88
+ function inferLaunchMode(args, launchMode) {
89
+ if (launchMode) {
90
+ return launchMode;
91
+ }
92
+
93
+ if (args.includes('--build')) {
94
+ return 'build';
95
+ }
96
+
97
+ if (args.includes('--preview')) {
98
+ return 'preview';
99
+ }
100
+
101
+ if (args.includes('--dev')) {
102
+ return 'dev';
103
+ }
104
+
105
+ return 'start';
106
+ }
107
+
108
+ /**
109
+ * Builds the command and environment needed to launch the app.
110
+ *
111
+ * In `start` mode, the server bundle of one build output directory is used
112
+ * directly: `options.distDir` names it, otherwise the only directory below the
113
+ * working directory that holds `.server/manifest.json`. A missing or ambiguous
114
+ * bundle throws an error that says how to fix it.
115
+ *
116
+ * In `build`, `dev`, `preview`, and `types` modes, the source entry file is executed via tsx
117
+ * on Node, or as `bun run` with the same forwarded arguments. `--watch` is added for both
118
+ * when watch mode is on.
119
+ *
120
+ * @param {string[]} args - Arguments forwarded to the entry file.
121
+ * @param {object} options - CLI options (nodeEnv, runtime, port, etc.).
122
+ * @param {string} entryFile - Path to the entry file (default: `app.ts`).
123
+ * @param {'build' | 'dev' | 'preview' | 'start' | 'types'} launchMode - The CLI command mode.
124
+ * @returns {{ runtime: string, command: string, commandArgs: string[], envOverrides: object, env: object }}
125
+ * @throws {Error} When `launchMode` is `start` and no single bundle can be selected.
126
+ */
127
+
128
+ export async function createLaunchPlan(args, options, entryFile, launchMode) {
129
+ const resolvedOptions = options ?? {};
130
+ const resolvedEntryFile = entryFile ?? 'app.ts';
131
+ const { envOverrides, env } = buildLaunchEnv(resolvedOptions);
132
+ const runtime = detectRuntime(resolvedOptions);
133
+ const resolvedLaunchMode = inferLaunchMode(args, launchMode);
134
+ const shouldUseBundle = usesProductionBundle(resolvedLaunchMode);
135
+ const distDir = shouldUseBundle
136
+ ? await resolveProductionDistDir({ cwd: process.cwd(), distDir: resolvedOptions.distDir })
137
+ : undefined;
138
+ const isExplicitConfig = Boolean(resolvedOptions.configFile || getEcopagesEnv('ECOPAGES_CONFIG_FILE'));
139
+ const resolvedConfigFile = resolveEcoConfigFilePath(resolvedOptions, process.cwd(), {
140
+ preferEmitted: shouldUseBundle && !isExplicitConfig,
141
+ distDir,
142
+ });
143
+
144
+ if (shouldUseBundle) {
145
+ const distServerApp = resolveProductionServerEntry(process.cwd(), distDir);
146
+ if (!distServerApp) {
147
+ throw new Error(
148
+ `Production server entry not found in ${path.relative(process.cwd(), distDir) || '.'}. Run \`ecopages build\` again.`,
149
+ );
150
+ }
151
+ assertProductionConfigIdentity(process.cwd(), resolvedConfigFile, {
152
+ isExplicitOverride: isExplicitConfig,
153
+ distDir,
154
+ });
155
+ const runtimeConfigFile = resolveEmittedEcoConfigPath(process.cwd(), distDir) ?? resolvedConfigFile;
156
+ if (runtimeConfigFile) {
157
+ envOverrides.ECOPAGES_CONFIG_FILE = runtimeConfigFile;
158
+ env.ECOPAGES_CONFIG_FILE = runtimeConfigFile;
159
+ }
160
+ if (runtime === 'node') {
161
+ return {
162
+ runtime,
163
+ command: process.execPath,
164
+ commandArgs: [distServerApp, ...args],
165
+ envOverrides,
166
+ env,
167
+ };
168
+ }
169
+
170
+ return {
171
+ runtime,
172
+ command: 'bun',
173
+ commandArgs: ['run', distServerApp, ...args],
174
+ envOverrides,
175
+ env,
176
+ };
177
+ }
178
+
179
+ if (runtime === 'node') {
180
+ const commandArgs = ['--import', nodeRequirePreload, '--import', tsxLoader];
181
+ if (resolvedOptions.watch) {
182
+ commandArgs.push('--watch');
183
+ }
184
+ commandArgs.push(resolvedEntryFile, ...args);
185
+
186
+ return {
187
+ runtime,
188
+ command: process.execPath,
189
+ commandArgs,
190
+ envOverrides,
191
+ env,
192
+ };
193
+ }
194
+
195
+ const commandArgs = [];
196
+ if (resolvedOptions.watch) {
197
+ commandArgs.push('--watch');
198
+ }
199
+ commandArgs.push('run', resolvedEntryFile, ...args);
200
+
201
+ return {
202
+ runtime,
203
+ command: 'bun',
204
+ commandArgs,
205
+ envOverrides,
206
+ env,
207
+ };
77
208
  }
78
- export {
79
- buildBunArgs,
80
- buildEnvOverrides,
81
- buildLaunchEnv,
82
- createLaunchPlan,
83
- detectRuntime
84
- };
@@ -1,3 +1,4 @@
1
- import path from "node:path";
2
- import { createRequire } from "node:module";
3
- globalThis.require = createRequire(path.join(process.cwd(), "package.json"));
1
+ import path from 'node:path';
2
+ import { createRequire } from 'node:module';
3
+
4
+ globalThis.require = createRequire(path.join(process.cwd(), 'package.json'));
@@ -5,14 +5,11 @@
5
5
  * @import 'ecopages/css/view-transitions.css';
6
6
  *
7
7
  * Works with both @ecopages/browser-router and @ecopages/react-router.
8
+ *
9
+ * Root opt-out (`html { view-transition-name: none }`) is injected by the router when
10
+ * view transitions are enabled — do not duplicate here.
8
11
  */
9
12
 
10
- /* Disable root animation to prevent full page flash during transitions */
11
- ::view-transition-old(root),
12
- ::view-transition-new(root) {
13
- animation: none;
14
- }
15
-
16
13
  /* Shared element transitions animate position/size smoothly */
17
14
  ::view-transition-group(*) {
18
15
  animation-duration: 180ms;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecopages",
3
- "version": "0.2.1-beta.0",
3
+ "version": "0.3.0",
4
4
  "description": "CLI utilities for Ecopages",
5
5
  "type": "module",
6
6
  "engines": {
@@ -28,17 +28,21 @@
28
28
  "lit",
29
29
  "mdx"
30
30
  ],
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
31
34
  "bin": {
32
35
  "ecopages": "bin/cli.js"
33
36
  },
34
37
  "dependencies": {
35
- "@ecopages/core": "0.2.1-beta.0",
38
+ "@clack/prompts": "^1.7.0",
39
+ "@ecopages/core": "0.3.0",
40
+ "@ecopages/file-system": "0.3.0",
36
41
  "@ecopages/logger": "^0.2.3",
37
42
  "giget": "^2.0.0",
38
43
  "tsx": "^4.22.3"
39
44
  },
40
45
  "peerDependencies": {
41
- "bun-types": "*",
42
46
  "typescript": "^5"
43
47
  }
44
- }
48
+ }
package/templates.json ADDED
@@ -0,0 +1,115 @@
1
+ {
2
+ "templates": [
3
+ {
4
+ "id": "jsx",
5
+ "displayName": "JSX",
6
+ "description": "A minimal Ecopages JSX application.",
7
+ "category": "integration",
8
+ "order": 10,
9
+ "default": true,
10
+ "source": "jsx",
11
+ "packageDirectory": ".",
12
+ "integrations": ["ecopages-jsx", "mdx"]
13
+ },
14
+ {
15
+ "id": "html",
16
+ "displayName": "HTML",
17
+ "description": "An Ecopages application built from plain HTML Pages.",
18
+ "category": "integration",
19
+ "order": 15,
20
+ "source": "html",
21
+ "packageDirectory": ".",
22
+ "integrations": ["html-pages"]
23
+ },
24
+ {
25
+ "id": "react",
26
+ "displayName": "React",
27
+ "description": "A minimal Ecopages React application.",
28
+ "category": "integration",
29
+ "order": 20,
30
+ "source": "react",
31
+ "packageDirectory": ".",
32
+ "integrations": ["react"]
33
+ },
34
+ {
35
+ "id": "react-shadcn",
36
+ "displayName": "React shadcn",
37
+ "description": "A React application styled with shadcn/ui on React Aria.",
38
+ "category": "integration",
39
+ "order": 25,
40
+ "source": "react-shadcn",
41
+ "packageDirectory": ".",
42
+ "integrations": ["react"]
43
+ },
44
+ {
45
+ "id": "lit-jsx",
46
+ "displayName": "Lit JSX",
47
+ "description": "A KitaJS and Lit Ecopages application.",
48
+ "category": "integration",
49
+ "order": 30,
50
+ "source": "lit-jsx",
51
+ "packageDirectory": ".",
52
+ "integrations": ["kitajs", "lit"]
53
+ },
54
+ {
55
+ "id": "radiant",
56
+ "displayName": "Radiant UI",
57
+ "description": "An Ecopages JSX application built with Radiant UI components.",
58
+ "category": "integration",
59
+ "order": 35,
60
+ "source": "radiant",
61
+ "packageDirectory": ".",
62
+ "integrations": ["ecopages-jsx", "radiant-ui"]
63
+ },
64
+ {
65
+ "id": "blog-jsx",
66
+ "displayName": "Blog JSX",
67
+ "description": "A content-driven blog rendered with Ecopages JSX.",
68
+ "category": "application",
69
+ "order": 40,
70
+ "source": "blog-jsx",
71
+ "packageDirectory": ".",
72
+ "integrations": ["ecopages-jsx", "mdx"]
73
+ },
74
+ {
75
+ "id": "blog-react",
76
+ "displayName": "Blog React",
77
+ "description": "A content-driven blog rendered with React.",
78
+ "category": "application",
79
+ "order": 50,
80
+ "source": "blog-react",
81
+ "packageDirectory": ".",
82
+ "integrations": ["react", "mdx"]
83
+ },
84
+ {
85
+ "id": "docs-starter",
86
+ "displayName": "Docs Starter",
87
+ "description": "A documentation site powered by the content processor.",
88
+ "category": "application",
89
+ "order": 60,
90
+ "source": "docs-starter",
91
+ "packageDirectory": ".",
92
+ "integrations": ["ecopages-jsx", "mdx"]
93
+ },
94
+ {
95
+ "id": "react-better-auth",
96
+ "displayName": "React Better Auth",
97
+ "description": "A React application with Better Auth and Drizzle.",
98
+ "category": "application",
99
+ "order": 70,
100
+ "source": "react-better-auth",
101
+ "packageDirectory": ".",
102
+ "integrations": ["react"]
103
+ },
104
+ {
105
+ "id": "llm-wiki",
106
+ "displayName": "LLM Wiki",
107
+ "description": "A persistent, LLM-maintained knowledge base and site.",
108
+ "category": "application",
109
+ "order": 80,
110
+ "source": "llm-wiki",
111
+ "packageDirectory": "app",
112
+ "integrations": ["ecopages-jsx", "mdx"]
113
+ }
114
+ ]
115
+ }