@lytjs/cli 3.1.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/dist/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("./index.js")
package/dist/index.js ADDED
@@ -0,0 +1,483 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var se=Object.create;var F=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var pe=(e,t)=>{for(var n in t)F(e,n,{get:t[n],enumerable:!0})},N=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ae(t))!le.call(e,s)&&s!==n&&F(e,s,{get:()=>t[s],enumerable:!(r=ie(t,s))||r.enumerable});return e};var m=(e,t,n)=>(n=e!=null?se(ce(e)):{},N(t||!e||!e.__esModule?F(n,"default",{value:e,enumerable:!0}):n,e)),ue=e=>N(F({},"__esModule",{value:!0}),e);var ot={};pe(ot,{createHMREndpoint:()=>Z,createHMRServer:()=>Q,createProject:()=>B,getHMRClientScript:()=>ee});module.exports=ue(ot);var oe=m(require("fs")),ne=m(require("path"));var b=m(require("fs")),H=m(require("path")),fe="\x1B[0m",de={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"};function o(e,t){let n=de[t];return n?`${n}${e}${fe}`:e}function W(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 i=s.indexOf("=");if(i!==-1){let a=s.slice(2,i),c=s.slice(i+1);n.options[a]=c}else{let a=s.slice(2),c=t[r+1];c&&!c.startsWith("-")?(n.options[a]=c,r++):n.options[a]=!0}r++}else if(s.startsWith("-")&&s.length>1){let i=s.slice(1),a=t[r+1];a&&!a.startsWith("-")?(n.options[i]=a,r++):n.options[i]=!0,r++}else n.command?(n.args.push(s),r++):(n.command=s,r++)}return n}function $(e){b.existsSync(e)||b.mkdirSync(e,{recursive:!0})}function T(e){return b.existsSync(e)}function Y(e){return b.readFileSync(e,"utf-8")}function P(e,t){let n=H.dirname(e);$(n),b.writeFileSync(e,t,"utf-8")}function z(e){let t=H.extname(e).toLowerCase();return{".html":"text/html; charset=utf-8",".htm":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".cjs":"application/javascript; charset=utf-8",".ts":"application/javascript; charset=utf-8",".tsx":"application/javascript; charset=utf-8",".json":"application/json; charset=utf-8",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml; charset=utf-8",".ico":"image/x-icon",".webp":"image/webp",".bmp":"image/bmp",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject",".txt":"text/plain; charset=utf-8",".xml":"application/xml; charset=utf-8",".csv":"text/csv; charset=utf-8",".map":"application/json; charset=utf-8",".mp4":"video/mp4",".webm":"video/webm",".mp3":"audio/mpeg",".wav":"audio/wav",".pdf":"application/pdf",".zip":"application/zip",".gz":"application/gzip",".webmanifest":"application/manifest+json; charset=utf-8"}[t]||"application/octet-stream"}var l={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}`)}};var D=m(require("path"));function he(){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
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/src/main.ts"></script>
12
+ </body>
13
+ </html>
14
+ `}function me(){return`import { createApp } from 'lyt';
15
+ import App from './App';
16
+
17
+ // \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B
18
+ const app = createApp(App);
19
+
20
+ // \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20
21
+ app.mount('#app');
22
+ `}function ge(){return`import { defineComponent } from 'lyt';
23
+
24
+ // \u5B9A\u4E49\u6839\u7EC4\u4EF6
25
+ const App = defineComponent({
26
+ name: 'App',
27
+
28
+ // \u7EC4\u4EF6\u6A21\u677F
29
+ template: \`
30
+ <div class="app">
31
+ <h1>Hello Lyt!</h1>
32
+ <p>\u6B22\u8FCE\u4F7F\u7528 Lyt \u6846\u67B6</p>
33
+ </div>
34
+ \`,
35
+
36
+ // \u7EC4\u4EF6\u72B6\u6001
37
+ setup() {
38
+ const message: string = 'Hello World';
39
+
40
+ return {
41
+ message,
42
+ };
43
+ },
44
+ });
45
+
46
+ export default App;
47
+ `}function ye(){return`/* Lyt \u5168\u5C40\u6837\u5F0F */
48
+
49
+ * {
50
+ margin: 0;
51
+ padding: 0;
52
+ box-sizing: border-box;
53
+ }
54
+
55
+ body {
56
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
57
+ 'Helvetica Neue', Arial, sans-serif;
58
+ -webkit-font-smoothing: antialiased;
59
+ -moz-osx-font-smoothing: grayscale;
60
+ color: #2c3e50;
61
+ }
62
+
63
+ .app {
64
+ text-align: center;
65
+ padding: 40px 20px;
66
+ }
67
+
68
+ .app h1 {
69
+ font-size: 2.5rem;
70
+ color: #42b883;
71
+ margin-bottom: 10px;
72
+ }
73
+
74
+ .app p {
75
+ font-size: 1.2rem;
76
+ color: #666;
77
+ }
78
+ `}function be(e){return JSON.stringify({name:e,version:"0.1.0",private:!0,type:"module",scripts:{dev:"lyt dev",build:"lyt build",preview:"lyt preview"},dependencies:{lyt:"latest"},devDependencies:{typescript:"^5.0.0"}},null,2)+`
79
+ `}function xe(){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)+`
80
+ `}function ve(){return`# \u4F9D\u8D56
81
+ node_modules/
82
+
83
+ # \u6784\u5EFA\u8F93\u51FA
84
+ dist/
85
+
86
+ # \u7F16\u8F91\u5668\u914D\u7F6E
87
+ .vscode/
88
+ .idea/
89
+ *.swp
90
+ *.swo
91
+
92
+ # \u7CFB\u7EDF\u6587\u4EF6
93
+ .DS_Store
94
+ Thumbs.db
95
+
96
+ # \u73AF\u5883\u53D8\u91CF
97
+ .env.local
98
+ .env.*.local
99
+
100
+ # \u65E5\u5FD7
101
+ *.log
102
+ npm-debug.log*
103
+ `}async function _(e,t={}){let n=t.template||"spa",r=D.resolve(process.cwd(),e);l.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(e,"brightCyan")}`),l.info(`\u4F7F\u7528\u6A21\u677F: ${o(n,"brightCyan")}`),T(r)&&(l.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:he()},{filePath:"src/main.ts",content:me()},{filePath:"src/App.ts",content:ge()},{filePath:"src/style.css",content:ye()},{filePath:"package.json",content:be(e)},{filePath:"tsconfig.json",content:xe()},{filePath:".gitignore",content:ve()}];for(let i of s){let a=D.join(r,i.filePath);P(a,i.content),l.success(` \u521B\u5EFA ${i.filePath}`)}console.log(""),l.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 O=m(require("path"));function we(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:{lyt:"^2.0.0"}};return e.ts&&(t.devDependencies={typescript:"^5.0.0"}),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"]="^2.0.0"),e.store&&(t.dependencies["@lytjs/store"]="^2.0.0"),JSON.stringify(t,null,2)+`
104
+ `}function $e(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)+`
105
+ `}function Ce(e){let t=e.ts?".ts":".js";return`<!DOCTYPE html>
106
+ <html lang="zh-CN">
107
+ <head>
108
+ <meta charset="UTF-8" />
109
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
110
+ <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
111
+ <title>${e.name}</title>
112
+ </head>
113
+ <body>
114
+ <div id="app"></div>
115
+ <script type="module" src="/src/main${t}"></script>
116
+ </body>
117
+ </html>
118
+ `}function Se(e){let t=["// Lytx \u914D\u7F6E\u6587\u4EF6","import { defineConfig } from 'lyt'","","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(`
119
+ `)}function Pe(e){let t=e.ts?".ts":".js",n=["import { createApp } from 'lyt'","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(`
120
+ `)+`
121
+ `}function Me(){return`<template>
122
+ <div class="app">
123
+ <Header />
124
+ <main>
125
+ <h1>Hello Lyt!</h1>
126
+ <p>\u6B22\u8FCE\u4F7F\u7528 Lyt \u6846\u67B6</p>
127
+ </main>
128
+ </div>
129
+ </template>
130
+
131
+ <script lang="ts">
132
+ import { defineComponent } from 'lyt'
133
+ import Header from './components/Header'
134
+
135
+ export default defineComponent({
136
+ name: 'App',
137
+ components: {
138
+ Header,
139
+ },
140
+ })
141
+ </script>
142
+
143
+ <style scoped>
144
+ .app {
145
+ text-align: center;
146
+ padding: 20px;
147
+ }
148
+ </style>
149
+ `}function Ae(){return`import { defineComponent } from 'lyt'
150
+
151
+ export default defineComponent({
152
+ name: 'HomePage',
153
+
154
+ template: \`
155
+ <div class="page-home">
156
+ <h1>\u9996\u9875</h1>
157
+ <p>\u8FD9\u662F\u9996\u9875\u5185\u5BB9</p>
158
+ </div>
159
+ \`,
160
+ })
161
+ `}function je(){return`import { defineComponent } from 'lyt'
162
+
163
+ export default defineComponent({
164
+ name: 'AboutPage',
165
+
166
+ template: \`
167
+ <div class="page-about">
168
+ <h1>\u5173\u4E8E</h1>
169
+ <p>\u8FD9\u662F\u5173\u4E8E\u9875\u9762</p>
170
+ </div>
171
+ \`,
172
+ })
173
+ `}function Ee(){return`import { defineComponent } from 'lyt'
174
+
175
+ export default defineComponent({
176
+ name: 'Header',
177
+
178
+ template: \`
179
+ <header class="header">
180
+ <nav>
181
+ <a href="/">\u9996\u9875</a>
182
+ <a href="/about">\u5173\u4E8E</a>
183
+ </nav>
184
+ </header>
185
+ \`,
186
+ })
187
+ `}function Re(){return`import { createRouter, createWebHistory } from '@lytjs/router'
188
+ import HomePage from '../pages/index'
189
+ import AboutPage from '../pages/about'
190
+
191
+ export const router = createRouter({
192
+ history: createWebHistory(),
193
+ routes: [
194
+ {
195
+ path: '/',
196
+ component: HomePage,
197
+ },
198
+ {
199
+ path: '/about',
200
+ component: AboutPage,
201
+ },
202
+ ],
203
+ })
204
+ `}function ke(){return`import { createStore } from '@lytjs/store'
205
+
206
+ export const store = createStore({
207
+ state: {
208
+ count: 0,
209
+ message: 'Hello Lyt!',
210
+ },
211
+
212
+ mutations: {
213
+ increment(state: any) {
214
+ state.count++
215
+ },
216
+
217
+ setMessage(state: any, message: string) {
218
+ state.message = message
219
+ },
220
+ },
221
+
222
+ actions: {
223
+ async fetchMessage({ commit }: any) {
224
+ commit('setMessage', 'Fetched from API')
225
+ },
226
+ },
227
+
228
+ getters: {
229
+ doubleCount: (state: any) => state.count * 2,
230
+ },
231
+ })
232
+ `}function Fe(){return`/* \u5168\u5C40\u6837\u5F0F */
233
+
234
+ * {
235
+ margin: 0;
236
+ padding: 0;
237
+ box-sizing: border-box;
238
+ }
239
+
240
+ body {
241
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
242
+ 'Helvetica Neue', Arial, sans-serif;
243
+ -webkit-font-smoothing: antialiased;
244
+ -moz-osx-font-smoothing: grayscale;
245
+ color: #2c3e50;
246
+ }
247
+
248
+ a {
249
+ color: #42b883;
250
+ text-decoration: none;
251
+ }
252
+
253
+ a:hover {
254
+ text-decoration: underline;
255
+ }
256
+ `}function He(){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
257
+ <rect width="32" height="32" rx="6" fill="#42b883"/>
258
+ <text x="16" y="22" text-anchor="middle" fill="white" font-size="18" font-weight="bold">L</text>
259
+ </svg>
260
+ `}function Te(){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)+`
261
+ `}async function B(e){let{name:t,template:n,ts:r,router:s,store:i,eslint:a}=e,c=O.resolve(process.cwd(),t);if(l.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(t,"brightCyan")}`),l.info(`\u4F7F\u7528\u6A21\u677F: ${o(n,"brightCyan")}`),T(c))throw l.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`);$(c);let p=[{filePath:"package.json",content:we(e)},{filePath:"index.html",content:Ce(e)},{filePath:"lytx.config.ts",content:Se(e)},{filePath:"src/main.ts",content:Pe(e)},{filePath:"src/App.lyt",content:Me()},{filePath:"src/pages/index.ts",content:Ae()},{filePath:"src/pages/about.ts",content:je()},{filePath:"src/components/Header.ts",content:Ee()},{filePath:"src/styles/main.css",content:Fe()},{filePath:"public/favicon.svg",content:He()}];r&&p.push({filePath:"tsconfig.json",content:$e(e)}),s&&p.push({filePath:"src/router/index.ts",content:Re()}),i&&p.push({filePath:"src/store/index.ts",content:ke()}),a&&p.push({filePath:".eslintrc.json",content:Te()});for(let u of p){let f=O.join(c,u.filePath);P(f,u.content),l.success(` \u521B\u5EFA ${u.filePath}`)}console.log(""),l.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 J=m(require("http")),C=m(require("fs")),g=m(require("path")),q=m(require("crypto"));var De=require("esbuild");function Oe(e,t){try{return De.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}}var I=class{constructor(){this.clients=[]}handleUpgrade(t,n,r){let s=t.headers["sec-websocket-key"];if(!s){n.destroy();return}let i=q.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");n.write(`HTTP/1.1 101 Switching Protocols\r
262
+ Upgrade: websocket\r
263
+ Connection: Upgrade\r
264
+ Sec-WebSocket-Accept: ${i}\r
265
+ \r
266
+ `);let a={socket:n,isAlive:!0};n.on("close",()=>{this.clients=this.clients.filter(c=>c!==a)}),n.on("error",()=>{this.clients=this.clients.filter(c=>c!==a)}),this.clients.push(a),l.info("WebSocket \u5BA2\u6237\u7AEF\u5DF2\u8FDE\u63A5")}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"),i=this.createFrame(129,s);r.socket.write(i)}catch(s){n.push(r)}for(let r of n)this.clients=this.clients.filter(s=>s!==r),r.socket.destroy()}createFrame(t,n){let s=n.length,i;s<126?i=2:s<65536?i=4:i=10;let a=Buffer.alloc(i+s);return a[0]=t,s<126?a[1]=s:s<65536?(a[1]=126,a.writeUInt16BE(s,2)):(a[1]=127,a.writeUInt32BE(0,2),a.writeUInt32BE(s,6)),n.copy(a,i),a}getClientCount(){return this.clients.length}};function Be(e,t){let n=new Set([".ts",".tsx",".js",".jsx",".css",".html",".json"]);function r(s){try{let i=C.readdirSync(s,{withFileTypes:!0});for(let a of i){let c=g.join(s,a.name);if(a.isDirectory()){if(a.name==="node_modules"||a.name===".git"||a.name==="dist")continue;r(c)}else if(a.isFile()){let p=g.extname(a.name);n.has(p)&&C.watch(c,{persistent:!1},u=>{if(u==="change"){let f=g.relative(e,c);l.info(`\u6587\u4EF6\u53D8\u5316: ${o(f,"brightYellow")}`);let d=JSON.stringify({type:"hmr-update",path:`/${f}`,timestamp:Date.now()});t.broadcast(d)}})}}}catch(i){}}r(e),l.info(`\u6B63\u5728\u76D1\u542C ${o(e,"brightCyan")} \u76EE\u5F55\u7684\u6587\u4EF6\u53D8\u5316...`)}function Le(e,t){let n=e.url||"/";if(n==="/favicon.ico")return{statusCode:204,headers:{},body:""};let r=n.split("?")[0],s=g.normalize(r).replace(/^(\.\.[\/\\])+/,""),i=g.join(t,s);try{C.statSync(i).isDirectory()&&(i=g.join(i,"index.html"))}catch(a){}try{let a=C.readFileSync(i),c=g.extname(i);if(c===".ts"||c===".tsx"){let u=a.toString("utf-8"),f=Oe(u,i);return{statusCode:200,headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-cache, no-store, must-revalidate","Access-Control-Allow-Origin":"*"},body:f}}return{statusCode:200,headers:{"Content-Type":z(i),"Cache-Control":c===".html"?"no-cache":"public, max-age=3600","Access-Control-Allow-Origin":"*"},body:a}}catch(a){let c=a.code;return c==="ENOENT"?{statusCode:404,headers:{"Content-Type":"text/html; charset=utf-8"},body:`<!DOCTYPE html>
267
+ <html>
268
+ <head><title>404 Not Found</title></head>
269
+ <body>
270
+ <h1>404 Not Found</h1>
271
+ <p>\u627E\u4E0D\u5230\u6587\u4EF6: ${r}</p>
272
+ </body>
273
+ </html>`}:c==="EACCES"?{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"}:{statusCode:500,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"500 Internal Server Error"}}}function U(e={}){let t=e.port||3e3,n=g.resolve(e.root||process.cwd()),r=e.hmr!==!1,s=new I,i=J.createServer((c,p)=>{let u=Le(c,n);p.writeHead(u.statusCode,u.headers),p.end(u.body)});r&&i.on("upgrade",(c,p,u)=>{s.handleUpgrade(c,p,u)}),i.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\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\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("")}),i.on("error",c=>{c.code==="EADDRINUSE"?(l.error(`\u7AEF\u53E3 ${t} \u5DF2\u88AB\u5360\u7528\uFF0C\u8BF7\u4F7F\u7528 --port \u6307\u5B9A\u5176\u4ED6\u7AEF\u53E3`),process.exit(1)):(l.error(`\u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25: ${c.message}`),process.exit(1))}),r&&Be(n,s);let a=()=>{l.info("\u6B63\u5728\u5173\u95ED\u5F00\u53D1\u670D\u52A1\u5668..."),i.close(()=>{l.success("\u670D\u52A1\u5668\u5DF2\u5173\u95ED"),process.exit(0)}),setTimeout(()=>{l.warn("\u670D\u52A1\u5668\u5173\u95ED\u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(1)},5e3)};process.on("SIGINT",a),process.on("SIGTERM",a)}var y=m(require("fs")),h=m(require("path"));var Ie=require("esbuild");async function V(e={}){let t=Date.now(),n=h.resolve(e.root||process.cwd()),r=h.resolve(n,e.outDir||"dist"),s=e.entry||"index.html",i=e.minify||!1;l.info("\u5F00\u59CB\u6784\u5EFA\u9879\u76EE..."),l.info(` \u6839\u76EE\u5F55: ${o(n,"brightCyan")}`),l.info(` \u8F93\u51FA\u76EE\u5F55: ${o(r,"brightCyan")}`),l.info(` \u538B\u7F29: ${o(i?"\u5F00\u542F":"\u5173\u95ED",i?"brightGreen":"brightYellow")}`);let a=h.join(n,s);y.existsSync(a)||(l.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${a}`),process.exit(1));let c=Y(a),p=/<script\s+type="module"\s+src="([^"]+)"\s*><\/script>/g,u,f=[];for(;(u=p.exec(c))!==null;)f.push(u[1]);f.length===0&&l.warn("\u672A\u5728\u5165\u53E3 HTML \u4E2D\u627E\u5230\u6A21\u5757\u811A\u672C\u5F15\u7528");let d={inputFiles:0,outputFiles:0,totalSize:0,buildTime:0};$(r),$(h.join(r,"assets"));for(let v of f){let E=h.join(n,v);if(!y.existsSync(E)){l.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${v}`);continue}l.info(`\u6B63\u5728\u6253\u5305: ${o(v,"brightYellow")}`);let R=`${h.basename(v,h.extname(v))}.bundle.js`,M=h.join(r,"assets",R);try{await Ie.build({entryPoints:[E],bundle:!0,minify:i,target:"es2018",format:"esm",outfile:M,sourcemap:!0,external:k=>k.startsWith("@lytjs/"),drop:i?["console"]:[],metafile:!0});let w=y.readFileSync(M,"utf-8");d.totalSize+=Buffer.byteLength(w,"utf-8"),d.outputFiles++;let S=M+".map";if(y.existsSync(S)){let k=y.readFileSync(S,"utf-8");d.totalSize+=Buffer.byteLength(k,"utf-8"),d.outputFiles++}c=c.replace(`<script type="module" src="${v}"></script>`,`<script src="/assets/${R}"></script>`),d.inputFiles++}catch(w){let S=w instanceof Error?w.message:String(w);l.error(`\u6253\u5305\u5931\u8D25 ${v}: ${S}`),process.exit(1)}}Ue(n,r,d);let j=h.join(r,"index.html");P(j,c),d.outputFiles++,d.totalSize+=Buffer.byteLength(c,"utf-8"),d.buildTime=Date.now()-t,console.log(""),l.success("\u6784\u5EFA\u5B8C\u6210\uFF01"),console.log(""),console.log(` ${o("\u8F93\u5165\u6587\u4EF6:","brightWhite")} ${d.inputFiles} \u4E2A`),console.log(` ${o("\u8F93\u51FA\u6587\u4EF6:","brightWhite")} ${d.outputFiles} \u4E2A`),console.log(` ${o("\u603B\u5927\u5C0F:","brightWhite")} ${Ge(d.totalSize)}`),console.log(` ${o("\u6784\u5EFA\u8017\u65F6:","brightWhite")} ${d.buildTime}ms`),console.log(` ${o("\u8F93\u51FA\u76EE\u5F55:","brightWhite")} ${o(r,"brightCyan")}`),console.log("")}function Ue(e,t,n){let r=h.join(e,"src");if(!y.existsSync(r))return;function s(i,a){let c=y.readdirSync(i,{withFileTypes:!0});for(let p of c){let u=h.join(i,p.name);if(p.isDirectory()){if(p.name==="node_modules")continue;s(u,a)}else if(p.isFile()){let f=h.extname(p.name);if([".ts",".tsx",".js",".jsx"].includes(f))continue;let d=h.relative(a,u),j=h.join(t,d);P(j,y.readFileSync(u).toString("utf-8")),n.outputFiles++,n.totalSize+=y.statSync(u).size}}}s(r,r)}function Ge(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 K=m(require("http")),A=m(require("fs")),x=m(require("path")),X=m(require("crypto")),L=class{constructor(){this.clients=[]}handleUpgrade(t,n,r){let s=t.headers["sec-websocket-key"];if(!s){n.destroy();return}let i=X.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");n.write(`HTTP/1.1 101 Switching Protocols\r
274
+ Upgrade: websocket\r
275
+ Connection: Upgrade\r
276
+ Sec-WebSocket-Accept: ${i}\r
277
+ \r
278
+ `);let a={socket:n,isAlive:!0};n.on("close",()=>{this.clients=this.clients.filter(c=>c!==a)}),n.on("error",()=>{this.clients=this.clients.filter(c=>c!==a)}),this.clients.push(a)}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"),i=this.createFrame(129,s);r.socket.write(i)}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 i=Buffer.alloc(s+r);return i[0]=t,r<126?i[1]=r:r<65536?(i[1]=126,i.writeUInt16BE(r,2)):(i[1]=127,i.writeUInt32BE(0,2),i.writeUInt32BE(r,6)),n.copy(i,s),i}getClientCount(){return this.clients.length}closeAll(){for(let t of this.clients)try{t.socket.destroy()}catch(n){}this.clients=[]}};function Q(e){let t=new L,n=[],r=[],s=null,i=!1;function a(p){let u=x.extname(p).toLowerCase();if(u===".css")return"css";let f=x.basename(p);return f.startsWith("lytx.config")||f==="tsconfig.json"||f==="package.json"?"reload":u===".ts"||u===".tsx"||u===".lyt"||u===".js"||u===".jsx"?"update":"reload"}function c(p){try{let u=A.readdirSync(p,{withFileTypes:!0});for(let f of u){let d=x.join(p,f.name);if(f.isDirectory()){if(f.name==="node_modules"||f.name===".git"||f.name==="dist")continue;c(d)}else if(f.isFile()){let j=x.extname(f.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(j))try{let E=A.watch(d,{persistent:!1},G=>{if(G==="change"){let R=x.relative(e,d);for(let S of n)try{S(R)}catch(k){}let M=a(d),w={type:M,path:`/${R}`};if(M==="css")try{w.content=A.readFileSync(d,"utf-8")}catch(S){}t.broadcast(JSON.stringify(w))}});r.push(E)}catch(E){}}}}catch(u){}}return{start(p){i||(i=!0,s=K.createServer((u,f)=>{f.writeHead(426,{"Content-Type":"text/plain"}),f.end("Upgrade Required")}),s.on("upgrade",(u,f,d)=>{t.handleUpgrade(u,f,d)}),s.listen(p,()=>{}),c(e))},stop(){i=!1;for(let p of r)try{p.close()}catch(u){}if(r.length=0,t.closeAll(),s){try{s.close()}catch(p){}s=null}},onFileChange(p){n.push(p)},notifyClient(p){t.broadcast(JSON.stringify(p))}}}function Z(e){let t=new L;return e.on("upgrade",(n,r,s)=>{t.handleUpgrade(n,r,s)}),{broadcast(n){t.broadcast(n)},getClientCount(){return t.getClientCount()}}}function ee(){return`(function() {
279
+ 'use strict';
280
+
281
+ var ws = null;
282
+ var reconnectTimer = null;
283
+ var reconnectAttempts = 0;
284
+ var maxReconnectAttempts = 10;
285
+
286
+ function connect() {
287
+ var protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
288
+ var wsUrl = protocol + '//' + location.host + '/__hmr__';
289
+ ws = new WebSocket(wsUrl);
290
+
291
+ ws.onopen = function() {
292
+ reconnectAttempts = 0;
293
+ console.log('[HMR] Connected');
294
+ };
295
+
296
+ ws.onmessage = function(event) {
297
+ try {
298
+ var update = JSON.parse(event.data);
299
+
300
+ if (update.type === 'css') {
301
+ handleCSSUpdate(update);
302
+ } else if (update.type === 'update') {
303
+ handleModuleUpdate(update);
304
+ } else if (update.type === 'reload') {
305
+ handleFullReload(update);
306
+ }
307
+ } catch (e) {
308
+ console.error('[HMR] Failed to parse update:', e);
309
+ }
310
+ };
311
+
312
+ ws.onclose = function() {
313
+ console.log('[HMR] Disconnected');
314
+ scheduleReconnect();
315
+ };
316
+
317
+ ws.onerror = function() {
318
+ ws.close();
319
+ };
320
+ }
321
+
322
+ function scheduleReconnect() {
323
+ if (reconnectAttempts >= maxReconnectAttempts) {
324
+ console.log('[HMR] Max reconnect attempts reached');
325
+ return;
326
+ }
327
+ reconnectAttempts++;
328
+ var delay = Math.min(1000 * Math.pow(2, reconnectAttempts), 30000);
329
+ console.log('[HMR] Reconnecting in ' + delay + 'ms (attempt ' + reconnectAttempts + ')');
330
+ reconnectTimer = setTimeout(connect, delay);
331
+ }
332
+
333
+ function handleCSSUpdate(update) {
334
+ console.log('[HMR] CSS update:', update.path);
335
+ // \u67E5\u627E\u6240\u6709 link[rel="stylesheet"] \u5E76\u91CD\u65B0\u52A0\u8F7D
336
+ var links = document.querySelectorAll('link[rel="stylesheet"]');
337
+ links.forEach(function(link) {
338
+ var href = link.getAttribute('href');
339
+ if (href && href.indexOf(update.path) !== -1) {
340
+ var newLink = document.createElement('link');
341
+ newLink.rel = 'stylesheet';
342
+ newLink.href = href + (href.indexOf('?') !== -1 ? '&' : '?') + 't=' + Date.now();
343
+ link.parentNode.replaceChild(newLink, link);
344
+ }
345
+ });
346
+
347
+ // \u5982\u679C\u6709\u5185\u8054 CSS \u5185\u5BB9\uFF0C\u76F4\u63A5\u6CE8\u5165
348
+ if (update.content) {
349
+ var style = document.createElement('style');
350
+ style.textContent = update.content;
351
+ document.head.appendChild(style);
352
+ }
353
+ }
354
+
355
+ function handleModuleUpdate(update) {
356
+ console.log('[HMR] Module update:', update.path);
357
+ // \u5C1D\u8BD5\u70ED\u66F4\u65B0\u6A21\u5757
358
+ if (typeof module !== 'undefined' && module.hot) {
359
+ module.hot.accept(update.path, function() {
360
+ console.log('[HMR] Module accepted:', update.path);
361
+ });
362
+ } else {
363
+ // \u56DE\u9000\u5230\u5168\u91CF\u5237\u65B0
364
+ console.log('[HMR] Full reload (module.hot not available)');
365
+ location.reload();
366
+ }
367
+ }
368
+
369
+ function handleFullReload(update) {
370
+ console.log('[HMR] Full reload:', update.path);
371
+ location.reload();
372
+ }
373
+
374
+ // \u542F\u52A8\u8FDE\u63A5
375
+ connect();
376
+ })();`}var Ne="0.2.0",re="lytx",We="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",te=`
377
+ ${o(re,"brightCyan")} - ${We}
378
+
379
+ ${o("\u7528\u6CD5:","brightGreen")}
380
+ lytx <command> [options] [args]
381
+
382
+ ${o("\u547D\u4EE4:","brightGreen")}
383
+ ${o("create","brightYellow")} <name> \u521B\u5EFA\u4E00\u4E2A\u65B0\u7684 Lyt \u9879\u76EE
384
+ ${o("dev","brightYellow")} \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
385
+ ${o("build","brightYellow")} \u6784\u5EFA\u751F\u4EA7\u7248\u672C
386
+ ${o("preview","brightYellow")} \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
387
+
388
+ ${o("\u5168\u5C40\u9009\u9879:","brightGreen")}
389
+ ${o("-h, --help","brightYellow")} \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
390
+ ${o("-v, --version","brightYellow")} \u663E\u793A\u7248\u672C\u53F7
391
+
392
+ ${o("\u793A\u4F8B:","brightGreen")}
393
+ ${o("$","dim")} lytx create my-app
394
+ ${o("$","dim")} lytx create my-app --template spa --ts --router --store
395
+ ${o("$","dim")} lytx dev
396
+ ${o("$","dim")} lytx dev --port 8080 --hmr
397
+ ${o("$","dim")} lytx build
398
+ ${o("$","dim")} lytx build --mode ssr
399
+ ${o("$","dim")} lytx preview --port 4173
400
+
401
+ `,Ye=`
402
+ ${o("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
403
+
404
+ ${o("\u7528\u6CD5:","brightGreen")}
405
+ lytx create <name> [options]
406
+
407
+ ${o("\u53C2\u6570:","brightGreen")}
408
+ ${o("<name>","brightYellow")} \u9879\u76EE\u540D\u79F0\uFF08\u540C\u65F6\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF09
409
+
410
+ ${o("\u9009\u9879:","brightGreen")}
411
+ ${o("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
412
+ \u53EF\u9009\u503C: spa, ssr, ssg
413
+ ${o("--ts","brightYellow")} \u4F7F\u7528 TypeScript
414
+ ${o("--router","brightYellow")} \u5305\u542B\u8DEF\u7531
415
+ ${o("--store","brightYellow")} \u5305\u542B\u72B6\u6001\u7BA1\u7406
416
+ ${o("--eslint","brightYellow")} \u5305\u542B ESLint \u914D\u7F6E
417
+
418
+ ${o("\u793A\u4F8B:","brightGreen")}
419
+ ${o("$","dim")} lytx create my-app
420
+ ${o("$","dim")} lytx create my-app --template spa --ts --router --store
421
+ ${o("$","dim")} lytx create my-app --template ssr --ts
422
+
423
+ `,ze=`
424
+ ${o("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
425
+
426
+ ${o("\u7528\u6CD5:","brightGreen")}
427
+ lytx dev [options]
428
+
429
+ ${o("\u9009\u9879:","brightGreen")}
430
+ ${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 3000\uFF09
431
+ ${o("--hmr","brightYellow")} \u5F00\u542F\u70ED\u66F4\u65B0\uFF08\u9ED8\u8BA4: \u5F00\u542F\uFF09
432
+ ${o("--no-hmr","brightYellow")} \u5173\u95ED\u70ED\u66F4\u65B0
433
+
434
+ ${o("\u529F\u80FD:","brightGreen")}
435
+ - \u9759\u6001\u6587\u4EF6\u670D\u52A1
436
+ - TypeScript \u5373\u65F6\u7F16\u8BD1
437
+ - \u70ED\u6A21\u5757\u66FF\u6362\uFF08HMR\uFF09
438
+ - WebSocket \u5B9E\u65F6\u901A\u4FE1
439
+
440
+ ${o("\u793A\u4F8B:","brightGreen")}
441
+ ${o("$","dim")} lytx dev
442
+ ${o("$","dim")} lytx dev --port 8080
443
+ ${o("$","dim")} lytx dev --no-hmr
444
+
445
+ `,_e=`
446
+ ${o("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
447
+
448
+ ${o("\u7528\u6CD5:","brightGreen")}
449
+ lytx build [options]
450
+
451
+ ${o("\u9009\u9879:","brightGreen")}
452
+ ${o("--mode <mode>","brightYellow")} \u6784\u5EFA\u6A21\u5F0F\uFF08\u9ED8\u8BA4: spa\uFF09
453
+ \u53EF\u9009\u503C: spa, ssr, ssg
454
+ ${o("--minify","brightYellow")} \u538B\u7F29\u4EE3\u7801\uFF08\u53BB\u9664\u7A7A\u767D\u548C\u6CE8\u91CA\uFF09
455
+ ${o("-o, --outDir <dir>","brightYellow")} \u8F93\u51FA\u76EE\u5F55\uFF08\u9ED8\u8BA4: dist\uFF09
456
+ ${o("--entry <file>","brightYellow")} \u5165\u53E3\u6587\u4EF6\uFF08\u9ED8\u8BA4: index.html\uFF09
457
+
458
+ ${o("\u529F\u80FD:","brightGreen")}
459
+ - TypeScript \u7F16\u8BD1
460
+ - \u6A21\u5757\u6253\u5305\uFF08\u5185\u8054\u4F9D\u8D56\uFF09
461
+ - \u53BB\u9664 console.log
462
+ - Source Map \u751F\u6210
463
+ - \u9759\u6001\u8D44\u6E90\u590D\u5236
464
+
465
+ ${o("\u793A\u4F8B:","brightGreen")}
466
+ ${o("$","dim")} lytx build
467
+ ${o("$","dim")} lytx build --mode ssr
468
+ ${o("$","dim")} lytx build --minify --outDir ./output
469
+
470
+ `,Je=`
471
+ ${o("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
472
+
473
+ ${o("\u7528\u6CD5:","brightGreen")}
474
+ lytx preview [options]
475
+
476
+ ${o("\u9009\u9879:","brightGreen")}
477
+ ${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 4173\uFF09
478
+
479
+ ${o("\u793A\u4F8B:","brightGreen")}
480
+ ${o("$","dim")} lytx preview
481
+ ${o("$","dim")} lytx preview --port 5000
482
+
483
+ `;function qe(){console.log(""),console.log(` ${o(re,"brightCyan")} v${o(Ne,"brightWhite")}`),console.log("")}function Ve(e){l.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 Ke(e){return typeof e=="string"&&["spa","ssr","ssg"].includes(e)?e:"spa"}async function Xe(e){if(e.options.help){console.log(Ye);return}e.args.length===0&&(l.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];if(e.options.ts===!0||e.options.router===!0||e.options.store===!0||e.options.eslint===!0||typeof e.options.template=="string"&&["ssr","ssg"].includes(e.options.template)){let r={name:t,template:Ke(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(r)}else{let r={template:typeof e.options.template=="string"?e.options.template:"spa"};await _(t,r)}}function Qe(e){if(e.options.help){console.log(ze);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)&&(l.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1)),U(t)}async function Ze(e){if(e.options.help){console.log(_e);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 V(t)}function et(e){if(e.options.help){console.log(Je);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)&&(l.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1));let n=ne.resolve(process.cwd(),"dist");oe.existsSync(n)||(l.error("\u672A\u627E\u5230\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55 dist/\uFF0C\u8BF7\u5148\u8FD0\u884C lytx build"),process.exit(1)),U({port:t,root:n,hmr:!1})}async function tt(){let e=W(process.argv);if(e.options.version){qe();return}if(e.options.help&&!e.command){console.log(te);return}e.command||(console.log(te),process.exit(1));try{switch(e.command){case"create":await Xe(e);break;case"dev":Qe(e);break;case"build":await Ze(e);break;case"preview":et(e);break;default:Ve(e.command),process.exit(1)}}catch(t){let n=t instanceof Error?t.message:String(t);l.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)}}tt();0&&(module.exports={createHMREndpoint,createHMRServer,createProject,getHMRClientScript});
package/dist/index.mjs ADDED
@@ -0,0 +1,483 @@
1
+ #!/usr/bin/env node
2
+ var U=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(o,n)=>(typeof require!="undefined"?require:o)[n]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import*as X from"fs";import*as Q from"path";import*as y from"fs";import*as k from"path";var ee="\x1B[0m",te={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"};function t(e,o){let n=te[o];return n?`${n}${e}${ee}`:e}function G(e){let o=e.slice(2),n={command:"",args:[],options:{},raw:o},r=0;for(;r<o.length;){let s=o[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 i=s.indexOf("=");if(i!==-1){let a=s.slice(2,i),c=s.slice(i+1);n.options[a]=c}else{let a=s.slice(2),c=o[r+1];c&&!c.startsWith("-")?(n.options[a]=c,r++):n.options[a]=!0}r++}else if(s.startsWith("-")&&s.length>1){let i=s.slice(1),a=o[r+1];a&&!a.startsWith("-")?(n.options[i]=a,r++):n.options[i]=!0,r++}else n.command?(n.args.push(s),r++):(n.command=s,r++)}return n}function w(e){y.existsSync(e)||y.mkdirSync(e,{recursive:!0})}function F(e){return y.existsSync(e)}function N(e){return y.readFileSync(e,"utf-8")}function S(e,o){let n=k.dirname(e);w(n),y.writeFileSync(e,o,"utf-8")}function W(e){let o=k.extname(e).toLowerCase();return{".html":"text/html; charset=utf-8",".htm":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".cjs":"application/javascript; charset=utf-8",".ts":"application/javascript; charset=utf-8",".tsx":"application/javascript; charset=utf-8",".json":"application/json; charset=utf-8",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml; charset=utf-8",".ico":"image/x-icon",".webp":"image/webp",".bmp":"image/bmp",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject",".txt":"text/plain; charset=utf-8",".xml":"application/xml; charset=utf-8",".csv":"text/csv; charset=utf-8",".map":"application/json; charset=utf-8",".mp4":"video/mp4",".webm":"video/webm",".mp3":"audio/mpeg",".wav":"audio/wav",".pdf":"application/pdf",".zip":"application/zip",".gz":"application/gzip",".webmanifest":"application/manifest+json; charset=utf-8"}[o]||"application/octet-stream"}var l={info(e){console.log(`${t("[INFO]","blue")} ${e}`)},warn(e){console.log(`${t("[WARN]","yellow")} ${e}`)},error(e){console.error(`${t("[ERROR]","red")} ${e}`)},success(e){console.log(`${t("[SUCCESS]","green")} ${e}`)}};import*as H from"path";function oe(){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
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/src/main.ts"></script>
12
+ </body>
13
+ </html>
14
+ `}function ne(){return`import { createApp } from 'lyt';
15
+ import App from './App';
16
+
17
+ // \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B
18
+ const app = createApp(App);
19
+
20
+ // \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20
21
+ app.mount('#app');
22
+ `}function re(){return`import { defineComponent } from 'lyt';
23
+
24
+ // \u5B9A\u4E49\u6839\u7EC4\u4EF6
25
+ const App = defineComponent({
26
+ name: 'App',
27
+
28
+ // \u7EC4\u4EF6\u6A21\u677F
29
+ template: \`
30
+ <div class="app">
31
+ <h1>Hello Lyt!</h1>
32
+ <p>\u6B22\u8FCE\u4F7F\u7528 Lyt \u6846\u67B6</p>
33
+ </div>
34
+ \`,
35
+
36
+ // \u7EC4\u4EF6\u72B6\u6001
37
+ setup() {
38
+ const message: string = 'Hello World';
39
+
40
+ return {
41
+ message,
42
+ };
43
+ },
44
+ });
45
+
46
+ export default App;
47
+ `}function se(){return`/* Lyt \u5168\u5C40\u6837\u5F0F */
48
+
49
+ * {
50
+ margin: 0;
51
+ padding: 0;
52
+ box-sizing: border-box;
53
+ }
54
+
55
+ body {
56
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
57
+ 'Helvetica Neue', Arial, sans-serif;
58
+ -webkit-font-smoothing: antialiased;
59
+ -moz-osx-font-smoothing: grayscale;
60
+ color: #2c3e50;
61
+ }
62
+
63
+ .app {
64
+ text-align: center;
65
+ padding: 40px 20px;
66
+ }
67
+
68
+ .app h1 {
69
+ font-size: 2.5rem;
70
+ color: #42b883;
71
+ margin-bottom: 10px;
72
+ }
73
+
74
+ .app p {
75
+ font-size: 1.2rem;
76
+ color: #666;
77
+ }
78
+ `}function ie(e){return JSON.stringify({name:e,version:"0.1.0",private:!0,type:"module",scripts:{dev:"lyt dev",build:"lyt build",preview:"lyt preview"},dependencies:{lyt:"latest"},devDependencies:{typescript:"^5.0.0"}},null,2)+`
79
+ `}function ae(){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)+`
80
+ `}function ce(){return`# \u4F9D\u8D56
81
+ node_modules/
82
+
83
+ # \u6784\u5EFA\u8F93\u51FA
84
+ dist/
85
+
86
+ # \u7F16\u8F91\u5668\u914D\u7F6E
87
+ .vscode/
88
+ .idea/
89
+ *.swp
90
+ *.swo
91
+
92
+ # \u7CFB\u7EDF\u6587\u4EF6
93
+ .DS_Store
94
+ Thumbs.db
95
+
96
+ # \u73AF\u5883\u53D8\u91CF
97
+ .env.local
98
+ .env.*.local
99
+
100
+ # \u65E5\u5FD7
101
+ *.log
102
+ npm-debug.log*
103
+ `}async function Y(e,o={}){let n=o.template||"spa",r=H.resolve(process.cwd(),e);l.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${t(e,"brightCyan")}`),l.info(`\u4F7F\u7528\u6A21\u677F: ${t(n,"brightCyan")}`),F(r)&&(l.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)),w(r);let s=[{filePath:"index.html",content:oe()},{filePath:"src/main.ts",content:ne()},{filePath:"src/App.ts",content:re()},{filePath:"src/style.css",content:se()},{filePath:"package.json",content:ie(e)},{filePath:"tsconfig.json",content:ae()},{filePath:".gitignore",content:ce()}];for(let i of s){let a=H.join(r,i.filePath);S(a,i.content),l.success(` \u521B\u5EFA ${i.filePath}`)}console.log(""),l.success(`\u9879\u76EE ${t(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(` ${t("cd","brightGreen")} ${e}`),console.log(` ${t("npm install","brightGreen")}`),console.log(` ${t("npm run dev","brightGreen")}`),console.log("")}import*as T from"path";function le(e){let o={name:e.name,version:"0.1.0",private:!0,type:"module",scripts:{dev:"lytx dev",build:"lytx build",preview:"lytx preview"},dependencies:{lyt:"^2.0.0"}};return e.ts&&(o.devDependencies={typescript:"^5.0.0"}),e.eslint&&(o.devDependencies=o.devDependencies||{},o.devDependencies.eslint="^8.0.0",o.scripts=o.scripts||{},o.scripts.lint="eslint src --ext .ts,.js"),e.router&&(o.dependencies["@lytjs/router"]="^2.0.0"),e.store&&(o.dependencies["@lytjs/store"]="^2.0.0"),JSON.stringify(o,null,2)+`
104
+ `}function pe(e){let o={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"&&(o.compilerOptions.types=["node"]),JSON.stringify(o,null,2)+`
105
+ `}function ue(e){let o=e.ts?".ts":".js";return`<!DOCTYPE html>
106
+ <html lang="zh-CN">
107
+ <head>
108
+ <meta charset="UTF-8" />
109
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
110
+ <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
111
+ <title>${e.name}</title>
112
+ </head>
113
+ <body>
114
+ <div id="app"></div>
115
+ <script type="module" src="/src/main${o}"></script>
116
+ </body>
117
+ </html>
118
+ `}function fe(e){let o=["// Lytx \u914D\u7F6E\u6587\u4EF6","import { defineConfig } from 'lyt'","","export default defineConfig({"," // \u6784\u5EFA\u6A21\u5F0F",` mode: '${e.template}',`];return e.router&&(o.push(" // \u8DEF\u7531\u914D\u7F6E"),o.push(" router: {"),o.push(" historyMode: true,"),o.push(" },")),e.store&&(o.push(" // \u72B6\u6001\u7BA1\u7406\u914D\u7F6E"),o.push(" store: {"),o.push(" strict: true,"),o.push(" },")),o.push("})"),o.push(""),o.join(`
119
+ `)}function de(e){let o=e.ts?".ts":".js",n=["import { createApp } from 'lyt'","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(`
120
+ `)+`
121
+ `}function he(){return`<template>
122
+ <div class="app">
123
+ <Header />
124
+ <main>
125
+ <h1>Hello Lyt!</h1>
126
+ <p>\u6B22\u8FCE\u4F7F\u7528 Lyt \u6846\u67B6</p>
127
+ </main>
128
+ </div>
129
+ </template>
130
+
131
+ <script lang="ts">
132
+ import { defineComponent } from 'lyt'
133
+ import Header from './components/Header'
134
+
135
+ export default defineComponent({
136
+ name: 'App',
137
+ components: {
138
+ Header,
139
+ },
140
+ })
141
+ </script>
142
+
143
+ <style scoped>
144
+ .app {
145
+ text-align: center;
146
+ padding: 20px;
147
+ }
148
+ </style>
149
+ `}function me(){return`import { defineComponent } from 'lyt'
150
+
151
+ export default defineComponent({
152
+ name: 'HomePage',
153
+
154
+ template: \`
155
+ <div class="page-home">
156
+ <h1>\u9996\u9875</h1>
157
+ <p>\u8FD9\u662F\u9996\u9875\u5185\u5BB9</p>
158
+ </div>
159
+ \`,
160
+ })
161
+ `}function ge(){return`import { defineComponent } from 'lyt'
162
+
163
+ export default defineComponent({
164
+ name: 'AboutPage',
165
+
166
+ template: \`
167
+ <div class="page-about">
168
+ <h1>\u5173\u4E8E</h1>
169
+ <p>\u8FD9\u662F\u5173\u4E8E\u9875\u9762</p>
170
+ </div>
171
+ \`,
172
+ })
173
+ `}function ye(){return`import { defineComponent } from 'lyt'
174
+
175
+ export default defineComponent({
176
+ name: 'Header',
177
+
178
+ template: \`
179
+ <header class="header">
180
+ <nav>
181
+ <a href="/">\u9996\u9875</a>
182
+ <a href="/about">\u5173\u4E8E</a>
183
+ </nav>
184
+ </header>
185
+ \`,
186
+ })
187
+ `}function be(){return`import { createRouter, createWebHistory } from '@lytjs/router'
188
+ import HomePage from '../pages/index'
189
+ import AboutPage from '../pages/about'
190
+
191
+ export const router = createRouter({
192
+ history: createWebHistory(),
193
+ routes: [
194
+ {
195
+ path: '/',
196
+ component: HomePage,
197
+ },
198
+ {
199
+ path: '/about',
200
+ component: AboutPage,
201
+ },
202
+ ],
203
+ })
204
+ `}function xe(){return`import { createStore } from '@lytjs/store'
205
+
206
+ export const store = createStore({
207
+ state: {
208
+ count: 0,
209
+ message: 'Hello Lyt!',
210
+ },
211
+
212
+ mutations: {
213
+ increment(state: any) {
214
+ state.count++
215
+ },
216
+
217
+ setMessage(state: any, message: string) {
218
+ state.message = message
219
+ },
220
+ },
221
+
222
+ actions: {
223
+ async fetchMessage({ commit }: any) {
224
+ commit('setMessage', 'Fetched from API')
225
+ },
226
+ },
227
+
228
+ getters: {
229
+ doubleCount: (state: any) => state.count * 2,
230
+ },
231
+ })
232
+ `}function ve(){return`/* \u5168\u5C40\u6837\u5F0F */
233
+
234
+ * {
235
+ margin: 0;
236
+ padding: 0;
237
+ box-sizing: border-box;
238
+ }
239
+
240
+ body {
241
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
242
+ 'Helvetica Neue', Arial, sans-serif;
243
+ -webkit-font-smoothing: antialiased;
244
+ -moz-osx-font-smoothing: grayscale;
245
+ color: #2c3e50;
246
+ }
247
+
248
+ a {
249
+ color: #42b883;
250
+ text-decoration: none;
251
+ }
252
+
253
+ a:hover {
254
+ text-decoration: underline;
255
+ }
256
+ `}function we(){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
257
+ <rect width="32" height="32" rx="6" fill="#42b883"/>
258
+ <text x="16" y="22" text-anchor="middle" fill="white" font-size="18" font-weight="bold">L</text>
259
+ </svg>
260
+ `}function $e(){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)+`
261
+ `}async function O(e){let{name:o,template:n,ts:r,router:s,store:i,eslint:a}=e,c=T.resolve(process.cwd(),o);if(l.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${t(o,"brightCyan")}`),l.info(`\u4F7F\u7528\u6A21\u677F: ${t(n,"brightCyan")}`),F(c))throw l.error(`\u76EE\u5F55 "${o}" \u5DF2\u5B58\u5728\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u540D\u79F0\u6216\u5220\u9664\u5DF2\u6709\u76EE\u5F55`),new Error(`Directory "${o}" already exists`);w(c);let p=[{filePath:"package.json",content:le(e)},{filePath:"index.html",content:ue(e)},{filePath:"lytx.config.ts",content:fe(e)},{filePath:"src/main.ts",content:de(e)},{filePath:"src/App.lyt",content:he()},{filePath:"src/pages/index.ts",content:me()},{filePath:"src/pages/about.ts",content:ge()},{filePath:"src/components/Header.ts",content:ye()},{filePath:"src/styles/main.css",content:ve()},{filePath:"public/favicon.svg",content:we()}];r&&p.push({filePath:"tsconfig.json",content:pe(e)}),s&&p.push({filePath:"src/router/index.ts",content:be()}),i&&p.push({filePath:"src/store/index.ts",content:xe()}),a&&p.push({filePath:".eslintrc.json",content:$e()});for(let u of p){let f=T.join(c,u.filePath);S(f,u.content),l.success(` \u521B\u5EFA ${u.filePath}`)}console.log(""),l.success(`\u9879\u76EE ${t(o,"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(` ${t("cd","brightGreen")} ${o}`),console.log(` ${t("npm install","brightGreen")}`),console.log(` ${t("npm run dev","brightGreen")}`),console.log("")}import*as z from"http";import*as $ from"fs";import*as m from"path";import*as _ from"crypto";var Ce=U("esbuild");function Se(e,o){try{return Ce.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 ${o||""}:`,r),e}}var B=class{constructor(){this.clients=[]}handleUpgrade(o,n,r){let s=o.headers["sec-websocket-key"];if(!s){n.destroy();return}let i=_.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");n.write(`HTTP/1.1 101 Switching Protocols\r
262
+ Upgrade: websocket\r
263
+ Connection: Upgrade\r
264
+ Sec-WebSocket-Accept: ${i}\r
265
+ \r
266
+ `);let a={socket:n,isAlive:!0};n.on("close",()=>{this.clients=this.clients.filter(c=>c!==a)}),n.on("error",()=>{this.clients=this.clients.filter(c=>c!==a)}),this.clients.push(a),l.info("WebSocket \u5BA2\u6237\u7AEF\u5DF2\u8FDE\u63A5")}broadcast(o){let n=[];for(let r of this.clients)try{if(!r.isAlive){n.push(r);continue}let s=Buffer.from(o,"utf-8"),i=this.createFrame(129,s);r.socket.write(i)}catch(s){n.push(r)}for(let r of n)this.clients=this.clients.filter(s=>s!==r),r.socket.destroy()}createFrame(o,n){let s=n.length,i;s<126?i=2:s<65536?i=4:i=10;let a=Buffer.alloc(i+s);return a[0]=o,s<126?a[1]=s:s<65536?(a[1]=126,a.writeUInt16BE(s,2)):(a[1]=127,a.writeUInt32BE(0,2),a.writeUInt32BE(s,6)),n.copy(a,i),a}getClientCount(){return this.clients.length}};function Pe(e,o){let n=new Set([".ts",".tsx",".js",".jsx",".css",".html",".json"]);function r(s){try{let i=$.readdirSync(s,{withFileTypes:!0});for(let a of i){let c=m.join(s,a.name);if(a.isDirectory()){if(a.name==="node_modules"||a.name===".git"||a.name==="dist")continue;r(c)}else if(a.isFile()){let p=m.extname(a.name);n.has(p)&&$.watch(c,{persistent:!1},u=>{if(u==="change"){let f=m.relative(e,c);l.info(`\u6587\u4EF6\u53D8\u5316: ${t(f,"brightYellow")}`);let d=JSON.stringify({type:"hmr-update",path:`/${f}`,timestamp:Date.now()});o.broadcast(d)}})}}}catch(i){}}r(e),l.info(`\u6B63\u5728\u76D1\u542C ${t(e,"brightCyan")} \u76EE\u5F55\u7684\u6587\u4EF6\u53D8\u5316...`)}function Me(e,o){let n=e.url||"/";if(n==="/favicon.ico")return{statusCode:204,headers:{},body:""};let r=n.split("?")[0],s=m.normalize(r).replace(/^(\.\.[\/\\])+/,""),i=m.join(o,s);try{$.statSync(i).isDirectory()&&(i=m.join(i,"index.html"))}catch(a){}try{let a=$.readFileSync(i),c=m.extname(i);if(c===".ts"||c===".tsx"){let u=a.toString("utf-8"),f=Se(u,i);return{statusCode:200,headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-cache, no-store, must-revalidate","Access-Control-Allow-Origin":"*"},body:f}}return{statusCode:200,headers:{"Content-Type":W(i),"Cache-Control":c===".html"?"no-cache":"public, max-age=3600","Access-Control-Allow-Origin":"*"},body:a}}catch(a){let c=a.code;return c==="ENOENT"?{statusCode:404,headers:{"Content-Type":"text/html; charset=utf-8"},body:`<!DOCTYPE html>
267
+ <html>
268
+ <head><title>404 Not Found</title></head>
269
+ <body>
270
+ <h1>404 Not Found</h1>
271
+ <p>\u627E\u4E0D\u5230\u6587\u4EF6: ${r}</p>
272
+ </body>
273
+ </html>`}:c==="EACCES"?{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"}:{statusCode:500,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"500 Internal Server Error"}}}function L(e={}){let o=e.port||3e3,n=m.resolve(e.root||process.cwd()),r=e.hmr!==!1,s=new B,i=z.createServer((c,p)=>{let u=Me(c,n);p.writeHead(u.statusCode,u.headers),p.end(u.body)});r&&i.on("upgrade",(c,p,u)=>{s.handleUpgrade(c,p,u)}),i.listen(o,()=>{console.log(""),console.log(t(" \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\u2557","brightCyan")),console.log(t(" \u2551","brightCyan")+t(" Lyt \u5F00\u53D1\u670D\u52A1\u5668\u5DF2\u542F\u52A8 ","brightWhite")+t("\u2551","brightCyan")),console.log(t(" \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\u255D","brightCyan")),console.log(""),console.log(` ${t("\u279C","brightGreen")} \u672C\u5730\u8BBF\u95EE: ${t(`http://localhost:${o}`,"brightBlue")}`),console.log(` ${t("\u279C","brightGreen")} \u7F51\u7EDC\u8BBF\u95EE: ${t(`http://127.0.0.1:${o}`,"brightBlue")}`),console.log(` ${t("\u279C","brightGreen")} \u9879\u76EE\u76EE\u5F55: ${t(n,"brightBlue")}`),console.log(` ${t("\u279C","brightGreen")} \u70ED\u66F4\u65B0: ${t(r?"\u5DF2\u5F00\u542F":"\u5DF2\u5173\u95ED",r?"brightGreen":"brightRed")}`),console.log(""),console.log(` ${t("\u6309 Ctrl+C \u505C\u6B62\u670D\u52A1\u5668","dim")}`),console.log("")}),i.on("error",c=>{c.code==="EADDRINUSE"?(l.error(`\u7AEF\u53E3 ${o} \u5DF2\u88AB\u5360\u7528\uFF0C\u8BF7\u4F7F\u7528 --port \u6307\u5B9A\u5176\u4ED6\u7AEF\u53E3`),process.exit(1)):(l.error(`\u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25: ${c.message}`),process.exit(1))}),r&&Pe(n,s);let a=()=>{l.info("\u6B63\u5728\u5173\u95ED\u5F00\u53D1\u670D\u52A1\u5668..."),i.close(()=>{l.success("\u670D\u52A1\u5668\u5DF2\u5173\u95ED"),process.exit(0)}),setTimeout(()=>{l.warn("\u670D\u52A1\u5668\u5173\u95ED\u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(1)},5e3)};process.on("SIGINT",a),process.on("SIGTERM",a)}import*as g from"fs";import*as h from"path";var Ae=U("esbuild");async function J(e={}){let o=Date.now(),n=h.resolve(e.root||process.cwd()),r=h.resolve(n,e.outDir||"dist"),s=e.entry||"index.html",i=e.minify||!1;l.info("\u5F00\u59CB\u6784\u5EFA\u9879\u76EE..."),l.info(` \u6839\u76EE\u5F55: ${t(n,"brightCyan")}`),l.info(` \u8F93\u51FA\u76EE\u5F55: ${t(r,"brightCyan")}`),l.info(` \u538B\u7F29: ${t(i?"\u5F00\u542F":"\u5173\u95ED",i?"brightGreen":"brightYellow")}`);let a=h.join(n,s);g.existsSync(a)||(l.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${a}`),process.exit(1));let c=N(a),p=/<script\s+type="module"\s+src="([^"]+)"\s*><\/script>/g,u,f=[];for(;(u=p.exec(c))!==null;)f.push(u[1]);f.length===0&&l.warn("\u672A\u5728\u5165\u53E3 HTML \u4E2D\u627E\u5230\u6A21\u5757\u811A\u672C\u5F15\u7528");let d={inputFiles:0,outputFiles:0,totalSize:0,buildTime:0};w(r),w(h.join(r,"assets"));for(let x of f){let j=h.join(n,x);if(!g.existsSync(j)){l.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${x}`);continue}l.info(`\u6B63\u5728\u6253\u5305: ${t(x,"brightYellow")}`);let E=`${h.basename(x,h.extname(x))}.bundle.js`,P=h.join(r,"assets",E);try{await Ae.build({entryPoints:[j],bundle:!0,minify:i,target:"es2018",format:"esm",outfile:P,sourcemap:!0,external:R=>R.startsWith("@lytjs/"),drop:i?["console"]:[],metafile:!0});let v=g.readFileSync(P,"utf-8");d.totalSize+=Buffer.byteLength(v,"utf-8"),d.outputFiles++;let C=P+".map";if(g.existsSync(C)){let R=g.readFileSync(C,"utf-8");d.totalSize+=Buffer.byteLength(R,"utf-8"),d.outputFiles++}c=c.replace(`<script type="module" src="${x}"></script>`,`<script src="/assets/${E}"></script>`),d.inputFiles++}catch(v){let C=v instanceof Error?v.message:String(v);l.error(`\u6253\u5305\u5931\u8D25 ${x}: ${C}`),process.exit(1)}}je(n,r,d);let A=h.join(r,"index.html");S(A,c),d.outputFiles++,d.totalSize+=Buffer.byteLength(c,"utf-8"),d.buildTime=Date.now()-o,console.log(""),l.success("\u6784\u5EFA\u5B8C\u6210\uFF01"),console.log(""),console.log(` ${t("\u8F93\u5165\u6587\u4EF6:","brightWhite")} ${d.inputFiles} \u4E2A`),console.log(` ${t("\u8F93\u51FA\u6587\u4EF6:","brightWhite")} ${d.outputFiles} \u4E2A`),console.log(` ${t("\u603B\u5927\u5C0F:","brightWhite")} ${Ee(d.totalSize)}`),console.log(` ${t("\u6784\u5EFA\u8017\u65F6:","brightWhite")} ${d.buildTime}ms`),console.log(` ${t("\u8F93\u51FA\u76EE\u5F55:","brightWhite")} ${t(r,"brightCyan")}`),console.log("")}function je(e,o,n){let r=h.join(e,"src");if(!g.existsSync(r))return;function s(i,a){let c=g.readdirSync(i,{withFileTypes:!0});for(let p of c){let u=h.join(i,p.name);if(p.isDirectory()){if(p.name==="node_modules")continue;s(u,a)}else if(p.isFile()){let f=h.extname(p.name);if([".ts",".tsx",".js",".jsx"].includes(f))continue;let d=h.relative(a,u),A=h.join(o,d);S(A,g.readFileSync(u).toString("utf-8")),n.outputFiles++,n.totalSize+=g.statSync(u).size}}}s(r,r)}function Ee(e){if(e===0)return"0 B";let o=["B","KB","MB","GB"],n=1024,r=Math.floor(Math.log(e)/Math.log(n));return`${(e/Math.pow(n,r)).toFixed(2)} ${o[r]}`}import*as q from"http";import*as M from"fs";import*as b from"path";import*as V from"crypto";var D=class{constructor(){this.clients=[]}handleUpgrade(o,n,r){let s=o.headers["sec-websocket-key"];if(!s){n.destroy();return}let i=V.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");n.write(`HTTP/1.1 101 Switching Protocols\r
274
+ Upgrade: websocket\r
275
+ Connection: Upgrade\r
276
+ Sec-WebSocket-Accept: ${i}\r
277
+ \r
278
+ `);let a={socket:n,isAlive:!0};n.on("close",()=>{this.clients=this.clients.filter(c=>c!==a)}),n.on("error",()=>{this.clients=this.clients.filter(c=>c!==a)}),this.clients.push(a)}broadcast(o){let n=[];for(let r of this.clients)try{if(!r.isAlive){n.push(r);continue}let s=Buffer.from(o,"utf-8"),i=this.createFrame(129,s);r.socket.write(i)}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(o,n){let r=n.length,s;r<126?s=2:r<65536?s=4:s=10;let i=Buffer.alloc(s+r);return i[0]=o,r<126?i[1]=r:r<65536?(i[1]=126,i.writeUInt16BE(r,2)):(i[1]=127,i.writeUInt32BE(0,2),i.writeUInt32BE(r,6)),n.copy(i,s),i}getClientCount(){return this.clients.length}closeAll(){for(let o of this.clients)try{o.socket.destroy()}catch(n){}this.clients=[]}};function Re(e){let o=new D,n=[],r=[],s=null,i=!1;function a(p){let u=b.extname(p).toLowerCase();if(u===".css")return"css";let f=b.basename(p);return f.startsWith("lytx.config")||f==="tsconfig.json"||f==="package.json"?"reload":u===".ts"||u===".tsx"||u===".lyt"||u===".js"||u===".jsx"?"update":"reload"}function c(p){try{let u=M.readdirSync(p,{withFileTypes:!0});for(let f of u){let d=b.join(p,f.name);if(f.isDirectory()){if(f.name==="node_modules"||f.name===".git"||f.name==="dist")continue;c(d)}else if(f.isFile()){let A=b.extname(f.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(A))try{let j=M.watch(d,{persistent:!1},I=>{if(I==="change"){let E=b.relative(e,d);for(let C of n)try{C(E)}catch(R){}let P=a(d),v={type:P,path:`/${E}`};if(P==="css")try{v.content=M.readFileSync(d,"utf-8")}catch(C){}o.broadcast(JSON.stringify(v))}});r.push(j)}catch(j){}}}}catch(u){}}return{start(p){i||(i=!0,s=q.createServer((u,f)=>{f.writeHead(426,{"Content-Type":"text/plain"}),f.end("Upgrade Required")}),s.on("upgrade",(u,f,d)=>{o.handleUpgrade(u,f,d)}),s.listen(p,()=>{}),c(e))},stop(){i=!1;for(let p of r)try{p.close()}catch(u){}if(r.length=0,o.closeAll(),s){try{s.close()}catch(p){}s=null}},onFileChange(p){n.push(p)},notifyClient(p){o.broadcast(JSON.stringify(p))}}}function ke(e){let o=new D;return e.on("upgrade",(n,r,s)=>{o.handleUpgrade(n,r,s)}),{broadcast(n){o.broadcast(n)},getClientCount(){return o.getClientCount()}}}function Fe(){return`(function() {
279
+ 'use strict';
280
+
281
+ var ws = null;
282
+ var reconnectTimer = null;
283
+ var reconnectAttempts = 0;
284
+ var maxReconnectAttempts = 10;
285
+
286
+ function connect() {
287
+ var protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
288
+ var wsUrl = protocol + '//' + location.host + '/__hmr__';
289
+ ws = new WebSocket(wsUrl);
290
+
291
+ ws.onopen = function() {
292
+ reconnectAttempts = 0;
293
+ console.log('[HMR] Connected');
294
+ };
295
+
296
+ ws.onmessage = function(event) {
297
+ try {
298
+ var update = JSON.parse(event.data);
299
+
300
+ if (update.type === 'css') {
301
+ handleCSSUpdate(update);
302
+ } else if (update.type === 'update') {
303
+ handleModuleUpdate(update);
304
+ } else if (update.type === 'reload') {
305
+ handleFullReload(update);
306
+ }
307
+ } catch (e) {
308
+ console.error('[HMR] Failed to parse update:', e);
309
+ }
310
+ };
311
+
312
+ ws.onclose = function() {
313
+ console.log('[HMR] Disconnected');
314
+ scheduleReconnect();
315
+ };
316
+
317
+ ws.onerror = function() {
318
+ ws.close();
319
+ };
320
+ }
321
+
322
+ function scheduleReconnect() {
323
+ if (reconnectAttempts >= maxReconnectAttempts) {
324
+ console.log('[HMR] Max reconnect attempts reached');
325
+ return;
326
+ }
327
+ reconnectAttempts++;
328
+ var delay = Math.min(1000 * Math.pow(2, reconnectAttempts), 30000);
329
+ console.log('[HMR] Reconnecting in ' + delay + 'ms (attempt ' + reconnectAttempts + ')');
330
+ reconnectTimer = setTimeout(connect, delay);
331
+ }
332
+
333
+ function handleCSSUpdate(update) {
334
+ console.log('[HMR] CSS update:', update.path);
335
+ // \u67E5\u627E\u6240\u6709 link[rel="stylesheet"] \u5E76\u91CD\u65B0\u52A0\u8F7D
336
+ var links = document.querySelectorAll('link[rel="stylesheet"]');
337
+ links.forEach(function(link) {
338
+ var href = link.getAttribute('href');
339
+ if (href && href.indexOf(update.path) !== -1) {
340
+ var newLink = document.createElement('link');
341
+ newLink.rel = 'stylesheet';
342
+ newLink.href = href + (href.indexOf('?') !== -1 ? '&' : '?') + 't=' + Date.now();
343
+ link.parentNode.replaceChild(newLink, link);
344
+ }
345
+ });
346
+
347
+ // \u5982\u679C\u6709\u5185\u8054 CSS \u5185\u5BB9\uFF0C\u76F4\u63A5\u6CE8\u5165
348
+ if (update.content) {
349
+ var style = document.createElement('style');
350
+ style.textContent = update.content;
351
+ document.head.appendChild(style);
352
+ }
353
+ }
354
+
355
+ function handleModuleUpdate(update) {
356
+ console.log('[HMR] Module update:', update.path);
357
+ // \u5C1D\u8BD5\u70ED\u66F4\u65B0\u6A21\u5757
358
+ if (typeof module !== 'undefined' && module.hot) {
359
+ module.hot.accept(update.path, function() {
360
+ console.log('[HMR] Module accepted:', update.path);
361
+ });
362
+ } else {
363
+ // \u56DE\u9000\u5230\u5168\u91CF\u5237\u65B0
364
+ console.log('[HMR] Full reload (module.hot not available)');
365
+ location.reload();
366
+ }
367
+ }
368
+
369
+ function handleFullReload(update) {
370
+ console.log('[HMR] Full reload:', update.path);
371
+ location.reload();
372
+ }
373
+
374
+ // \u542F\u52A8\u8FDE\u63A5
375
+ connect();
376
+ })();`}var He="0.2.0",Z="lytx",Te="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",K=`
377
+ ${t(Z,"brightCyan")} - ${Te}
378
+
379
+ ${t("\u7528\u6CD5:","brightGreen")}
380
+ lytx <command> [options] [args]
381
+
382
+ ${t("\u547D\u4EE4:","brightGreen")}
383
+ ${t("create","brightYellow")} <name> \u521B\u5EFA\u4E00\u4E2A\u65B0\u7684 Lyt \u9879\u76EE
384
+ ${t("dev","brightYellow")} \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
385
+ ${t("build","brightYellow")} \u6784\u5EFA\u751F\u4EA7\u7248\u672C
386
+ ${t("preview","brightYellow")} \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
387
+
388
+ ${t("\u5168\u5C40\u9009\u9879:","brightGreen")}
389
+ ${t("-h, --help","brightYellow")} \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
390
+ ${t("-v, --version","brightYellow")} \u663E\u793A\u7248\u672C\u53F7
391
+
392
+ ${t("\u793A\u4F8B:","brightGreen")}
393
+ ${t("$","dim")} lytx create my-app
394
+ ${t("$","dim")} lytx create my-app --template spa --ts --router --store
395
+ ${t("$","dim")} lytx dev
396
+ ${t("$","dim")} lytx dev --port 8080 --hmr
397
+ ${t("$","dim")} lytx build
398
+ ${t("$","dim")} lytx build --mode ssr
399
+ ${t("$","dim")} lytx preview --port 4173
400
+
401
+ `,De=`
402
+ ${t("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
403
+
404
+ ${t("\u7528\u6CD5:","brightGreen")}
405
+ lytx create <name> [options]
406
+
407
+ ${t("\u53C2\u6570:","brightGreen")}
408
+ ${t("<name>","brightYellow")} \u9879\u76EE\u540D\u79F0\uFF08\u540C\u65F6\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF09
409
+
410
+ ${t("\u9009\u9879:","brightGreen")}
411
+ ${t("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
412
+ \u53EF\u9009\u503C: spa, ssr, ssg
413
+ ${t("--ts","brightYellow")} \u4F7F\u7528 TypeScript
414
+ ${t("--router","brightYellow")} \u5305\u542B\u8DEF\u7531
415
+ ${t("--store","brightYellow")} \u5305\u542B\u72B6\u6001\u7BA1\u7406
416
+ ${t("--eslint","brightYellow")} \u5305\u542B ESLint \u914D\u7F6E
417
+
418
+ ${t("\u793A\u4F8B:","brightGreen")}
419
+ ${t("$","dim")} lytx create my-app
420
+ ${t("$","dim")} lytx create my-app --template spa --ts --router --store
421
+ ${t("$","dim")} lytx create my-app --template ssr --ts
422
+
423
+ `,Oe=`
424
+ ${t("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
425
+
426
+ ${t("\u7528\u6CD5:","brightGreen")}
427
+ lytx dev [options]
428
+
429
+ ${t("\u9009\u9879:","brightGreen")}
430
+ ${t("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 3000\uFF09
431
+ ${t("--hmr","brightYellow")} \u5F00\u542F\u70ED\u66F4\u65B0\uFF08\u9ED8\u8BA4: \u5F00\u542F\uFF09
432
+ ${t("--no-hmr","brightYellow")} \u5173\u95ED\u70ED\u66F4\u65B0
433
+
434
+ ${t("\u529F\u80FD:","brightGreen")}
435
+ - \u9759\u6001\u6587\u4EF6\u670D\u52A1
436
+ - TypeScript \u5373\u65F6\u7F16\u8BD1
437
+ - \u70ED\u6A21\u5757\u66FF\u6362\uFF08HMR\uFF09
438
+ - WebSocket \u5B9E\u65F6\u901A\u4FE1
439
+
440
+ ${t("\u793A\u4F8B:","brightGreen")}
441
+ ${t("$","dim")} lytx dev
442
+ ${t("$","dim")} lytx dev --port 8080
443
+ ${t("$","dim")} lytx dev --no-hmr
444
+
445
+ `,Be=`
446
+ ${t("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
447
+
448
+ ${t("\u7528\u6CD5:","brightGreen")}
449
+ lytx build [options]
450
+
451
+ ${t("\u9009\u9879:","brightGreen")}
452
+ ${t("--mode <mode>","brightYellow")} \u6784\u5EFA\u6A21\u5F0F\uFF08\u9ED8\u8BA4: spa\uFF09
453
+ \u53EF\u9009\u503C: spa, ssr, ssg
454
+ ${t("--minify","brightYellow")} \u538B\u7F29\u4EE3\u7801\uFF08\u53BB\u9664\u7A7A\u767D\u548C\u6CE8\u91CA\uFF09
455
+ ${t("-o, --outDir <dir>","brightYellow")} \u8F93\u51FA\u76EE\u5F55\uFF08\u9ED8\u8BA4: dist\uFF09
456
+ ${t("--entry <file>","brightYellow")} \u5165\u53E3\u6587\u4EF6\uFF08\u9ED8\u8BA4: index.html\uFF09
457
+
458
+ ${t("\u529F\u80FD:","brightGreen")}
459
+ - TypeScript \u7F16\u8BD1
460
+ - \u6A21\u5757\u6253\u5305\uFF08\u5185\u8054\u4F9D\u8D56\uFF09
461
+ - \u53BB\u9664 console.log
462
+ - Source Map \u751F\u6210
463
+ - \u9759\u6001\u8D44\u6E90\u590D\u5236
464
+
465
+ ${t("\u793A\u4F8B:","brightGreen")}
466
+ ${t("$","dim")} lytx build
467
+ ${t("$","dim")} lytx build --mode ssr
468
+ ${t("$","dim")} lytx build --minify --outDir ./output
469
+
470
+ `,Le=`
471
+ ${t("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
472
+
473
+ ${t("\u7528\u6CD5:","brightGreen")}
474
+ lytx preview [options]
475
+
476
+ ${t("\u9009\u9879:","brightGreen")}
477
+ ${t("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 4173\uFF09
478
+
479
+ ${t("\u793A\u4F8B:","brightGreen")}
480
+ ${t("$","dim")} lytx preview
481
+ ${t("$","dim")} lytx preview --port 5000
482
+
483
+ `;function Ie(){console.log(""),console.log(` ${t(Z,"brightCyan")} v${t(He,"brightWhite")}`),console.log("")}function Ue(e){l.error(`\u672A\u77E5\u547D\u4EE4: ${t(e,"brightRed")}`),console.log(""),console.log(` \u8FD0\u884C ${t("lytx --help","brightCyan")} \u67E5\u770B\u53EF\u7528\u547D\u4EE4`),console.log("")}function Ge(e){return typeof e=="string"&&["spa","ssr","ssg"].includes(e)?e:"spa"}async function Ne(e){if(e.options.help){console.log(De);return}e.args.length===0&&(l.error("\u8BF7\u63D0\u4F9B\u9879\u76EE\u540D\u79F0"),console.log(""),console.log(` \u7528\u6CD5: ${t("lytx create <name>","brightCyan")}`),console.log(""),console.log(` \u8FD0\u884C ${t("lytx create --help","brightCyan")} \u67E5\u770B\u66F4\u591A\u9009\u9879`),console.log(""),process.exit(1));let o=e.args[0];if(e.options.ts===!0||e.options.router===!0||e.options.store===!0||e.options.eslint===!0||typeof e.options.template=="string"&&["ssr","ssg"].includes(e.options.template)){let r={name:o,template:Ge(e.options.template),ts:e.options.ts===!0,router:e.options.router===!0,store:e.options.store===!0,eslint:e.options.eslint===!0};await O(r)}else{let r={template:typeof e.options.template=="string"?e.options.template:"spa"};await Y(o,r)}}function We(e){if(e.options.help){console.log(Oe);return}let o={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(o.port)||o.port<1||o.port>65535)&&(l.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1)),L(o)}async function Ye(e){if(e.options.help){console.log(Be);return}let o={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 J(o)}function ze(e){if(e.options.help){console.log(Le);return}let o=typeof e.options.port=="string"?parseInt(e.options.port,10):typeof e.options.p=="string"?parseInt(e.options.p,10):4173;(isNaN(o)||o<1||o>65535)&&(l.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1));let n=Q.resolve(process.cwd(),"dist");X.existsSync(n)||(l.error("\u672A\u627E\u5230\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55 dist/\uFF0C\u8BF7\u5148\u8FD0\u884C lytx build"),process.exit(1)),L({port:o,root:n,hmr:!1})}async function _e(){let e=G(process.argv);if(e.options.version){Ie();return}if(e.options.help&&!e.command){console.log(K);return}e.command||(console.log(K),process.exit(1));try{switch(e.command){case"create":await Ne(e);break;case"dev":We(e);break;case"build":await Ye(e);break;case"preview":ze(e);break;default:Ue(e.command),process.exit(1)}}catch(o){let n=o instanceof Error?o.message:String(o);l.error(`\u6267\u884C\u5931\u8D25: ${n}`),console.log(""),console.log(` ${t("\u63D0\u793A:","brightYellow")} \u8BF7\u68C0\u67E5\u8F93\u5165\u53C2\u6570\u6216\u8FD0\u884C ${t("lytx --help","brightCyan")} \u67E5\u770B\u5E2E\u52A9`),console.log(""),process.exit(1)}}_e();export{ke as createHMREndpoint,Re as createHMRServer,O as createProject,Fe as getHMRClientScript};
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@lytjs/cli",
3
+ "version": "3.1.0",
4
+ "description": "Lyt.js 命令行工具 - 提供项目创建、开发服务器和构建功能",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/types/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js",
13
+ "default": "./dist/index.mjs"
14
+ }
15
+ },
16
+ "bin": {
17
+ "lyt": "dist/cli.js"
18
+ },
19
+ "sideEffects": false,
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "license": "MIT",
24
+ "author": "lytjs",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://gitee.com/lytjs/lytjs"
28
+ },
29
+ "homepage": "https://gitee.com/lytjs/lytjs",
30
+ "keywords": [
31
+ "lyt",
32
+ "lytjs",
33
+ "javascript",
34
+ "framework",
35
+ "frontend",
36
+ "vue-like",
37
+ "lightweight",
38
+ "zero-dependency",
39
+ "cli",
40
+ "scaffold",
41
+ "dev-server",
42
+ "build"
43
+ ],
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }