ecopages 0.2.1 → 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.
- package/README.md +109 -47
- package/bin/brand.js +42 -0
- package/bin/cli.js +348 -192
- package/bin/git-template-source-providers.js +56 -0
- package/bin/git-template-source-shared.js +7 -0
- package/bin/git-template-source.js +62 -0
- package/bin/init.js +392 -0
- package/bin/launch-plan.js +156 -60
- package/bin/node-require-preload.js +4 -0
- package/css/view-transitions.css +3 -6
- package/package.json +13 -12
- package/templates.json +115 -0
- package/bin/cli.test.ts +0 -136
- package/bin/launch-plan.test.ts +0 -160
package/bin/launch-plan.js
CHANGED
|
@@ -1,18 +1,72 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
|
|
16
|
+
function getEnvFilePaths(nodeEnv) {
|
|
17
|
+
return getDevEnvFileNames(nodeEnv).filter((envFile) => existsSync(envFile));
|
|
18
|
+
}
|
|
5
19
|
|
|
6
20
|
export function buildEnvOverrides(options) {
|
|
7
|
-
const env = {};
|
|
21
|
+
const env = options.nodeEnv ? { NODE_ENV: options.nodeEnv } : {};
|
|
8
22
|
if (options.port) env.ECOPAGES_PORT = String(options.port);
|
|
9
23
|
if (options.hostname) env.ECOPAGES_HOSTNAME = options.hostname;
|
|
10
24
|
if (options.baseUrl) env.ECOPAGES_BASE_URL = options.baseUrl;
|
|
11
25
|
if (options.debug) env.ECOPAGES_LOGGER_DEBUG = 'true';
|
|
12
|
-
if (options.
|
|
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
|
+
}
|
|
13
35
|
return env;
|
|
14
36
|
}
|
|
15
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
|
+
});
|
|
46
|
+
}
|
|
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
|
+
};
|
|
58
|
+
}
|
|
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
|
+
*/
|
|
16
70
|
export function detectRuntime(options = {}) {
|
|
17
71
|
if (options.runtime === 'bun' || options.runtime === 'node') {
|
|
18
72
|
return options.runtime;
|
|
@@ -20,93 +74,135 @@ export function detectRuntime(options = {}) {
|
|
|
20
74
|
|
|
21
75
|
const userAgent = process.env.npm_config_user_agent || '';
|
|
22
76
|
|
|
23
|
-
if (userAgent.startsWith('bun/')) {
|
|
24
|
-
return 'bun';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (typeof Bun !== 'undefined') {
|
|
77
|
+
if (userAgent.startsWith('bun/') || process.versions.bun) {
|
|
28
78
|
return 'bun';
|
|
29
79
|
}
|
|
30
80
|
|
|
31
81
|
return 'node';
|
|
32
82
|
}
|
|
33
83
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (options.watch) bunArgs.push('--watch');
|
|
38
|
-
if (options.hot) bunArgs.push('--hot');
|
|
39
|
-
|
|
40
|
-
bunArgs.push('run');
|
|
84
|
+
function usesProductionBundle(launchMode) {
|
|
85
|
+
return launchMode === 'start';
|
|
86
|
+
}
|
|
41
87
|
|
|
42
|
-
|
|
43
|
-
|
|
88
|
+
function inferLaunchMode(args, launchMode) {
|
|
89
|
+
if (launchMode) {
|
|
90
|
+
return launchMode;
|
|
44
91
|
}
|
|
45
92
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (options.reactFastRefresh) {
|
|
49
|
-
bunArgs.push('--react-fast-refresh');
|
|
93
|
+
if (args.includes('--build')) {
|
|
94
|
+
return 'build';
|
|
50
95
|
}
|
|
51
96
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export function buildNodeArgs(args, options, entryFile, hasConfig) {
|
|
56
|
-
const nodeArgs = [];
|
|
57
|
-
|
|
58
|
-
if (hasConfig) {
|
|
59
|
-
nodeArgs.push('--import', './eco.config.ts');
|
|
97
|
+
if (args.includes('--preview')) {
|
|
98
|
+
return 'preview';
|
|
60
99
|
}
|
|
61
100
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (options.reactFastRefresh) {
|
|
65
|
-
nodeArgs.push('--react-fast-refresh');
|
|
101
|
+
if (args.includes('--dev')) {
|
|
102
|
+
return 'dev';
|
|
66
103
|
}
|
|
67
104
|
|
|
68
|
-
return
|
|
105
|
+
return 'start';
|
|
69
106
|
}
|
|
70
107
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
}
|
|
80
169
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
170
|
+
return {
|
|
171
|
+
runtime,
|
|
172
|
+
command: 'bun',
|
|
173
|
+
commandArgs: ['run', distServerApp, ...args],
|
|
174
|
+
envOverrides,
|
|
175
|
+
env,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
86
178
|
|
|
87
179
|
if (runtime === 'node') {
|
|
88
|
-
const
|
|
180
|
+
const commandArgs = ['--import', nodeRequirePreload, '--import', tsxLoader];
|
|
181
|
+
if (resolvedOptions.watch) {
|
|
182
|
+
commandArgs.push('--watch');
|
|
183
|
+
}
|
|
184
|
+
commandArgs.push(resolvedEntryFile, ...args);
|
|
89
185
|
|
|
90
186
|
return {
|
|
91
187
|
runtime,
|
|
92
|
-
executionStrategy: 'direct-runtime',
|
|
93
188
|
command: process.execPath,
|
|
94
|
-
commandArgs
|
|
189
|
+
commandArgs,
|
|
95
190
|
envOverrides,
|
|
96
191
|
env,
|
|
97
192
|
};
|
|
98
193
|
}
|
|
99
194
|
|
|
195
|
+
const commandArgs = [];
|
|
196
|
+
if (resolvedOptions.watch) {
|
|
197
|
+
commandArgs.push('--watch');
|
|
198
|
+
}
|
|
199
|
+
commandArgs.push('run', resolvedEntryFile, ...args);
|
|
200
|
+
|
|
100
201
|
return {
|
|
101
202
|
runtime,
|
|
102
|
-
executionStrategy: 'direct-runtime',
|
|
103
203
|
command: 'bun',
|
|
104
|
-
commandArgs
|
|
204
|
+
commandArgs,
|
|
105
205
|
envOverrides,
|
|
106
206
|
env,
|
|
107
207
|
};
|
|
108
208
|
}
|
|
109
|
-
|
|
110
|
-
export function launchPlanRequiresExistingEntryFile(launchPlan) {
|
|
111
|
-
return launchPlan.executionStrategy !== 'config-only-bootstrap';
|
|
112
|
-
}
|
package/css/view-transitions.css
CHANGED
|
@@ -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,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ecopages",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "CLI utilities for Ecopages",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=24.0.0"
|
|
8
|
+
},
|
|
6
9
|
"license": "MIT",
|
|
7
10
|
"author": "Ecopages Team",
|
|
8
11
|
"repository": {
|
|
@@ -25,23 +28,21 @@
|
|
|
25
28
|
"lit",
|
|
26
29
|
"mdx"
|
|
27
30
|
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
28
34
|
"bin": {
|
|
29
35
|
"ecopages": "bin/cli.js"
|
|
30
36
|
},
|
|
31
|
-
"files": [
|
|
32
|
-
"bin/",
|
|
33
|
-
"css/",
|
|
34
|
-
"README.md"
|
|
35
|
-
],
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@ecopages/
|
|
39
|
-
"
|
|
38
|
+
"@clack/prompts": "^1.7.0",
|
|
39
|
+
"@ecopages/core": "0.3.0",
|
|
40
|
+
"@ecopages/file-system": "0.3.0",
|
|
41
|
+
"@ecopages/logger": "^0.2.3",
|
|
40
42
|
"giget": "^2.0.0",
|
|
41
|
-
"tsx": "^4.
|
|
43
|
+
"tsx": "^4.22.3"
|
|
42
44
|
},
|
|
43
45
|
"peerDependencies": {
|
|
44
|
-
"bun-types": "*",
|
|
45
46
|
"typescript": "^5"
|
|
46
47
|
}
|
|
47
|
-
}
|
|
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
|
+
}
|
package/bin/cli.test.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { runCommand } from 'citty';
|
|
3
|
-
import { mainCommand } from './cli.js';
|
|
4
|
-
import * as giget from 'giget';
|
|
5
|
-
import * as fs from 'node:fs';
|
|
6
|
-
import * as launchPlan from './launch-plan.js';
|
|
7
|
-
|
|
8
|
-
vi.mock('giget', () => ({
|
|
9
|
-
downloadTemplate: vi.fn(),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
vi.mock('node:fs', async (importOriginal) => {
|
|
13
|
-
const actual = await importOriginal<typeof import('node:fs')>();
|
|
14
|
-
return {
|
|
15
|
-
...actual,
|
|
16
|
-
existsSync: vi.fn((path) => actual.existsSync(path)),
|
|
17
|
-
writeFileSync: vi.fn(),
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
vi.mock('./launch-plan.js', () => ({
|
|
22
|
-
createLaunchPlan: vi.fn(),
|
|
23
|
-
launchPlanRequiresExistingEntryFile: vi.fn(),
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
vi.mock('node:child_process', () => ({
|
|
27
|
-
spawn: vi.fn().mockImplementation(() => ({
|
|
28
|
-
on: vi.fn(),
|
|
29
|
-
})),
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
vi.mock('@ecopages/logger', () => ({
|
|
33
|
-
Logger: class {
|
|
34
|
-
info = vi.fn();
|
|
35
|
-
warn = vi.fn();
|
|
36
|
-
error = vi.fn();
|
|
37
|
-
debug = vi.fn();
|
|
38
|
-
},
|
|
39
|
-
}));
|
|
40
|
-
|
|
41
|
-
describe('CLI Commands', () => {
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
vi.clearAllMocks();
|
|
44
|
-
|
|
45
|
-
// Default mocks
|
|
46
|
-
vi.mocked(fs.existsSync).mockReturnValue(false); // pretend no existing dir
|
|
47
|
-
vi.mocked(launchPlan.createLaunchPlan).mockResolvedValue({
|
|
48
|
-
runtime: 'node',
|
|
49
|
-
command: 'node',
|
|
50
|
-
commandArgs: [],
|
|
51
|
-
envOverrides: {},
|
|
52
|
-
env: {},
|
|
53
|
-
} as any);
|
|
54
|
-
vi.mocked(launchPlan.launchPlanRequiresExistingEntryFile).mockReturnValue(false);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('runs init command with default template and repo', async () => {
|
|
58
|
-
await runCommand(mainCommand, { rawArgs: ['init', 'my-new-project'] });
|
|
59
|
-
expect(giget.downloadTemplate).toHaveBeenCalledWith('github:ecopages/ecopages/examples/starter-jsx', {
|
|
60
|
-
dir: 'my-new-project',
|
|
61
|
-
force: true,
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('runs init command with custom template and repo', async () => {
|
|
66
|
-
await runCommand(mainCommand, {
|
|
67
|
-
rawArgs: ['init', 'my-dir', '--template', 'starter-lit', '--repo', 'custom/repo'],
|
|
68
|
-
});
|
|
69
|
-
expect(giget.downloadTemplate).toHaveBeenCalledWith('github:custom/repo/examples/starter-lit', {
|
|
70
|
-
dir: 'my-dir',
|
|
71
|
-
force: true,
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('runs dev command and passes defaults to launch plan', async () => {
|
|
76
|
-
await runCommand(mainCommand, { rawArgs: ['dev'] });
|
|
77
|
-
expect(launchPlan.createLaunchPlan).toHaveBeenCalledWith(
|
|
78
|
-
['--dev'],
|
|
79
|
-
expect.objectContaining({ nodeEnv: 'development' }),
|
|
80
|
-
'app.ts',
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('runs dev:hot command', async () => {
|
|
85
|
-
await runCommand(mainCommand, { rawArgs: ['dev:hot'] });
|
|
86
|
-
expect(launchPlan.createLaunchPlan).toHaveBeenCalledWith(
|
|
87
|
-
['--dev'],
|
|
88
|
-
expect.objectContaining({ hot: true, nodeEnv: 'development' }),
|
|
89
|
-
'app.ts',
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('runs dev:watch command', async () => {
|
|
94
|
-
await runCommand(mainCommand, { rawArgs: ['dev:watch'] });
|
|
95
|
-
expect(launchPlan.createLaunchPlan).toHaveBeenCalledWith(
|
|
96
|
-
['--dev'],
|
|
97
|
-
expect.objectContaining({ watch: true, nodeEnv: 'development' }),
|
|
98
|
-
'app.ts',
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('runs build command with custom entry file', async () => {
|
|
103
|
-
await runCommand(mainCommand, { rawArgs: ['build', 'server.ts'] });
|
|
104
|
-
expect(launchPlan.createLaunchPlan).toHaveBeenCalledWith(
|
|
105
|
-
['--build'],
|
|
106
|
-
expect.objectContaining({ nodeEnv: 'production' }),
|
|
107
|
-
'server.ts',
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('passes shared server options like port and hostname correctly', async () => {
|
|
112
|
-
await runCommand(mainCommand, { rawArgs: ['start', '-p', '4000', '--hostname', '0.0.0.0'] });
|
|
113
|
-
expect(launchPlan.createLaunchPlan).toHaveBeenCalledWith(
|
|
114
|
-
[],
|
|
115
|
-
expect.objectContaining({
|
|
116
|
-
nodeEnv: 'production',
|
|
117
|
-
port: '4000',
|
|
118
|
-
hostname: '0.0.0.0',
|
|
119
|
-
}),
|
|
120
|
-
'app.ts',
|
|
121
|
-
);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('allows overriding base url and debug options', async () => {
|
|
125
|
-
await runCommand(mainCommand, { rawArgs: ['preview', '--base-url', '/my-app/', '-d'] });
|
|
126
|
-
expect(launchPlan.createLaunchPlan).toHaveBeenCalledWith(
|
|
127
|
-
['--preview'],
|
|
128
|
-
expect.objectContaining({
|
|
129
|
-
nodeEnv: 'production',
|
|
130
|
-
'base-url': '/my-app/',
|
|
131
|
-
debug: true,
|
|
132
|
-
}),
|
|
133
|
-
'app.ts',
|
|
134
|
-
);
|
|
135
|
-
});
|
|
136
|
-
});
|