@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 +386 -99
- package/dist/index.mjs +386 -99
- package/dist/types/generate.d.ts +14 -0
- package/dist/types/generate.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cli.js +0 -2
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var z=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(t,r)=>(typeof require!="undefined"?require:t)[r]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import*as oe from"fs";import*as re from"path";import*as x from"fs";import*as G from"path";var se="\x1B[0m",ie={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=ie[t];return r?`${r}${e}${se}`:e}function W(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 w(e){x.existsSync(e)||x.mkdirSync(e,{recursive:!0})}function I(e){return x.existsSync(e)}function k(e){return x.readFileSync(e,"utf-8")}function S(e,t){let r=G.dirname(e);w(r),x.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}`)}};import*as H from"path";function ae(){return`<!DOCTYPE html>
|
|
3
3
|
<html lang="zh-CN">
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="UTF-8" />
|
|
@@ -12,7 +12,7 @@ var W=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Prox
|
|
|
12
12
|
<script type="module" src="/src/main.ts"></script>
|
|
13
13
|
</body>
|
|
14
14
|
</html>
|
|
15
|
-
`}function
|
|
15
|
+
`}function le(){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
|
|
23
|
+
`}function ce(){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
|
|
118
|
+
`}function pe(){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
|
|
308
|
-
`}function
|
|
309
|
-
`}function
|
|
307
|
+
`}function de(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 ue(){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 me(){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
|
|
337
|
+
`}function ge(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
|
|
397
|
-
`}function
|
|
398
|
-
`}function
|
|
396
|
+
`}async function _(e,t={}){let r=t.template||"spa",n=H.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")}`),I(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)),w(n);let s=[{filePath:"index.html",content:ae()},{filePath:"src/main.ts",content:le()},{filePath:"src/App.ts",content:ce()},{filePath:"src/style.css",content:pe()},{filePath:"package.json",content:de(e)},{filePath:"tsconfig.json",content:ue()},{filePath:".gitignore",content:me()},{filePath:"README.md",content:ge(e)}];for(let a of s){let u=H.join(n,a.filePath);S(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("")}import*as F from"path";function fe(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 he(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 ye(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${
|
|
408
|
+
<script type="module" src="/src/main${t}"></script>
|
|
409
409
|
</body>
|
|
410
410
|
</html>
|
|
411
|
-
`}function
|
|
412
|
-
`)}function
|
|
411
|
+
`}function be(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 xe(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
|
|
414
|
+
`}function ve(){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
|
|
442
|
+
`}function $e(){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
|
|
454
|
+
`}function we(){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
|
|
466
|
+
`}function je(){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
|
|
480
|
+
`}function Se(){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
|
|
497
|
+
`}function Ce(){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
|
|
525
|
+
`}function Pe(){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
|
|
549
|
+
`}function ke(){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
|
|
554
|
-
`}async function
|
|
553
|
+
`}function Ae(){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 D(e){let{name:t,template:r,ts:n,router:s,store:a,eslint:u}=e,p=F.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")}`),I(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`);w(p);let d=[{filePath:"package.json",content:fe(e)},{filePath:"index.html",content:ye(e)},{filePath:"lytx.config.ts",content:be(e)},{filePath:"src/main.ts",content:xe(e)},{filePath:"src/App.lyt",content:ve()},{filePath:"src/pages/index.ts",content:$e()},{filePath:"src/pages/about.ts",content:we()},{filePath:"src/components/Header.ts",content:je()},{filePath:"src/styles/main.css",content:Pe()},{filePath:"public/favicon.svg",content:ke()}];n&&d.push({filePath:"tsconfig.json",content:he(e)}),s&&d.push({filePath:"src/router/index.ts",content:Se()}),a&&d.push({filePath:"src/store/index.ts",content:Ce()}),u&&d.push({filePath:".eslintrc.json",content:Ae()});for(let c of d){let m=F.join(p,c.filePath);S(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("")}import*as q from"http";import*as C from"fs";import*as y from"path";import*as J from"http";import*as A from"fs";import*as v from"path";import*as V from"crypto";var L=class{constructor(){this.clients=[]}handleUpgrade(t,r,n){let s=t.headers["sec-websocket-key"];if(!s){r.destroy();return}let a=V.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: ${
|
|
557
|
+
Sec-WebSocket-Accept: ${a}\r
|
|
558
558
|
\r
|
|
559
|
-
`);let
|
|
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 Me(e){let t=new L,r=[],n=[],s=null,a=!1;function u(d){let c=v.extname(d).toLowerCase();if(c===".css")return"css";let m=v.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=A.readdirSync(d,{withFileTypes:!0});for(let m of c){let l=v.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=v.extname(m.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(f))try{let R=A.watch(l,{persistent:!1},N=>{if(N==="change"){let E=v.relative(e,l);for(let j of r)try{j(E)}catch(T){}let P=u(l),$={type:P,path:`/${E}`};if(P==="css")try{$.content=A.readFileSync(l,"utf-8")}catch(j){}t.broadcast(JSON.stringify($))}});n.push(R)}catch(R){}}}}catch(c){}}return{start(d){a||(a=!0,s=J.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 L;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
|
|
658
|
-
</head>`)),{statusCode:200,headers:{"Content-Type":
|
|
659
|
-
${
|
|
657
|
+
})();`}var K;try{K=z("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 Re(e,t){try{return K.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 Ee(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=y.join(t,"node_modules",r.slice(1)):c=y.join(t,r.slice(1)),r.match(/^\/(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/)&&!r.includes(".")){let m=y.join(c,"package.json");if(C.existsSync(m))try{let l=JSON.parse(k(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=y.join(c,f)}catch(l){}}if(C.existsSync(c)&&C.statSync(c).isFile()){let m=y.extname(c).toLowerCase(),f={".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".json":"application/json; charset=utf-8"}[m]||"application/octet-stream",b=k(c);return{statusCode:200,headers:{"Content-Type":f},body:b}}}let n=y.join(t,r);if(!n.startsWith(t))return{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"};if(!C.existsSync(n)||!C.statSync(n).isFile())return{statusCode:404,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"404 Not Found"};let s=y.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=k(n);return(s===".ts"||s===".tsx")&&(p=Re(p,r)),s===".html"&&(p=p.replace("</head>",`<script>${Y()}</script>
|
|
658
|
+
</head>`)),{statusCode:200,headers:{"Content-Type":u},body:p}}function U(e={}){let t=e.port||3e3,r=y.resolve(e.root||process.cwd()),n=e.hmr!==!1,s=q.createServer((p,d)=>{let c=Ee(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)}import*as h from"fs";import*as g from"path";var Z;try{Z=z("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 X(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);h.existsSync(u)||(i.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${u}`),process.exit(1));let p=k(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};w(n),w(g.join(n,"assets"));for(let b of m){let R=g.join(r,b);if(!h.existsSync(R)){i.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${b}`);continue}i.info(`\u6B63\u5728\u6253\u5305: ${o(b,"brightYellow")}`);let E=`${g.basename(b,g.extname(b))}.bundle.js`,P=g.join(n,"assets",E);try{await Z.build({entryPoints:[R],bundle:!0,minify:a,target:"es2018",format:"esm",outfile:P,sourcemap:!0,external:T=>T.startsWith("@lytjs/"),drop:a?["console"]:[],metafile:!0});let $=h.readFileSync(P,"utf-8");l.totalSize+=Buffer.byteLength($,"utf-8"),l.outputFiles++;let j=P+".map";if(h.existsSync(j)){let T=h.readFileSync(j,"utf-8");l.totalSize+=Buffer.byteLength(T,"utf-8"),l.outputFiles++}p=p.replace(`<script type="module" src="${b}"></script>`,`<script src="/assets/${E}"></script>`),l.inputFiles++}catch($){let j=$ instanceof Error?$.message:String($);i.error(`\u6253\u5305\u5931\u8D25 ${b}: ${j}`),process.exit(1)}}Te(r,n,l);let f=g.join(n,"index.html");S(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")} ${Ie(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 Te(e,t,r){let n=g.join(e,"src");if(!h.existsSync(n))return;function s(a,u){let p=h.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);S(f,h.readFileSync(c).toString("utf-8")),r.outputFiles++,r.totalSize+=h.statSync(c).size}}}s(n,n)}function Ie(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]}`}import*as M from"fs";import*as Q from"path";var O=`
|
|
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 He(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 Fe(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 Le(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 Oe(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 Ge(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 ee(e){let t=He(e);t.type||(i.error("\u8BF7\u63D0\u4F9B\u751F\u6210\u7C7B\u578B (component, store, page, api)"),console.log(""),console.log(O),process.exit(1)),t.name||(i.error("\u8BF7\u63D0\u4F9B\u540D\u79F0"),console.log(""),console.log(O),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=Fe(t.name,t),n=`./src/components/${t.name}.lyt`;break;case"store":r=Le(t.name),n=`./src/stores/${t.name}.js`;break;case"page":r=Oe(t.name),n=`./src/pages/${t.name}.lyt`;break;case"api":r=Ge(t.name),n=`./src/api/${t.name}.js`;break}let s=t.outputPath||n,a=Q.dirname(s);M.existsSync(a)||M.mkdirSync(a,{recursive:!0}),M.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 De="0.2.0",ne="lytx",Be="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",te=`
|
|
945
|
+
${o(ne,"brightCyan")} - ${Be}
|
|
660
946
|
|
|
661
|
-
${
|
|
947
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
662
948
|
lytx <command> [options] [args]
|
|
663
949
|
|
|
664
|
-
${
|
|
665
|
-
${
|
|
666
|
-
${
|
|
667
|
-
${
|
|
668
|
-
${
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
${
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
${
|
|
677
|
-
${
|
|
678
|
-
${
|
|
679
|
-
${
|
|
680
|
-
${
|
|
681
|
-
${
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
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
|
+
`,Ye=`
|
|
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
|
-
${
|
|
690
|
-
${
|
|
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
|
-
${
|
|
693
|
-
${
|
|
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
|
-
${
|
|
696
|
-
${
|
|
697
|
-
${
|
|
698
|
-
${
|
|
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
|
-
${
|
|
701
|
-
${
|
|
702
|
-
${
|
|
703
|
-
${
|
|
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
|
-
`,
|
|
706
|
-
${
|
|
992
|
+
`,Ue=`
|
|
993
|
+
${o("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
707
994
|
|
|
708
|
-
${
|
|
995
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
709
996
|
lytx dev [options]
|
|
710
997
|
|
|
711
|
-
${
|
|
712
|
-
${
|
|
713
|
-
${
|
|
714
|
-
${
|
|
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
|
-
${
|
|
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
|
-
${
|
|
723
|
-
${
|
|
724
|
-
${
|
|
725
|
-
${
|
|
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
|
-
`,
|
|
728
|
-
${
|
|
1014
|
+
`,Ne=`
|
|
1015
|
+
${o("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
729
1016
|
|
|
730
|
-
${
|
|
1017
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
731
1018
|
lytx build [options]
|
|
732
1019
|
|
|
733
|
-
${
|
|
734
|
-
${
|
|
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
|
-
${
|
|
737
|
-
${
|
|
738
|
-
${
|
|
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
|
-
${
|
|
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
|
-
${
|
|
748
|
-
${
|
|
749
|
-
${
|
|
750
|
-
${
|
|
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
|
-
`,
|
|
753
|
-
${
|
|
1039
|
+
`,ze=`
|
|
1040
|
+
${o("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
754
1041
|
|
|
755
|
-
${
|
|
1042
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
756
1043
|
lytx preview [options]
|
|
757
1044
|
|
|
758
|
-
${
|
|
759
|
-
${
|
|
1045
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
1046
|
+
${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 4173\uFF09
|
|
760
1047
|
|
|
761
|
-
${
|
|
762
|
-
${
|
|
763
|
-
${
|
|
1048
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
1049
|
+
${o("$","dim")} lytx preview
|
|
1050
|
+
${o("$","dim")} lytx preview --port 5000
|
|
764
1051
|
|
|
765
|
-
`;function
|
|
1052
|
+
`;function We(){console.log(""),console.log(` ${o(ne,"brightCyan")} v${o(De,"brightWhite")}`),console.log("")}function _e(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 Je(e){return typeof e=="string"&&["spa","ssr","ssg"].includes(e)?e:"spa"}async function Ve(e){if(e.options.help){console.log(Ye);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: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 D(n)}else{let n={template:typeof e.options.template=="string"?e.options.template:"spa"};await _(t,n)}}function qe(e){if(e.options.help){console.log(Ue);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)),U(t)}async function Ke(e){if(e.options.help){console.log(Ne);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 X(t)}function Ze(e){if(e.options.help){console.log(ze);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=re.resolve(process.cwd(),"dist");oe.existsSync(r)||(i.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:r,hmr:!1})}async function Xe(){let e=W(process.argv);if(e.options.version){We();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 Ve(e);break;case"dev":qe(e);break;case"build":await Ke(e);break;case"preview":Ze(e);break;case"generate":if(e.options.help){console.log(O);break}await ee(e.args);break;default:_e(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)}}Xe();export{B as createHMREndpoint,Me as createHMRServer,D as createProject,Y as getHMRClientScript};
|