@lytjs/cli 5.0.3 → 5.0.6
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/dist/bin/cli.cjs +1057 -1
- package/dist/bin/cli.mjs +1057 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types/bin/cli.d.ts +1 -2
- package/dist/types/bin/cli.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/bin/cli.mjs
CHANGED
|
@@ -1 +1,1058 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var ve=Object.defineProperty;var P=(e,t)=>()=>(e&&(t=e(e=0)),t);var $e=(e,t)=>{for(var n in t)ve(e,n,{get:t[n],enumerable:!0})};import*as v from"fs";import*as J from"path";function o(e,t){let n=Se[t];return n?`${n}${e}${we}`:e}function ee(e){let t=e.slice(2),n={command:"",args:[],options:{},raw:t},r=0;for(;r<t.length;){let s=t[r];if(s==="--help"||s==="-h")n.options.help=!0,r++;else if(s==="--version"||s==="-v")n.options.version=!0,r++;else if(s.startsWith("--")){let a=s.indexOf("=");if(a!==-1){let p=s.slice(2,a),d=s.slice(a+1);n.options[p]=d}else{let p=s.slice(2),d=t[r+1];d&&!d.startsWith("-")?(n.options[p]=d,r++):n.options[p]=!0}r++}else if(s.startsWith("-")&&s.length>1){let a=s.slice(1),p=t[r+1];p&&!p.startsWith("-")?(n.options[a]=p,r++):n.options[a]=!0,r++}else n.command?(n.args.push(s),r++):(n.command=s,r++)}return n}function $(e){v.existsSync(e)||v.mkdirSync(e,{recursive:!0})}function O(e){return v.existsSync(e)}function S(e){return v.readFileSync(e,"utf-8")}function w(e,t){let n=J.dirname(e);$(n),typeof t=="string"?v.writeFileSync(e,t,"utf-8"):v.writeFileSync(e,t)}var we,Se,i,R=P(()=>{"use strict";we="\x1B[0m",Se={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m",bgBlack:"\x1B[40m",bgRed:"\x1B[41m",bgGreen:"\x1B[42m",bgYellow:"\x1B[43m",bgBlue:"\x1B[44m",bgMagenta:"\x1B[45m",bgCyan:"\x1B[46m",bgWhite:"\x1B[47m",bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",strikethrough:"\x1B[9m"};i={info(e){console.log(`${o("[INFO]","blue")} ${e}`)},warn(e){console.log(`${o("[WARN]","yellow")} ${e}`)},error(e){console.error(`${o("[ERROR]","red")} ${e}`)},success(e){console.log(`${o("[SUCCESS]","green")} ${e}`)}}});import*as L from"path";function je(){return`<!DOCTYPE html>
|
|
3
|
+
<html lang="zh-CN">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Lyt App</title>
|
|
8
|
+
<link rel="stylesheet" href="/src/style.css" />
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="app"></div>
|
|
12
|
+
<script type="module" src="/src/main.ts"></script>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
15
|
+
`}function Ce(){return`import { createApp } from '@lytjs/lytjs';
|
|
16
|
+
import App from './App';
|
|
17
|
+
|
|
18
|
+
// \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B
|
|
19
|
+
const app = createApp(App);
|
|
20
|
+
|
|
21
|
+
// \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20
|
|
22
|
+
app.mount('#app');
|
|
23
|
+
`}function Pe(){return`import { defineComponent, ref, computed } from '@lytjs/lytjs';
|
|
24
|
+
|
|
25
|
+
// \u5B9A\u4E49\u6839\u7EC4\u4EF6
|
|
26
|
+
const App = defineComponent({
|
|
27
|
+
name: 'App',
|
|
28
|
+
|
|
29
|
+
// \u7EC4\u4EF6\u6A21\u677F
|
|
30
|
+
template: \`
|
|
31
|
+
<div class="app">
|
|
32
|
+
<header class="app-header">
|
|
33
|
+
<div class="logo">
|
|
34
|
+
<span class="logo-text">Lyt</span>
|
|
35
|
+
</div>
|
|
36
|
+
</header>
|
|
37
|
+
|
|
38
|
+
<main class="app-main">
|
|
39
|
+
<div class="welcome-section">
|
|
40
|
+
<h1>\u6B22\u8FCE\u4F7F\u7528 Lyt.js!</h1>
|
|
41
|
+
<p>\u8F7B\u5199\u8F7B\u8DD1\uFF0C\u6240\u89C1\u5373\u4EE3\u7801</p>
|
|
42
|
+
|
|
43
|
+
<div class="counter-section">
|
|
44
|
+
<h2>\u8BA1\u6570\u5668\u793A\u4F8B</h2>
|
|
45
|
+
<p class="count-display">
|
|
46
|
+
\u5F53\u524D\u8BA1\u6570: <strong>{{ count }}</strong>
|
|
47
|
+
</p>
|
|
48
|
+
<p class="double-display">
|
|
49
|
+
\u53CC\u500D: <strong>{{ double }}</strong>
|
|
50
|
+
</p>
|
|
51
|
+
|
|
52
|
+
<div class="button-group">
|
|
53
|
+
<button class="btn btn-primary" on-click="increment">+1</button>
|
|
54
|
+
<button class="btn btn-secondary" on-click="decrement">-1</button>
|
|
55
|
+
<button class="btn btn-success" on-click="reset">\u91CD\u7F6E</button>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<div class="features-section">
|
|
60
|
+
<h2>\u6838\u5FC3\u529F\u80FD</h2>
|
|
61
|
+
<ul>
|
|
62
|
+
<li v-for="feature in features" :key="feature">
|
|
63
|
+
{{ feature }}
|
|
64
|
+
</li>
|
|
65
|
+
</ul>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</main>
|
|
69
|
+
|
|
70
|
+
<footer class="app-footer">
|
|
71
|
+
<p>
|
|
72
|
+
\u7528 \u2764\uFE0F \u6253\u9020
|
|
73
|
+
</p>
|
|
74
|
+
</footer>
|
|
75
|
+
</div>
|
|
76
|
+
\`,
|
|
77
|
+
|
|
78
|
+
// \u54CD\u5E94\u5F0F\u6570\u636E
|
|
79
|
+
setup() {
|
|
80
|
+
const count = ref(0);
|
|
81
|
+
const double = computed(() => count.value * 2);
|
|
82
|
+
|
|
83
|
+
const features = [
|
|
84
|
+
'\u54CD\u5E94\u5F0F\u7CFB\u7EDF\uFF08Proxy + Signal\uFF09',
|
|
85
|
+
'\u865A\u62DF DOM + Patch Flag \u4F18\u5316',
|
|
86
|
+
'\u7EC4\u4EF6\u7CFB\u7EDF\uFF08Options + Composition API\uFF09',
|
|
87
|
+
'\u5185\u7F6E\u8DEF\u7531',
|
|
88
|
+
'\u72B6\u6001\u7BA1\u7406',
|
|
89
|
+
'CLI \u5DE5\u5177\u94FE',
|
|
90
|
+
'\u6D4F\u89C8\u5668 DevTools',
|
|
91
|
+
'28+ UI \u7EC4\u4EF6',
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
const increment = () => {
|
|
95
|
+
count.value++;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const decrement = () => {
|
|
99
|
+
count.value--;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const reset = () => {
|
|
103
|
+
count.value = 0;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
count,
|
|
108
|
+
double,
|
|
109
|
+
features,
|
|
110
|
+
increment,
|
|
111
|
+
decrement,
|
|
112
|
+
reset,
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export default App;
|
|
118
|
+
`}function ke(){return`/* Lyt.js \u5E94\u7528\u6837\u5F0F */
|
|
119
|
+
|
|
120
|
+
:root {
|
|
121
|
+
--primary-color: #42b883;
|
|
122
|
+
--primary-hover: #35a06f;
|
|
123
|
+
--secondary-color: #747b88;
|
|
124
|
+
--success-color: #10b981;
|
|
125
|
+
--danger-color: #ef4444;
|
|
126
|
+
--text-color: #333;
|
|
127
|
+
--bg-color: #f9fafb;
|
|
128
|
+
--card-bg: #ffffff;
|
|
129
|
+
--border-color: #e5e7eb;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
* {
|
|
133
|
+
margin: 0;
|
|
134
|
+
padding: 0;
|
|
135
|
+
box-sizing: border-box;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
body {
|
|
139
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
|
140
|
+
color: var(--text-color);
|
|
141
|
+
background-color: var(--bg-color);
|
|
142
|
+
line-height: 1.6;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.app {
|
|
146
|
+
min-height: 100vh;
|
|
147
|
+
display: flex;
|
|
148
|
+
flex-direction: column;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.app-header {
|
|
152
|
+
background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
|
|
153
|
+
padding: 1.5rem 2rem;
|
|
154
|
+
color: white;
|
|
155
|
+
box-shadow: 0 2px 10px rgba(66, 184, 131, 0.2);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.logo {
|
|
159
|
+
font-size: 1.8rem;
|
|
160
|
+
font-weight: 700;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.logo-text {
|
|
164
|
+
letter-spacing: 2px;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.app-main {
|
|
168
|
+
flex: 1;
|
|
169
|
+
padding: 3rem 2rem;
|
|
170
|
+
max-width: 900px;
|
|
171
|
+
margin: 0 auto;
|
|
172
|
+
width: 100%;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.welcome-section {
|
|
176
|
+
text-align: center;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.welcome-section h1 {
|
|
180
|
+
font-size: 2.5rem;
|
|
181
|
+
margin-bottom: 0.5rem;
|
|
182
|
+
color: var(--primary-color);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.welcome-section p {
|
|
186
|
+
font-size: 1.2rem;
|
|
187
|
+
color: var(--secondary-color);
|
|
188
|
+
margin-bottom: 2rem;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.counter-section {
|
|
192
|
+
background: var(--card-bg);
|
|
193
|
+
border-radius: 12px;
|
|
194
|
+
padding: 2rem;
|
|
195
|
+
margin: 2rem 0;
|
|
196
|
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
|
|
197
|
+
border: 1px solid var(--border-color);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.counter-section h2 {
|
|
201
|
+
margin-bottom: 1rem;
|
|
202
|
+
color: var(--text-color);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.count-display,
|
|
206
|
+
.double-display {
|
|
207
|
+
font-size: 1.25rem;
|
|
208
|
+
margin: 0.75rem 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.button-group {
|
|
212
|
+
display: flex;
|
|
213
|
+
justify-content: center;
|
|
214
|
+
gap: 1rem;
|
|
215
|
+
margin-top: 1.5rem;
|
|
216
|
+
flex-wrap: wrap;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.btn {
|
|
220
|
+
padding: 0.75rem 1.5rem;
|
|
221
|
+
border: none;
|
|
222
|
+
border-radius: 8px;
|
|
223
|
+
font-size: 1rem;
|
|
224
|
+
font-weight: 500;
|
|
225
|
+
cursor: pointer;
|
|
226
|
+
transition: all 0.2s ease;
|
|
227
|
+
color: white;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.btn:hover {
|
|
231
|
+
transform: translateY(-2px);
|
|
232
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.btn:active {
|
|
236
|
+
transform: translateY(0);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.btn-primary {
|
|
240
|
+
background: var(--primary-color);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.btn-primary:hover {
|
|
244
|
+
background: var(--primary-hover);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.btn-secondary {
|
|
248
|
+
background: var(--secondary-color);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.btn-secondary:hover {
|
|
252
|
+
background: #5d6470;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.btn-success {
|
|
256
|
+
background: var(--success-color);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.btn-success:hover {
|
|
260
|
+
background: #059669;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.features-section {
|
|
264
|
+
margin-top: 2rem;
|
|
265
|
+
text-align: left;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.features-section h2 {
|
|
269
|
+
text-align: center;
|
|
270
|
+
margin-bottom: 1.5rem;
|
|
271
|
+
color: var(--text-color);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.features-section ul {
|
|
275
|
+
list-style: none;
|
|
276
|
+
padding: 0;
|
|
277
|
+
max-width: 600px;
|
|
278
|
+
margin: 0 auto;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.features-section li {
|
|
282
|
+
padding: 0.75rem 1rem;
|
|
283
|
+
margin: 0.5rem 0;
|
|
284
|
+
background: var(--card-bg);
|
|
285
|
+
border-radius: 8px;
|
|
286
|
+
border-left: 4px solid var(--primary-color);
|
|
287
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.app-footer {
|
|
291
|
+
padding: 1.5rem 2rem;
|
|
292
|
+
text-align: center;
|
|
293
|
+
color: var(--secondary-color);
|
|
294
|
+
border-top: 1px solid var(--border-color);
|
|
295
|
+
background: var(--card-bg);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
@media (max-width: 640px) {
|
|
299
|
+
.welcome-section h1 {
|
|
300
|
+
font-size: 2rem;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.app-main {
|
|
304
|
+
padding: 2rem 1rem;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
`}function Ae(e){return JSON.stringify({name:e,version:"0.1.0",type:"module",private:!0,scripts:{dev:"lytx dev",build:"lytx build",preview:"lytx preview"},dependencies:{"@lytjs/lytjs":"latest"},devDependencies:{"@lytjs/cli":"latest"}},null,2)+`
|
|
308
|
+
`}function Re(){return JSON.stringify({compilerOptions:{target:"ES2020",module:"ESNext",moduleResolution:"bundler",strict:!0,jsx:"preserve",resolveJsonModule:!0,isolatedModules:!0,esModuleInterop:!0,lib:["ES2020","DOM","DOM.Iterable"],skipLibCheck:!0,noEmit:!0,paths:{"@/*":["./src/*"]}},include:["src/**/*.ts","src/**/*.tsx"],exclude:["node_modules","dist"]},null,2)+`
|
|
309
|
+
`}function Te(){return`# Dependencies
|
|
310
|
+
node_modules/
|
|
311
|
+
.pnp
|
|
312
|
+
.pnp.js
|
|
313
|
+
|
|
314
|
+
# Build outputs
|
|
315
|
+
dist/
|
|
316
|
+
build/
|
|
317
|
+
*.log
|
|
318
|
+
npm-debug.log*
|
|
319
|
+
|
|
320
|
+
# IDE
|
|
321
|
+
.vscode/
|
|
322
|
+
.idea/
|
|
323
|
+
*.swp
|
|
324
|
+
*.swo
|
|
325
|
+
|
|
326
|
+
# OS
|
|
327
|
+
.DS_Store
|
|
328
|
+
Thumbs.db
|
|
329
|
+
|
|
330
|
+
# Environment
|
|
331
|
+
.env.local
|
|
332
|
+
.env.*.local
|
|
333
|
+
|
|
334
|
+
# Cache
|
|
335
|
+
*.cache
|
|
336
|
+
.cache/
|
|
337
|
+
`}function Me(e){return`# ${e}
|
|
338
|
+
|
|
339
|
+
\u8FD9\u662F\u4E00\u4E2A\u4F7F\u7528 [Lyt.js](https://gitee.com/lytjs/lytjs) \u6846\u67B6\u521B\u5EFA\u7684\u9879\u76EE\u3002
|
|
340
|
+
|
|
341
|
+
## \u7279\u6027
|
|
342
|
+
|
|
343
|
+
- \u26A1 **\u96F6\u4F9D\u8D56** - \u7EAF\u539F\u751F\u5B9E\u73B0\uFF0C\u4E0D\u4F9D\u8D56\u4EFB\u4F55\u7B2C\u4E09\u65B9\u5E93
|
|
344
|
+
- \u{1F680} **\u8D85\u8F7B\u91CF** - \u6838\u5FC3\u4EC5 34.56KB\uFF0C\u6781\u901F\u52A0\u8F7D
|
|
345
|
+
- \u{1F3A8} **Vue 3 \u517C\u5BB9** - API \u9AD8\u5EA6\u517C\u5BB9\uFF0C\u8FC1\u79FB\u6210\u672C\u4F4E
|
|
346
|
+
- \u{1F527} **\u5F00\u7BB1\u5373\u7528** - \u5185\u7F6E\u8DEF\u7531\u3001\u72B6\u6001\u7BA1\u7406\u3001\u7EC4\u4EF6\u5E93
|
|
347
|
+
|
|
348
|
+
## \u5FEB\u901F\u5F00\u59CB
|
|
349
|
+
|
|
350
|
+
### \u5B89\u88C5\u4F9D\u8D56
|
|
351
|
+
|
|
352
|
+
\`\`\`bash
|
|
353
|
+
npm install
|
|
354
|
+
\`\`\`
|
|
355
|
+
|
|
356
|
+
### \u542F\u52A8\u5F00\u53D1\u670D\u52A1\u5668
|
|
357
|
+
|
|
358
|
+
\`\`\`bash
|
|
359
|
+
npm run dev
|
|
360
|
+
\`\`\`
|
|
361
|
+
|
|
362
|
+
### \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
363
|
+
|
|
364
|
+
\`\`\`bash
|
|
365
|
+
npm run build
|
|
366
|
+
\`\`\`
|
|
367
|
+
|
|
368
|
+
## \u9879\u76EE\u7ED3\u6784
|
|
369
|
+
|
|
370
|
+
\`\`\`
|
|
371
|
+
${e}/
|
|
372
|
+
\u251C\u2500\u2500 index.html # HTML \u5165\u53E3
|
|
373
|
+
\u251C\u2500\u2500 package.json # \u9879\u76EE\u914D\u7F6E
|
|
374
|
+
\u251C\u2500\u2500 tsconfig.json # TypeScript \u914D\u7F6E
|
|
375
|
+
\u251C\u2500\u2500 src/
|
|
376
|
+
\u2502 \u251C\u2500\u2500 main.ts # \u5E94\u7528\u5165\u53E3
|
|
377
|
+
\u2502 \u251C\u2500\u2500 App.ts # \u6839\u7EC4\u4EF6
|
|
378
|
+
\u2502 \u2514\u2500\u2500 style.css # \u5168\u5C40\u6837\u5F0F
|
|
379
|
+
\u2514\u2500\u2500 README.md # \u9879\u76EE\u6587\u6863
|
|
380
|
+
\`\`\`
|
|
381
|
+
|
|
382
|
+
## \u5B66\u4E60\u8D44\u6E90
|
|
383
|
+
|
|
384
|
+
- \u{1F4D6} [Lyt.js \u5B98\u65B9\u6587\u6863](https://gitee.com/lytjs/lytjs)
|
|
385
|
+
- \u{1F4A1} [\u5FEB\u901F\u5F00\u59CB\u6307\u5357](https://gitee.com/lytjs/lytjs)
|
|
386
|
+
- \u{1F527} [API \u53C2\u8003](https://gitee.com/lytjs/lytjs)
|
|
387
|
+
|
|
388
|
+
## \u793E\u533A\u652F\u6301
|
|
389
|
+
|
|
390
|
+
- \u{1F310} Gitee: [https://gitee.com/lytjs/lytjs](https://gitee.com/lytjs/lytjs)
|
|
391
|
+
- \u{1F4AC} Issues: [https://gitee.com/lytjs/lytjs/issues](https://gitee.com/lytjs/lytjs/issues)
|
|
392
|
+
|
|
393
|
+
## License
|
|
394
|
+
|
|
395
|
+
MIT
|
|
396
|
+
`}async function te(e,t={}){let n=t.template||"spa",r=L.resolve(process.cwd(),e);i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(e,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(n,"brightCyan")}`),O(r)&&(i.error(`\u76EE\u5F55 "${e}" \u5DF2\u5B58\u5728\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u540D\u79F0\u6216\u5220\u9664\u5DF2\u6709\u76EE\u5F55`),process.exit(1)),$(r);let s=[{filePath:"index.html",content:je()},{filePath:"src/main.ts",content:Ce()},{filePath:"src/App.ts",content:Pe()},{filePath:"src/style.css",content:ke()},{filePath:"package.json",content:Ae(e)},{filePath:"tsconfig.json",content:Re()},{filePath:".gitignore",content:Te()},{filePath:"README.md",content:Me(e)}];for(let a of s){let p=L.join(r,a.filePath);w(p,a.content),i.success(` \u521B\u5EFA ${a.filePath}`)}console.log(""),i.success(`\u9879\u76EE ${o(e,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`),console.log(""),console.log(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u542F\u52A8\u9879\u76EE\uFF1A"),console.log(""),console.log(` ${o("cd","brightGreen")} ${e}`),console.log(` ${o("npm install","brightGreen")}`),console.log(` ${o("npm run dev","brightGreen")}`),console.log("")}var oe=P(()=>{"use strict";R()});import*as H from"fs";import*as h from"path";function V(){let e={};for(let[t,n]of Object.entries(D))e[t]=n.description;return e}function K(e){return e in D}function Ee(e){let t={name:e.name,version:"0.1.0",private:!0,type:"module",scripts:{dev:"lytx dev",build:"lytx build",preview:"lytx preview"},dependencies:{"@lytjs/lytjs":"latest"}};return e.ts&&(t.devDependencies={"@lytjs/cli":"latest",typescript:"^5.0.1"}),e.eslint&&(t.devDependencies=t.devDependencies||{},t.devDependencies.eslint="^8.0.0",t.scripts=t.scripts||{},t.scripts.lint="eslint src --ext .ts,.js"),e.router&&(t.dependencies["@lytjs/router"]="latest"),e.store&&(t.dependencies["@lytjs/store"]="latest"),JSON.stringify(t,null,2)+`
|
|
397
|
+
`}function Ie(e){let t={compilerOptions:{target:"ES2020",module:"ESNext",moduleResolution:"bundler",strict:!0,jsx:"preserve",resolveJsonModule:!0,isolatedModules:!0,esModuleInterop:!0,lib:["ES2020","DOM","DOM.Iterable"],skipLibCheck:!0,noEmit:!0,paths:{"@/*":["./src/*"]}},include:["src/**/*.ts","src/**/*.tsx"],exclude:["node_modules","dist"]};return e.template==="ssr"&&(t.compilerOptions.types=["node"]),JSON.stringify(t,null,2)+`
|
|
398
|
+
`}function Fe(e){let t=e.ts?".ts":".js";return`<!DOCTYPE html>
|
|
399
|
+
<html lang="zh-CN">
|
|
400
|
+
<head>
|
|
401
|
+
<meta charset="UTF-8" />
|
|
402
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
403
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
|
404
|
+
<title>${e.name}</title>
|
|
405
|
+
</head>
|
|
406
|
+
<body>
|
|
407
|
+
<div id="app"></div>
|
|
408
|
+
<script type="module" src="/src/main${t}"></script>
|
|
409
|
+
</body>
|
|
410
|
+
</html>
|
|
411
|
+
`}function Oe(e){let t=["// Lytx \u914D\u7F6E\u6587\u4EF6","import { defineConfig } from '@lytjs/lytjs'","","export default defineConfig({"," // \u6784\u5EFA\u6A21\u5F0F",` mode: '${e.template}',`];return e.router&&(t.push(" // \u8DEF\u7531\u914D\u7F6E"),t.push(" router: {"),t.push(" historyMode: true,"),t.push(" },")),e.store&&(t.push(" // \u72B6\u6001\u7BA1\u7406\u914D\u7F6E"),t.push(" store: {"),t.push(" strict: true,"),t.push(" },")),t.push("})"),t.push(""),t.join(`
|
|
412
|
+
`)}function He(e){let t=e.ts?".ts":".js",n=["import { createApp } from '@lytjs/lytjs'","import App from './App.lyt'","import './styles/main.css'"];return e.router&&n.push("import { router } from './router'"),e.store&&n.push("import { store } from './store'"),n.push(""),n.push("// \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B"),n.push("const app = createApp(App)"),e.router&&n.push("app.use(router)"),e.store&&n.push("app.use(store)"),n.push(""),n.push("// \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20"),n.push("app.mount('#app')"),n.join(`
|
|
413
|
+
`)+`
|
|
414
|
+
`}function Ge(){return`<template>
|
|
415
|
+
<div class="app">
|
|
416
|
+
<Header />
|
|
417
|
+
<main>
|
|
418
|
+
<h1>Hello Lyt!</h1>
|
|
419
|
+
<p>\u6B22\u8FCE\u4F7F\u7528 Lyt \u6846\u67B6</p>
|
|
420
|
+
</main>
|
|
421
|
+
</div>
|
|
422
|
+
</template>
|
|
423
|
+
|
|
424
|
+
<script lang="ts">
|
|
425
|
+
import { defineComponent } from '@lytjs/lytjs'
|
|
426
|
+
import Header from './components/Header'
|
|
427
|
+
|
|
428
|
+
export default defineComponent({
|
|
429
|
+
name: 'App',
|
|
430
|
+
components: {
|
|
431
|
+
Header,
|
|
432
|
+
},
|
|
433
|
+
})
|
|
434
|
+
</script>
|
|
435
|
+
|
|
436
|
+
<style scoped>
|
|
437
|
+
.app {
|
|
438
|
+
text-align: center;
|
|
439
|
+
padding: 20px;
|
|
440
|
+
}
|
|
441
|
+
</style>
|
|
442
|
+
`}function Le(){return`import { defineComponent } from '@lytjs/lytjs'
|
|
443
|
+
|
|
444
|
+
export default defineComponent({
|
|
445
|
+
name: 'HomePage',
|
|
446
|
+
|
|
447
|
+
template: \`
|
|
448
|
+
<div class="page-home">
|
|
449
|
+
<h1>\u9996\u9875</h1>
|
|
450
|
+
<p>\u8FD9\u662F\u9996\u9875\u5185\u5BB9</p>
|
|
451
|
+
</div>
|
|
452
|
+
\`,
|
|
453
|
+
})
|
|
454
|
+
`}function De(){return`import { defineComponent } from '@lytjs/lytjs'
|
|
455
|
+
|
|
456
|
+
export default defineComponent({
|
|
457
|
+
name: 'AboutPage',
|
|
458
|
+
|
|
459
|
+
template: \`
|
|
460
|
+
<div class="page-about">
|
|
461
|
+
<h1>\u5173\u4E8E</h1>
|
|
462
|
+
<p>\u8FD9\u662F\u5173\u4E8E\u9875\u9762</p>
|
|
463
|
+
</div>
|
|
464
|
+
\`,
|
|
465
|
+
})
|
|
466
|
+
`}function Be(){return`import { defineComponent } from '@lytjs/lytjs'
|
|
467
|
+
|
|
468
|
+
export default defineComponent({
|
|
469
|
+
name: 'Header',
|
|
470
|
+
|
|
471
|
+
template: \`
|
|
472
|
+
<header class="header">
|
|
473
|
+
<nav>
|
|
474
|
+
<a href="/">\u9996\u9875</a>
|
|
475
|
+
<a href="/about">\u5173\u4E8E</a>
|
|
476
|
+
</nav>
|
|
477
|
+
</header>
|
|
478
|
+
\`,
|
|
479
|
+
})
|
|
480
|
+
`}function Ye(){return`import { createRouter, createWebHistory } from '@lytjs/router'
|
|
481
|
+
import HomePage from '../pages/index'
|
|
482
|
+
import AboutPage from '../pages/about'
|
|
483
|
+
|
|
484
|
+
export const router = createRouter({
|
|
485
|
+
history: createWebHistory(),
|
|
486
|
+
routes: [
|
|
487
|
+
{
|
|
488
|
+
path: '/',
|
|
489
|
+
component: HomePage,
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
path: '/about',
|
|
493
|
+
component: AboutPage,
|
|
494
|
+
},
|
|
495
|
+
],
|
|
496
|
+
})
|
|
497
|
+
`}function Ue(){return`import { createStore } from '@lytjs/store'
|
|
498
|
+
|
|
499
|
+
export const store = createStore({
|
|
500
|
+
state: {
|
|
501
|
+
count: 0,
|
|
502
|
+
message: 'Hello Lyt!',
|
|
503
|
+
},
|
|
504
|
+
|
|
505
|
+
mutations: {
|
|
506
|
+
increment(state: any) {
|
|
507
|
+
state.count++
|
|
508
|
+
},
|
|
509
|
+
|
|
510
|
+
setMessage(state: any, message: string) {
|
|
511
|
+
state.message = message
|
|
512
|
+
},
|
|
513
|
+
},
|
|
514
|
+
|
|
515
|
+
actions: {
|
|
516
|
+
async fetchMessage({ commit }: any) {
|
|
517
|
+
commit('setMessage', 'Fetched from API')
|
|
518
|
+
},
|
|
519
|
+
},
|
|
520
|
+
|
|
521
|
+
getters: {
|
|
522
|
+
doubleCount: (state: any) => state.count * 2,
|
|
523
|
+
},
|
|
524
|
+
})
|
|
525
|
+
`}function Ne(){return`/* \u5168\u5C40\u6837\u5F0F */
|
|
526
|
+
|
|
527
|
+
* {
|
|
528
|
+
margin: 0;
|
|
529
|
+
padding: 0;
|
|
530
|
+
box-sizing: border-box;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
body {
|
|
534
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
535
|
+
'Helvetica Neue', Arial, sans-serif;
|
|
536
|
+
-webkit-font-smoothing: antialiased;
|
|
537
|
+
-moz-osx-font-smoothing: grayscale;
|
|
538
|
+
color: #2c3e50;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
a {
|
|
542
|
+
color: #42b883;
|
|
543
|
+
text-decoration: none;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
a:hover {
|
|
547
|
+
text-decoration: underline;
|
|
548
|
+
}
|
|
549
|
+
`}function ze(){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
|
550
|
+
<rect width="32" height="32" rx="6" fill="#42b883"/>
|
|
551
|
+
<text x="16" y="22" text-anchor="middle" fill="white" font-size="18" font-weight="bold">L</text>
|
|
552
|
+
</svg>
|
|
553
|
+
`}function We(){return JSON.stringify({root:!0,env:{browser:!0,es2021:!0,node:!0},extends:["eslint:recommended"],parserOptions:{ecmaVersion:"latest",sourceType:"module"},rules:{"no-unused-vars":"warn","no-console":"warn"}},null,2)+`
|
|
554
|
+
`}function ne(e,t){if(!H.existsSync(e))throw new Error(`\u6A21\u677F\u76EE\u5F55\u4E0D\u5B58\u5728: ${e}`);let n=H.readdirSync(e,{withFileTypes:!0});for(let r of n){let s=h.join(e,r.name),a=h.join(t,r.name);if(!(r.name===".DS_Store"||r.name==="node_modules"))if(r.isDirectory())ne(s,a);else{$(h.dirname(a));let p=S(s);w(a,p),i.success(` \u521B\u5EFA ${h.relative(t,a)}`)}}}async function _e(e){let{name:t,template:n}=e,r=h.resolve(process.cwd(),t);if(i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(t,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(n,"brightCyan")} (${D[n].description})`),O(r))throw i.error(`\u76EE\u5F55 "${t}" \u5DF2\u5B58\u5728\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u540D\u79F0\u6216\u5220\u9664\u5DF2\u6709\u76EE\u5F55`),new Error(`Directory "${t}" already exists`);$(r);let s=h.resolve(__dirname,".."),a=h.join(s,"templates",n);ne(a,r);let p=h.join(r,"package.json");if(H.existsSync(p)){let d=S(p),u=JSON.parse(d);u.name=t,w(p,JSON.stringify(u,null,2)+`
|
|
555
|
+
`),i.success(` \u66F4\u65B0 package.json (name: ${t})`)}console.log(""),i.success(`\u9879\u76EE ${o(t,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`),console.log(""),console.log(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u542F\u52A8\u9879\u76EE\uFF1A"),console.log(""),console.log(` ${o("cd","brightGreen")} ${t}`),console.log(` ${o("npm install","brightGreen")}`),console.log(` ${o("npm run dev","brightGreen")}`),console.log("")}async function B(e){var c;if(((c=D[e.template])==null?void 0:c.type)==="example")return _e(e);let{name:t,template:n,ts:r,router:s,store:a,eslint:p}=e,d=h.resolve(process.cwd(),t);if(i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(t,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(n,"brightCyan")}`),O(d))throw i.error(`\u76EE\u5F55 "${t}" \u5DF2\u5B58\u5728\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u540D\u79F0\u6216\u5220\u9664\u5DF2\u6709\u76EE\u5F55`),new Error(`Directory "${t}" already exists`);$(d);let u=[{filePath:"package.json",content:Ee(e)},{filePath:"index.html",content:Fe(e)},{filePath:"lytx.config.ts",content:Oe(e)},{filePath:"src/main.ts",content:He(e)},{filePath:"src/App.lyt",content:Ge()},{filePath:"src/pages/index.ts",content:Le()},{filePath:"src/pages/about.ts",content:De()},{filePath:"src/components/Header.ts",content:Be()},{filePath:"src/styles/main.css",content:Ne()},{filePath:"public/favicon.svg",content:ze()}];r&&u.push({filePath:"tsconfig.json",content:Ie(e)}),s&&u.push({filePath:"src/router/index.ts",content:Ye()}),a&&u.push({filePath:"src/store/index.ts",content:Ue()}),p&&u.push({filePath:".eslintrc.json",content:We()});for(let m of u){let l=h.join(d,m.filePath);w(l,m.content),i.success(` \u521B\u5EFA ${m.filePath}`)}console.log(""),i.success(`\u9879\u76EE ${o(t,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`),console.log(""),console.log(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u542F\u52A8\u9879\u76EE\uFF1A"),console.log(""),console.log(` ${o("cd","brightGreen")} ${t}`),console.log(` ${o("npm install","brightGreen")}`),console.log(` ${o("npm run dev","brightGreen")}`),console.log("")}var D,q=P(()=>{"use strict";R();D={spa:{description:"\u57FA\u7840 SPA \u5355\u9875\u5E94\u7528\uFF08\u8BA1\u6570\u5668\u793A\u4F8B\uFF09",type:"builtin"},ssr:{description:"SSR \u670D\u52A1\u7AEF\u6E32\u67D3\u5E94\u7528",type:"builtin"},ssg:{description:"SSG \u9759\u6001\u7AD9\u70B9\u751F\u6210",type:"builtin"},"todo-app":{description:"Todo \u5F85\u529E\u4E8B\u9879\u5E94\u7528\uFF08\u54CD\u5E94\u5F0F + LocalStorage \u6301\u4E45\u5316\uFF09",type:"example"},"admin-dashboard":{description:"Admin Dashboard \u4F01\u4E1A\u7EA7\u540E\u53F0\u7BA1\u7406\u7CFB\u7EDF\uFF0810 \u4E2A\u9875\u9762\uFF09",type:"example"}}});import*as re from"http";import*as E from"fs";import*as j from"path";import*as se from"crypto";function ie(e){let t=new Y,n=[],r=[],s=null,a=!1;function p(u){let c=j.extname(u).toLowerCase();if(c===".css")return"css";let m=j.basename(u);return m.startsWith("lytx.config")||m==="tsconfig.json"||m==="package.json"?"reload":c===".ts"||c===".tsx"||c===".lyt"||c===".js"||c===".jsx"?"update":"reload"}function d(u){try{let c=E.readdirSync(u,{withFileTypes:!0});for(let m of c){let l=j.join(u,m.name);if(m.isDirectory()){if(m.name==="node_modules"||m.name===".git"||m.name==="dist")continue;d(l)}else if(m.isFile()){let f=j.extname(m.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(f))try{let k=E.watch(l,{persistent:!1},Q=>{if(Q==="change"){let F=j.relative(e,l);for(let A of n)try{A(F)}catch(G){}let M=p(l),C={type:M,path:`/${F}`};if(M==="css")try{C.content=E.readFileSync(l,"utf-8")}catch(A){}t.broadcast(JSON.stringify(C))}});r.push(k)}catch(k){}}}}catch(c){}}return{start(u){a||(a=!0,s=re.createServer((c,m)=>{m.writeHead(426,{"Content-Type":"text/plain"}),m.end("Upgrade Required")}),s.on("upgrade",(c,m,l)=>{t.handleUpgrade(c,m,l)}),s.listen(u,()=>{}),d(e))},stop(){a=!1;for(let u of r)try{u.close()}catch(c){}if(r.length=0,t.closeAll(),s){try{s.close()}catch(u){}s=null}},onFileChange(u){n.push(u)},notifyClient(u){t.broadcast(JSON.stringify(u))}}}function U(e){let t=new Y;return e.on("upgrade",(n,r,s)=>{t.handleUpgrade(n,r,s)}),{broadcast(n){t.broadcast(n)},getClientCount(){return t.getClientCount()}}}function N(){return`(function() {
|
|
556
|
+
'use strict';
|
|
557
|
+
|
|
558
|
+
var ws = null;
|
|
559
|
+
var reconnectTimer = null;
|
|
560
|
+
var reconnectAttempts = 0;
|
|
561
|
+
var maxReconnectAttempts = 10;
|
|
562
|
+
|
|
563
|
+
function connect() {
|
|
564
|
+
var protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
565
|
+
var wsUrl = protocol + '//' + location.host + '/__hmr__';
|
|
566
|
+
ws = new WebSocket(wsUrl);
|
|
567
|
+
|
|
568
|
+
ws.onopen = function() {
|
|
569
|
+
reconnectAttempts = 0;
|
|
570
|
+
console.log('[HMR] Connected');
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
ws.onmessage = function(event) {
|
|
574
|
+
try {
|
|
575
|
+
var update = JSON.parse(event.data);
|
|
576
|
+
|
|
577
|
+
if (update.type === 'css') {
|
|
578
|
+
handleCSSUpdate(update);
|
|
579
|
+
} else if (update.type === 'update') {
|
|
580
|
+
handleModuleUpdate(update);
|
|
581
|
+
} else if (update.type === 'reload') {
|
|
582
|
+
handleFullReload(update);
|
|
583
|
+
}
|
|
584
|
+
} catch (e) {
|
|
585
|
+
console.error('[HMR] Failed to parse update:', e);
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
ws.onclose = function() {
|
|
590
|
+
console.log('[HMR] Disconnected');
|
|
591
|
+
scheduleReconnect();
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
ws.onerror = function() {
|
|
595
|
+
ws.close();
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function scheduleReconnect() {
|
|
600
|
+
if (reconnectAttempts >= maxReconnectAttempts) {
|
|
601
|
+
console.log('[HMR] Max reconnect attempts reached');
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
reconnectAttempts++;
|
|
605
|
+
var delay = Math.min(1000 * Math.pow(2, reconnectAttempts), 30000);
|
|
606
|
+
console.log('[HMR] Reconnecting in ' + delay + 'ms (attempt ' + reconnectAttempts + ')');
|
|
607
|
+
reconnectTimer = setTimeout(connect, delay);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function handleCSSUpdate(update) {
|
|
611
|
+
console.log('[HMR] CSS update:', update.path);
|
|
612
|
+
// \u67E5\u627E\u6240\u6709 link[rel="stylesheet"] \u5E76\u91CD\u65B0\u52A0\u8F7D
|
|
613
|
+
var links = document.querySelectorAll('link[rel="stylesheet"]');
|
|
614
|
+
links.forEach(function(link) {
|
|
615
|
+
var href = link.getAttribute('href');
|
|
616
|
+
if (href && href.indexOf(update.path) !== -1) {
|
|
617
|
+
var newLink = document.createElement('link');
|
|
618
|
+
newLink.rel = 'stylesheet';
|
|
619
|
+
newLink.href = href + (href.indexOf('?') !== -1 ? '&' : '?') + 't=' + Date.now();
|
|
620
|
+
link.parentNode.replaceChild(newLink, link);
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
// \u5982\u679C\u6709\u5185\u8054 CSS \u5185\u5BB9\uFF0C\u76F4\u63A5\u6CE8\u5165
|
|
625
|
+
if (update.content) {
|
|
626
|
+
var style = document.createElement('style');
|
|
627
|
+
style.textContent = update.content;
|
|
628
|
+
document.head.appendChild(style);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function handleModuleUpdate(update) {
|
|
633
|
+
console.log('[HMR] Module update:', update.path);
|
|
634
|
+
// \u5C1D\u8BD5\u70ED\u66F4\u65B0\u6A21\u5757
|
|
635
|
+
if (typeof module !== 'undefined' && module.hot) {
|
|
636
|
+
module.hot.accept(update.path, function() {
|
|
637
|
+
console.log('[HMR] Module accepted:', update.path);
|
|
638
|
+
});
|
|
639
|
+
} else {
|
|
640
|
+
// \u56DE\u9000\u5230\u5168\u91CF\u5237\u65B0
|
|
641
|
+
console.log('[HMR] Full reload (module.hot not available)');
|
|
642
|
+
location.reload();
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function handleFullReload(update) {
|
|
647
|
+
console.log('[HMR] Full reload:', update.path);
|
|
648
|
+
location.reload();
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// \u542F\u52A8\u8FDE\u63A5
|
|
652
|
+
connect();
|
|
653
|
+
})();`}var Y,Z=P(()=>{"use strict";Y=class{constructor(){this.clients=[]}handleUpgrade(t,n,r){let s=t.headers["sec-websocket-key"];if(!s){n.destroy();return}let a=se.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");n.write(`HTTP/1.1 101 Switching Protocols\r
|
|
654
|
+
Upgrade: websocket\r
|
|
655
|
+
Connection: Upgrade\r
|
|
656
|
+
Sec-WebSocket-Accept: ${a}\r
|
|
657
|
+
\r
|
|
658
|
+
`);let p={socket:n,isAlive:!0};n.on("close",()=>{this.clients=this.clients.filter(d=>d!==p)}),n.on("error",()=>{this.clients=this.clients.filter(d=>d!==p)}),this.clients.push(p)}broadcast(t){let n=[];for(let r of this.clients)try{if(!r.isAlive){n.push(r);continue}let s=Buffer.from(t,"utf-8"),a=this.createFrame(129,s);r.socket.write(a)}catch(s){n.push(r)}for(let r of n){this.clients=this.clients.filter(s=>s!==r);try{r.socket.destroy()}catch(s){}}}createFrame(t,n){let r=n.length,s;r<126?s=2:r<65536?s=4:s=10;let a=Buffer.alloc(s+r);return a[0]=t,r<126?a[1]=r:r<65536?(a[1]=126,a.writeUInt16BE(r,2)):(a[1]=127,a.writeUInt32BE(0,2),a.writeUInt32BE(r,6)),n.copy(a,s),a}getClientCount(){return this.clients.length}closeAll(){for(let t of this.clients)try{t.socket.destroy()}catch(n){}this.clients=[]}}});import*as ae from"http";import*as T from"fs";import*as x from"path";async function Je(){if(!z)try{z=await import("esbuild")}catch(e){i.error("\u7F3A\u5C11\u4F9D\u8D56: esbuild"),i.error(""),i.error(" Lyt CLI \u7684\u5F00\u53D1\u670D\u52A1\u5668\u9700\u8981 esbuild \u6765\u5B9E\u65F6\u7F16\u8BD1 TypeScript\u3002"),i.error(""),i.error(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5B89\u88C5:"),i.error(` ${o("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${o("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}return z}function Ve(e,t){try{return z.transformSync(e,{loader:"ts",target:"es2018",format:"esm",sourcemap:"inline"}).code}catch(n){let r=n instanceof Error?n.message:String(n);return console.error(`[Lyt CLI] \u7F16\u8BD1\u9519\u8BEF ${t||""}:`,r),e}}function Ke(e,t){var u;let n=((u=e.url)==null?void 0:u.split("?")[0])||"/";if(n==="/"&&(n="/index.html"),n.startsWith("/node_modules/")||n.startsWith("/@")){let c;if(n.startsWith("/@")&&!n.startsWith("/node_modules/")?c=x.join(t,"node_modules",n.slice(1)):c=x.join(t,n.slice(1)),n.match(/^\/(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/)&&!n.includes(".")){let m=x.join(c,"package.json");if(T.existsSync(m))try{let l=JSON.parse(S(m)),f=l.module||l.main||"index.js";l.exports&&(typeof l.exports=="string"?f=l.exports:typeof l.exports=="object"&&l.exports["."]&&(typeof l.exports["."]=="string"?f=l.exports["."]:l.exports["."].import?f=l.exports["."].import:l.exports["."].default?f=l.exports["."].default:Object.values(l.exports["."])[0]&&(f=Object.values(l.exports["."])[0]))),f.startsWith("./")&&(f=f.slice(2)),c=x.join(c,f)}catch(l){}}if(T.existsSync(c)&&T.statSync(c).isFile()){let m=x.extname(c).toLowerCase(),f={".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".json":"application/json; charset=utf-8"}[m]||"application/octet-stream",b=S(c);return{statusCode:200,headers:{"Content-Type":f},body:b}}}let r=x.join(t,n);if(!r.startsWith(t))return{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"};if(!T.existsSync(r)||!T.statSync(r).isFile())return{statusCode:404,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"404 Not Found"};let s=x.extname(r).toLowerCase(),p={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".ts":"application/typescript; charset=utf-8",".json":"application/json; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".txt":"text/plain; charset=utf-8"}[s]||"application/octet-stream",d=S(r);return(s===".ts"||s===".tsx")&&(d=Ve(d,n)),s===".html"&&(d=d.replace("</head>",`<script>${N()}</script>
|
|
659
|
+
</head>`)),{statusCode:200,headers:{"Content-Type":p},body:d}}async function X(e={}){let t=e.port||3e3,n=x.resolve(e.root||process.cwd()),r=e.hmr!==!1;await Je();let s=ae.createServer((d,u)=>{let c=Ke(d,n);u.writeHead(c.statusCode,c.headers),u.end(c.body)}),a=r?U(s):null;s.listen(t,()=>{console.log(""),console.log(o(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557","brightCyan")),console.log(o(" \u2551","brightCyan")+o(" Lyt \u5F00\u53D1\u670D\u52A1\u5668\u5DF2\u542F\u52A8 ","brightWhite")+o("\u2551","brightCyan")),console.log(o(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D","brightCyan")),console.log(""),console.log(` ${o("\u279C","brightGreen")} \u672C\u5730\u8BBF\u95EE: ${o(`http://localhost:${t}`,"brightBlue")}`),console.log(` ${o("\u279C","brightGreen")} \u7F51\u7EDC\u8BBF\u95EE: ${o(`http://127.0.0.1:${t}`,"brightBlue")}`),console.log(` ${o("\u279C","brightGreen")} \u9879\u76EE\u76EE\u5F55: ${o(n,"brightBlue")}`),console.log(` ${o("\u279C","brightGreen")} \u70ED\u66F4\u65B0: ${o(r?"\u5DF2\u5F00\u542F":"\u5DF2\u5173\u95ED",r?"brightGreen":"brightRed")}`),console.log(""),console.log(` ${o("\u6309 Ctrl+C \u505C\u6B62\u670D\u52A1\u5668","dim")}`),console.log("")}),s.on("error",d=>{d.code==="EADDRINUSE"?(i.error(`\u7AEF\u53E3 ${t} \u5DF2\u88AB\u5360\u7528\uFF0C\u8BF7\u4F7F\u7528 --port \u6307\u5B9A\u5176\u4ED6\u7AEF\u53E3`),process.exit(1)):(i.error(`\u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25: ${d.message}`),process.exit(1))});let p=()=>{i.info("\u6B63\u5728\u5173\u95ED\u5F00\u53D1\u670D\u52A1\u5668..."),s.close(()=>{i.success("\u670D\u52A1\u5668\u5DF2\u5173\u95ED"),process.exit(0)}),setTimeout(()=>{i.warn("\u670D\u52A1\u5668\u5173\u95ED\u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(1)},5e3)};process.on("SIGINT",p),process.on("SIGTERM",p)}var z,le=P(()=>{"use strict";R();Z();z=null});import*as y from"fs";import*as g from"path";async function qe(){if(!W)try{W=await import("esbuild")}catch(e){i.error("\u7F3A\u5C11\u4F9D\u8D56: esbuild"),i.error(""),i.error(" Lyt CLI \u7684\u6784\u5EFA\u529F\u80FD\u9700\u8981 esbuild\u3002"),i.error(""),i.error(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5B89\u88C5:"),i.error(` ${o("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${o("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}return W}async function ce(e={}){let t=Date.now(),n=g.resolve(e.root||process.cwd()),r=g.resolve(n,e.outDir||"dist"),s=e.entry||"index.html",a=e.minify||!1;await qe(),i.info("\u5F00\u59CB\u6784\u5EFA\u9879\u76EE..."),i.info(` \u6839\u76EE\u5F55: ${o(n,"brightCyan")}`),i.info(` \u8F93\u51FA\u76EE\u5F55: ${o(r,"brightCyan")}`),i.info(` \u538B\u7F29: ${o(a?"\u5F00\u542F":"\u5173\u95ED",a?"brightGreen":"brightYellow")}`);let p=g.join(n,s);y.existsSync(p)||(i.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${p}`),process.exit(1));let d=S(p),u=/<script\s+type="module"\s+src="([^"]+)"\s*><\/script>/g,c,m=[];for(;(c=u.exec(d))!==null;)m.push(c[1]);m.length===0&&i.warn("\u672A\u5728\u5165\u53E3 HTML \u4E2D\u627E\u5230\u6A21\u5757\u811A\u672C\u5F15\u7528");let l={inputFiles:0,outputFiles:0,totalSize:0,buildTime:0};$(r),$(g.join(r,"assets"));for(let b of m){let k=g.join(n,b);if(!y.existsSync(k)){i.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${b}`);continue}i.info(`\u6B63\u5728\u6253\u5305: ${o(b,"brightYellow")}`);let F=`${g.basename(b,g.extname(b))}.bundle.js`,M=g.join(r,"assets",F);try{await W.build({entryPoints:[k],bundle:!0,minify:a,target:"es2018",format:"esm",outfile:M,sourcemap:!0,external:G=>G.startsWith("@lytjs/"),drop:a?["console"]:[],metafile:!0});let C=y.readFileSync(M,"utf-8");l.totalSize+=Buffer.byteLength(C,"utf-8"),l.outputFiles++;let A=M+".map";if(y.existsSync(A)){let G=y.readFileSync(A,"utf-8");l.totalSize+=Buffer.byteLength(G,"utf-8"),l.outputFiles++}d=d.replace(`<script type="module" src="${b}"></script>`,`<script src="/assets/${F}"></script>`),l.inputFiles++}catch(C){let A=C instanceof Error?C.message:String(C);i.error(`\u6253\u5305\u5931\u8D25 ${b}: ${A}`),process.exit(1)}}Ze(n,r,l);let f=g.join(r,"index.html");w(f,d),l.outputFiles++,l.totalSize+=Buffer.byteLength(d,"utf-8"),l.buildTime=Date.now()-t,console.log(""),i.success("\u6784\u5EFA\u5B8C\u6210\uFF01"),console.log(""),console.log(` ${o("\u8F93\u5165\u6587\u4EF6:","brightWhite")} ${l.inputFiles} \u4E2A`),console.log(` ${o("\u8F93\u51FA\u6587\u4EF6:","brightWhite")} ${l.outputFiles} \u4E2A`),console.log(` ${o("\u603B\u5927\u5C0F:","brightWhite")} ${Xe(l.totalSize)}`),console.log(` ${o("\u6784\u5EFA\u8017\u65F6:","brightWhite")} ${l.buildTime}ms`),console.log(` ${o("\u8F93\u51FA\u76EE\u5F55:","brightWhite")} ${o(r,"brightCyan")}`),console.log("")}function Ze(e,t,n){let r=g.join(e,"src");if(!y.existsSync(r))return;function s(a,p){let d=y.readdirSync(a,{withFileTypes:!0});for(let u of d){let c=g.join(a,u.name);if(u.isDirectory()){if(u.name==="node_modules")continue;s(c,p)}else if(u.isFile()){let m=g.extname(u.name);if([".ts",".tsx",".js",".jsx"].includes(m))continue;let l=g.relative(p,c),f=g.join(t,l);if(/\.(png|jpe?g|gif|svg|ico|woff2?|ttf|eot|mp[34]|webm|avi|pdf|zip|gz)$/i.test(c)){let k=y.readFileSync(c);w(f,k)}else w(f,y.readFileSync(c).toString("utf-8"));n.outputFiles++,n.totalSize+=y.statSync(c).size}}}s(r,r)}function Xe(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],n=1024,r=Math.floor(Math.log(e)/Math.log(n));return`${(e/Math.pow(n,r)).toFixed(2)} ${t[r]}`}var W,pe=P(()=>{"use strict";R();W=null});import*as I from"fs";import*as de from"path";function Qe(e){let t={type:"component",name:"",useAI:!1,style:!0};for(let n=0;n<e.length;n++){let r=e[n];r==="--ai"?t.useAI=!0:r==="--no-ai"?t.useAI=!1:r==="-t"||r==="--type"?t.componentType=e[++n]:r==="-o"||r==="--output"?t.outputPath=e[++n]:r==="--no-style"?t.style=!1:r==="--api-key"?t.apiKey=e[++n]:r==="--model"?t.model=e[++n]:r==="--provider"?t.provider=e[++n]:r==="--base-url"?t.baseUrl=e[++n]:r==="-d"||r==="--description"?t.description=e[++n]:!t.type&&["component","store","page","api"].includes(r)?t.type=r:!t.name&&!r.startsWith("-")&&(t.name=r)}return t}function et(e,t){let n=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),r=t.componentType||"functional",s={functional:`<!-- ${e} \u7EC4\u4EF6 -->
|
|
660
|
+
<template>
|
|
661
|
+
<div class="${n}">
|
|
662
|
+
<slot></slot>
|
|
663
|
+
</div>
|
|
664
|
+
</template>
|
|
665
|
+
|
|
666
|
+
<script setup>
|
|
667
|
+
// \u7EC4\u4EF6\u903B\u8F91
|
|
668
|
+
</script>
|
|
669
|
+
|
|
670
|
+
<style scoped>
|
|
671
|
+
.${n} {
|
|
672
|
+
/* \u6837\u5F0F */
|
|
673
|
+
}
|
|
674
|
+
</style>
|
|
675
|
+
`,button:`<!-- ${e} \u6309\u94AE\u7EC4\u4EF6 -->
|
|
676
|
+
<template>
|
|
677
|
+
<button class="${n}" :disabled="disabled" @click="handleClick">
|
|
678
|
+
<slot></slot>
|
|
679
|
+
</button>
|
|
680
|
+
</template>
|
|
681
|
+
|
|
682
|
+
<script setup>
|
|
683
|
+
import { defineProps, defineEmits } from '@lytjs/core';
|
|
684
|
+
|
|
685
|
+
const props = defineProps({
|
|
686
|
+
disabled: {
|
|
687
|
+
type: Boolean,
|
|
688
|
+
default: false
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
const emit = defineEmits(['click']);
|
|
693
|
+
|
|
694
|
+
function handleClick(event) {
|
|
695
|
+
emit('click', event);
|
|
696
|
+
}
|
|
697
|
+
</script>
|
|
698
|
+
|
|
699
|
+
<style scoped>
|
|
700
|
+
.${n} {
|
|
701
|
+
padding: 8px 16px;
|
|
702
|
+
border: none;
|
|
703
|
+
border-radius: 4px;
|
|
704
|
+
background: #3b82f6;
|
|
705
|
+
color: white;
|
|
706
|
+
cursor: pointer;
|
|
707
|
+
font-size: 14px;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
.${n}:hover:not(:disabled) {
|
|
711
|
+
background: #2563eb;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
.${n}:disabled {
|
|
715
|
+
background: #9ca3af;
|
|
716
|
+
cursor: not-allowed;
|
|
717
|
+
}
|
|
718
|
+
</style>
|
|
719
|
+
`,input:`<!-- ${e} \u8F93\u5165\u6846\u7EC4\u4EF6 -->
|
|
720
|
+
<template>
|
|
721
|
+
<div class="${n}">
|
|
722
|
+
<input
|
|
723
|
+
:value="modelValue"
|
|
724
|
+
:type="type"
|
|
725
|
+
:placeholder="placeholder"
|
|
726
|
+
:disabled="disabled"
|
|
727
|
+
@input="handleInput"
|
|
728
|
+
@change="handleChange"
|
|
729
|
+
/>
|
|
730
|
+
</div>
|
|
731
|
+
</template>
|
|
732
|
+
|
|
733
|
+
<script setup>
|
|
734
|
+
import { defineProps, defineEmits } from '@lytjs/core';
|
|
735
|
+
|
|
736
|
+
const props = defineProps({
|
|
737
|
+
modelValue: {
|
|
738
|
+
type: [String, Number],
|
|
739
|
+
default: ''
|
|
740
|
+
},
|
|
741
|
+
type: {
|
|
742
|
+
type: String,
|
|
743
|
+
default: 'text'
|
|
744
|
+
},
|
|
745
|
+
placeholder: {
|
|
746
|
+
type: String,
|
|
747
|
+
default: ''
|
|
748
|
+
},
|
|
749
|
+
disabled: {
|
|
750
|
+
type: Boolean,
|
|
751
|
+
default: false
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
const emit = defineEmits(['update:modelValue', 'change']);
|
|
756
|
+
|
|
757
|
+
function handleInput(event) {
|
|
758
|
+
emit('update:modelValue', event.target.value);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function handleChange(event) {
|
|
762
|
+
emit('change', event.target.value);
|
|
763
|
+
}
|
|
764
|
+
</script>
|
|
765
|
+
|
|
766
|
+
<style scoped>
|
|
767
|
+
.${n} input {
|
|
768
|
+
padding: 8px 12px;
|
|
769
|
+
border: 1px solid #d1d5db;
|
|
770
|
+
border-radius: 4px;
|
|
771
|
+
font-size: 14px;
|
|
772
|
+
outline: none;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
.${n} input:focus {
|
|
776
|
+
border-color: #3b82f6;
|
|
777
|
+
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
|
|
778
|
+
}
|
|
779
|
+
</style>
|
|
780
|
+
`,card:`<!-- ${e} \u5361\u7247\u7EC4\u4EF6 -->
|
|
781
|
+
<template>
|
|
782
|
+
<div class="${n}">
|
|
783
|
+
<div class="${n}-header" if="$slots.header">
|
|
784
|
+
<slot name="header"></slot>
|
|
785
|
+
</div>
|
|
786
|
+
<div class="${n}-body">
|
|
787
|
+
<slot></slot>
|
|
788
|
+
</div>
|
|
789
|
+
<div class="${n}-footer" if="$slots.footer">
|
|
790
|
+
<slot name="footer"></slot>
|
|
791
|
+
</div>
|
|
792
|
+
</div>
|
|
793
|
+
</template>
|
|
794
|
+
|
|
795
|
+
<script setup>
|
|
796
|
+
// \u7EC4\u4EF6\u903B\u8F91
|
|
797
|
+
</script>
|
|
798
|
+
|
|
799
|
+
<style scoped>
|
|
800
|
+
.${n} {
|
|
801
|
+
background: white;
|
|
802
|
+
border-radius: 8px;
|
|
803
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
804
|
+
overflow: hidden;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
.${n}-header,
|
|
808
|
+
.${n}-body,
|
|
809
|
+
.${n}-footer {
|
|
810
|
+
padding: 16px;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
.${n}-header {
|
|
814
|
+
border-bottom: 1px solid #e5e7eb;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
.${n}-footer {
|
|
818
|
+
border-top: 1px solid #e5e7eb;
|
|
819
|
+
}
|
|
820
|
+
</style>
|
|
821
|
+
`};return s[r]||s.functional}function tt(e){let t=e.charAt(0).toLowerCase()+e.slice(1);return`/**
|
|
822
|
+
* ${e} Store
|
|
823
|
+
*/
|
|
824
|
+
|
|
825
|
+
import { createStore } from '@lytjs/store';
|
|
826
|
+
|
|
827
|
+
export const ${t}Store = createStore('${e}', {
|
|
828
|
+
state: {
|
|
829
|
+
// \u72B6\u6001\u5B9A\u4E49
|
|
830
|
+
count: 0
|
|
831
|
+
},
|
|
832
|
+
|
|
833
|
+
getters: {
|
|
834
|
+
// \u8BA1\u7B97\u5C5E\u6027
|
|
835
|
+
double: state => state.count * 2
|
|
836
|
+
},
|
|
837
|
+
|
|
838
|
+
actions: {
|
|
839
|
+
// \u65B9\u6CD5\u5B9A\u4E49
|
|
840
|
+
increment(state) {
|
|
841
|
+
state.count++;
|
|
842
|
+
},
|
|
843
|
+
|
|
844
|
+
decrement(state) {
|
|
845
|
+
state.count--;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
`}function ot(e){let t=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();return`<!-- ${e} \u9875\u9762 -->
|
|
850
|
+
<template>
|
|
851
|
+
<div class="${t}-page">
|
|
852
|
+
<h1>${e}</h1>
|
|
853
|
+
<slot></slot>
|
|
854
|
+
</div>
|
|
855
|
+
</template>
|
|
856
|
+
|
|
857
|
+
<script setup>
|
|
858
|
+
import { ref, computed } from '@lytjs/reactivity';
|
|
859
|
+
|
|
860
|
+
// \u9875\u9762\u903B\u8F91
|
|
861
|
+
</script>
|
|
862
|
+
|
|
863
|
+
<style scoped>
|
|
864
|
+
.${t}-page {
|
|
865
|
+
padding: 20px;
|
|
866
|
+
}
|
|
867
|
+
</style>
|
|
868
|
+
`}function nt(e){return`/**
|
|
869
|
+
* ${e} API
|
|
870
|
+
*/
|
|
871
|
+
|
|
872
|
+
export default async function handler(req, res) {
|
|
873
|
+
const method = req.method;
|
|
874
|
+
|
|
875
|
+
switch (method) {
|
|
876
|
+
case 'GET':
|
|
877
|
+
// \u83B7\u53D6\u8D44\u6E90
|
|
878
|
+
res.json({
|
|
879
|
+
success: true,
|
|
880
|
+
message: 'Get ${e}',
|
|
881
|
+
data: []
|
|
882
|
+
});
|
|
883
|
+
break;
|
|
884
|
+
|
|
885
|
+
case 'POST':
|
|
886
|
+
// \u521B\u5EFA\u8D44\u6E90
|
|
887
|
+
res.status(201).json({
|
|
888
|
+
success: true,
|
|
889
|
+
message: 'Create ${e}',
|
|
890
|
+
data: {}
|
|
891
|
+
});
|
|
892
|
+
break;
|
|
893
|
+
|
|
894
|
+
case 'PUT':
|
|
895
|
+
// \u66F4\u65B0\u8D44\u6E90
|
|
896
|
+
res.json({
|
|
897
|
+
success: true,
|
|
898
|
+
message: 'Update ${e}'
|
|
899
|
+
});
|
|
900
|
+
break;
|
|
901
|
+
|
|
902
|
+
case 'DELETE':
|
|
903
|
+
// \u5220\u9664\u8D44\u6E90
|
|
904
|
+
res.json({
|
|
905
|
+
success: true,
|
|
906
|
+
message: 'Delete ${e}'
|
|
907
|
+
});
|
|
908
|
+
break;
|
|
909
|
+
|
|
910
|
+
default:
|
|
911
|
+
res.status(405).json({
|
|
912
|
+
success: false,
|
|
913
|
+
message: 'Method not allowed'
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
`}async function ue(e){let t=Qe(e);t.type||(i.error("\u8BF7\u63D0\u4F9B\u751F\u6210\u7C7B\u578B (component, store, page, api)"),console.log(""),console.log(_),process.exit(1)),t.name||(i.error("\u8BF7\u63D0\u4F9B\u540D\u79F0"),console.log(""),console.log(_),process.exit(1)),i.info(`\u751F\u6210 ${t.type}: ${t.name}`),i.info(`\u4F7F\u7528 AI: ${t.useAI?"Yes":"No"}`);let n,r;switch(t.type){case"component":n=et(t.name,t),r=`./src/components/${t.name}.lyt`;break;case"store":n=tt(t.name),r=`./src/stores/${t.name}.js`;break;case"page":n=ot(t.name),r=`./src/pages/${t.name}.lyt`;break;case"api":n=nt(t.name),r=`./src/api/${t.name}.js`;break}let s=t.outputPath||r,a=de.dirname(s);I.existsSync(a)||I.mkdirSync(a,{recursive:!0}),I.writeFileSync(s,n,"utf-8"),i.success(`\u6587\u4EF6\u5DF2\u4FDD\u5B58: ${s}`),t.useAI&&(console.log(""),console.log(o("\u63D0\u793A:","brightYellow")),console.log(" AI \u751F\u6210\u529F\u80FD\u9700\u8981\u5728\u9879\u76EE\u4E2D\u5B89\u88C5 @lytjs/ai"),console.log(" \u8BF7\u5148\u8FD0\u884C: lyt-ai init \u521D\u59CB\u5316\u914D\u7F6E"),console.log(""))}var _,me=P(()=>{"use strict";R();_=`
|
|
918
|
+
${o("lytx generate","brightCyan")} - \u751F\u6210\u4EE3\u7801\uFF08\u7EC4\u4EF6\u3001Store\u3001\u9875\u9762\u3001API\uFF09
|
|
919
|
+
|
|
920
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
921
|
+
lytx generate <type> <name> [options]
|
|
922
|
+
|
|
923
|
+
${o("\u53C2\u6570:","brightGreen")}
|
|
924
|
+
${o("<type>","brightYellow")} \u751F\u6210\u7C7B\u578B (component, store, page, api)
|
|
925
|
+
${o("<name>","brightYellow")} \u540D\u79F0
|
|
926
|
+
|
|
927
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
928
|
+
${o("--ai","brightYellow")} \u4F7F\u7528 AI \u751F\u6210\uFF08\u9700\u8981\u914D\u7F6E API Key\uFF09
|
|
929
|
+
${o("--no-ai","brightYellow")} \u4E0D\u4F7F\u7528 AI\uFF08\u6A21\u677F\u751F\u6210\uFF09
|
|
930
|
+
${o("-t, --type <type>","brightYellow")} \u7EC4\u4EF6\u7C7B\u578B (button, input, form, card, list, table, modal, dropdown, tabs, navigation, custom)
|
|
931
|
+
${o("-o, --output <path>","brightYellow")}\u8F93\u51FA\u6587\u4EF6\u8DEF\u5F84
|
|
932
|
+
${o("--no-style","brightYellow")} \u4E0D\u6DFB\u52A0\u6837\u5F0F
|
|
933
|
+
${o("--api-key <key>","brightYellow")} AI API Key
|
|
934
|
+
${o("--model <model>","brightYellow")} AI \u6A21\u578B\u540D\u79F0
|
|
935
|
+
${o("--provider <name>","brightYellow")} AI \u63D0\u4F9B\u5546 (openai, anthropic, custom)
|
|
936
|
+
${o("--base-url <url>","brightYellow")} AI API \u57FA\u7840 URL
|
|
937
|
+
|
|
938
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
939
|
+
${o("$","dim")} lytx generate component MyButton
|
|
940
|
+
${o("$","dim")} lytx generate component MyButton --type button
|
|
941
|
+
${o("$","dim")} lytx generate component MyButton --type button --ai
|
|
942
|
+
${o("$","dim")} lytx generate store counter
|
|
943
|
+
${o("$","dim")} lytx generate page Home
|
|
944
|
+
${o("$","dim")} lytx generate api users
|
|
945
|
+
`});var be={};$e(be,{createHMREndpoint:()=>U,createHMRServer:()=>ie,createProject:()=>B,getHMRClientScript:()=>N});import*as fe from"fs";import*as he from"path";function it(){let e=V(),t="";for(let[n,r]of Object.entries(e))t+=` ${o(n,"brightYellow")} \u2014 ${r}
|
|
946
|
+
`;return`
|
|
947
|
+
${o("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
|
|
948
|
+
|
|
949
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
950
|
+
lytx create <name> [options]
|
|
951
|
+
|
|
952
|
+
${o("\u53C2\u6570:","brightGreen")}
|
|
953
|
+
${o("<name>","brightYellow")} \u9879\u76EE\u540D\u79F0\uFF08\u540C\u65F6\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF09
|
|
954
|
+
|
|
955
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
956
|
+
${o("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
957
|
+
${t}
|
|
958
|
+
${o("--ts","brightYellow")} \u4F7F\u7528 TypeScript\uFF08\u4EC5\u5185\u7F6E\u6A21\u677F\uFF09
|
|
959
|
+
${o("--router","brightYellow")} \u5305\u542B\u8DEF\u7531\uFF08\u4EC5\u5185\u7F6E\u6A21\u677F\uFF09
|
|
960
|
+
${o("--store","brightYellow")} \u5305\u542B\u72B6\u6001\u7BA1\u7406\uFF08\u4EC5\u5185\u7F6E\u6A21\u677F\uFF09
|
|
961
|
+
${o("--eslint","brightYellow")} \u5305\u542B ESLint \u914D\u7F6E\uFF08\u4EC5\u5185\u7F6E\u6A21\u677F\uFF09
|
|
962
|
+
|
|
963
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
964
|
+
${o("$","dim")} lytx create my-app
|
|
965
|
+
${o("$","dim")} lytx create my-app --template spa --ts --router --store
|
|
966
|
+
${o("$","dim")} lytx create my-todo --template todo-app
|
|
967
|
+
${o("$","dim")} lytx create my-admin --template admin-dashboard
|
|
968
|
+
${o("$","dim")} lytx create my-app --template ssr --ts
|
|
969
|
+
|
|
970
|
+
`}function pt(){console.log(""),console.log(` ${o(ye,"brightCyan")} v${o(rt,"brightWhite")}`),console.log("")}function dt(e){i.error(`\u672A\u77E5\u547D\u4EE4: ${o(e,"brightRed")}`),console.log(""),console.log(` \u8FD0\u884C ${o("lytx --help","brightCyan")} \u67E5\u770B\u53EF\u7528\u547D\u4EE4`),console.log("")}function ut(e){return typeof e=="string"&&K(e)?e:"spa"}async function mt(e){if(e.options.help){console.log(it());return}e.args.length===0&&(i.error("\u8BF7\u63D0\u4F9B\u9879\u76EE\u540D\u79F0"),console.log(""),console.log(` \u7528\u6CD5: ${o("lytx create <name>","brightCyan")}`),console.log(""),console.log(` \u8FD0\u884C ${o("lytx create --help","brightCyan")} \u67E5\u770B\u66F4\u591A\u9009\u9879`),console.log(""),process.exit(1));let t=e.args[0],n=typeof e.options.template=="string"?e.options.template:"spa";if(!K(n)){i.error(`\u672A\u77E5\u6A21\u677F: ${o(n,"brightRed")}`),console.log(""),console.log(" \u53EF\u7528\u6A21\u677F\uFF1A");let s=V();for(let[a,p]of Object.entries(s))console.log(` ${o(a,"brightYellow")} \u2014 ${p}`);console.log(""),process.exit(1)}if(e.options.ts===!0||e.options.router===!0||e.options.store===!0||e.options.eslint===!0||typeof e.options.template=="string"&&["ssr","ssg","todo-app","admin-dashboard"].includes(e.options.template)){let s={name:t,template:ut(e.options.template),ts:e.options.ts===!0,router:e.options.router===!0,store:e.options.store===!0,eslint:e.options.eslint===!0};await B(s)}else{let s={template:typeof e.options.template=="string"?e.options.template:"spa"};await te(t,s)}}function gt(e){if(e.options.help){console.log(at);return}let t={port:typeof e.options.port=="string"?parseInt(e.options.port,10):typeof e.options.p=="string"?parseInt(e.options.p,10):3e3,hmr:e.options["no-hmr"]!==!0};(isNaN(t.port)||t.port<1||t.port>65535)&&(i.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1)),X(t)}async function ft(e){if(e.options.help){console.log(lt);return}let t={minify:e.options.minify===!0,outDir:typeof e.options.outDir=="string"?e.options.outDir:typeof e.options.o=="string"?e.options.o:"dist",entry:typeof e.options.entry=="string"?e.options.entry:"index.html"};await ce(t)}function ht(e){if(e.options.help){console.log(ct);return}let t=typeof e.options.port=="string"?parseInt(e.options.port,10):typeof e.options.p=="string"?parseInt(e.options.p,10):4173;(isNaN(t)||t<1||t>65535)&&(i.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1));let n=he.resolve(process.cwd(),"dist");fe.existsSync(n)||(i.error("\u672A\u627E\u5230\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55 dist/\uFF0C\u8BF7\u5148\u8FD0\u884C lytx build"),process.exit(1)),X({port:t,root:n,hmr:!1})}async function yt(){let e=ee(process.argv);if(e.options.version){pt();return}if(e.options.help&&!e.command){console.log(ge);return}e.command||(console.log(ge),process.exit(1));try{switch(e.command){case"create":await mt(e);break;case"dev":gt(e);break;case"build":await ft(e);break;case"preview":ht(e);break;case"generate":if(e.options.help){console.log(_);break}await ue(e.args);break;default:dt(e.command),process.exit(1)}}catch(t){let n=t instanceof Error?t.message:String(t);i.error(`\u6267\u884C\u5931\u8D25: ${n}`),console.log(""),console.log(` ${o("\u63D0\u793A:","brightYellow")} \u8BF7\u68C0\u67E5\u8F93\u5165\u53C2\u6570\u6216\u8FD0\u884C ${o("lytx --help","brightCyan")} \u67E5\u770B\u5E2E\u52A9`),console.log(""),process.exit(1)}}var rt,ye,st,ge,at,lt,ct,xe=P(()=>{"use strict";R();oe();q();le();pe();me();q();Z();rt="5.0.5",ye="lytx",st="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",ge=`
|
|
971
|
+
${o(ye,"brightCyan")} - ${st}
|
|
972
|
+
|
|
973
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
974
|
+
lytx <command> [options] [args]
|
|
975
|
+
|
|
976
|
+
${o("\u547D\u4EE4:","brightGreen")}
|
|
977
|
+
${o("create","brightYellow")} <name> \u521B\u5EFA\u4E00\u4E2A\u65B0\u7684 Lyt \u9879\u76EE
|
|
978
|
+
${o("dev","brightYellow")} \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
979
|
+
${o("build","brightYellow")} \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
980
|
+
${o("preview","brightYellow")} \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
981
|
+
${o("generate","brightYellow")} <type> <name> \u751F\u6210\u4EE3\u7801\uFF08\u7EC4\u4EF6\u3001Store\u3001\u9875\u9762\u3001API\uFF09
|
|
982
|
+
|
|
983
|
+
${o("\u5168\u5C40\u9009\u9879:","brightGreen")}
|
|
984
|
+
${o("-h, --help","brightYellow")} \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
|
|
985
|
+
${o("-v, --version","brightYellow")} \u663E\u793A\u7248\u672C\u53F7
|
|
986
|
+
|
|
987
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
988
|
+
${o("$","dim")} lytx create my-app
|
|
989
|
+
${o("$","dim")} lytx create my-app --template spa --ts --router --store
|
|
990
|
+
${o("$","dim")} lytx create my-todo --template todo-app
|
|
991
|
+
${o("$","dim")} lytx create my-admin --template admin-dashboard
|
|
992
|
+
${o("$","dim")} lytx dev
|
|
993
|
+
${o("$","dim")} lytx dev --port 8080 --hmr
|
|
994
|
+
${o("$","dim")} lytx build
|
|
995
|
+
${o("$","dim")} lytx build --mode ssr
|
|
996
|
+
${o("$","dim")} lytx preview --port 4173
|
|
997
|
+
|
|
998
|
+
`;at=`
|
|
999
|
+
${o("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
1000
|
+
|
|
1001
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
1002
|
+
lytx dev [options]
|
|
1003
|
+
|
|
1004
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
1005
|
+
${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 3000\uFF09
|
|
1006
|
+
${o("--hmr","brightYellow")} \u5F00\u542F\u70ED\u66F4\u65B0\uFF08\u9ED8\u8BA4: \u5F00\u542F\uFF09
|
|
1007
|
+
${o("--no-hmr","brightYellow")} \u5173\u95ED\u70ED\u66F4\u65B0
|
|
1008
|
+
|
|
1009
|
+
${o("\u529F\u80FD:","brightGreen")}
|
|
1010
|
+
- \u9759\u6001\u6587\u4EF6\u670D\u52A1
|
|
1011
|
+
- TypeScript \u5373\u65F6\u7F16\u8BD1
|
|
1012
|
+
- \u70ED\u6A21\u5757\u66FF\u6362\uFF08HMR\uFF09
|
|
1013
|
+
- WebSocket \u5B9E\u65F6\u901A\u4FE1
|
|
1014
|
+
|
|
1015
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
1016
|
+
${o("$","dim")} lytx dev
|
|
1017
|
+
${o("$","dim")} lytx dev --port 8080
|
|
1018
|
+
${o("$","dim")} lytx dev --no-hmr
|
|
1019
|
+
|
|
1020
|
+
`,lt=`
|
|
1021
|
+
${o("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
1022
|
+
|
|
1023
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
1024
|
+
lytx build [options]
|
|
1025
|
+
|
|
1026
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
1027
|
+
${o("--mode <mode>","brightYellow")} \u6784\u5EFA\u6A21\u5F0F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
1028
|
+
\u53EF\u9009\u503C: spa, ssr, ssg
|
|
1029
|
+
${o("--minify","brightYellow")} \u538B\u7F29\u4EE3\u7801\uFF08\u53BB\u9664\u7A7A\u767D\u548C\u6CE8\u91CA\uFF09
|
|
1030
|
+
${o("-o, --outDir <dir>","brightYellow")} \u8F93\u51FA\u76EE\u5F55\uFF08\u9ED8\u8BA4: dist\uFF09
|
|
1031
|
+
${o("--entry <file>","brightYellow")} \u5165\u53E3\u6587\u4EF6\uFF08\u9ED8\u8BA4: index.html\uFF09
|
|
1032
|
+
|
|
1033
|
+
${o("\u529F\u80FD:","brightGreen")}
|
|
1034
|
+
- TypeScript \u7F16\u8BD1
|
|
1035
|
+
- \u6A21\u5757\u6253\u5305\uFF08\u5185\u8054\u4F9D\u8D56\uFF09
|
|
1036
|
+
- \u53BB\u9664 console.log
|
|
1037
|
+
- Source Map \u751F\u6210
|
|
1038
|
+
- \u9759\u6001\u8D44\u6E90\u590D\u5236
|
|
1039
|
+
|
|
1040
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
1041
|
+
${o("$","dim")} lytx build
|
|
1042
|
+
${o("$","dim")} lytx build --mode ssr
|
|
1043
|
+
${o("$","dim")} lytx build --minify --outDir ./output
|
|
1044
|
+
|
|
1045
|
+
`,ct=`
|
|
1046
|
+
${o("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
1047
|
+
|
|
1048
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
1049
|
+
lytx preview [options]
|
|
1050
|
+
|
|
1051
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
1052
|
+
${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 4173\uFF09
|
|
1053
|
+
|
|
1054
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
1055
|
+
${o("$","dim")} lytx preview
|
|
1056
|
+
${o("$","dim")} lytx preview --port 5000
|
|
1057
|
+
|
|
1058
|
+
`;yt()});Promise.resolve().then(()=>xe());
|