@lytjs/cli 4.1.0 → 4.2.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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var ne=Object.create;var F=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var le=(e,o)=>{for(var r in o)F(e,r,{get:o[r],enumerable:!0})},N=(e,o,r,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of ie(o))!ce.call(e,s)&&s!==r&&F(e,s,{get:()=>o[s],enumerable:!(n=se(o,s))||n.enumerable});return e};var h=(e,o,r)=>(r=e!=null?ne(ae(e)):{},N(o||!e||!e.__esModule?F(r,"default",{value:e,enumerable:!0}):r,e)),pe=e=>N(F({},"__esModule",{value:!0}),e);var Ze={};le(Ze,{createHMREndpoint:()=>G,createHMRServer:()=>V,createProject:()=>O,getHMRClientScript:()=>B});module.exports=pe(Ze);var te=h(require("fs")),oe=h(require("path"));var v=h(require("fs")),U=h(require("path")),ue="\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 t(e,o){let r=de[o];return r?`${r}${e}${ue}`:e}function Y(e){let o=e.slice(2),r={command:"",args:[],options:{},raw:o},n=0;for(;n<o.length;){let s=o[n];if(s==="--help"||s==="-h")r.options.help=!0,n++;else if(s==="--version"||s==="-v")r.options.version=!0,n++;else if(s.startsWith("--")){let c=s.indexOf("=");if(c!==-1){let d=s.slice(2,c),p=s.slice(c+1);r.options[d]=p}else{let d=s.slice(2),p=o[n+1];p&&!p.startsWith("-")?(r.options[d]=p,n++):r.options[d]=!0}n++}else if(s.startsWith("-")&&s.length>1){let c=s.slice(1),d=o[n+1];d&&!d.startsWith("-")?(r.options[c]=d,n++):r.options[c]=!0,n++}else r.command?(r.args.push(s),n++):(r.command=s,n++)}return r}function j(e){v.existsSync(e)||v.mkdirSync(e,{recursive:!0})}function H(e){return v.existsSync(e)}function R(e){return v.readFileSync(e,"utf-8")}function C(e,o){let r=U.dirname(e);j(r),v.writeFileSync(e,o,"utf-8")}var i={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}`)}};var D=h(require("path"));function fe(){return`<!DOCTYPE html>
2
+ var le=Object.create;var H=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var me=(e,t)=>{for(var r in t)H(e,r,{get:t[r],enumerable:!0})},_=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of pe(t))!ue.call(e,s)&&s!==r&&H(e,s,{get:()=>t[s],enumerable:!(n=ce(t,s))||n.enumerable});return e};var h=(e,t,r)=>(r=e!=null?le(de(e)):{},_(t||!e||!e.__esModule?H(r,"default",{value:e,enumerable:!0}):r,e)),ge=e=>_(H({},"__esModule",{value:!0}),e);var lt={};me(lt,{createHMREndpoint:()=>B,createHMRServer:()=>Z,createProject:()=>G,getHMRClientScript:()=>Y});module.exports=ge(lt);var se=h(require("fs")),ie=h(require("path"));var v=h(require("fs")),N=h(require("path")),fe="\x1B[0m",he={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 r=he[t];return r?`${r}${e}${fe}`:e}function J(e){let t=e.slice(2),r={command:"",args:[],options:{},raw:t},n=0;for(;n<t.length;){let s=t[n];if(s==="--help"||s==="-h")r.options.help=!0,n++;else if(s==="--version"||s==="-v")r.options.version=!0,n++;else if(s.startsWith("--")){let a=s.indexOf("=");if(a!==-1){let u=s.slice(2,a),p=s.slice(a+1);r.options[u]=p}else{let u=s.slice(2),p=t[n+1];p&&!p.startsWith("-")?(r.options[u]=p,n++):r.options[u]=!0}n++}else if(s.startsWith("-")&&s.length>1){let a=s.slice(1),u=t[n+1];u&&!u.startsWith("-")?(r.options[a]=u,n++):r.options[a]=!0,n++}else r.command?(r.args.push(s),n++):(r.command=s,n++)}return r}function j(e){v.existsSync(e)||v.mkdirSync(e,{recursive:!0})}function F(e){return v.existsSync(e)}function A(e){return v.readFileSync(e,"utf-8")}function C(e,t){let r=N.dirname(e);j(r),v.writeFileSync(e,t,"utf-8")}var 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}`)}};var L=h(require("path"));function ye(){return`<!DOCTYPE html>
3
3
  <html lang="zh-CN">
4
4
  <head>
5
5
  <meta charset="UTF-8" />
@@ -12,7 +12,7 @@ var ne=Object.create;var F=Object.defineProperty;var se=Object.getOwnPropertyDes
12
12
  <script type="module" src="/src/main.ts"></script>
13
13
  </body>
14
14
  </html>
15
- `}function me(){return`import { createApp } from '@lytjs/lytjs';
15
+ `}function be(){return`import { createApp } from '@lytjs/lytjs';
16
16
  import App from './App';
17
17
 
18
18
  // \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B
@@ -20,7 +20,7 @@ const app = createApp(App);
20
20
 
21
21
  // \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20
22
22
  app.mount('#app');
23
- `}function ge(){return`import { defineComponent, ref, computed } from '@lytjs/lytjs';
23
+ `}function xe(){return`import { defineComponent, ref, computed } from '@lytjs/lytjs';
24
24
 
25
25
  // \u5B9A\u4E49\u6839\u7EC4\u4EF6
26
26
  const App = defineComponent({
@@ -115,7 +115,7 @@ const App = defineComponent({
115
115
  });
116
116
 
117
117
  export default App;
118
- `}function he(){return`/* Lyt.js \u5E94\u7528\u6837\u5F0F */
118
+ `}function ve(){return`/* Lyt.js \u5E94\u7528\u6837\u5F0F */
119
119
 
120
120
  :root {
121
121
  --primary-color: #42b883;
@@ -304,9 +304,9 @@ body {
304
304
  padding: 2rem 1rem;
305
305
  }
306
306
  }
307
- `}function ye(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 be(){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 xe(){return`# Dependencies
307
+ `}function $e(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 we(){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 je(){return`# Dependencies
310
310
  node_modules/
311
311
  .pnp
312
312
  .pnp.js
@@ -334,7 +334,7 @@ Thumbs.db
334
334
  # Cache
335
335
  *.cache
336
336
  .cache/
337
- `}function ve(e){return`# ${e}
337
+ `}function Se(e){return`# ${e}
338
338
 
339
339
  \u8FD9\u662F\u4E00\u4E2A\u4F7F\u7528 [Lyt.js](https://gitee.com/lytjs/lytjs) \u6846\u67B6\u521B\u5EFA\u7684\u9879\u76EE\u3002
340
340
 
@@ -393,9 +393,9 @@ ${e}/
393
393
  ## License
394
394
 
395
395
  MIT
396
- `}async function _(e,o={}){let r=o.template||"spa",n=D.resolve(process.cwd(),e);i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${t(e,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${t(r,"brightCyan")}`),H(n)&&(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)),j(n);let s=[{filePath:"index.html",content:fe()},{filePath:"src/main.ts",content:me()},{filePath:"src/App.ts",content:ge()},{filePath:"src/style.css",content:he()},{filePath:"package.json",content:ye(e)},{filePath:"tsconfig.json",content:be()},{filePath:".gitignore",content:xe()},{filePath:"README.md",content:ve(e)}];for(let c of s){let d=D.join(n,c.filePath);C(d,c.content),i.success(` \u521B\u5EFA ${c.filePath}`)}console.log(""),i.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("")}var L=h(require("path"));function we(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:{"@lytjs/lytjs":"latest"}};return e.ts&&(o.devDependencies={"@lytjs/cli":"latest",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"]="latest"),e.store&&(o.dependencies["@lytjs/store"]="latest"),JSON.stringify(o,null,2)+`
397
- `}function $e(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)+`
398
- `}function je(e){let o=e.ts?".ts":".js";return`<!DOCTYPE html>
396
+ `}async function V(e,t={}){let r=t.template||"spa",n=L.resolve(process.cwd(),e);i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(e,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(r,"brightCyan")}`),F(n)&&(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)),j(n);let s=[{filePath:"index.html",content:ye()},{filePath:"src/main.ts",content:be()},{filePath:"src/App.ts",content:xe()},{filePath:"src/style.css",content:ve()},{filePath:"package.json",content:$e(e)},{filePath:"tsconfig.json",content:we()},{filePath:".gitignore",content:je()},{filePath:"README.md",content:Se(e)}];for(let a of s){let u=L.join(n,a.filePath);C(u,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 O=h(require("path"));function Ce(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.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"]="latest"),e.store&&(t.dependencies["@lytjs/store"]="latest"),JSON.stringify(t,null,2)+`
397
+ `}function Pe(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 ke(e){let t=e.ts?".ts":".js";return`<!DOCTYPE html>
399
399
  <html lang="zh-CN">
400
400
  <head>
401
401
  <meta charset="UTF-8" />
@@ -405,13 +405,13 @@ MIT
405
405
  </head>
406
406
  <body>
407
407
  <div id="app"></div>
408
- <script type="module" src="/src/main${o}"></script>
408
+ <script type="module" src="/src/main${t}"></script>
409
409
  </body>
410
410
  </html>
411
- `}function Se(e){let o=["// Lytx \u914D\u7F6E\u6587\u4EF6","import { defineConfig } from '@lytjs/lytjs'","","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(`
412
- `)}function Ce(e){let o=e.ts?".ts":".js",r=["import { createApp } from '@lytjs/lytjs'","import App from './App.lyt'","import './styles/main.css'"];return e.router&&r.push("import { router } from './router'"),e.store&&r.push("import { store } from './store'"),r.push(""),r.push("// \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B"),r.push("const app = createApp(App)"),e.router&&r.push("app.use(router)"),e.store&&r.push("app.use(store)"),r.push(""),r.push("// \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20"),r.push("app.mount('#app')"),r.join(`
411
+ `}function Ae(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 Me(e){let t=e.ts?".ts":".js",r=["import { createApp } from '@lytjs/lytjs'","import App from './App.lyt'","import './styles/main.css'"];return e.router&&r.push("import { router } from './router'"),e.store&&r.push("import { store } from './store'"),r.push(""),r.push("// \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B"),r.push("const app = createApp(App)"),e.router&&r.push("app.use(router)"),e.store&&r.push("app.use(store)"),r.push(""),r.push("// \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20"),r.push("app.mount('#app')"),r.join(`
413
413
  `)+`
414
- `}function Pe(){return`<template>
414
+ `}function Re(){return`<template>
415
415
  <div class="app">
416
416
  <Header />
417
417
  <main>
@@ -439,7 +439,7 @@ export default defineComponent({
439
439
  padding: 20px;
440
440
  }
441
441
  </style>
442
- `}function Me(){return`import { defineComponent } from '@lytjs/lytjs'
442
+ `}function Ee(){return`import { defineComponent } from '@lytjs/lytjs'
443
443
 
444
444
  export default defineComponent({
445
445
  name: 'HomePage',
@@ -451,7 +451,7 @@ export default defineComponent({
451
451
  </div>
452
452
  \`,
453
453
  })
454
- `}function Re(){return`import { defineComponent } from '@lytjs/lytjs'
454
+ `}function Te(){return`import { defineComponent } from '@lytjs/lytjs'
455
455
 
456
456
  export default defineComponent({
457
457
  name: 'AboutPage',
@@ -463,7 +463,7 @@ export default defineComponent({
463
463
  </div>
464
464
  \`,
465
465
  })
466
- `}function ke(){return`import { defineComponent } from '@lytjs/lytjs'
466
+ `}function Ie(){return`import { defineComponent } from '@lytjs/lytjs'
467
467
 
468
468
  export default defineComponent({
469
469
  name: 'Header',
@@ -477,7 +477,7 @@ export default defineComponent({
477
477
  </header>
478
478
  \`,
479
479
  })
480
- `}function Ae(){return`import { createRouter, createWebHistory } from '@lytjs/router'
480
+ `}function He(){return`import { createRouter, createWebHistory } from '@lytjs/router'
481
481
  import HomePage from '../pages/index'
482
482
  import AboutPage from '../pages/about'
483
483
 
@@ -494,7 +494,7 @@ export const router = createRouter({
494
494
  },
495
495
  ],
496
496
  })
497
- `}function Ee(){return`import { createStore } from '@lytjs/store'
497
+ `}function Fe(){return`import { createStore } from '@lytjs/store'
498
498
 
499
499
  export const store = createStore({
500
500
  state: {
@@ -522,7 +522,7 @@ export const store = createStore({
522
522
  doubleCount: (state: any) => state.count * 2,
523
523
  },
524
524
  })
525
- `}function Te(){return`/* \u5168\u5C40\u6837\u5F0F */
525
+ `}function Le(){return`/* \u5168\u5C40\u6837\u5F0F */
526
526
 
527
527
  * {
528
528
  margin: 0;
@@ -546,17 +546,17 @@ a {
546
546
  a:hover {
547
547
  text-decoration: underline;
548
548
  }
549
- `}function Fe(){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
549
+ `}function Oe(){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
550
550
  <rect width="32" height="32" rx="6" fill="#42b883"/>
551
551
  <text x="16" y="22" text-anchor="middle" fill="white" font-size="18" font-weight="bold">L</text>
552
552
  </svg>
553
- `}function He(){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
- `}async function O(e){let{name:o,template:r,ts:n,router:s,store:c,eslint:d}=e,p=L.resolve(process.cwd(),o);if(i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${t(o,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${t(r,"brightCyan")}`),H(p))throw i.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`);j(p);let u=[{filePath:"package.json",content:we(e)},{filePath:"index.html",content:je(e)},{filePath:"lytx.config.ts",content:Se(e)},{filePath:"src/main.ts",content:Ce(e)},{filePath:"src/App.lyt",content:Pe()},{filePath:"src/pages/index.ts",content:Me()},{filePath:"src/pages/about.ts",content:Re()},{filePath:"src/components/Header.ts",content:ke()},{filePath:"src/styles/main.css",content:Te()},{filePath:"public/favicon.svg",content:Fe()}];n&&u.push({filePath:"tsconfig.json",content:$e(e)}),s&&u.push({filePath:"src/router/index.ts",content:Ae()}),c&&u.push({filePath:"src/store/index.ts",content:Ee()}),d&&u.push({filePath:".eslintrc.json",content:He()});for(let l of u){let f=L.join(p,l.filePath);C(f,l.content),i.success(` \u521B\u5EFA ${l.filePath}`)}console.log(""),i.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("")}var K=h(require("http")),P=h(require("fs")),b=h(require("path"));var J=h(require("http")),k=h(require("fs")),w=h(require("path")),q=h(require("crypto")),I=class{constructor(){this.clients=[]}handleUpgrade(o,r,n){let s=o.headers["sec-websocket-key"];if(!s){r.destroy();return}let c=q.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");r.write(`HTTP/1.1 101 Switching Protocols\r
553
+ `}function Ge(){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
+ `}async function G(e){let{name:t,template:r,ts:n,router:s,store:a,eslint:u}=e,p=O.resolve(process.cwd(),t);if(i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(t,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(r,"brightCyan")}`),F(p))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`);j(p);let d=[{filePath:"package.json",content:Ce(e)},{filePath:"index.html",content:ke(e)},{filePath:"lytx.config.ts",content:Ae(e)},{filePath:"src/main.ts",content:Me(e)},{filePath:"src/App.lyt",content:Re()},{filePath:"src/pages/index.ts",content:Ee()},{filePath:"src/pages/about.ts",content:Te()},{filePath:"src/components/Header.ts",content:Ie()},{filePath:"src/styles/main.css",content:Le()},{filePath:"public/favicon.svg",content:Oe()}];n&&d.push({filePath:"tsconfig.json",content:Pe(e)}),s&&d.push({filePath:"src/router/index.ts",content:He()}),a&&d.push({filePath:"src/store/index.ts",content:Fe()}),u&&d.push({filePath:".eslintrc.json",content:Ge()});for(let c of d){let m=O.join(p,c.filePath);C(m,c.content),i.success(` \u521B\u5EFA ${c.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 X=h(require("http")),P=h(require("fs")),b=h(require("path"));var q=h(require("http")),M=h(require("fs")),$=h(require("path")),K=h(require("crypto")),D=class{constructor(){this.clients=[]}handleUpgrade(t,r,n){let s=t.headers["sec-websocket-key"];if(!s){r.destroy();return}let a=K.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");r.write(`HTTP/1.1 101 Switching Protocols\r
555
555
  Upgrade: websocket\r
556
556
  Connection: Upgrade\r
557
- Sec-WebSocket-Accept: ${c}\r
557
+ Sec-WebSocket-Accept: ${a}\r
558
558
  \r
559
- `);let d={socket:r,isAlive:!0};r.on("close",()=>{this.clients=this.clients.filter(p=>p!==d)}),r.on("error",()=>{this.clients=this.clients.filter(p=>p!==d)}),this.clients.push(d)}broadcast(o){let r=[];for(let n of this.clients)try{if(!n.isAlive){r.push(n);continue}let s=Buffer.from(o,"utf-8"),c=this.createFrame(129,s);n.socket.write(c)}catch(s){r.push(n)}for(let n of r){this.clients=this.clients.filter(s=>s!==n);try{n.socket.destroy()}catch(s){}}}createFrame(o,r){let n=r.length,s;n<126?s=2:n<65536?s=4:s=10;let c=Buffer.alloc(s+n);return c[0]=o,n<126?c[1]=n:n<65536?(c[1]=126,c.writeUInt16BE(n,2)):(c[1]=127,c.writeUInt32BE(0,2),c.writeUInt32BE(n,6)),r.copy(c,s),c}getClientCount(){return this.clients.length}closeAll(){for(let o of this.clients)try{o.socket.destroy()}catch(r){}this.clients=[]}};function V(e){let o=new I,r=[],n=[],s=null,c=!1;function d(u){let l=w.extname(u).toLowerCase();if(l===".css")return"css";let f=w.basename(u);return f.startsWith("lytx.config")||f==="tsconfig.json"||f==="package.json"?"reload":l===".ts"||l===".tsx"||l===".lyt"||l===".js"||l===".jsx"?"update":"reload"}function p(u){try{let l=k.readdirSync(u,{withFileTypes:!0});for(let f of l){let a=w.join(u,f.name);if(f.isDirectory()){if(f.name==="node_modules"||f.name===".git"||f.name==="dist")continue;p(a)}else if(f.isFile()){let g=w.extname(f.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(g))try{let A=k.watch(a,{persistent:!1},z=>{if(z==="change"){let E=w.relative(e,a);for(let S of r)try{S(E)}catch(T){}let M=d(a),$={type:M,path:`/${E}`};if(M==="css")try{$.content=k.readFileSync(a,"utf-8")}catch(S){}o.broadcast(JSON.stringify($))}});n.push(A)}catch(A){}}}}catch(l){}}return{start(u){c||(c=!0,s=J.createServer((l,f)=>{f.writeHead(426,{"Content-Type":"text/plain"}),f.end("Upgrade Required")}),s.on("upgrade",(l,f,a)=>{o.handleUpgrade(l,f,a)}),s.listen(u,()=>{}),p(e))},stop(){c=!1;for(let u of n)try{u.close()}catch(l){}if(n.length=0,o.closeAll(),s){try{s.close()}catch(u){}s=null}},onFileChange(u){r.push(u)},notifyClient(u){o.broadcast(JSON.stringify(u))}}}function G(e){let o=new I;return e.on("upgrade",(r,n,s)=>{o.handleUpgrade(r,n,s)}),{broadcast(r){o.broadcast(r)},getClientCount(){return o.getClientCount()}}}function B(){return`(function() {
559
+ `);let u={socket:r,isAlive:!0};r.on("close",()=>{this.clients=this.clients.filter(p=>p!==u)}),r.on("error",()=>{this.clients=this.clients.filter(p=>p!==u)}),this.clients.push(u)}broadcast(t){let r=[];for(let n of this.clients)try{if(!n.isAlive){r.push(n);continue}let s=Buffer.from(t,"utf-8"),a=this.createFrame(129,s);n.socket.write(a)}catch(s){r.push(n)}for(let n of r){this.clients=this.clients.filter(s=>s!==n);try{n.socket.destroy()}catch(s){}}}createFrame(t,r){let n=r.length,s;n<126?s=2:n<65536?s=4:s=10;let a=Buffer.alloc(s+n);return a[0]=t,n<126?a[1]=n:n<65536?(a[1]=126,a.writeUInt16BE(n,2)):(a[1]=127,a.writeUInt32BE(0,2),a.writeUInt32BE(n,6)),r.copy(a,s),a}getClientCount(){return this.clients.length}closeAll(){for(let t of this.clients)try{t.socket.destroy()}catch(r){}this.clients=[]}};function Z(e){let t=new D,r=[],n=[],s=null,a=!1;function u(d){let c=$.extname(d).toLowerCase();if(c===".css")return"css";let m=$.basename(d);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 p(d){try{let c=M.readdirSync(d,{withFileTypes:!0});for(let m of c){let l=$.join(d,m.name);if(m.isDirectory()){if(m.name==="node_modules"||m.name===".git"||m.name==="dist")continue;p(l)}else if(m.isFile()){let f=$.extname(m.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(f))try{let E=M.watch(l,{persistent:!1},W=>{if(W==="change"){let T=$.relative(e,l);for(let S of r)try{S(T)}catch(I){}let k=u(l),w={type:k,path:`/${T}`};if(k==="css")try{w.content=M.readFileSync(l,"utf-8")}catch(S){}t.broadcast(JSON.stringify(w))}});n.push(E)}catch(E){}}}}catch(c){}}return{start(d){a||(a=!0,s=q.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(d,()=>{}),p(e))},stop(){a=!1;for(let d of n)try{d.close()}catch(c){}if(n.length=0,t.closeAll(),s){try{s.close()}catch(d){}s=null}},onFileChange(d){r.push(d)},notifyClient(d){t.broadcast(JSON.stringify(d))}}}function B(e){let t=new D;return e.on("upgrade",(r,n,s)=>{t.handleUpgrade(r,n,s)}),{broadcast(r){t.broadcast(r)},getClientCount(){return t.getClientCount()}}}function Y(){return`(function() {
560
560
  'use strict';
561
561
 
562
562
  var ws = null;
@@ -654,112 +654,399 @@ Sec-WebSocket-Accept: ${c}\r
654
654
 
655
655
  // \u542F\u52A8\u8FDE\u63A5
656
656
  connect();
657
- })();`}var X;try{X=require("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(` ${t("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${t("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}function De(e,o){try{return X.transformSync(e,{loader:"ts",target:"es2018",format:"esm",sourcemap:"inline"}).code}catch(r){let n=r instanceof Error?r.message:String(r);return console.error(`[Lyt CLI] \u7F16\u8BD1\u9519\u8BEF ${o||""}:`,n),e}}function Le(e,o){var u;let r=((u=e.url)==null?void 0:u.split("?")[0])||"/";if(r==="/"&&(r="/index.html"),r.startsWith("/node_modules/")||r.startsWith("/@")){let l;if(r.startsWith("/@")&&!r.startsWith("/node_modules/")?l=b.join(o,"node_modules",r.slice(1)):l=b.join(o,r.slice(1)),r.match(/^\/(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/)&&!r.includes(".")){let f=b.join(l,"package.json");if(P.existsSync(f))try{let a=JSON.parse(R(f)),g=a.module||a.main||"index.js";a.exports&&(typeof a.exports=="string"?g=a.exports:typeof a.exports=="object"&&a.exports["."]&&(typeof a.exports["."]=="string"?g=a.exports["."]:a.exports["."].import?g=a.exports["."].import:a.exports["."].default?g=a.exports["."].default:Object.values(a.exports["."])[0]&&(g=Object.values(a.exports["."])[0]))),g.startsWith("./")&&(g=g.slice(2)),l=b.join(l,g)}catch(a){}}if(P.existsSync(l)&&P.statSync(l).isFile()){let f=b.extname(l).toLowerCase(),g={".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".json":"application/json; charset=utf-8"}[f]||"application/octet-stream",x=R(l);return{statusCode:200,headers:{"Content-Type":g},body:x}}}let n=b.join(o,r);if(!n.startsWith(o))return{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"};if(!P.existsSync(n)||!P.statSync(n).isFile())return{statusCode:404,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"404 Not Found"};let s=b.extname(n).toLowerCase(),d={".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",p=R(n);return(s===".ts"||s===".tsx")&&(p=De(p,r)),s===".html"&&(p=p.replace("</head>",`<script>${B()}</script>
658
- </head>`)),{statusCode:200,headers:{"Content-Type":d},body:p}}function W(e={}){let o=e.port||3e3,r=b.resolve(e.root||process.cwd()),n=e.hmr!==!1,s=K.createServer((p,u)=>{let l=Le(p,r);u.writeHead(l.statusCode,l.headers),u.end(l.body)}),c=n?G(s):null;s.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\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\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(r,"brightBlue")}`),console.log(` ${t("\u279C","brightGreen")} \u70ED\u66F4\u65B0: ${t(n?"\u5DF2\u5F00\u542F":"\u5DF2\u5173\u95ED",n?"brightGreen":"brightRed")}`),console.log(""),console.log(` ${t("\u6309 Ctrl+C \u505C\u6B62\u670D\u52A1\u5668","dim")}`),console.log("")}),s.on("error",p=>{p.code==="EADDRINUSE"?(i.error(`\u7AEF\u53E3 ${o} \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: ${p.message}`),process.exit(1))});let d=()=>{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",d),process.on("SIGTERM",d)}var y=h(require("fs")),m=h(require("path"));var Q;try{Q=require("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(` ${t("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${t("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}async function Z(e={}){let o=Date.now(),r=m.resolve(e.root||process.cwd()),n=m.resolve(r,e.outDir||"dist"),s=e.entry||"index.html",c=e.minify||!1;i.info("\u5F00\u59CB\u6784\u5EFA\u9879\u76EE..."),i.info(` \u6839\u76EE\u5F55: ${t(r,"brightCyan")}`),i.info(` \u8F93\u51FA\u76EE\u5F55: ${t(n,"brightCyan")}`),i.info(` \u538B\u7F29: ${t(c?"\u5F00\u542F":"\u5173\u95ED",c?"brightGreen":"brightYellow")}`);let d=m.join(r,s);y.existsSync(d)||(i.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${d}`),process.exit(1));let p=R(d),u=/<script\s+type="module"\s+src="([^"]+)"\s*><\/script>/g,l,f=[];for(;(l=u.exec(p))!==null;)f.push(l[1]);f.length===0&&i.warn("\u672A\u5728\u5165\u53E3 HTML \u4E2D\u627E\u5230\u6A21\u5757\u811A\u672C\u5F15\u7528");let a={inputFiles:0,outputFiles:0,totalSize:0,buildTime:0};j(n),j(m.join(n,"assets"));for(let x of f){let A=m.join(r,x);if(!y.existsSync(A)){i.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${x}`);continue}i.info(`\u6B63\u5728\u6253\u5305: ${t(x,"brightYellow")}`);let E=`${m.basename(x,m.extname(x))}.bundle.js`,M=m.join(n,"assets",E);try{await Q.build({entryPoints:[A],bundle:!0,minify:c,target:"es2018",format:"esm",outfile:M,sourcemap:!0,external:T=>T.startsWith("@lytjs/"),drop:c?["console"]:[],metafile:!0});let $=y.readFileSync(M,"utf-8");a.totalSize+=Buffer.byteLength($,"utf-8"),a.outputFiles++;let S=M+".map";if(y.existsSync(S)){let T=y.readFileSync(S,"utf-8");a.totalSize+=Buffer.byteLength(T,"utf-8"),a.outputFiles++}p=p.replace(`<script type="module" src="${x}"></script>`,`<script src="/assets/${E}"></script>`),a.inputFiles++}catch($){let S=$ instanceof Error?$.message:String($);i.error(`\u6253\u5305\u5931\u8D25 ${x}: ${S}`),process.exit(1)}}Oe(r,n,a);let g=m.join(n,"index.html");C(g,p),a.outputFiles++,a.totalSize+=Buffer.byteLength(p,"utf-8"),a.buildTime=Date.now()-o,console.log(""),i.success("\u6784\u5EFA\u5B8C\u6210\uFF01"),console.log(""),console.log(` ${t("\u8F93\u5165\u6587\u4EF6:","brightWhite")} ${a.inputFiles} \u4E2A`),console.log(` ${t("\u8F93\u51FA\u6587\u4EF6:","brightWhite")} ${a.outputFiles} \u4E2A`),console.log(` ${t("\u603B\u5927\u5C0F:","brightWhite")} ${Ie(a.totalSize)}`),console.log(` ${t("\u6784\u5EFA\u8017\u65F6:","brightWhite")} ${a.buildTime}ms`),console.log(` ${t("\u8F93\u51FA\u76EE\u5F55:","brightWhite")} ${t(n,"brightCyan")}`),console.log("")}function Oe(e,o,r){let n=m.join(e,"src");if(!y.existsSync(n))return;function s(c,d){let p=y.readdirSync(c,{withFileTypes:!0});for(let u of p){let l=m.join(c,u.name);if(u.isDirectory()){if(u.name==="node_modules")continue;s(l,d)}else if(u.isFile()){let f=m.extname(u.name);if([".ts",".tsx",".js",".jsx"].includes(f))continue;let a=m.relative(d,l),g=m.join(o,a);C(g,y.readFileSync(l).toString("utf-8")),r.outputFiles++,r.totalSize+=y.statSync(l).size}}}s(n,n)}function Ie(e){if(e===0)return"0 B";let o=["B","KB","MB","GB"],r=1024,n=Math.floor(Math.log(e)/Math.log(r));return`${(e/Math.pow(r,n)).toFixed(2)} ${o[n]}`}var Ge="0.2.0",re="lytx",Be="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",ee=`
659
- ${t(re,"brightCyan")} - ${Be}
657
+ })();`}var Q;try{Q=require("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)}function De(e,t){try{return Q.transformSync(e,{loader:"ts",target:"es2018",format:"esm",sourcemap:"inline"}).code}catch(r){let n=r instanceof Error?r.message:String(r);return console.error(`[Lyt CLI] \u7F16\u8BD1\u9519\u8BEF ${t||""}:`,n),e}}function Be(e,t){var d;let r=((d=e.url)==null?void 0:d.split("?")[0])||"/";if(r==="/"&&(r="/index.html"),r.startsWith("/node_modules/")||r.startsWith("/@")){let c;if(r.startsWith("/@")&&!r.startsWith("/node_modules/")?c=b.join(t,"node_modules",r.slice(1)):c=b.join(t,r.slice(1)),r.match(/^\/(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/)&&!r.includes(".")){let m=b.join(c,"package.json");if(P.existsSync(m))try{let l=JSON.parse(A(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=b.join(c,f)}catch(l){}}if(P.existsSync(c)&&P.statSync(c).isFile()){let m=b.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",x=A(c);return{statusCode:200,headers:{"Content-Type":f},body:x}}}let n=b.join(t,r);if(!n.startsWith(t))return{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"};if(!P.existsSync(n)||!P.statSync(n).isFile())return{statusCode:404,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"404 Not Found"};let s=b.extname(n).toLowerCase(),u={".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",p=A(n);return(s===".ts"||s===".tsx")&&(p=De(p,r)),s===".html"&&(p=p.replace("</head>",`<script>${Y()}</script>
658
+ </head>`)),{statusCode:200,headers:{"Content-Type":u},body:p}}function z(e={}){let t=e.port||3e3,r=b.resolve(e.root||process.cwd()),n=e.hmr!==!1,s=X.createServer((p,d)=>{let c=Be(p,r);d.writeHead(c.statusCode,c.headers),d.end(c.body)}),a=n?B(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(r,"brightBlue")}`),console.log(` ${o("\u279C","brightGreen")} \u70ED\u66F4\u65B0: ${o(n?"\u5DF2\u5F00\u542F":"\u5DF2\u5173\u95ED",n?"brightGreen":"brightRed")}`),console.log(""),console.log(` ${o("\u6309 Ctrl+C \u505C\u6B62\u670D\u52A1\u5668","dim")}`),console.log("")}),s.on("error",p=>{p.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: ${p.message}`),process.exit(1))});let u=()=>{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",u),process.on("SIGTERM",u)}var y=h(require("fs")),g=h(require("path"));var ee;try{ee=require("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)}async function te(e={}){let t=Date.now(),r=g.resolve(e.root||process.cwd()),n=g.resolve(r,e.outDir||"dist"),s=e.entry||"index.html",a=e.minify||!1;i.info("\u5F00\u59CB\u6784\u5EFA\u9879\u76EE..."),i.info(` \u6839\u76EE\u5F55: ${o(r,"brightCyan")}`),i.info(` \u8F93\u51FA\u76EE\u5F55: ${o(n,"brightCyan")}`),i.info(` \u538B\u7F29: ${o(a?"\u5F00\u542F":"\u5173\u95ED",a?"brightGreen":"brightYellow")}`);let u=g.join(r,s);y.existsSync(u)||(i.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${u}`),process.exit(1));let p=A(u),d=/<script\s+type="module"\s+src="([^"]+)"\s*><\/script>/g,c,m=[];for(;(c=d.exec(p))!==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};j(n),j(g.join(n,"assets"));for(let x of m){let E=g.join(r,x);if(!y.existsSync(E)){i.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${x}`);continue}i.info(`\u6B63\u5728\u6253\u5305: ${o(x,"brightYellow")}`);let T=`${g.basename(x,g.extname(x))}.bundle.js`,k=g.join(n,"assets",T);try{await ee.build({entryPoints:[E],bundle:!0,minify:a,target:"es2018",format:"esm",outfile:k,sourcemap:!0,external:I=>I.startsWith("@lytjs/"),drop:a?["console"]:[],metafile:!0});let w=y.readFileSync(k,"utf-8");l.totalSize+=Buffer.byteLength(w,"utf-8"),l.outputFiles++;let S=k+".map";if(y.existsSync(S)){let I=y.readFileSync(S,"utf-8");l.totalSize+=Buffer.byteLength(I,"utf-8"),l.outputFiles++}p=p.replace(`<script type="module" src="${x}"></script>`,`<script src="/assets/${T}"></script>`),l.inputFiles++}catch(w){let S=w instanceof Error?w.message:String(w);i.error(`\u6253\u5305\u5931\u8D25 ${x}: ${S}`),process.exit(1)}}Ye(r,n,l);let f=g.join(n,"index.html");C(f,p),l.outputFiles++,l.totalSize+=Buffer.byteLength(p,"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")} ${Ue(l.totalSize)}`),console.log(` ${o("\u6784\u5EFA\u8017\u65F6:","brightWhite")} ${l.buildTime}ms`),console.log(` ${o("\u8F93\u51FA\u76EE\u5F55:","brightWhite")} ${o(n,"brightCyan")}`),console.log("")}function Ye(e,t,r){let n=g.join(e,"src");if(!y.existsSync(n))return;function s(a,u){let p=y.readdirSync(a,{withFileTypes:!0});for(let d of p){let c=g.join(a,d.name);if(d.isDirectory()){if(d.name==="node_modules")continue;s(c,u)}else if(d.isFile()){let m=g.extname(d.name);if([".ts",".tsx",".js",".jsx"].includes(m))continue;let l=g.relative(u,c),f=g.join(t,l);C(f,y.readFileSync(c).toString("utf-8")),r.outputFiles++,r.totalSize+=y.statSync(c).size}}}s(n,n)}function Ue(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],r=1024,n=Math.floor(Math.log(e)/Math.log(r));return`${(e/Math.pow(r,n)).toFixed(2)} ${t[n]}`}var R=h(require("fs")),oe=h(require("path"));var U=`
659
+ ${o("lytx generate","brightCyan")} - \u751F\u6210\u4EE3\u7801\uFF08\u7EC4\u4EF6\u3001Store\u3001\u9875\u9762\u3001API\uFF09
660
+
661
+ ${o("\u7528\u6CD5:","brightGreen")}
662
+ lytx generate <type> <name> [options]
663
+
664
+ ${o("\u53C2\u6570:","brightGreen")}
665
+ ${o("<type>","brightYellow")} \u751F\u6210\u7C7B\u578B (component, store, page, api)
666
+ ${o("<name>","brightYellow")} \u540D\u79F0
667
+
668
+ ${o("\u9009\u9879:","brightGreen")}
669
+ ${o("--ai","brightYellow")} \u4F7F\u7528 AI \u751F\u6210\uFF08\u9700\u8981\u914D\u7F6E API Key\uFF09
670
+ ${o("--no-ai","brightYellow")} \u4E0D\u4F7F\u7528 AI\uFF08\u6A21\u677F\u751F\u6210\uFF09
671
+ ${o("-t, --type <type>","brightYellow")} \u7EC4\u4EF6\u7C7B\u578B (button, input, form, card, list, table, modal, dropdown, tabs, navigation, custom)
672
+ ${o("-o, --output <path>","brightYellow")}\u8F93\u51FA\u6587\u4EF6\u8DEF\u5F84
673
+ ${o("--no-style","brightYellow")} \u4E0D\u6DFB\u52A0\u6837\u5F0F
674
+ ${o("--api-key <key>","brightYellow")} AI API Key
675
+ ${o("--model <model>","brightYellow")} AI \u6A21\u578B\u540D\u79F0
676
+ ${o("--provider <name>","brightYellow")} AI \u63D0\u4F9B\u5546 (openai, anthropic, custom)
677
+ ${o("--base-url <url>","brightYellow")} AI API \u57FA\u7840 URL
678
+
679
+ ${o("\u793A\u4F8B:","brightGreen")}
680
+ ${o("$","dim")} lytx generate component MyButton
681
+ ${o("$","dim")} lytx generate component MyButton --type button
682
+ ${o("$","dim")} lytx generate component MyButton --type button --ai
683
+ ${o("$","dim")} lytx generate store counter
684
+ ${o("$","dim")} lytx generate page Home
685
+ ${o("$","dim")} lytx generate api users
686
+ `;function Ne(e){let t={type:"component",name:"",useAI:!1,style:!0};for(let r=0;r<e.length;r++){let n=e[r];n==="--ai"?t.useAI=!0:n==="--no-ai"?t.useAI=!1:n==="-t"||n==="--type"?t.componentType=e[++r]:n==="-o"||n==="--output"?t.outputPath=e[++r]:n==="--no-style"?t.style=!1:n==="--api-key"?t.apiKey=e[++r]:n==="--model"?t.model=e[++r]:n==="--provider"?t.provider=e[++r]:n==="--base-url"?t.baseUrl=e[++r]:n==="-d"||n==="--description"?t.description=e[++r]:!t.type&&["component","store","page","api"].includes(n)?t.type=n:!t.name&&!n.startsWith("-")&&(t.name=n)}return t}function ze(e,t){let r=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),n=t.componentType||"functional",s={functional:`<!-- ${e} \u7EC4\u4EF6 -->
687
+ <template>
688
+ <div class="${r}">
689
+ <slot></slot>
690
+ </div>
691
+ </template>
692
+
693
+ <script setup>
694
+ // \u7EC4\u4EF6\u903B\u8F91
695
+ </script>
696
+
697
+ <style scoped>
698
+ .${r} {
699
+ /* \u6837\u5F0F */
700
+ }
701
+ </style>
702
+ `,button:`<!-- ${e} \u6309\u94AE\u7EC4\u4EF6 -->
703
+ <template>
704
+ <button class="${r}" :disabled="disabled" @click="handleClick">
705
+ <slot></slot>
706
+ </button>
707
+ </template>
708
+
709
+ <script setup>
710
+ import { defineProps, defineEmits } from '@lytjs/core';
711
+
712
+ const props = defineProps({
713
+ disabled: {
714
+ type: Boolean,
715
+ default: false
716
+ }
717
+ });
718
+
719
+ const emit = defineEmits(['click']);
720
+
721
+ function handleClick(event) {
722
+ emit('click', event);
723
+ }
724
+ </script>
725
+
726
+ <style scoped>
727
+ .${r} {
728
+ padding: 8px 16px;
729
+ border: none;
730
+ border-radius: 4px;
731
+ background: #3b82f6;
732
+ color: white;
733
+ cursor: pointer;
734
+ font-size: 14px;
735
+ }
736
+
737
+ .${r}:hover:not(:disabled) {
738
+ background: #2563eb;
739
+ }
740
+
741
+ .${r}:disabled {
742
+ background: #9ca3af;
743
+ cursor: not-allowed;
744
+ }
745
+ </style>
746
+ `,input:`<!-- ${e} \u8F93\u5165\u6846\u7EC4\u4EF6 -->
747
+ <template>
748
+ <div class="${r}">
749
+ <input
750
+ :value="modelValue"
751
+ :type="type"
752
+ :placeholder="placeholder"
753
+ :disabled="disabled"
754
+ @input="handleInput"
755
+ @change="handleChange"
756
+ />
757
+ </div>
758
+ </template>
759
+
760
+ <script setup>
761
+ import { defineProps, defineEmits } from '@lytjs/core';
762
+
763
+ const props = defineProps({
764
+ modelValue: {
765
+ type: [String, Number],
766
+ default: ''
767
+ },
768
+ type: {
769
+ type: String,
770
+ default: 'text'
771
+ },
772
+ placeholder: {
773
+ type: String,
774
+ default: ''
775
+ },
776
+ disabled: {
777
+ type: Boolean,
778
+ default: false
779
+ }
780
+ });
781
+
782
+ const emit = defineEmits(['update:modelValue', 'change']);
783
+
784
+ function handleInput(event) {
785
+ emit('update:modelValue', event.target.value);
786
+ }
787
+
788
+ function handleChange(event) {
789
+ emit('change', event.target.value);
790
+ }
791
+ </script>
792
+
793
+ <style scoped>
794
+ .${r} input {
795
+ padding: 8px 12px;
796
+ border: 1px solid #d1d5db;
797
+ border-radius: 4px;
798
+ font-size: 14px;
799
+ outline: none;
800
+ }
801
+
802
+ .${r} input:focus {
803
+ border-color: #3b82f6;
804
+ box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
805
+ }
806
+ </style>
807
+ `,card:`<!-- ${e} \u5361\u7247\u7EC4\u4EF6 -->
808
+ <template>
809
+ <div class="${r}">
810
+ <div class="${r}-header" if="$slots.header">
811
+ <slot name="header"></slot>
812
+ </div>
813
+ <div class="${r}-body">
814
+ <slot></slot>
815
+ </div>
816
+ <div class="${r}-footer" if="$slots.footer">
817
+ <slot name="footer"></slot>
818
+ </div>
819
+ </div>
820
+ </template>
821
+
822
+ <script setup>
823
+ // \u7EC4\u4EF6\u903B\u8F91
824
+ </script>
825
+
826
+ <style scoped>
827
+ .${r} {
828
+ background: white;
829
+ border-radius: 8px;
830
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
831
+ overflow: hidden;
832
+ }
833
+
834
+ .${r}-header,
835
+ .${r}-body,
836
+ .${r}-footer {
837
+ padding: 16px;
838
+ }
839
+
840
+ .${r}-header {
841
+ border-bottom: 1px solid #e5e7eb;
842
+ }
843
+
844
+ .${r}-footer {
845
+ border-top: 1px solid #e5e7eb;
846
+ }
847
+ </style>
848
+ `};return s[n]||s.functional}function We(e){let t=e.charAt(0).toLowerCase()+e.slice(1);return`/**
849
+ * ${e} Store
850
+ */
851
+
852
+ import { createStore } from '@lytjs/store';
853
+
854
+ export const ${t}Store = createStore('${e}', {
855
+ state: {
856
+ // \u72B6\u6001\u5B9A\u4E49
857
+ count: 0
858
+ },
859
+
860
+ getters: {
861
+ // \u8BA1\u7B97\u5C5E\u6027
862
+ double: state => state.count * 2
863
+ },
864
+
865
+ actions: {
866
+ // \u65B9\u6CD5\u5B9A\u4E49
867
+ increment(state) {
868
+ state.count++;
869
+ },
870
+
871
+ decrement(state) {
872
+ state.count--;
873
+ }
874
+ }
875
+ });
876
+ `}function _e(e){let t=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();return`<!-- ${e} \u9875\u9762 -->
877
+ <template>
878
+ <div class="${t}-page">
879
+ <h1>${e}</h1>
880
+ <slot></slot>
881
+ </div>
882
+ </template>
883
+
884
+ <script setup>
885
+ import { ref, computed } from '@lytjs/reactivity';
886
+
887
+ // \u9875\u9762\u903B\u8F91
888
+ </script>
889
+
890
+ <style scoped>
891
+ .${t}-page {
892
+ padding: 20px;
893
+ }
894
+ </style>
895
+ `}function Je(e){return`/**
896
+ * ${e} API
897
+ */
898
+
899
+ export default async function handler(req, res) {
900
+ const method = req.method;
901
+
902
+ switch (method) {
903
+ case 'GET':
904
+ // \u83B7\u53D6\u8D44\u6E90
905
+ res.json({
906
+ success: true,
907
+ message: 'Get ${e}',
908
+ data: []
909
+ });
910
+ break;
911
+
912
+ case 'POST':
913
+ // \u521B\u5EFA\u8D44\u6E90
914
+ res.status(201).json({
915
+ success: true,
916
+ message: 'Create ${e}',
917
+ data: {}
918
+ });
919
+ break;
920
+
921
+ case 'PUT':
922
+ // \u66F4\u65B0\u8D44\u6E90
923
+ res.json({
924
+ success: true,
925
+ message: 'Update ${e}'
926
+ });
927
+ break;
928
+
929
+ case 'DELETE':
930
+ // \u5220\u9664\u8D44\u6E90
931
+ res.json({
932
+ success: true,
933
+ message: 'Delete ${e}'
934
+ });
935
+ break;
936
+
937
+ default:
938
+ res.status(405).json({
939
+ success: false,
940
+ message: 'Method not allowed'
941
+ });
942
+ }
943
+ }
944
+ `}async function re(e){let t=Ne(e);t.type||(i.error("\u8BF7\u63D0\u4F9B\u751F\u6210\u7C7B\u578B (component, store, page, api)"),console.log(""),console.log(U),process.exit(1)),t.name||(i.error("\u8BF7\u63D0\u4F9B\u540D\u79F0"),console.log(""),console.log(U),process.exit(1)),i.info(`\u751F\u6210 ${t.type}: ${t.name}`),i.info(`\u4F7F\u7528 AI: ${t.useAI?"Yes":"No"}`);let r,n;switch(t.type){case"component":r=ze(t.name,t),n=`./src/components/${t.name}.lyt`;break;case"store":r=We(t.name),n=`./src/stores/${t.name}.js`;break;case"page":r=_e(t.name),n=`./src/pages/${t.name}.lyt`;break;case"api":r=Je(t.name),n=`./src/api/${t.name}.js`;break}let s=t.outputPath||n,a=oe.dirname(s);R.existsSync(a)||R.mkdirSync(a,{recursive:!0}),R.writeFileSync(s,r,"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 Ve="0.2.0",ae="lytx",qe="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",ne=`
945
+ ${o(ae,"brightCyan")} - ${qe}
660
946
 
661
- ${t("\u7528\u6CD5:","brightGreen")}
947
+ ${o("\u7528\u6CD5:","brightGreen")}
662
948
  lytx <command> [options] [args]
663
949
 
664
- ${t("\u547D\u4EE4:","brightGreen")}
665
- ${t("create","brightYellow")} <name> \u521B\u5EFA\u4E00\u4E2A\u65B0\u7684 Lyt \u9879\u76EE
666
- ${t("dev","brightYellow")} \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
667
- ${t("build","brightYellow")} \u6784\u5EFA\u751F\u4EA7\u7248\u672C
668
- ${t("preview","brightYellow")} \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
669
-
670
- ${t("\u5168\u5C40\u9009\u9879:","brightGreen")}
671
- ${t("-h, --help","brightYellow")} \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
672
- ${t("-v, --version","brightYellow")} \u663E\u793A\u7248\u672C\u53F7
673
-
674
- ${t("\u793A\u4F8B:","brightGreen")}
675
- ${t("$","dim")} lytx create my-app
676
- ${t("$","dim")} lytx create my-app --template spa --ts --router --store
677
- ${t("$","dim")} lytx dev
678
- ${t("$","dim")} lytx dev --port 8080 --hmr
679
- ${t("$","dim")} lytx build
680
- ${t("$","dim")} lytx build --mode ssr
681
- ${t("$","dim")} lytx preview --port 4173
682
-
683
- `,Ue=`
684
- ${t("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
685
-
686
- ${t("\u7528\u6CD5:","brightGreen")}
950
+ ${o("\u547D\u4EE4:","brightGreen")}
951
+ ${o("create","brightYellow")} <name> \u521B\u5EFA\u4E00\u4E2A\u65B0\u7684 Lyt \u9879\u76EE
952
+ ${o("dev","brightYellow")} \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
953
+ ${o("build","brightYellow")} \u6784\u5EFA\u751F\u4EA7\u7248\u672C
954
+ ${o("preview","brightYellow")} \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
955
+ ${o("generate","brightYellow")} <type> <name> \u751F\u6210\u4EE3\u7801\uFF08\u7EC4\u4EF6\u3001Store\u3001\u9875\u9762\u3001API\uFF09
956
+
957
+ ${o("\u5168\u5C40\u9009\u9879:","brightGreen")}
958
+ ${o("-h, --help","brightYellow")} \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
959
+ ${o("-v, --version","brightYellow")} \u663E\u793A\u7248\u672C\u53F7
960
+
961
+ ${o("\u793A\u4F8B:","brightGreen")}
962
+ ${o("$","dim")} lytx create my-app
963
+ ${o("$","dim")} lytx create my-app --template spa --ts --router --store
964
+ ${o("$","dim")} lytx dev
965
+ ${o("$","dim")} lytx dev --port 8080 --hmr
966
+ ${o("$","dim")} lytx build
967
+ ${o("$","dim")} lytx build --mode ssr
968
+ ${o("$","dim")} lytx preview --port 4173
969
+
970
+ `,Ke=`
971
+ ${o("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
972
+
973
+ ${o("\u7528\u6CD5:","brightGreen")}
687
974
  lytx create <name> [options]
688
975
 
689
- ${t("\u53C2\u6570:","brightGreen")}
690
- ${t("<name>","brightYellow")} \u9879\u76EE\u540D\u79F0\uFF08\u540C\u65F6\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF09
976
+ ${o("\u53C2\u6570:","brightGreen")}
977
+ ${o("<name>","brightYellow")} \u9879\u76EE\u540D\u79F0\uFF08\u540C\u65F6\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF09
691
978
 
692
- ${t("\u9009\u9879:","brightGreen")}
693
- ${t("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
979
+ ${o("\u9009\u9879:","brightGreen")}
980
+ ${o("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
694
981
  \u53EF\u9009\u503C: spa, ssr, ssg
695
- ${t("--ts","brightYellow")} \u4F7F\u7528 TypeScript
696
- ${t("--router","brightYellow")} \u5305\u542B\u8DEF\u7531
697
- ${t("--store","brightYellow")} \u5305\u542B\u72B6\u6001\u7BA1\u7406
698
- ${t("--eslint","brightYellow")} \u5305\u542B ESLint \u914D\u7F6E
982
+ ${o("--ts","brightYellow")} \u4F7F\u7528 TypeScript
983
+ ${o("--router","brightYellow")} \u5305\u542B\u8DEF\u7531
984
+ ${o("--store","brightYellow")} \u5305\u542B\u72B6\u6001\u7BA1\u7406
985
+ ${o("--eslint","brightYellow")} \u5305\u542B ESLint \u914D\u7F6E
699
986
 
700
- ${t("\u793A\u4F8B:","brightGreen")}
701
- ${t("$","dim")} lytx create my-app
702
- ${t("$","dim")} lytx create my-app --template spa --ts --router --store
703
- ${t("$","dim")} lytx create my-app --template ssr --ts
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-app --template ssr --ts
704
991
 
705
- `,We=`
706
- ${t("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
992
+ `,Ze=`
993
+ ${o("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
707
994
 
708
- ${t("\u7528\u6CD5:","brightGreen")}
995
+ ${o("\u7528\u6CD5:","brightGreen")}
709
996
  lytx dev [options]
710
997
 
711
- ${t("\u9009\u9879:","brightGreen")}
712
- ${t("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 3000\uFF09
713
- ${t("--hmr","brightYellow")} \u5F00\u542F\u70ED\u66F4\u65B0\uFF08\u9ED8\u8BA4: \u5F00\u542F\uFF09
714
- ${t("--no-hmr","brightYellow")} \u5173\u95ED\u70ED\u66F4\u65B0
998
+ ${o("\u9009\u9879:","brightGreen")}
999
+ ${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 3000\uFF09
1000
+ ${o("--hmr","brightYellow")} \u5F00\u542F\u70ED\u66F4\u65B0\uFF08\u9ED8\u8BA4: \u5F00\u542F\uFF09
1001
+ ${o("--no-hmr","brightYellow")} \u5173\u95ED\u70ED\u66F4\u65B0
715
1002
 
716
- ${t("\u529F\u80FD:","brightGreen")}
1003
+ ${o("\u529F\u80FD:","brightGreen")}
717
1004
  - \u9759\u6001\u6587\u4EF6\u670D\u52A1
718
1005
  - TypeScript \u5373\u65F6\u7F16\u8BD1
719
1006
  - \u70ED\u6A21\u5757\u66FF\u6362\uFF08HMR\uFF09
720
1007
  - WebSocket \u5B9E\u65F6\u901A\u4FE1
721
1008
 
722
- ${t("\u793A\u4F8B:","brightGreen")}
723
- ${t("$","dim")} lytx dev
724
- ${t("$","dim")} lytx dev --port 8080
725
- ${t("$","dim")} lytx dev --no-hmr
1009
+ ${o("\u793A\u4F8B:","brightGreen")}
1010
+ ${o("$","dim")} lytx dev
1011
+ ${o("$","dim")} lytx dev --port 8080
1012
+ ${o("$","dim")} lytx dev --no-hmr
726
1013
 
727
- `,ze=`
728
- ${t("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
1014
+ `,Xe=`
1015
+ ${o("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
729
1016
 
730
- ${t("\u7528\u6CD5:","brightGreen")}
1017
+ ${o("\u7528\u6CD5:","brightGreen")}
731
1018
  lytx build [options]
732
1019
 
733
- ${t("\u9009\u9879:","brightGreen")}
734
- ${t("--mode <mode>","brightYellow")} \u6784\u5EFA\u6A21\u5F0F\uFF08\u9ED8\u8BA4: spa\uFF09
1020
+ ${o("\u9009\u9879:","brightGreen")}
1021
+ ${o("--mode <mode>","brightYellow")} \u6784\u5EFA\u6A21\u5F0F\uFF08\u9ED8\u8BA4: spa\uFF09
735
1022
  \u53EF\u9009\u503C: spa, ssr, ssg
736
- ${t("--minify","brightYellow")} \u538B\u7F29\u4EE3\u7801\uFF08\u53BB\u9664\u7A7A\u767D\u548C\u6CE8\u91CA\uFF09
737
- ${t("-o, --outDir <dir>","brightYellow")} \u8F93\u51FA\u76EE\u5F55\uFF08\u9ED8\u8BA4: dist\uFF09
738
- ${t("--entry <file>","brightYellow")} \u5165\u53E3\u6587\u4EF6\uFF08\u9ED8\u8BA4: index.html\uFF09
1023
+ ${o("--minify","brightYellow")} \u538B\u7F29\u4EE3\u7801\uFF08\u53BB\u9664\u7A7A\u767D\u548C\u6CE8\u91CA\uFF09
1024
+ ${o("-o, --outDir <dir>","brightYellow")} \u8F93\u51FA\u76EE\u5F55\uFF08\u9ED8\u8BA4: dist\uFF09
1025
+ ${o("--entry <file>","brightYellow")} \u5165\u53E3\u6587\u4EF6\uFF08\u9ED8\u8BA4: index.html\uFF09
739
1026
 
740
- ${t("\u529F\u80FD:","brightGreen")}
1027
+ ${o("\u529F\u80FD:","brightGreen")}
741
1028
  - TypeScript \u7F16\u8BD1
742
1029
  - \u6A21\u5757\u6253\u5305\uFF08\u5185\u8054\u4F9D\u8D56\uFF09
743
1030
  - \u53BB\u9664 console.log
744
1031
  - Source Map \u751F\u6210
745
1032
  - \u9759\u6001\u8D44\u6E90\u590D\u5236
746
1033
 
747
- ${t("\u793A\u4F8B:","brightGreen")}
748
- ${t("$","dim")} lytx build
749
- ${t("$","dim")} lytx build --mode ssr
750
- ${t("$","dim")} lytx build --minify --outDir ./output
1034
+ ${o("\u793A\u4F8B:","brightGreen")}
1035
+ ${o("$","dim")} lytx build
1036
+ ${o("$","dim")} lytx build --mode ssr
1037
+ ${o("$","dim")} lytx build --minify --outDir ./output
751
1038
 
752
- `,Ne=`
753
- ${t("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
1039
+ `,Qe=`
1040
+ ${o("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
754
1041
 
755
- ${t("\u7528\u6CD5:","brightGreen")}
1042
+ ${o("\u7528\u6CD5:","brightGreen")}
756
1043
  lytx preview [options]
757
1044
 
758
- ${t("\u9009\u9879:","brightGreen")}
759
- ${t("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 4173\uFF09
1045
+ ${o("\u9009\u9879:","brightGreen")}
1046
+ ${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 4173\uFF09
760
1047
 
761
- ${t("\u793A\u4F8B:","brightGreen")}
762
- ${t("$","dim")} lytx preview
763
- ${t("$","dim")} lytx preview --port 5000
1048
+ ${o("\u793A\u4F8B:","brightGreen")}
1049
+ ${o("$","dim")} lytx preview
1050
+ ${o("$","dim")} lytx preview --port 5000
764
1051
 
765
- `;function Ye(){console.log(""),console.log(` ${t(re,"brightCyan")} v${t(Ge,"brightWhite")}`),console.log("")}function _e(e){i.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 Je(e){return typeof e=="string"&&["spa","ssr","ssg"].includes(e)?e:"spa"}async function qe(e){if(e.options.help){console.log(Ue);return}e.args.length===0&&(i.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 n={name:o,template:Je(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(n)}else{let n={template:typeof e.options.template=="string"?e.options.template:"spa"};await _(o,n)}}function Ve(e){if(e.options.help){console.log(We);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)&&(i.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1)),W(o)}async function Ke(e){if(e.options.help){console.log(ze);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 Z(o)}function Xe(e){if(e.options.help){console.log(Ne);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)&&(i.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1));let r=oe.resolve(process.cwd(),"dist");te.existsSync(r)||(i.error("\u672A\u627E\u5230\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55 dist/\uFF0C\u8BF7\u5148\u8FD0\u884C lytx build"),process.exit(1)),W({port:o,root:r,hmr:!1})}async function Qe(){let e=Y(process.argv);if(e.options.version){Ye();return}if(e.options.help&&!e.command){console.log(ee);return}e.command||(console.log(ee),process.exit(1));try{switch(e.command){case"create":await qe(e);break;case"dev":Ve(e);break;case"build":await Ke(e);break;case"preview":Xe(e);break;default:_e(e.command),process.exit(1)}}catch(o){let r=o instanceof Error?o.message:String(o);i.error(`\u6267\u884C\u5931\u8D25: ${r}`),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)}}Qe();0&&(module.exports={createHMREndpoint,createHMRServer,createProject,getHMRClientScript});
1052
+ `;function et(){console.log(""),console.log(` ${o(ae,"brightCyan")} v${o(Ve,"brightWhite")}`),console.log("")}function tt(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 ot(e){return typeof e=="string"&&["spa","ssr","ssg"].includes(e)?e:"spa"}async function rt(e){if(e.options.help){console.log(Ke);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];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 n={name:t,template:ot(e.options.template),ts:e.options.ts===!0,router:e.options.router===!0,store:e.options.store===!0,eslint:e.options.eslint===!0};await G(n)}else{let n={template:typeof e.options.template=="string"?e.options.template:"spa"};await V(t,n)}}function nt(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)&&(i.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1)),z(t)}async function st(e){if(e.options.help){console.log(Xe);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 te(t)}function it(e){if(e.options.help){console.log(Qe);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 r=ie.resolve(process.cwd(),"dist");se.existsSync(r)||(i.error("\u672A\u627E\u5230\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55 dist/\uFF0C\u8BF7\u5148\u8FD0\u884C lytx build"),process.exit(1)),z({port:t,root:r,hmr:!1})}async function at(){let e=J(process.argv);if(e.options.version){et();return}if(e.options.help&&!e.command){console.log(ne);return}e.command||(console.log(ne),process.exit(1));try{switch(e.command){case"create":await rt(e);break;case"dev":nt(e);break;case"build":await st(e);break;case"preview":it(e);break;case"generate":if(e.options.help){console.log(U);break}await re(e.args);break;default:tt(e.command),process.exit(1)}}catch(t){let r=t instanceof Error?t.message:String(t);i.error(`\u6267\u884C\u5931\u8D25: ${r}`),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)}}at();0&&(module.exports={createHMREndpoint,createHMRServer,createProject,getHMRClientScript});