@lytjs/cli 4.2.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 +67 -61
- package/dist/index.mjs +67 -61
- 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/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/bin/cli.cjs
ADDED
package/dist/bin/cli.js
ADDED
package/dist/bin/cli.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
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 le=Object.create;var H=Object.defineProperty;var ce=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" />
|
|
@@ -408,10 +408,10 @@ MIT
|
|
|
408
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
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,8 +655,8 @@ Sec-WebSocket-Accept: ${a}\r
|
|
|
654
655
|
|
|
655
656
|
// \u542F\u52A8\u8FDE\u63A5
|
|
656
657
|
connect();
|
|
657
|
-
})();`}var
|
|
658
|
-
</head>`)),{statusCode:200,headers:{"Content-Type":
|
|
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 _=`
|
|
659
660
|
${o("lytx generate","brightCyan")} - \u751F\u6210\u4EE3\u7801\uFF08\u7EC4\u4EF6\u3001Store\u3001\u9875\u9762\u3001API\uFF09
|
|
660
661
|
|
|
661
662
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -683,9 +684,9 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
683
684
|
${o("$","dim")} lytx generate store counter
|
|
684
685
|
${o("$","dim")} lytx generate page Home
|
|
685
686
|
${o("$","dim")} lytx generate api users
|
|
686
|
-
`;function
|
|
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 -->
|
|
687
688
|
<template>
|
|
688
|
-
<div class="${
|
|
689
|
+
<div class="${n}">
|
|
689
690
|
<slot></slot>
|
|
690
691
|
</div>
|
|
691
692
|
</template>
|
|
@@ -695,13 +696,13 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
695
696
|
</script>
|
|
696
697
|
|
|
697
698
|
<style scoped>
|
|
698
|
-
.${
|
|
699
|
+
.${n} {
|
|
699
700
|
/* \u6837\u5F0F */
|
|
700
701
|
}
|
|
701
702
|
</style>
|
|
702
703
|
`,button:`<!-- ${e} \u6309\u94AE\u7EC4\u4EF6 -->
|
|
703
704
|
<template>
|
|
704
|
-
<button class="${
|
|
705
|
+
<button class="${n}" :disabled="disabled" @click="handleClick">
|
|
705
706
|
<slot></slot>
|
|
706
707
|
</button>
|
|
707
708
|
</template>
|
|
@@ -724,7 +725,7 @@ function handleClick(event) {
|
|
|
724
725
|
</script>
|
|
725
726
|
|
|
726
727
|
<style scoped>
|
|
727
|
-
.${
|
|
728
|
+
.${n} {
|
|
728
729
|
padding: 8px 16px;
|
|
729
730
|
border: none;
|
|
730
731
|
border-radius: 4px;
|
|
@@ -734,18 +735,18 @@ function handleClick(event) {
|
|
|
734
735
|
font-size: 14px;
|
|
735
736
|
}
|
|
736
737
|
|
|
737
|
-
.${
|
|
738
|
+
.${n}:hover:not(:disabled) {
|
|
738
739
|
background: #2563eb;
|
|
739
740
|
}
|
|
740
741
|
|
|
741
|
-
.${
|
|
742
|
+
.${n}:disabled {
|
|
742
743
|
background: #9ca3af;
|
|
743
744
|
cursor: not-allowed;
|
|
744
745
|
}
|
|
745
746
|
</style>
|
|
746
747
|
`,input:`<!-- ${e} \u8F93\u5165\u6846\u7EC4\u4EF6 -->
|
|
747
748
|
<template>
|
|
748
|
-
<div class="${
|
|
749
|
+
<div class="${n}">
|
|
749
750
|
<input
|
|
750
751
|
:value="modelValue"
|
|
751
752
|
:type="type"
|
|
@@ -791,7 +792,7 @@ function handleChange(event) {
|
|
|
791
792
|
</script>
|
|
792
793
|
|
|
793
794
|
<style scoped>
|
|
794
|
-
.${
|
|
795
|
+
.${n} input {
|
|
795
796
|
padding: 8px 12px;
|
|
796
797
|
border: 1px solid #d1d5db;
|
|
797
798
|
border-radius: 4px;
|
|
@@ -799,21 +800,21 @@ function handleChange(event) {
|
|
|
799
800
|
outline: none;
|
|
800
801
|
}
|
|
801
802
|
|
|
802
|
-
.${
|
|
803
|
+
.${n} input:focus {
|
|
803
804
|
border-color: #3b82f6;
|
|
804
805
|
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
|
|
805
806
|
}
|
|
806
807
|
</style>
|
|
807
808
|
`,card:`<!-- ${e} \u5361\u7247\u7EC4\u4EF6 -->
|
|
808
809
|
<template>
|
|
809
|
-
<div class="${
|
|
810
|
-
<div class="${
|
|
810
|
+
<div class="${n}">
|
|
811
|
+
<div class="${n}-header" if="$slots.header">
|
|
811
812
|
<slot name="header"></slot>
|
|
812
813
|
</div>
|
|
813
|
-
<div class="${
|
|
814
|
+
<div class="${n}-body">
|
|
814
815
|
<slot></slot>
|
|
815
816
|
</div>
|
|
816
|
-
<div class="${
|
|
817
|
+
<div class="${n}-footer" if="$slots.footer">
|
|
817
818
|
<slot name="footer"></slot>
|
|
818
819
|
</div>
|
|
819
820
|
</div>
|
|
@@ -824,28 +825,28 @@ function handleChange(event) {
|
|
|
824
825
|
</script>
|
|
825
826
|
|
|
826
827
|
<style scoped>
|
|
827
|
-
.${
|
|
828
|
+
.${n} {
|
|
828
829
|
background: white;
|
|
829
830
|
border-radius: 8px;
|
|
830
831
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
831
832
|
overflow: hidden;
|
|
832
833
|
}
|
|
833
834
|
|
|
834
|
-
.${
|
|
835
|
-
.${
|
|
836
|
-
.${
|
|
835
|
+
.${n}-header,
|
|
836
|
+
.${n}-body,
|
|
837
|
+
.${n}-footer {
|
|
837
838
|
padding: 16px;
|
|
838
839
|
}
|
|
839
840
|
|
|
840
|
-
.${
|
|
841
|
+
.${n}-header {
|
|
841
842
|
border-bottom: 1px solid #e5e7eb;
|
|
842
843
|
}
|
|
843
844
|
|
|
844
|
-
.${
|
|
845
|
+
.${n}-footer {
|
|
845
846
|
border-top: 1px solid #e5e7eb;
|
|
846
847
|
}
|
|
847
848
|
</style>
|
|
848
|
-
`};return s[
|
|
849
|
+
`};return s[r]||s.functional}function Qe(e){let t=e.charAt(0).toLowerCase()+e.slice(1);return`/**
|
|
849
850
|
* ${e} Store
|
|
850
851
|
*/
|
|
851
852
|
|
|
@@ -873,7 +874,7 @@ export const ${t}Store = createStore('${e}', {
|
|
|
873
874
|
}
|
|
874
875
|
}
|
|
875
876
|
});
|
|
876
|
-
`}function
|
|
877
|
+
`}function et(e){let t=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();return`<!-- ${e} \u9875\u9762 -->
|
|
877
878
|
<template>
|
|
878
879
|
<div class="${t}-page">
|
|
879
880
|
<h1>${e}</h1>
|
|
@@ -892,7 +893,7 @@ import { ref, computed } from '@lytjs/reactivity';
|
|
|
892
893
|
padding: 20px;
|
|
893
894
|
}
|
|
894
895
|
</style>
|
|
895
|
-
`}function
|
|
896
|
+
`}function tt(e){return`/**
|
|
896
897
|
* ${e} API
|
|
897
898
|
*/
|
|
898
899
|
|
|
@@ -941,8 +942,8 @@ export default async function handler(req, res) {
|
|
|
941
942
|
});
|
|
942
943
|
}
|
|
943
944
|
}
|
|
944
|
-
`}async function
|
|
945
|
-
${o(
|
|
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}
|
|
946
947
|
|
|
947
948
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
948
949
|
lytx <command> [options] [args]
|
|
@@ -961,13 +962,16 @@ ${o("\u5168\u5C40\u9009\u9879:","brightGreen")}
|
|
|
961
962
|
${o("\u793A\u4F8B:","brightGreen")}
|
|
962
963
|
${o("$","dim")} lytx create my-app
|
|
963
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
|
|
964
967
|
${o("$","dim")} lytx dev
|
|
965
968
|
${o("$","dim")} lytx dev --port 8080 --hmr
|
|
966
969
|
${o("$","dim")} lytx build
|
|
967
970
|
${o("$","dim")} lytx build --mode ssr
|
|
968
971
|
${o("$","dim")} lytx preview --port 4173
|
|
969
972
|
|
|
970
|
-
|
|
973
|
+
`;function rt(){let e=V(),t="";for(let[n,r]of Object.entries(e))t+=` ${o(n,"brightYellow")} \u2014 ${r}
|
|
974
|
+
`;return`
|
|
971
975
|
${o("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
|
|
972
976
|
|
|
973
977
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -978,18 +982,20 @@ ${o("\u53C2\u6570:","brightGreen")}
|
|
|
978
982
|
|
|
979
983
|
${o("\u9009\u9879:","brightGreen")}
|
|
980
984
|
${o("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
981
|
-
|
|
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
|
|
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
|
|
986
990
|
|
|
987
991
|
${o("\u793A\u4F8B:","brightGreen")}
|
|
988
992
|
${o("$","dim")} lytx create my-app
|
|
989
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
|
|
990
996
|
${o("$","dim")} lytx create my-app --template ssr --ts
|
|
991
997
|
|
|
992
|
-
|
|
998
|
+
`}var st=`
|
|
993
999
|
${o("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
994
1000
|
|
|
995
1001
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -1011,7 +1017,7 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
1011
1017
|
${o("$","dim")} lytx dev --port 8080
|
|
1012
1018
|
${o("$","dim")} lytx dev --no-hmr
|
|
1013
1019
|
|
|
1014
|
-
`,
|
|
1020
|
+
`,it=`
|
|
1015
1021
|
${o("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
1016
1022
|
|
|
1017
1023
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -1036,7 +1042,7 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
1036
1042
|
${o("$","dim")} lytx build --mode ssr
|
|
1037
1043
|
${o("$","dim")} lytx build --minify --outDir ./output
|
|
1038
1044
|
|
|
1039
|
-
`,
|
|
1045
|
+
`,at=`
|
|
1040
1046
|
${o("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
1041
1047
|
|
|
1042
1048
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -1049,4 +1055,4 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
1049
1055
|
${o("$","dim")} lytx preview
|
|
1050
1056
|
${o("$","dim")} lytx preview --port 5000
|
|
1051
1057
|
|
|
1052
|
-
`;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});
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import*as ie from"fs";import*as ae from"path";import*as v from"fs";import*as U from"path";var ce="\x1B[0m",pe={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=pe[t];return n?`${n}${e}${ce}`: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 $(e){v.existsSync(e)||v.mkdirSync(e,{recursive:!0})}function I(e){return v.existsSync(e)}function S(e){return v.readFileSync(e,"utf-8")}function w(e,t){let n=U.dirname(e);$(n),typeof t=="string"?v.writeFileSync(e,t,"utf-8"):v.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}`)}};import*as H from"path";function de(){return`<!DOCTYPE html>
|
|
3
3
|
<html lang="zh-CN">
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="UTF-8" />
|
|
@@ -12,7 +12,7 @@ var z=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Prox
|
|
|
12
12
|
<script type="module" src="/src/main.ts"></script>
|
|
13
13
|
</body>
|
|
14
14
|
</html>
|
|
15
|
-
`}function
|
|
15
|
+
`}function ue(){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 me(){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 ge(){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 fe(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 he(){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 ye(){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 be(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 Z(e,t={}){let n=t.template||"spa",r=H.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")}`),I(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)),$(r);let s=[{filePath:"index.html",content:de()},{filePath:"src/main.ts",content:ue()},{filePath:"src/App.ts",content:me()},{filePath:"src/style.css",content:ge()},{filePath:"package.json",content:fe(e)},{filePath:"tsconfig.json",content:he()},{filePath:".gitignore",content:ye()},{filePath:"README.md",content:be(e)}];for(let a of s){let p=H.join(r,a.filePath);w(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("")}import*as F from"fs";import*as h from"path";var G={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 N(){let e={};for(let[t,n]of Object.entries(G))e[t]=n.description;return e}function z(e){return e in G}function xe(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 ve(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 $e(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" />
|
|
@@ -408,10 +408,10 @@ MIT
|
|
|
408
408
|
<script type="module" src="/src/main${t}"></script>
|
|
409
409
|
</body>
|
|
410
410
|
</html>
|
|
411
|
-
`}function
|
|
412
|
-
`)}function
|
|
411
|
+
`}function we(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 Se(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 je(){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 Ce(){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 Pe(){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 ke(){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 Ae(){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 Re(){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 Te(){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 Me(){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 Ee(){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 X(e,t){if(!F.existsSync(e))throw new Error(`\u6A21\u677F\u76EE\u5F55\u4E0D\u5B58\u5728: ${e}`);let n=F.readdirSync(e,{withFileTypes:!0});for(let r of n){let s=h.join(e,r.name),a=h.join(t,r.name);if(!(r.name===".DS_Store"||r.name==="node_modules"))if(r.isDirectory())X(s,a);else{$(h.dirname(a));let p=S(s);w(a,p),i.success(` \u521B\u5EFA ${h.relative(t,a)}`)}}}async function Ie(e){let{name:t,template:n}=e,r=h.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")} (${G[n].description})`),I(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`);$(r);let s=h.resolve(__dirname,".."),a=h.join(s,"templates",n);X(a,r);let p=h.join(r,"package.json");if(F.existsSync(p)){let d=S(p),u=JSON.parse(d);u.name=t,w(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 W(e){var c;if(((c=G[e.template])==null?void 0:c.type)==="example")return Ie(e);let{name:t,template:n,ts:r,router:s,store:a,eslint:p}=e,d=h.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")}`),I(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`);$(d);let u=[{filePath:"package.json",content:xe(e)},{filePath:"index.html",content:$e(e)},{filePath:"lytx.config.ts",content:we(e)},{filePath:"src/main.ts",content:Se(e)},{filePath:"src/App.lyt",content:je()},{filePath:"src/pages/index.ts",content:Ce()},{filePath:"src/pages/about.ts",content:Pe()},{filePath:"src/components/Header.ts",content:ke()},{filePath:"src/styles/main.css",content:Te()},{filePath:"public/favicon.svg",content:Me()}];r&&u.push({filePath:"tsconfig.json",content:ve(e)}),s&&u.push({filePath:"src/router/index.ts",content:Ae()}),a&&u.push({filePath:"src/store/index.ts",content:Re()}),p&&u.push({filePath:".eslintrc.json",content:Ee()});for(let m of u){let l=h.join(d,m.filePath);w(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("")}import*as te from"http";import*as A from"fs";import*as x from"path";import*as Q from"http";import*as T from"fs";import*as j from"path";import*as ee from"crypto";var L=class{constructor(){this.clients=[]}handleUpgrade(t,n,r){let s=t.headers["sec-websocket-key"];if(!s){n.destroy();return}let a=ee.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
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 Fe(e){let t=new L,n=[],r=[],s=null,a=!1;function p(u){let c=j.extname(u).toLowerCase();if(c===".css")return"css";let m=j.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=T.readdirSync(u,{withFileTypes:!0});for(let m of c){let l=j.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 f=j.extname(m.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(f))try{let P=T.watch(l,{persistent:!1},K=>{if(K==="change"){let E=j.relative(e,l);for(let k of n)try{k(E)}catch(O){}let R=p(l),C={type:R,path:`/${E}`};if(R==="css")try{C.content=T.readFileSync(l,"utf-8")}catch(k){}t.broadcast(JSON.stringify(C))}});r.push(P)}catch(P){}}}}catch(c){}}return{start(u){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(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 _(e){let t=new L;return e.on("upgrade",(n,r,s)=>{t.handleUpgrade(n,r,s)}),{broadcast(n){t.broadcast(n)},getClientCount(){return t.getClientCount()}}}function J(){return`(function() {
|
|
560
561
|
'use strict';
|
|
561
562
|
|
|
562
563
|
var ws = null;
|
|
@@ -654,8 +655,8 @@ Sec-WebSocket-Accept: ${a}\r
|
|
|
654
655
|
|
|
655
656
|
// \u542F\u52A8\u8FDE\u63A5
|
|
656
657
|
connect();
|
|
657
|
-
})();`}var
|
|
658
|
-
</head>`)),{statusCode:200,headers:{"Content-Type":
|
|
658
|
+
})();`}var D=null;async function Oe(){if(!D)try{D=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 D}function He(e,t){try{return D.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 Ge(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=x.join(t,"node_modules",n.slice(1)):c=x.join(t,n.slice(1)),n.match(/^\/(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/)&&!n.includes(".")){let m=x.join(c,"package.json");if(A.existsSync(m))try{let l=JSON.parse(S(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=x.join(c,f)}catch(l){}}if(A.existsSync(c)&&A.statSync(c).isFile()){let m=x.extname(c).toLowerCase(),f={".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".json":"application/json; charset=utf-8"}[m]||"application/octet-stream",b=S(c);return{statusCode:200,headers:{"Content-Type":f},body:b}}}let r=x.join(t,n);if(!r.startsWith(t))return{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"};if(!A.existsSync(r)||!A.statSync(r).isFile())return{statusCode:404,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"404 Not Found"};let s=x.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=S(r);return(s===".ts"||s===".tsx")&&(d=He(d,n)),s===".html"&&(d=d.replace("</head>",`<script>${J()}</script>
|
|
659
|
+
</head>`)),{statusCode:200,headers:{"Content-Type":p},body:d}}async function V(e={}){let t=e.port||3e3,n=x.resolve(e.root||process.cwd()),r=e.hmr!==!1;await Oe();let s=te.createServer((d,u)=>{let c=Ge(d,n);u.writeHead(c.statusCode,c.headers),u.end(c.body)}),a=r?_(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)}import*as y from"fs";import*as g from"path";var B=null;async function Le(){if(!B)try{B=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 B}async function oe(e={}){let t=Date.now(),n=g.resolve(e.root||process.cwd()),r=g.resolve(n,e.outDir||"dist"),s=e.entry||"index.html",a=e.minify||!1;await Le(),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=g.join(n,s);y.existsSync(p)||(i.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${p}`),process.exit(1));let d=S(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};$(r),$(g.join(r,"assets"));for(let b of m){let P=g.join(n,b);if(!y.existsSync(P)){i.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${b}`);continue}i.info(`\u6B63\u5728\u6253\u5305: ${o(b,"brightYellow")}`);let E=`${g.basename(b,g.extname(b))}.bundle.js`,R=g.join(r,"assets",E);try{await B.build({entryPoints:[P],bundle:!0,minify:a,target:"es2018",format:"esm",outfile:R,sourcemap:!0,external:O=>O.startsWith("@lytjs/"),drop:a?["console"]:[],metafile:!0});let C=y.readFileSync(R,"utf-8");l.totalSize+=Buffer.byteLength(C,"utf-8"),l.outputFiles++;let k=R+".map";if(y.existsSync(k)){let O=y.readFileSync(k,"utf-8");l.totalSize+=Buffer.byteLength(O,"utf-8"),l.outputFiles++}d=d.replace(`<script type="module" src="${b}"></script>`,`<script src="/assets/${E}"></script>`),l.inputFiles++}catch(C){let k=C instanceof Error?C.message:String(C);i.error(`\u6253\u5305\u5931\u8D25 ${b}: ${k}`),process.exit(1)}}De(n,r,l);let f=g.join(r,"index.html");w(f,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")} ${Be(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 De(e,t,n){let r=g.join(e,"src");if(!y.existsSync(r))return;function s(a,p){let d=y.readdirSync(a,{withFileTypes:!0});for(let u of d){let c=g.join(a,u.name);if(u.isDirectory()){if(u.name==="node_modules")continue;s(c,p)}else if(u.isFile()){let m=g.extname(u.name);if([".ts",".tsx",".js",".jsx"].includes(m))continue;let l=g.relative(p,c),f=g.join(t,l);if(/\.(png|jpe?g|gif|svg|ico|woff2?|ttf|eot|mp[34]|webm|avi|pdf|zip|gz)$/i.test(c)){let P=y.readFileSync(c);w(f,P)}else w(f,y.readFileSync(c).toString("utf-8"));n.outputFiles++,n.totalSize+=y.statSync(c).size}}}s(r,r)}function Be(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]}`}import*as M from"fs";import*as ne from"path";var Y=`
|
|
659
660
|
${o("lytx generate","brightCyan")} - \u751F\u6210\u4EE3\u7801\uFF08\u7EC4\u4EF6\u3001Store\u3001\u9875\u9762\u3001API\uFF09
|
|
660
661
|
|
|
661
662
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -683,9 +684,9 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
683
684
|
${o("$","dim")} lytx generate store counter
|
|
684
685
|
${o("$","dim")} lytx generate page Home
|
|
685
686
|
${o("$","dim")} lytx generate api users
|
|
686
|
-
`;function
|
|
687
|
+
`;function Ye(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 Ue(e,t){let n=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),r=t.componentType||"functional",s={functional:`<!-- ${e} \u7EC4\u4EF6 -->
|
|
687
688
|
<template>
|
|
688
|
-
<div class="${
|
|
689
|
+
<div class="${n}">
|
|
689
690
|
<slot></slot>
|
|
690
691
|
</div>
|
|
691
692
|
</template>
|
|
@@ -695,13 +696,13 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
695
696
|
</script>
|
|
696
697
|
|
|
697
698
|
<style scoped>
|
|
698
|
-
.${
|
|
699
|
+
.${n} {
|
|
699
700
|
/* \u6837\u5F0F */
|
|
700
701
|
}
|
|
701
702
|
</style>
|
|
702
703
|
`,button:`<!-- ${e} \u6309\u94AE\u7EC4\u4EF6 -->
|
|
703
704
|
<template>
|
|
704
|
-
<button class="${
|
|
705
|
+
<button class="${n}" :disabled="disabled" @click="handleClick">
|
|
705
706
|
<slot></slot>
|
|
706
707
|
</button>
|
|
707
708
|
</template>
|
|
@@ -724,7 +725,7 @@ function handleClick(event) {
|
|
|
724
725
|
</script>
|
|
725
726
|
|
|
726
727
|
<style scoped>
|
|
727
|
-
.${
|
|
728
|
+
.${n} {
|
|
728
729
|
padding: 8px 16px;
|
|
729
730
|
border: none;
|
|
730
731
|
border-radius: 4px;
|
|
@@ -734,18 +735,18 @@ function handleClick(event) {
|
|
|
734
735
|
font-size: 14px;
|
|
735
736
|
}
|
|
736
737
|
|
|
737
|
-
.${
|
|
738
|
+
.${n}:hover:not(:disabled) {
|
|
738
739
|
background: #2563eb;
|
|
739
740
|
}
|
|
740
741
|
|
|
741
|
-
.${
|
|
742
|
+
.${n}:disabled {
|
|
742
743
|
background: #9ca3af;
|
|
743
744
|
cursor: not-allowed;
|
|
744
745
|
}
|
|
745
746
|
</style>
|
|
746
747
|
`,input:`<!-- ${e} \u8F93\u5165\u6846\u7EC4\u4EF6 -->
|
|
747
748
|
<template>
|
|
748
|
-
<div class="${
|
|
749
|
+
<div class="${n}">
|
|
749
750
|
<input
|
|
750
751
|
:value="modelValue"
|
|
751
752
|
:type="type"
|
|
@@ -791,7 +792,7 @@ function handleChange(event) {
|
|
|
791
792
|
</script>
|
|
792
793
|
|
|
793
794
|
<style scoped>
|
|
794
|
-
.${
|
|
795
|
+
.${n} input {
|
|
795
796
|
padding: 8px 12px;
|
|
796
797
|
border: 1px solid #d1d5db;
|
|
797
798
|
border-radius: 4px;
|
|
@@ -799,21 +800,21 @@ function handleChange(event) {
|
|
|
799
800
|
outline: none;
|
|
800
801
|
}
|
|
801
802
|
|
|
802
|
-
.${
|
|
803
|
+
.${n} input:focus {
|
|
803
804
|
border-color: #3b82f6;
|
|
804
805
|
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
|
|
805
806
|
}
|
|
806
807
|
</style>
|
|
807
808
|
`,card:`<!-- ${e} \u5361\u7247\u7EC4\u4EF6 -->
|
|
808
809
|
<template>
|
|
809
|
-
<div class="${
|
|
810
|
-
<div class="${
|
|
810
|
+
<div class="${n}">
|
|
811
|
+
<div class="${n}-header" if="$slots.header">
|
|
811
812
|
<slot name="header"></slot>
|
|
812
813
|
</div>
|
|
813
|
-
<div class="${
|
|
814
|
+
<div class="${n}-body">
|
|
814
815
|
<slot></slot>
|
|
815
816
|
</div>
|
|
816
|
-
<div class="${
|
|
817
|
+
<div class="${n}-footer" if="$slots.footer">
|
|
817
818
|
<slot name="footer"></slot>
|
|
818
819
|
</div>
|
|
819
820
|
</div>
|
|
@@ -824,28 +825,28 @@ function handleChange(event) {
|
|
|
824
825
|
</script>
|
|
825
826
|
|
|
826
827
|
<style scoped>
|
|
827
|
-
.${
|
|
828
|
+
.${n} {
|
|
828
829
|
background: white;
|
|
829
830
|
border-radius: 8px;
|
|
830
831
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
831
832
|
overflow: hidden;
|
|
832
833
|
}
|
|
833
834
|
|
|
834
|
-
.${
|
|
835
|
-
.${
|
|
836
|
-
.${
|
|
835
|
+
.${n}-header,
|
|
836
|
+
.${n}-body,
|
|
837
|
+
.${n}-footer {
|
|
837
838
|
padding: 16px;
|
|
838
839
|
}
|
|
839
840
|
|
|
840
|
-
.${
|
|
841
|
+
.${n}-header {
|
|
841
842
|
border-bottom: 1px solid #e5e7eb;
|
|
842
843
|
}
|
|
843
844
|
|
|
844
|
-
.${
|
|
845
|
+
.${n}-footer {
|
|
845
846
|
border-top: 1px solid #e5e7eb;
|
|
846
847
|
}
|
|
847
848
|
</style>
|
|
848
|
-
`};return s[
|
|
849
|
+
`};return s[r]||s.functional}function Ne(e){let t=e.charAt(0).toLowerCase()+e.slice(1);return`/**
|
|
849
850
|
* ${e} Store
|
|
850
851
|
*/
|
|
851
852
|
|
|
@@ -873,7 +874,7 @@ export const ${t}Store = createStore('${e}', {
|
|
|
873
874
|
}
|
|
874
875
|
}
|
|
875
876
|
});
|
|
876
|
-
`}function
|
|
877
|
+
`}function ze(e){let t=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();return`<!-- ${e} \u9875\u9762 -->
|
|
877
878
|
<template>
|
|
878
879
|
<div class="${t}-page">
|
|
879
880
|
<h1>${e}</h1>
|
|
@@ -892,7 +893,7 @@ import { ref, computed } from '@lytjs/reactivity';
|
|
|
892
893
|
padding: 20px;
|
|
893
894
|
}
|
|
894
895
|
</style>
|
|
895
|
-
`}function
|
|
896
|
+
`}function We(e){return`/**
|
|
896
897
|
* ${e} API
|
|
897
898
|
*/
|
|
898
899
|
|
|
@@ -941,8 +942,8 @@ export default async function handler(req, res) {
|
|
|
941
942
|
});
|
|
942
943
|
}
|
|
943
944
|
}
|
|
944
|
-
`}async function
|
|
945
|
-
${o(
|
|
945
|
+
`}async function re(e){let t=Ye(e);t.type||(i.error("\u8BF7\u63D0\u4F9B\u751F\u6210\u7C7B\u578B (component, store, page, api)"),console.log(""),console.log(Y),process.exit(1)),t.name||(i.error("\u8BF7\u63D0\u4F9B\u540D\u79F0"),console.log(""),console.log(Y),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=Ue(t.name,t),r=`./src/components/${t.name}.lyt`;break;case"store":n=Ne(t.name),r=`./src/stores/${t.name}.js`;break;case"page":n=ze(t.name),r=`./src/pages/${t.name}.lyt`;break;case"api":n=We(t.name),r=`./src/api/${t.name}.js`;break}let s=t.outputPath||r,a=ne.dirname(s);M.existsSync(a)||M.mkdirSync(a,{recursive:!0}),M.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 _e="4.2.0",le="lytx",Je="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",se=`
|
|
946
|
+
${o(le,"brightCyan")} - ${Je}
|
|
946
947
|
|
|
947
948
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
948
949
|
lytx <command> [options] [args]
|
|
@@ -961,13 +962,16 @@ ${o("\u5168\u5C40\u9009\u9879:","brightGreen")}
|
|
|
961
962
|
${o("\u793A\u4F8B:","brightGreen")}
|
|
962
963
|
${o("$","dim")} lytx create my-app
|
|
963
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
|
|
964
967
|
${o("$","dim")} lytx dev
|
|
965
968
|
${o("$","dim")} lytx dev --port 8080 --hmr
|
|
966
969
|
${o("$","dim")} lytx build
|
|
967
970
|
${o("$","dim")} lytx build --mode ssr
|
|
968
971
|
${o("$","dim")} lytx preview --port 4173
|
|
969
972
|
|
|
970
|
-
|
|
973
|
+
`;function Ve(){let e=N(),t="";for(let[n,r]of Object.entries(e))t+=` ${o(n,"brightYellow")} \u2014 ${r}
|
|
974
|
+
`;return`
|
|
971
975
|
${o("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
|
|
972
976
|
|
|
973
977
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -978,18 +982,20 @@ ${o("\u53C2\u6570:","brightGreen")}
|
|
|
978
982
|
|
|
979
983
|
${o("\u9009\u9879:","brightGreen")}
|
|
980
984
|
${o("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
981
|
-
|
|
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
|
|
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
|
|
986
990
|
|
|
987
991
|
${o("\u793A\u4F8B:","brightGreen")}
|
|
988
992
|
${o("$","dim")} lytx create my-app
|
|
989
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
|
|
990
996
|
${o("$","dim")} lytx create my-app --template ssr --ts
|
|
991
997
|
|
|
992
|
-
|
|
998
|
+
`}var Ke=`
|
|
993
999
|
${o("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
994
1000
|
|
|
995
1001
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -1011,7 +1017,7 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
1011
1017
|
${o("$","dim")} lytx dev --port 8080
|
|
1012
1018
|
${o("$","dim")} lytx dev --no-hmr
|
|
1013
1019
|
|
|
1014
|
-
`,
|
|
1020
|
+
`,qe=`
|
|
1015
1021
|
${o("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
1016
1022
|
|
|
1017
1023
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -1036,7 +1042,7 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
1036
1042
|
${o("$","dim")} lytx build --mode ssr
|
|
1037
1043
|
${o("$","dim")} lytx build --minify --outDir ./output
|
|
1038
1044
|
|
|
1039
|
-
`,
|
|
1045
|
+
`,Ze=`
|
|
1040
1046
|
${o("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
1041
1047
|
|
|
1042
1048
|
${o("\u7528\u6CD5:","brightGreen")}
|
|
@@ -1049,4 +1055,4 @@ ${o("\u793A\u4F8B:","brightGreen")}
|
|
|
1049
1055
|
${o("$","dim")} lytx preview
|
|
1050
1056
|
${o("$","dim")} lytx preview --port 5000
|
|
1051
1057
|
|
|
1052
|
-
`;function
|
|
1058
|
+
`;function Xe(){console.log(""),console.log(` ${o(le,"brightCyan")} v${o(_e,"brightWhite")}`),console.log("")}function Qe(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 et(e){return typeof e=="string"&&z(e)?e:"spa"}async function tt(e){if(e.options.help){console.log(Ve());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(!z(n)){i.error(`\u672A\u77E5\u6A21\u677F: ${o(n,"brightRed")}`),console.log(""),console.log(" \u53EF\u7528\u6A21\u677F\uFF1A");let s=N();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:et(e.options.template),ts:e.options.ts===!0,router:e.options.router===!0,store:e.options.store===!0,eslint:e.options.eslint===!0};await W(s)}else{let s={template:typeof e.options.template=="string"?e.options.template:"spa"};await Z(t,s)}}function ot(e){if(e.options.help){console.log(Ke);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)),V(t)}async function nt(e){if(e.options.help){console.log(qe);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 oe(t)}function rt(e){if(e.options.help){console.log(Ze);return}let t=typeof e.options.port=="string"?parseInt(e.options.port,10):typeof e.options.p=="string"?parseInt(e.options.p,10):4173;(isNaN(t)||t<1||t>65535)&&(i.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1));let n=ae.resolve(process.cwd(),"dist");ie.existsSync(n)||(i.error("\u672A\u627E\u5230\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55 dist/\uFF0C\u8BF7\u5148\u8FD0\u884C lytx build"),process.exit(1)),V({port:t,root:n,hmr:!1})}async function st(){let e=q(process.argv);if(e.options.version){Xe();return}if(e.options.help&&!e.command){console.log(se);return}e.command||(console.log(se),process.exit(1));try{switch(e.command){case"create":await tt(e);break;case"dev":ot(e);break;case"build":await nt(e);break;case"preview":rt(e);break;case"generate":if(e.options.help){console.log(Y);break}await re(e.args);break;default:Qe(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)}}st();export{_ as createHMREndpoint,Fe as createHMRServer,W as createProject,J as getHMRClientScript};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/bin/cli.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAIH,OAAO,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAmCH,WAAW;AACX,MAAM,WAAW,YAAY;IAC3B,sBAAsB;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,sBAAsB;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAkBD;;;GAGG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoI5E"}
|
package/dist/types/dev.d.ts
CHANGED
|
@@ -20,5 +20,5 @@ export interface DevServerOptions {
|
|
|
20
20
|
* @param options.root - 项目根目录(默认当前工作目录)
|
|
21
21
|
* @param options.hmr - 是否启用 HMR(默认 true)
|
|
22
22
|
*/
|
|
23
|
-
export declare function startDevServer(options?: DevServerOptions): void
|
|
23
|
+
export declare function startDevServer(options?: DevServerOptions): Promise<void>;
|
|
24
24
|
//# sourceMappingURL=dev.d.ts.map
|
package/dist/types/dev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/dev.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/dev.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqCH,cAAc;AACd,MAAM,WAAW,gBAAgB;IAC/B,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAyLD;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2DlF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;GAeG;AAkbH,OAAO,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAGjE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/types/scaffold.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface ScaffoldOptions {
|
|
|
8
8
|
/** 项目名称 */
|
|
9
9
|
name: string;
|
|
10
10
|
/** 项目模板类型 */
|
|
11
|
-
template: 'spa' | 'ssr' | 'ssg';
|
|
11
|
+
template: 'spa' | 'ssr' | 'ssg' | 'todo-app' | 'admin-dashboard';
|
|
12
12
|
/** 是否使用 TypeScript */
|
|
13
13
|
ts: boolean;
|
|
14
14
|
/** 是否包含路由 */
|
|
@@ -18,6 +18,21 @@ export interface ScaffoldOptions {
|
|
|
18
18
|
/** 是否包含 ESLint 配置 */
|
|
19
19
|
eslint: boolean;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* 获取所有可用模板列表
|
|
23
|
+
*/
|
|
24
|
+
export declare function getAvailableTemplates(): Record<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* 检查模板是否存在
|
|
27
|
+
*/
|
|
28
|
+
export declare function isValidTemplate(template: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* 获取模板信息
|
|
31
|
+
*/
|
|
32
|
+
export declare function getTemplateInfo(template: string): {
|
|
33
|
+
description: string;
|
|
34
|
+
type: string;
|
|
35
|
+
} | null;
|
|
21
36
|
/**
|
|
22
37
|
* 创建新的 Lyt 项目(增强版脚手架)
|
|
23
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/scaffold.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/scaffold.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,eAAe;AACf,MAAM,WAAW,eAAe;IAC9B,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,aAAa;IACb,QAAQ,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU,GAAG,iBAAiB,CAAC;IACjE,sBAAsB;IACtB,EAAE,EAAE,OAAO,CAAC;IACZ,aAAa;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe;IACf,KAAK,EAAE,OAAO,CAAC;IACf,qBAAqB;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB;AA6CD;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAM9D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAI9F;AA8dD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAkH3E"}
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export declare function readFile(filePath: string): string;
|
|
|
58
58
|
* @param filePath - 文件路径
|
|
59
59
|
* @param content - 要写入的内容
|
|
60
60
|
*/
|
|
61
|
-
export declare function writeFile(filePath: string, content: string): void;
|
|
61
|
+
export declare function writeFile(filePath: string, content: string | Buffer): void;
|
|
62
62
|
/**
|
|
63
63
|
* 根据文件扩展名获取 MIME 类型
|
|
64
64
|
* 手写的 MIME 类型映射表,覆盖常见前端文件类型
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoDH;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7D;AAMD,kBAAkB;AAClB,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC1C,iBAAiB;IACjB,GAAG,EAAE,MAAM,EAAE,CAAC;CACf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAoEpD;AAMD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI3C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoDH;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7D;AAMD,kBAAkB;AAClB,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC1C,iBAAiB;IACjB,GAAG,EAAE,MAAM,EAAE,CAAC;CACf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAoEpD;AAMD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI3C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAS1E;AAMD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAwDpD;AAMD,6CAA6C;AAC7C,eAAO,MAAM,MAAM;IACjB;;;OAGG;cACO,MAAM,GAAG,IAAI;IAIvB;;;OAGG;cACO,MAAM,GAAG,IAAI;IAIvB;;;OAGG;eACQ,MAAM,GAAG,IAAI;IAIxB;;;OAGG;iBACU,MAAM,GAAG,IAAI;CAG3B,CAAC"}
|