@lytjs/cli 4.1.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.cjs +2 -0
- package/dist/bin/cli.js +2 -0
- package/dist/bin/cli.mjs +1 -0
- package/dist/index.js +393 -100
- package/dist/index.mjs +393 -100
- package/dist/types/bin/cli.d.ts +9 -0
- package/dist/types/bin/cli.d.ts.map +1 -0
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/dev.d.ts +1 -1
- package/dist/types/dev.d.ts.map +1 -1
- 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/dist/types/scaffold.d.ts +16 -1
- package/dist/types/scaffold.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/utils.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
|
+
"use strict";var me=Object.create;var G=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var be=(e,t)=>{for(var n in t)G(e,n,{get:t[n],enumerable:!0})},X=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of fe(t))!ye.call(e,s)&&s!==n&&G(e,s,{get:()=>t[s],enumerable:!(r=ge(t,s))||r.enumerable});return e};var g=(e,t,n)=>(n=e!=null?me(he(e)):{},X(t||!e||!e.__esModule?G(n,"default",{value:e,enumerable:!0}):n,e)),xe=e=>X(G({},"__esModule",{value:!0}),e);var ht={};be(ht,{createHMREndpoint:()=>U,createHMRServer:()=>re,createProject:()=>B,getHMRClientScript:()=>N});module.exports=xe(ht);var pe=g(require("fs")),de=g(require("path"));var $=g(require("fs")),J=g(require("path")),ve="\x1B[0m",$e={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m",bgBlack:"\x1B[40m",bgRed:"\x1B[41m",bgGreen:"\x1B[42m",bgYellow:"\x1B[43m",bgBlue:"\x1B[44m",bgMagenta:"\x1B[45m",bgCyan:"\x1B[46m",bgWhite:"\x1B[47m",bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",strikethrough:"\x1B[9m"};function o(e,t){let n=$e[t];return n?`${n}${e}${ve}`:e}function Q(e){let t=e.slice(2),n={command:"",args:[],options:{},raw:t},r=0;for(;r<t.length;){let s=t[r];if(s==="--help"||s==="-h")n.options.help=!0,r++;else if(s==="--version"||s==="-v")n.options.version=!0,r++;else if(s.startsWith("--")){let a=s.indexOf("=");if(a!==-1){let p=s.slice(2,a),d=s.slice(a+1);n.options[p]=d}else{let p=s.slice(2),d=t[r+1];d&&!d.startsWith("-")?(n.options[p]=d,r++):n.options[p]=!0}r++}else if(s.startsWith("-")&&s.length>1){let a=s.slice(1),p=t[r+1];p&&!p.startsWith("-")?(n.options[a]=p,r++):n.options[a]=!0,r++}else n.command?(n.args.push(s),r++):(n.command=s,r++)}return n}function w(e){$.existsSync(e)||$.mkdirSync(e,{recursive:!0})}function F(e){return $.existsSync(e)}function j(e){return $.readFileSync(e,"utf-8")}function S(e,t){let n=J.dirname(e);w(n),typeof t=="string"?$.writeFileSync(e,t,"utf-8"):$.writeFileSync(e,t)}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=g(require("path"));function we(){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 Se(){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 je(){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 Ce(){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 Pe(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 ke(){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 Ae(){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 Re(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 ee(e,t={}){let n=t.template||"spa",r=L.resolve(process.cwd(),e);i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(e,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(n,"brightCyan")}`),F(r)&&(i.error(`\u76EE\u5F55 "${e}" \u5DF2\u5B58\u5728\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u540D\u79F0\u6216\u5220\u9664\u5DF2\u6709\u76EE\u5F55`),process.exit(1)),w(r);let s=[{filePath:"index.html",content:we()},{filePath:"src/main.ts",content:Se()},{filePath:"src/App.ts",content:je()},{filePath:"src/style.css",content:Ce()},{filePath:"package.json",content:Pe(e)},{filePath:"tsconfig.json",content:ke()},{filePath:".gitignore",content:Ae()},{filePath:"README.md",content:Re(e)}];for(let a of s){let p=L.join(r,a.filePath);S(p,a.content),i.success(` \u521B\u5EFA ${a.filePath}`)}console.log(""),i.success(`\u9879\u76EE ${o(e,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`),console.log(""),console.log(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u542F\u52A8\u9879\u76EE\uFF1A"),console.log(""),console.log(` ${o("cd","brightGreen")} ${e}`),console.log(` ${o("npm install","brightGreen")}`),console.log(` ${o("npm run dev","brightGreen")}`),console.log("")}var O=g(require("fs")),y=g(require("path"));var D={spa:{description:"\u57FA\u7840 SPA \u5355\u9875\u5E94\u7528\uFF08\u8BA1\u6570\u5668\u793A\u4F8B\uFF09",type:"builtin"},ssr:{description:"SSR \u670D\u52A1\u7AEF\u6E32\u67D3\u5E94\u7528",type:"builtin"},ssg:{description:"SSG \u9759\u6001\u7AD9\u70B9\u751F\u6210",type:"builtin"},"todo-app":{description:"Todo \u5F85\u529E\u4E8B\u9879\u5E94\u7528\uFF08\u54CD\u5E94\u5F0F + LocalStorage \u6301\u4E45\u5316\uFF09",type:"example"},"admin-dashboard":{description:"Admin Dashboard \u4F01\u4E1A\u7EA7\u540E\u53F0\u7BA1\u7406\u7CFB\u7EDF\uFF0810 \u4E2A\u9875\u9762\uFF09",type:"example"}};function V(){let e={};for(let[t,n]of Object.entries(D))e[t]=n.description;return e}function K(e){return e in D}function Te(e){let t={name:e.name,version:"0.1.0",private:!0,type:"module",scripts:{dev:"lytx dev",build:"lytx build",preview:"lytx preview"},dependencies:{"@lytjs/lytjs":"latest"}};return e.ts&&(t.devDependencies={"@lytjs/cli":"latest",typescript:"^5.0.1"}),e.eslint&&(t.devDependencies=t.devDependencies||{},t.devDependencies.eslint="^8.0.0",t.scripts=t.scripts||{},t.scripts.lint="eslint src --ext .ts,.js"),e.router&&(t.dependencies["@lytjs/router"]="latest"),e.store&&(t.dependencies["@lytjs/store"]="latest"),JSON.stringify(t,null,2)+`
|
|
397
|
+
`}function Me(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 Ee(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 Ie(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 Fe(e){let t=e.ts?".ts":".js",n=["import { createApp } from '@lytjs/lytjs'","import App from './App.lyt'","import './styles/main.css'"];return e.router&&n.push("import { router } from './router'"),e.store&&n.push("import { store } from './store'"),n.push(""),n.push("// \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B"),n.push("const app = createApp(App)"),e.router&&n.push("app.use(router)"),e.store&&n.push("app.use(store)"),n.push(""),n.push("// \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20"),n.push("app.mount('#app')"),n.join(`
|
|
413
413
|
`)+`
|
|
414
|
-
`}function
|
|
414
|
+
`}function Oe(){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 He(){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 Ge(){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 Le(){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 De(){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 Be(){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 Ye(){return`/* \u5168\u5C40\u6837\u5F0F */
|
|
526
526
|
|
|
527
527
|
* {
|
|
528
528
|
margin: 0;
|
|
@@ -546,17 +546,18 @@ a {
|
|
|
546
546
|
a:hover {
|
|
547
547
|
text-decoration: underline;
|
|
548
548
|
}
|
|
549
|
-
`}function
|
|
549
|
+
`}function Ue(){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
|
-
`}
|
|
553
|
+
`}function Ne(){return JSON.stringify({root:!0,env:{browser:!0,es2021:!0,node:!0},extends:["eslint:recommended"],parserOptions:{ecmaVersion:"latest",sourceType:"module"},rules:{"no-unused-vars":"warn","no-console":"warn"}},null,2)+`
|
|
554
|
+
`}function te(e,t){if(!O.existsSync(e))throw new Error(`\u6A21\u677F\u76EE\u5F55\u4E0D\u5B58\u5728: ${e}`);let n=O.readdirSync(e,{withFileTypes:!0});for(let r of n){let s=y.join(e,r.name),a=y.join(t,r.name);if(!(r.name===".DS_Store"||r.name==="node_modules"))if(r.isDirectory())te(s,a);else{w(y.dirname(a));let p=j(s);S(a,p),i.success(` \u521B\u5EFA ${y.relative(t,a)}`)}}}async function ze(e){let{name:t,template:n}=e,r=y.resolve(process.cwd(),t);if(i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(t,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(n,"brightCyan")} (${D[n].description})`),F(r))throw i.error(`\u76EE\u5F55 "${t}" \u5DF2\u5B58\u5728\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u540D\u79F0\u6216\u5220\u9664\u5DF2\u6709\u76EE\u5F55`),new Error(`Directory "${t}" already exists`);w(r);let s=y.resolve(__dirname,".."),a=y.join(s,"templates",n);te(a,r);let p=y.join(r,"package.json");if(O.existsSync(p)){let d=j(p),u=JSON.parse(d);u.name=t,S(p,JSON.stringify(u,null,2)+`
|
|
555
|
+
`),i.success(` \u66F4\u65B0 package.json (name: ${t})`)}console.log(""),i.success(`\u9879\u76EE ${o(t,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`),console.log(""),console.log(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u542F\u52A8\u9879\u76EE\uFF1A"),console.log(""),console.log(` ${o("cd","brightGreen")} ${t}`),console.log(` ${o("npm install","brightGreen")}`),console.log(` ${o("npm run dev","brightGreen")}`),console.log("")}async function B(e){var c;if(((c=D[e.template])==null?void 0:c.type)==="example")return ze(e);let{name:t,template:n,ts:r,router:s,store:a,eslint:p}=e,d=y.resolve(process.cwd(),t);if(i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(t,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(n,"brightCyan")}`),F(d))throw i.error(`\u76EE\u5F55 "${t}" \u5DF2\u5B58\u5728\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u540D\u79F0\u6216\u5220\u9664\u5DF2\u6709\u76EE\u5F55`),new Error(`Directory "${t}" already exists`);w(d);let u=[{filePath:"package.json",content:Te(e)},{filePath:"index.html",content:Ee(e)},{filePath:"lytx.config.ts",content:Ie(e)},{filePath:"src/main.ts",content:Fe(e)},{filePath:"src/App.lyt",content:Oe()},{filePath:"src/pages/index.ts",content:He()},{filePath:"src/pages/about.ts",content:Ge()},{filePath:"src/components/Header.ts",content:Le()},{filePath:"src/styles/main.css",content:Ye()},{filePath:"public/favicon.svg",content:Ue()}];r&&u.push({filePath:"tsconfig.json",content:Me(e)}),s&&u.push({filePath:"src/router/index.ts",content:De()}),a&&u.push({filePath:"src/store/index.ts",content:Be()}),p&&u.push({filePath:".eslintrc.json",content:Ne()});for(let m of u){let l=y.join(d,m.filePath);S(l,m.content),i.success(` \u521B\u5EFA ${m.filePath}`)}console.log(""),i.success(`\u9879\u76EE ${o(t,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`),console.log(""),console.log(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u542F\u52A8\u9879\u76EE\uFF1A"),console.log(""),console.log(` ${o("cd","brightGreen")} ${t}`),console.log(` ${o("npm install","brightGreen")}`),console.log(` ${o("npm run dev","brightGreen")}`),console.log("")}var se=g(require("http")),R=g(require("fs")),v=g(require("path"));var oe=g(require("http")),M=g(require("fs")),C=g(require("path")),ne=g(require("crypto")),Y=class{constructor(){this.clients=[]}handleUpgrade(t,n,r){let s=t.headers["sec-websocket-key"];if(!s){n.destroy();return}let a=ne.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");n.write(`HTTP/1.1 101 Switching Protocols\r
|
|
555
556
|
Upgrade: websocket\r
|
|
556
557
|
Connection: Upgrade\r
|
|
557
|
-
Sec-WebSocket-Accept: ${
|
|
558
|
+
Sec-WebSocket-Accept: ${a}\r
|
|
558
559
|
\r
|
|
559
|
-
`);let
|
|
560
|
+
`);let p={socket:n,isAlive:!0};n.on("close",()=>{this.clients=this.clients.filter(d=>d!==p)}),n.on("error",()=>{this.clients=this.clients.filter(d=>d!==p)}),this.clients.push(p)}broadcast(t){let n=[];for(let r of this.clients)try{if(!r.isAlive){n.push(r);continue}let s=Buffer.from(t,"utf-8"),a=this.createFrame(129,s);r.socket.write(a)}catch(s){n.push(r)}for(let r of n){this.clients=this.clients.filter(s=>s!==r);try{r.socket.destroy()}catch(s){}}}createFrame(t,n){let r=n.length,s;r<126?s=2:r<65536?s=4:s=10;let a=Buffer.alloc(s+r);return a[0]=t,r<126?a[1]=r:r<65536?(a[1]=126,a.writeUInt16BE(r,2)):(a[1]=127,a.writeUInt32BE(0,2),a.writeUInt32BE(r,6)),n.copy(a,s),a}getClientCount(){return this.clients.length}closeAll(){for(let t of this.clients)try{t.socket.destroy()}catch(n){}this.clients=[]}};function re(e){let t=new Y,n=[],r=[],s=null,a=!1;function p(u){let c=C.extname(u).toLowerCase();if(c===".css")return"css";let m=C.basename(u);return m.startsWith("lytx.config")||m==="tsconfig.json"||m==="package.json"?"reload":c===".ts"||c===".tsx"||c===".lyt"||c===".js"||c===".jsx"?"update":"reload"}function d(u){try{let c=M.readdirSync(u,{withFileTypes:!0});for(let m of c){let l=C.join(u,m.name);if(m.isDirectory()){if(m.name==="node_modules"||m.name===".git"||m.name==="dist")continue;d(l)}else if(m.isFile()){let h=C.extname(m.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(h))try{let k=M.watch(l,{persistent:!1},Z=>{if(Z==="change"){let I=C.relative(e,l);for(let A of n)try{A(I)}catch(H){}let T=p(l),P={type:T,path:`/${I}`};if(T==="css")try{P.content=M.readFileSync(l,"utf-8")}catch(A){}t.broadcast(JSON.stringify(P))}});r.push(k)}catch(k){}}}}catch(c){}}return{start(u){a||(a=!0,s=oe.createServer((c,m)=>{m.writeHead(426,{"Content-Type":"text/plain"}),m.end("Upgrade Required")}),s.on("upgrade",(c,m,l)=>{t.handleUpgrade(c,m,l)}),s.listen(u,()=>{}),d(e))},stop(){a=!1;for(let u of r)try{u.close()}catch(c){}if(r.length=0,t.closeAll(),s){try{s.close()}catch(u){}s=null}},onFileChange(u){n.push(u)},notifyClient(u){t.broadcast(JSON.stringify(u))}}}function U(e){let t=new Y;return e.on("upgrade",(n,r,s)=>{t.handleUpgrade(n,r,s)}),{broadcast(n){t.broadcast(n)},getClientCount(){return t.getClientCount()}}}function N(){return`(function() {
|
|
560
561
|
'use strict';
|
|
561
562
|
|
|
562
563
|
var ws = null;
|
|
@@ -654,112 +655,404 @@ Sec-WebSocket-Accept: ${c}\r
|
|
|
654
655
|
|
|
655
656
|
// \u542F\u52A8\u8FDE\u63A5
|
|
656
657
|
connect();
|
|
657
|
-
})();`}var
|
|
658
|
-
</head>`)),{statusCode:200,headers:{"Content-Type":
|
|
659
|
-
${
|
|
658
|
+
})();`}var z=null;async function We(){if(!z)try{z=await import("esbuild")}catch(e){i.error("\u7F3A\u5C11\u4F9D\u8D56: esbuild"),i.error(""),i.error(" Lyt CLI \u7684\u5F00\u53D1\u670D\u52A1\u5668\u9700\u8981 esbuild \u6765\u5B9E\u65F6\u7F16\u8BD1 TypeScript\u3002"),i.error(""),i.error(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5B89\u88C5:"),i.error(` ${o("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${o("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}return z}function _e(e,t){try{return z.transformSync(e,{loader:"ts",target:"es2018",format:"esm",sourcemap:"inline"}).code}catch(n){let r=n instanceof Error?n.message:String(n);return console.error(`[Lyt CLI] \u7F16\u8BD1\u9519\u8BEF ${t||""}:`,r),e}}function Je(e,t){var u;let n=((u=e.url)==null?void 0:u.split("?")[0])||"/";if(n==="/"&&(n="/index.html"),n.startsWith("/node_modules/")||n.startsWith("/@")){let c;if(n.startsWith("/@")&&!n.startsWith("/node_modules/")?c=v.join(t,"node_modules",n.slice(1)):c=v.join(t,n.slice(1)),n.match(/^\/(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/)&&!n.includes(".")){let m=v.join(c,"package.json");if(R.existsSync(m))try{let l=JSON.parse(j(m)),h=l.module||l.main||"index.js";l.exports&&(typeof l.exports=="string"?h=l.exports:typeof l.exports=="object"&&l.exports["."]&&(typeof l.exports["."]=="string"?h=l.exports["."]:l.exports["."].import?h=l.exports["."].import:l.exports["."].default?h=l.exports["."].default:Object.values(l.exports["."])[0]&&(h=Object.values(l.exports["."])[0]))),h.startsWith("./")&&(h=h.slice(2)),c=v.join(c,h)}catch(l){}}if(R.existsSync(c)&&R.statSync(c).isFile()){let m=v.extname(c).toLowerCase(),h={".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".json":"application/json; charset=utf-8"}[m]||"application/octet-stream",x=j(c);return{statusCode:200,headers:{"Content-Type":h},body:x}}}let r=v.join(t,n);if(!r.startsWith(t))return{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"};if(!R.existsSync(r)||!R.statSync(r).isFile())return{statusCode:404,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"404 Not Found"};let s=v.extname(r).toLowerCase(),p={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".ts":"application/typescript; charset=utf-8",".json":"application/json; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".txt":"text/plain; charset=utf-8"}[s]||"application/octet-stream",d=j(r);return(s===".ts"||s===".tsx")&&(d=_e(d,n)),s===".html"&&(d=d.replace("</head>",`<script>${N()}</script>
|
|
659
|
+
</head>`)),{statusCode:200,headers:{"Content-Type":p},body:d}}async function q(e={}){let t=e.port||3e3,n=v.resolve(e.root||process.cwd()),r=e.hmr!==!1;await We();let s=se.createServer((d,u)=>{let c=Je(d,n);u.writeHead(c.statusCode,c.headers),u.end(c.body)}),a=r?U(s):null;s.listen(t,()=>{console.log(""),console.log(o(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557","brightCyan")),console.log(o(" \u2551","brightCyan")+o(" Lyt \u5F00\u53D1\u670D\u52A1\u5668\u5DF2\u542F\u52A8 ","brightWhite")+o("\u2551","brightCyan")),console.log(o(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D","brightCyan")),console.log(""),console.log(` ${o("\u279C","brightGreen")} \u672C\u5730\u8BBF\u95EE: ${o(`http://localhost:${t}`,"brightBlue")}`),console.log(` ${o("\u279C","brightGreen")} \u7F51\u7EDC\u8BBF\u95EE: ${o(`http://127.0.0.1:${t}`,"brightBlue")}`),console.log(` ${o("\u279C","brightGreen")} \u9879\u76EE\u76EE\u5F55: ${o(n,"brightBlue")}`),console.log(` ${o("\u279C","brightGreen")} \u70ED\u66F4\u65B0: ${o(r?"\u5DF2\u5F00\u542F":"\u5DF2\u5173\u95ED",r?"brightGreen":"brightRed")}`),console.log(""),console.log(` ${o("\u6309 Ctrl+C \u505C\u6B62\u670D\u52A1\u5668","dim")}`),console.log("")}),s.on("error",d=>{d.code==="EADDRINUSE"?(i.error(`\u7AEF\u53E3 ${t} \u5DF2\u88AB\u5360\u7528\uFF0C\u8BF7\u4F7F\u7528 --port \u6307\u5B9A\u5176\u4ED6\u7AEF\u53E3`),process.exit(1)):(i.error(`\u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25: ${d.message}`),process.exit(1))});let p=()=>{i.info("\u6B63\u5728\u5173\u95ED\u5F00\u53D1\u670D\u52A1\u5668..."),s.close(()=>{i.success("\u670D\u52A1\u5668\u5DF2\u5173\u95ED"),process.exit(0)}),setTimeout(()=>{i.warn("\u670D\u52A1\u5668\u5173\u95ED\u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(1)},5e3)};process.on("SIGINT",p),process.on("SIGTERM",p)}var b=g(require("fs")),f=g(require("path"));var W=null;async function Ve(){if(!W)try{W=await import("esbuild")}catch(e){i.error("\u7F3A\u5C11\u4F9D\u8D56: esbuild"),i.error(""),i.error(" Lyt CLI \u7684\u6784\u5EFA\u529F\u80FD\u9700\u8981 esbuild\u3002"),i.error(""),i.error(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5B89\u88C5:"),i.error(` ${o("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${o("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}return W}async function ie(e={}){let t=Date.now(),n=f.resolve(e.root||process.cwd()),r=f.resolve(n,e.outDir||"dist"),s=e.entry||"index.html",a=e.minify||!1;await Ve(),i.info("\u5F00\u59CB\u6784\u5EFA\u9879\u76EE..."),i.info(` \u6839\u76EE\u5F55: ${o(n,"brightCyan")}`),i.info(` \u8F93\u51FA\u76EE\u5F55: ${o(r,"brightCyan")}`),i.info(` \u538B\u7F29: ${o(a?"\u5F00\u542F":"\u5173\u95ED",a?"brightGreen":"brightYellow")}`);let p=f.join(n,s);b.existsSync(p)||(i.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${p}`),process.exit(1));let d=j(p),u=/<script\s+type="module"\s+src="([^"]+)"\s*><\/script>/g,c,m=[];for(;(c=u.exec(d))!==null;)m.push(c[1]);m.length===0&&i.warn("\u672A\u5728\u5165\u53E3 HTML \u4E2D\u627E\u5230\u6A21\u5757\u811A\u672C\u5F15\u7528");let l={inputFiles:0,outputFiles:0,totalSize:0,buildTime:0};w(r),w(f.join(r,"assets"));for(let x of m){let k=f.join(n,x);if(!b.existsSync(k)){i.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${x}`);continue}i.info(`\u6B63\u5728\u6253\u5305: ${o(x,"brightYellow")}`);let I=`${f.basename(x,f.extname(x))}.bundle.js`,T=f.join(r,"assets",I);try{await W.build({entryPoints:[k],bundle:!0,minify:a,target:"es2018",format:"esm",outfile:T,sourcemap:!0,external:H=>H.startsWith("@lytjs/"),drop:a?["console"]:[],metafile:!0});let P=b.readFileSync(T,"utf-8");l.totalSize+=Buffer.byteLength(P,"utf-8"),l.outputFiles++;let A=T+".map";if(b.existsSync(A)){let H=b.readFileSync(A,"utf-8");l.totalSize+=Buffer.byteLength(H,"utf-8"),l.outputFiles++}d=d.replace(`<script type="module" src="${x}"></script>`,`<script src="/assets/${I}"></script>`),l.inputFiles++}catch(P){let A=P instanceof Error?P.message:String(P);i.error(`\u6253\u5305\u5931\u8D25 ${x}: ${A}`),process.exit(1)}}Ke(n,r,l);let h=f.join(r,"index.html");S(h,d),l.outputFiles++,l.totalSize+=Buffer.byteLength(d,"utf-8"),l.buildTime=Date.now()-t,console.log(""),i.success("\u6784\u5EFA\u5B8C\u6210\uFF01"),console.log(""),console.log(` ${o("\u8F93\u5165\u6587\u4EF6:","brightWhite")} ${l.inputFiles} \u4E2A`),console.log(` ${o("\u8F93\u51FA\u6587\u4EF6:","brightWhite")} ${l.outputFiles} \u4E2A`),console.log(` ${o("\u603B\u5927\u5C0F:","brightWhite")} ${qe(l.totalSize)}`),console.log(` ${o("\u6784\u5EFA\u8017\u65F6:","brightWhite")} ${l.buildTime}ms`),console.log(` ${o("\u8F93\u51FA\u76EE\u5F55:","brightWhite")} ${o(r,"brightCyan")}`),console.log("")}function Ke(e,t,n){let r=f.join(e,"src");if(!b.existsSync(r))return;function s(a,p){let d=b.readdirSync(a,{withFileTypes:!0});for(let u of d){let c=f.join(a,u.name);if(u.isDirectory()){if(u.name==="node_modules")continue;s(c,p)}else if(u.isFile()){let m=f.extname(u.name);if([".ts",".tsx",".js",".jsx"].includes(m))continue;let l=f.relative(p,c),h=f.join(t,l);if(/\.(png|jpe?g|gif|svg|ico|woff2?|ttf|eot|mp[34]|webm|avi|pdf|zip|gz)$/i.test(c)){let k=b.readFileSync(c);S(h,k)}else S(h,b.readFileSync(c).toString("utf-8"));n.outputFiles++,n.totalSize+=b.statSync(c).size}}}s(r,r)}function qe(e){if(e===0)return"0 B";let t=["B","KB","MB","GB"],n=1024,r=Math.floor(Math.log(e)/Math.log(n));return`${(e/Math.pow(n,r)).toFixed(2)} ${t[r]}`}var E=g(require("fs")),ae=g(require("path"));var _=`
|
|
660
|
+
${o("lytx generate","brightCyan")} - \u751F\u6210\u4EE3\u7801\uFF08\u7EC4\u4EF6\u3001Store\u3001\u9875\u9762\u3001API\uFF09
|
|
661
|
+
|
|
662
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
663
|
+
lytx generate <type> <name> [options]
|
|
664
|
+
|
|
665
|
+
${o("\u53C2\u6570:","brightGreen")}
|
|
666
|
+
${o("<type>","brightYellow")} \u751F\u6210\u7C7B\u578B (component, store, page, api)
|
|
667
|
+
${o("<name>","brightYellow")} \u540D\u79F0
|
|
668
|
+
|
|
669
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
670
|
+
${o("--ai","brightYellow")} \u4F7F\u7528 AI \u751F\u6210\uFF08\u9700\u8981\u914D\u7F6E API Key\uFF09
|
|
671
|
+
${o("--no-ai","brightYellow")} \u4E0D\u4F7F\u7528 AI\uFF08\u6A21\u677F\u751F\u6210\uFF09
|
|
672
|
+
${o("-t, --type <type>","brightYellow")} \u7EC4\u4EF6\u7C7B\u578B (button, input, form, card, list, table, modal, dropdown, tabs, navigation, custom)
|
|
673
|
+
${o("-o, --output <path>","brightYellow")}\u8F93\u51FA\u6587\u4EF6\u8DEF\u5F84
|
|
674
|
+
${o("--no-style","brightYellow")} \u4E0D\u6DFB\u52A0\u6837\u5F0F
|
|
675
|
+
${o("--api-key <key>","brightYellow")} AI API Key
|
|
676
|
+
${o("--model <model>","brightYellow")} AI \u6A21\u578B\u540D\u79F0
|
|
677
|
+
${o("--provider <name>","brightYellow")} AI \u63D0\u4F9B\u5546 (openai, anthropic, custom)
|
|
678
|
+
${o("--base-url <url>","brightYellow")} AI API \u57FA\u7840 URL
|
|
679
|
+
|
|
680
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
681
|
+
${o("$","dim")} lytx generate component MyButton
|
|
682
|
+
${o("$","dim")} lytx generate component MyButton --type button
|
|
683
|
+
${o("$","dim")} lytx generate component MyButton --type button --ai
|
|
684
|
+
${o("$","dim")} lytx generate store counter
|
|
685
|
+
${o("$","dim")} lytx generate page Home
|
|
686
|
+
${o("$","dim")} lytx generate api users
|
|
687
|
+
`;function Ze(e){let t={type:"component",name:"",useAI:!1,style:!0};for(let n=0;n<e.length;n++){let r=e[n];r==="--ai"?t.useAI=!0:r==="--no-ai"?t.useAI=!1:r==="-t"||r==="--type"?t.componentType=e[++n]:r==="-o"||r==="--output"?t.outputPath=e[++n]:r==="--no-style"?t.style=!1:r==="--api-key"?t.apiKey=e[++n]:r==="--model"?t.model=e[++n]:r==="--provider"?t.provider=e[++n]:r==="--base-url"?t.baseUrl=e[++n]:r==="-d"||r==="--description"?t.description=e[++n]:!t.type&&["component","store","page","api"].includes(r)?t.type=r:!t.name&&!r.startsWith("-")&&(t.name=r)}return t}function Xe(e,t){let n=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),r=t.componentType||"functional",s={functional:`<!-- ${e} \u7EC4\u4EF6 -->
|
|
688
|
+
<template>
|
|
689
|
+
<div class="${n}">
|
|
690
|
+
<slot></slot>
|
|
691
|
+
</div>
|
|
692
|
+
</template>
|
|
693
|
+
|
|
694
|
+
<script setup>
|
|
695
|
+
// \u7EC4\u4EF6\u903B\u8F91
|
|
696
|
+
</script>
|
|
697
|
+
|
|
698
|
+
<style scoped>
|
|
699
|
+
.${n} {
|
|
700
|
+
/* \u6837\u5F0F */
|
|
701
|
+
}
|
|
702
|
+
</style>
|
|
703
|
+
`,button:`<!-- ${e} \u6309\u94AE\u7EC4\u4EF6 -->
|
|
704
|
+
<template>
|
|
705
|
+
<button class="${n}" :disabled="disabled" @click="handleClick">
|
|
706
|
+
<slot></slot>
|
|
707
|
+
</button>
|
|
708
|
+
</template>
|
|
709
|
+
|
|
710
|
+
<script setup>
|
|
711
|
+
import { defineProps, defineEmits } from '@lytjs/core';
|
|
712
|
+
|
|
713
|
+
const props = defineProps({
|
|
714
|
+
disabled: {
|
|
715
|
+
type: Boolean,
|
|
716
|
+
default: false
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
const emit = defineEmits(['click']);
|
|
721
|
+
|
|
722
|
+
function handleClick(event) {
|
|
723
|
+
emit('click', event);
|
|
724
|
+
}
|
|
725
|
+
</script>
|
|
726
|
+
|
|
727
|
+
<style scoped>
|
|
728
|
+
.${n} {
|
|
729
|
+
padding: 8px 16px;
|
|
730
|
+
border: none;
|
|
731
|
+
border-radius: 4px;
|
|
732
|
+
background: #3b82f6;
|
|
733
|
+
color: white;
|
|
734
|
+
cursor: pointer;
|
|
735
|
+
font-size: 14px;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
.${n}:hover:not(:disabled) {
|
|
739
|
+
background: #2563eb;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
.${n}:disabled {
|
|
743
|
+
background: #9ca3af;
|
|
744
|
+
cursor: not-allowed;
|
|
745
|
+
}
|
|
746
|
+
</style>
|
|
747
|
+
`,input:`<!-- ${e} \u8F93\u5165\u6846\u7EC4\u4EF6 -->
|
|
748
|
+
<template>
|
|
749
|
+
<div class="${n}">
|
|
750
|
+
<input
|
|
751
|
+
:value="modelValue"
|
|
752
|
+
:type="type"
|
|
753
|
+
:placeholder="placeholder"
|
|
754
|
+
:disabled="disabled"
|
|
755
|
+
@input="handleInput"
|
|
756
|
+
@change="handleChange"
|
|
757
|
+
/>
|
|
758
|
+
</div>
|
|
759
|
+
</template>
|
|
760
|
+
|
|
761
|
+
<script setup>
|
|
762
|
+
import { defineProps, defineEmits } from '@lytjs/core';
|
|
763
|
+
|
|
764
|
+
const props = defineProps({
|
|
765
|
+
modelValue: {
|
|
766
|
+
type: [String, Number],
|
|
767
|
+
default: ''
|
|
768
|
+
},
|
|
769
|
+
type: {
|
|
770
|
+
type: String,
|
|
771
|
+
default: 'text'
|
|
772
|
+
},
|
|
773
|
+
placeholder: {
|
|
774
|
+
type: String,
|
|
775
|
+
default: ''
|
|
776
|
+
},
|
|
777
|
+
disabled: {
|
|
778
|
+
type: Boolean,
|
|
779
|
+
default: false
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
const emit = defineEmits(['update:modelValue', 'change']);
|
|
784
|
+
|
|
785
|
+
function handleInput(event) {
|
|
786
|
+
emit('update:modelValue', event.target.value);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function handleChange(event) {
|
|
790
|
+
emit('change', event.target.value);
|
|
791
|
+
}
|
|
792
|
+
</script>
|
|
793
|
+
|
|
794
|
+
<style scoped>
|
|
795
|
+
.${n} input {
|
|
796
|
+
padding: 8px 12px;
|
|
797
|
+
border: 1px solid #d1d5db;
|
|
798
|
+
border-radius: 4px;
|
|
799
|
+
font-size: 14px;
|
|
800
|
+
outline: none;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
.${n} input:focus {
|
|
804
|
+
border-color: #3b82f6;
|
|
805
|
+
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
|
|
806
|
+
}
|
|
807
|
+
</style>
|
|
808
|
+
`,card:`<!-- ${e} \u5361\u7247\u7EC4\u4EF6 -->
|
|
809
|
+
<template>
|
|
810
|
+
<div class="${n}">
|
|
811
|
+
<div class="${n}-header" if="$slots.header">
|
|
812
|
+
<slot name="header"></slot>
|
|
813
|
+
</div>
|
|
814
|
+
<div class="${n}-body">
|
|
815
|
+
<slot></slot>
|
|
816
|
+
</div>
|
|
817
|
+
<div class="${n}-footer" if="$slots.footer">
|
|
818
|
+
<slot name="footer"></slot>
|
|
819
|
+
</div>
|
|
820
|
+
</div>
|
|
821
|
+
</template>
|
|
822
|
+
|
|
823
|
+
<script setup>
|
|
824
|
+
// \u7EC4\u4EF6\u903B\u8F91
|
|
825
|
+
</script>
|
|
826
|
+
|
|
827
|
+
<style scoped>
|
|
828
|
+
.${n} {
|
|
829
|
+
background: white;
|
|
830
|
+
border-radius: 8px;
|
|
831
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
832
|
+
overflow: hidden;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
.${n}-header,
|
|
836
|
+
.${n}-body,
|
|
837
|
+
.${n}-footer {
|
|
838
|
+
padding: 16px;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
.${n}-header {
|
|
842
|
+
border-bottom: 1px solid #e5e7eb;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
.${n}-footer {
|
|
846
|
+
border-top: 1px solid #e5e7eb;
|
|
847
|
+
}
|
|
848
|
+
</style>
|
|
849
|
+
`};return s[r]||s.functional}function Qe(e){let t=e.charAt(0).toLowerCase()+e.slice(1);return`/**
|
|
850
|
+
* ${e} Store
|
|
851
|
+
*/
|
|
852
|
+
|
|
853
|
+
import { createStore } from '@lytjs/store';
|
|
854
|
+
|
|
855
|
+
export const ${t}Store = createStore('${e}', {
|
|
856
|
+
state: {
|
|
857
|
+
// \u72B6\u6001\u5B9A\u4E49
|
|
858
|
+
count: 0
|
|
859
|
+
},
|
|
860
|
+
|
|
861
|
+
getters: {
|
|
862
|
+
// \u8BA1\u7B97\u5C5E\u6027
|
|
863
|
+
double: state => state.count * 2
|
|
864
|
+
},
|
|
865
|
+
|
|
866
|
+
actions: {
|
|
867
|
+
// \u65B9\u6CD5\u5B9A\u4E49
|
|
868
|
+
increment(state) {
|
|
869
|
+
state.count++;
|
|
870
|
+
},
|
|
660
871
|
|
|
661
|
-
|
|
872
|
+
decrement(state) {
|
|
873
|
+
state.count--;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
`}function et(e){let t=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();return`<!-- ${e} \u9875\u9762 -->
|
|
878
|
+
<template>
|
|
879
|
+
<div class="${t}-page">
|
|
880
|
+
<h1>${e}</h1>
|
|
881
|
+
<slot></slot>
|
|
882
|
+
</div>
|
|
883
|
+
</template>
|
|
884
|
+
|
|
885
|
+
<script setup>
|
|
886
|
+
import { ref, computed } from '@lytjs/reactivity';
|
|
887
|
+
|
|
888
|
+
// \u9875\u9762\u903B\u8F91
|
|
889
|
+
</script>
|
|
890
|
+
|
|
891
|
+
<style scoped>
|
|
892
|
+
.${t}-page {
|
|
893
|
+
padding: 20px;
|
|
894
|
+
}
|
|
895
|
+
</style>
|
|
896
|
+
`}function tt(e){return`/**
|
|
897
|
+
* ${e} API
|
|
898
|
+
*/
|
|
899
|
+
|
|
900
|
+
export default async function handler(req, res) {
|
|
901
|
+
const method = req.method;
|
|
902
|
+
|
|
903
|
+
switch (method) {
|
|
904
|
+
case 'GET':
|
|
905
|
+
// \u83B7\u53D6\u8D44\u6E90
|
|
906
|
+
res.json({
|
|
907
|
+
success: true,
|
|
908
|
+
message: 'Get ${e}',
|
|
909
|
+
data: []
|
|
910
|
+
});
|
|
911
|
+
break;
|
|
912
|
+
|
|
913
|
+
case 'POST':
|
|
914
|
+
// \u521B\u5EFA\u8D44\u6E90
|
|
915
|
+
res.status(201).json({
|
|
916
|
+
success: true,
|
|
917
|
+
message: 'Create ${e}',
|
|
918
|
+
data: {}
|
|
919
|
+
});
|
|
920
|
+
break;
|
|
921
|
+
|
|
922
|
+
case 'PUT':
|
|
923
|
+
// \u66F4\u65B0\u8D44\u6E90
|
|
924
|
+
res.json({
|
|
925
|
+
success: true,
|
|
926
|
+
message: 'Update ${e}'
|
|
927
|
+
});
|
|
928
|
+
break;
|
|
929
|
+
|
|
930
|
+
case 'DELETE':
|
|
931
|
+
// \u5220\u9664\u8D44\u6E90
|
|
932
|
+
res.json({
|
|
933
|
+
success: true,
|
|
934
|
+
message: 'Delete ${e}'
|
|
935
|
+
});
|
|
936
|
+
break;
|
|
937
|
+
|
|
938
|
+
default:
|
|
939
|
+
res.status(405).json({
|
|
940
|
+
success: false,
|
|
941
|
+
message: 'Method not allowed'
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
`}async function le(e){let t=Ze(e);t.type||(i.error("\u8BF7\u63D0\u4F9B\u751F\u6210\u7C7B\u578B (component, store, page, api)"),console.log(""),console.log(_),process.exit(1)),t.name||(i.error("\u8BF7\u63D0\u4F9B\u540D\u79F0"),console.log(""),console.log(_),process.exit(1)),i.info(`\u751F\u6210 ${t.type}: ${t.name}`),i.info(`\u4F7F\u7528 AI: ${t.useAI?"Yes":"No"}`);let n,r;switch(t.type){case"component":n=Xe(t.name,t),r=`./src/components/${t.name}.lyt`;break;case"store":n=Qe(t.name),r=`./src/stores/${t.name}.js`;break;case"page":n=et(t.name),r=`./src/pages/${t.name}.lyt`;break;case"api":n=tt(t.name),r=`./src/api/${t.name}.js`;break}let s=t.outputPath||r,a=ae.dirname(s);E.existsSync(a)||E.mkdirSync(a,{recursive:!0}),E.writeFileSync(s,n,"utf-8"),i.success(`\u6587\u4EF6\u5DF2\u4FDD\u5B58: ${s}`),t.useAI&&(console.log(""),console.log(o("\u63D0\u793A:","brightYellow")),console.log(" AI \u751F\u6210\u529F\u80FD\u9700\u8981\u5728\u9879\u76EE\u4E2D\u5B89\u88C5 @lytjs/ai"),console.log(" \u8BF7\u5148\u8FD0\u884C: lyt-ai init \u521D\u59CB\u5316\u914D\u7F6E"),console.log(""))}var ot="4.2.0",ue="lytx",nt="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",ce=`
|
|
946
|
+
${o(ue,"brightCyan")} - ${nt}
|
|
947
|
+
|
|
948
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
662
949
|
lytx <command> [options] [args]
|
|
663
950
|
|
|
664
|
-
${
|
|
665
|
-
${
|
|
666
|
-
${
|
|
667
|
-
${
|
|
668
|
-
${
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
${
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
${
|
|
677
|
-
${
|
|
678
|
-
${
|
|
679
|
-
${
|
|
680
|
-
${
|
|
681
|
-
${
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
${
|
|
685
|
-
|
|
686
|
-
|
|
951
|
+
${o("\u547D\u4EE4:","brightGreen")}
|
|
952
|
+
${o("create","brightYellow")} <name> \u521B\u5EFA\u4E00\u4E2A\u65B0\u7684 Lyt \u9879\u76EE
|
|
953
|
+
${o("dev","brightYellow")} \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
954
|
+
${o("build","brightYellow")} \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
955
|
+
${o("preview","brightYellow")} \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
956
|
+
${o("generate","brightYellow")} <type> <name> \u751F\u6210\u4EE3\u7801\uFF08\u7EC4\u4EF6\u3001Store\u3001\u9875\u9762\u3001API\uFF09
|
|
957
|
+
|
|
958
|
+
${o("\u5168\u5C40\u9009\u9879:","brightGreen")}
|
|
959
|
+
${o("-h, --help","brightYellow")} \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
|
|
960
|
+
${o("-v, --version","brightYellow")} \u663E\u793A\u7248\u672C\u53F7
|
|
961
|
+
|
|
962
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
963
|
+
${o("$","dim")} lytx create my-app
|
|
964
|
+
${o("$","dim")} lytx create my-app --template spa --ts --router --store
|
|
965
|
+
${o("$","dim")} lytx create my-todo --template todo-app
|
|
966
|
+
${o("$","dim")} lytx create my-admin --template admin-dashboard
|
|
967
|
+
${o("$","dim")} lytx dev
|
|
968
|
+
${o("$","dim")} lytx dev --port 8080 --hmr
|
|
969
|
+
${o("$","dim")} lytx build
|
|
970
|
+
${o("$","dim")} lytx build --mode ssr
|
|
971
|
+
${o("$","dim")} lytx preview --port 4173
|
|
972
|
+
|
|
973
|
+
`;function rt(){let e=V(),t="";for(let[n,r]of Object.entries(e))t+=` ${o(n,"brightYellow")} \u2014 ${r}
|
|
974
|
+
`;return`
|
|
975
|
+
${o("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
|
|
976
|
+
|
|
977
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
687
978
|
lytx create <name> [options]
|
|
688
979
|
|
|
689
|
-
${
|
|
690
|
-
${
|
|
980
|
+
${o("\u53C2\u6570:","brightGreen")}
|
|
981
|
+
${o("<name>","brightYellow")} \u9879\u76EE\u540D\u79F0\uFF08\u540C\u65F6\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF09
|
|
691
982
|
|
|
692
|
-
${
|
|
693
|
-
${
|
|
694
|
-
|
|
695
|
-
${
|
|
696
|
-
${
|
|
697
|
-
${
|
|
698
|
-
${
|
|
983
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
984
|
+
${o("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
985
|
+
${t}
|
|
986
|
+
${o("--ts","brightYellow")} \u4F7F\u7528 TypeScript\uFF08\u4EC5\u5185\u7F6E\u6A21\u677F\uFF09
|
|
987
|
+
${o("--router","brightYellow")} \u5305\u542B\u8DEF\u7531\uFF08\u4EC5\u5185\u7F6E\u6A21\u677F\uFF09
|
|
988
|
+
${o("--store","brightYellow")} \u5305\u542B\u72B6\u6001\u7BA1\u7406\uFF08\u4EC5\u5185\u7F6E\u6A21\u677F\uFF09
|
|
989
|
+
${o("--eslint","brightYellow")} \u5305\u542B ESLint \u914D\u7F6E\uFF08\u4EC5\u5185\u7F6E\u6A21\u677F\uFF09
|
|
699
990
|
|
|
700
|
-
${
|
|
701
|
-
${
|
|
702
|
-
${
|
|
703
|
-
${
|
|
991
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
992
|
+
${o("$","dim")} lytx create my-app
|
|
993
|
+
${o("$","dim")} lytx create my-app --template spa --ts --router --store
|
|
994
|
+
${o("$","dim")} lytx create my-todo --template todo-app
|
|
995
|
+
${o("$","dim")} lytx create my-admin --template admin-dashboard
|
|
996
|
+
${o("$","dim")} lytx create my-app --template ssr --ts
|
|
704
997
|
|
|
705
|
-
|
|
706
|
-
${
|
|
998
|
+
`}var st=`
|
|
999
|
+
${o("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
707
1000
|
|
|
708
|
-
${
|
|
1001
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
709
1002
|
lytx dev [options]
|
|
710
1003
|
|
|
711
|
-
${
|
|
712
|
-
${
|
|
713
|
-
${
|
|
714
|
-
${
|
|
1004
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
1005
|
+
${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 3000\uFF09
|
|
1006
|
+
${o("--hmr","brightYellow")} \u5F00\u542F\u70ED\u66F4\u65B0\uFF08\u9ED8\u8BA4: \u5F00\u542F\uFF09
|
|
1007
|
+
${o("--no-hmr","brightYellow")} \u5173\u95ED\u70ED\u66F4\u65B0
|
|
715
1008
|
|
|
716
|
-
${
|
|
1009
|
+
${o("\u529F\u80FD:","brightGreen")}
|
|
717
1010
|
- \u9759\u6001\u6587\u4EF6\u670D\u52A1
|
|
718
1011
|
- TypeScript \u5373\u65F6\u7F16\u8BD1
|
|
719
1012
|
- \u70ED\u6A21\u5757\u66FF\u6362\uFF08HMR\uFF09
|
|
720
1013
|
- WebSocket \u5B9E\u65F6\u901A\u4FE1
|
|
721
1014
|
|
|
722
|
-
${
|
|
723
|
-
${
|
|
724
|
-
${
|
|
725
|
-
${
|
|
1015
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
1016
|
+
${o("$","dim")} lytx dev
|
|
1017
|
+
${o("$","dim")} lytx dev --port 8080
|
|
1018
|
+
${o("$","dim")} lytx dev --no-hmr
|
|
726
1019
|
|
|
727
|
-
`,
|
|
728
|
-
${
|
|
1020
|
+
`,it=`
|
|
1021
|
+
${o("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
729
1022
|
|
|
730
|
-
${
|
|
1023
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
731
1024
|
lytx build [options]
|
|
732
1025
|
|
|
733
|
-
${
|
|
734
|
-
${
|
|
1026
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
1027
|
+
${o("--mode <mode>","brightYellow")} \u6784\u5EFA\u6A21\u5F0F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
735
1028
|
\u53EF\u9009\u503C: spa, ssr, ssg
|
|
736
|
-
${
|
|
737
|
-
${
|
|
738
|
-
${
|
|
1029
|
+
${o("--minify","brightYellow")} \u538B\u7F29\u4EE3\u7801\uFF08\u53BB\u9664\u7A7A\u767D\u548C\u6CE8\u91CA\uFF09
|
|
1030
|
+
${o("-o, --outDir <dir>","brightYellow")} \u8F93\u51FA\u76EE\u5F55\uFF08\u9ED8\u8BA4: dist\uFF09
|
|
1031
|
+
${o("--entry <file>","brightYellow")} \u5165\u53E3\u6587\u4EF6\uFF08\u9ED8\u8BA4: index.html\uFF09
|
|
739
1032
|
|
|
740
|
-
${
|
|
1033
|
+
${o("\u529F\u80FD:","brightGreen")}
|
|
741
1034
|
- TypeScript \u7F16\u8BD1
|
|
742
1035
|
- \u6A21\u5757\u6253\u5305\uFF08\u5185\u8054\u4F9D\u8D56\uFF09
|
|
743
1036
|
- \u53BB\u9664 console.log
|
|
744
1037
|
- Source Map \u751F\u6210
|
|
745
1038
|
- \u9759\u6001\u8D44\u6E90\u590D\u5236
|
|
746
1039
|
|
|
747
|
-
${
|
|
748
|
-
${
|
|
749
|
-
${
|
|
750
|
-
${
|
|
1040
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
1041
|
+
${o("$","dim")} lytx build
|
|
1042
|
+
${o("$","dim")} lytx build --mode ssr
|
|
1043
|
+
${o("$","dim")} lytx build --minify --outDir ./output
|
|
751
1044
|
|
|
752
|
-
`,
|
|
753
|
-
${
|
|
1045
|
+
`,at=`
|
|
1046
|
+
${o("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
754
1047
|
|
|
755
|
-
${
|
|
1048
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
756
1049
|
lytx preview [options]
|
|
757
1050
|
|
|
758
|
-
${
|
|
759
|
-
${
|
|
1051
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
1052
|
+
${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 4173\uFF09
|
|
760
1053
|
|
|
761
|
-
${
|
|
762
|
-
${
|
|
763
|
-
${
|
|
1054
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
1055
|
+
${o("$","dim")} lytx preview
|
|
1056
|
+
${o("$","dim")} lytx preview --port 5000
|
|
764
1057
|
|
|
765
|
-
`;function
|
|
1058
|
+
`;function lt(){console.log(""),console.log(` ${o(ue,"brightCyan")} v${o(ot,"brightWhite")}`),console.log("")}function ct(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 pt(e){return typeof e=="string"&&K(e)?e:"spa"}async function dt(e){if(e.options.help){console.log(rt());return}e.args.length===0&&(i.error("\u8BF7\u63D0\u4F9B\u9879\u76EE\u540D\u79F0"),console.log(""),console.log(` \u7528\u6CD5: ${o("lytx create <name>","brightCyan")}`),console.log(""),console.log(` \u8FD0\u884C ${o("lytx create --help","brightCyan")} \u67E5\u770B\u66F4\u591A\u9009\u9879`),console.log(""),process.exit(1));let t=e.args[0],n=typeof e.options.template=="string"?e.options.template:"spa";if(!K(n)){i.error(`\u672A\u77E5\u6A21\u677F: ${o(n,"brightRed")}`),console.log(""),console.log(" \u53EF\u7528\u6A21\u677F\uFF1A");let s=V();for(let[a,p]of Object.entries(s))console.log(` ${o(a,"brightYellow")} \u2014 ${p}`);console.log(""),process.exit(1)}if(e.options.ts===!0||e.options.router===!0||e.options.store===!0||e.options.eslint===!0||typeof e.options.template=="string"&&["ssr","ssg","todo-app","admin-dashboard"].includes(e.options.template)){let s={name:t,template:pt(e.options.template),ts:e.options.ts===!0,router:e.options.router===!0,store:e.options.store===!0,eslint:e.options.eslint===!0};await B(s)}else{let s={template:typeof e.options.template=="string"?e.options.template:"spa"};await ee(t,s)}}function ut(e){if(e.options.help){console.log(st);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)),q(t)}async function mt(e){if(e.options.help){console.log(it);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 ie(t)}function gt(e){if(e.options.help){console.log(at);return}let t=typeof e.options.port=="string"?parseInt(e.options.port,10):typeof e.options.p=="string"?parseInt(e.options.p,10):4173;(isNaN(t)||t<1||t>65535)&&(i.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1));let n=de.resolve(process.cwd(),"dist");pe.existsSync(n)||(i.error("\u672A\u627E\u5230\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55 dist/\uFF0C\u8BF7\u5148\u8FD0\u884C lytx build"),process.exit(1)),q({port:t,root:n,hmr:!1})}async function ft(){let e=Q(process.argv);if(e.options.version){lt();return}if(e.options.help&&!e.command){console.log(ce);return}e.command||(console.log(ce),process.exit(1));try{switch(e.command){case"create":await dt(e);break;case"dev":ut(e);break;case"build":await mt(e);break;case"preview":gt(e);break;case"generate":if(e.options.help){console.log(_);break}await le(e.args);break;default:ct(e.command),process.exit(1)}}catch(t){let n=t instanceof Error?t.message:String(t);i.error(`\u6267\u884C\u5931\u8D25: ${n}`),console.log(""),console.log(` ${o("\u63D0\u793A:","brightYellow")} \u8BF7\u68C0\u67E5\u8F93\u5165\u53C2\u6570\u6216\u8FD0\u884C ${o("lytx --help","brightCyan")} \u67E5\u770B\u5E2E\u52A9`),console.log(""),process.exit(1)}}ft();0&&(module.exports={createHMREndpoint,createHMRServer,createProject,getHMRClientScript});
|