@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.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
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
|
|
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
|
|
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
|
|
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
|
|
308
|
-
`}function
|
|
309
|
-
`}function
|
|
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
|
|
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
|
|
397
|
-
`}function
|
|
398
|
-
`}function
|
|
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${
|
|
408
|
+
<script type="module" src="/src/main${t}"></script>
|
|
409
409
|
</body>
|
|
410
410
|
</html>
|
|
411
|
-
`}function
|
|
412
|
-
`)}function
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
554
|
-
`}async function
|
|
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: ${
|
|
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 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
|
|
658
|
-
</head>`)),{statusCode:200,headers:{"Content-Type":
|
|
659
|
-
${
|
|
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
|
-
${
|
|
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
|
+
`,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
|
-
${
|
|
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
|
+
`,Ze=`
|
|
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
|
+
`,Xe=`
|
|
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
|
+
`,Qe=`
|
|
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 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});
|