@lytjs/cli 3.2.7 → 4.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/index.js +98 -98
- package/dist/index.mjs +98 -98
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var oe=Object.create;var H=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var le=(e,t)=>{for(var o in t)H(e,o,{get:t[o],enumerable:!0})},Y=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ne(t))!ie.call(e,s)&&s!==o&&H(e,s,{get:()=>t[s],enumerable:!(n=re(t,s))||n.enumerable});return e};var m=(e,t,o)=>(o=e!=null?oe(se(e)):{},Y(t||!e||!e.__esModule?H(o,"default",{value:e,enumerable:!0}):o,e)),ae=e=>Y(H({},"__esModule",{value:!0}),e);var Ye={};le(Ye,{createHMREndpoint:()=>I,createHMRServer:()=>q,createProject:()=>D,getHMRClientScript:()=>G});module.exports=ae(Ye);var ee=m(require("fs")),te=m(require("path"));var y=m(require("fs")),U=m(require("path")),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 r(e,t){let o=pe[t];return o?`${o}${e}${ce}`:e}function _(e){let t=e.slice(2),o={command:"",args:[],options:{},raw:t},n=0;for(;n<t.length;){let s=t[n];if(s==="--help"||s==="-h")o.options.help=!0,n++;else if(s==="--version"||s==="-v")o.options.version=!0,n++;else if(s.startsWith("--")){let l=s.indexOf("=");if(l!==-1){let p=s.slice(2,l),a=s.slice(l+1);o.options[p]=a}else{let p=s.slice(2),a=t[n+1];a&&!a.startsWith("-")?(o.options[p]=a,n++):o.options[p]=!0}n++}else if(s.startsWith("-")&&s.length>1){let l=s.slice(1),p=t[n+1];p&&!p.startsWith("-")?(o.options[l]=p,n++):o.options[l]=!0,n++}else o.command?(o.args.push(s),n++):(o.command=s,n++)}return o}function $(e){y.existsSync(e)||y.mkdirSync(e,{recursive:!0})}function A(e){return y.existsSync(e)}function F(e){return y.readFileSync(e,"utf-8")}function S(e,t){let o=U.dirname(e);$(o),y.writeFileSync(e,t,"utf-8")}var i={info(e){},warn(e){},error(e){},success(e){}};var k=m(require("path"));function ue(){return`<!DOCTYPE html>
|
|
3
3
|
<html lang="zh-CN">
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="UTF-8" />
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<script type="module" src="/src/main.ts"></script>
|
|
12
12
|
</body>
|
|
13
13
|
</html>
|
|
14
|
-
`}function
|
|
14
|
+
`}function de(){return`import { createApp } from '@lytjs/lytjs';
|
|
15
15
|
import App from './App';
|
|
16
16
|
|
|
17
17
|
// \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B
|
|
@@ -19,7 +19,7 @@ const app = createApp(App);
|
|
|
19
19
|
|
|
20
20
|
// \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20
|
|
21
21
|
app.mount('#app');
|
|
22
|
-
`}function
|
|
22
|
+
`}function fe(){return`import { defineComponent } from '@lytjs/lytjs';
|
|
23
23
|
|
|
24
24
|
// \u5B9A\u4E49\u6839\u7EC4\u4EF6
|
|
25
25
|
const App = defineComponent({
|
|
@@ -44,7 +44,7 @@ const App = defineComponent({
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
export default App;
|
|
47
|
-
`}function
|
|
47
|
+
`}function ge(){return`/* Lyt \u5168\u5C40\u6837\u5F0F */
|
|
48
48
|
|
|
49
49
|
* {
|
|
50
50
|
margin: 0;
|
|
@@ -75,9 +75,9 @@ body {
|
|
|
75
75
|
font-size: 1.2rem;
|
|
76
76
|
color: #666;
|
|
77
77
|
}
|
|
78
|
-
`}function
|
|
79
|
-
`}function
|
|
80
|
-
`}function
|
|
78
|
+
`}function me(e){return JSON.stringify({name:e,version:"0.1.0",private:!0,type:"module",scripts:{dev:"lyt dev",build:"lyt build",preview:"lyt preview"},dependencies:{"@lytjs/lytjs":"latest"},devDependencies:{"@lytjs/cli":"latest",typescript:"^5.0.0"}},null,2)+`
|
|
79
|
+
`}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)+`
|
|
80
|
+
`}function ye(){return`# \u4F9D\u8D56
|
|
81
81
|
node_modules/
|
|
82
82
|
|
|
83
83
|
# \u6784\u5EFA\u8F93\u51FA
|
|
@@ -100,9 +100,9 @@ Thumbs.db
|
|
|
100
100
|
# \u65E5\u5FD7
|
|
101
101
|
*.log
|
|
102
102
|
npm-debug.log*
|
|
103
|
-
`}async function
|
|
104
|
-
`}function
|
|
105
|
-
`}function
|
|
103
|
+
`}async function z(e,t={}){let o=t.template||"spa",n=k.resolve(process.cwd(),e);i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${r(e,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${r(o,"brightCyan")}`),A(n)&&(i.error(`\u76EE\u5F55 "${e}" \u5DF2\u5B58\u5728\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u540D\u79F0\u6216\u5220\u9664\u5DF2\u6709\u76EE\u5F55`),process.exit(1)),$(n);let s=[{filePath:"index.html",content:ue()},{filePath:"src/main.ts",content:de()},{filePath:"src/App.ts",content:fe()},{filePath:"src/style.css",content:ge()},{filePath:"package.json",content:me(e)},{filePath:"tsconfig.json",content:he()},{filePath:".gitignore",content:ye()}];for(let l of s){let p=k.join(n,l.filePath);S(p,l.content),i.success(` \u521B\u5EFA ${l.filePath}`)}i.success(`\u9879\u76EE ${r(e,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`)}var L=m(require("path"));function be(e){let t={name:e.name,version:"0.1.0",private:!0,type:"module",scripts:{dev:"lytx dev",build:"lytx build",preview:"lytx preview"},dependencies:{"@lytjs/lytjs":"latest"}};return e.ts&&(t.devDependencies={"@lytjs/cli":"latest",typescript:"^5.0.0"}),e.eslint&&(t.devDependencies=t.devDependencies||{},t.devDependencies.eslint="^8.0.0",t.scripts=t.scripts||{},t.scripts.lint="eslint src --ext .ts,.js"),e.router&&(t.dependencies["@lytjs/router"]="latest"),e.store&&(t.dependencies["@lytjs/store"]="latest"),JSON.stringify(t,null,2)+`
|
|
104
|
+
`}function xe(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)+`
|
|
105
|
+
`}function ve(e){let t=e.ts?".ts":".js";return`<!DOCTYPE html>
|
|
106
106
|
<html lang="zh-CN">
|
|
107
107
|
<head>
|
|
108
108
|
<meta charset="UTF-8" />
|
|
@@ -112,13 +112,13 @@ npm-debug.log*
|
|
|
112
112
|
</head>
|
|
113
113
|
<body>
|
|
114
114
|
<div id="app"></div>
|
|
115
|
-
<script type="module" src="/src/main${
|
|
115
|
+
<script type="module" src="/src/main${t}"></script>
|
|
116
116
|
</body>
|
|
117
117
|
</html>
|
|
118
|
-
`}function
|
|
119
|
-
`)}function
|
|
118
|
+
`}function $e(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(`
|
|
119
|
+
`)}function we(e){let t=e.ts?".ts":".js",o=["import { createApp } from '@lytjs/lytjs'","import App from './App.lyt'","import './styles/main.css'"];return e.router&&o.push("import { router } from './router'"),e.store&&o.push("import { store } from './store'"),o.push(""),o.push("// \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B"),o.push("const app = createApp(App)"),e.router&&o.push("app.use(router)"),e.store&&o.push("app.use(store)"),o.push(""),o.push("// \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20"),o.push("app.mount('#app')"),o.join(`
|
|
120
120
|
`)+`
|
|
121
|
-
`}function
|
|
121
|
+
`}function Se(){return`<template>
|
|
122
122
|
<div class="app">
|
|
123
123
|
<Header />
|
|
124
124
|
<main>
|
|
@@ -146,7 +146,7 @@ export default defineComponent({
|
|
|
146
146
|
padding: 20px;
|
|
147
147
|
}
|
|
148
148
|
</style>
|
|
149
|
-
`}function
|
|
149
|
+
`}function Ce(){return`import { defineComponent } from '@lytjs/lytjs'
|
|
150
150
|
|
|
151
151
|
export default defineComponent({
|
|
152
152
|
name: 'HomePage',
|
|
@@ -158,7 +158,7 @@ export default defineComponent({
|
|
|
158
158
|
</div>
|
|
159
159
|
\`,
|
|
160
160
|
})
|
|
161
|
-
`}function
|
|
161
|
+
`}function je(){return`import { defineComponent } from '@lytjs/lytjs'
|
|
162
162
|
|
|
163
163
|
export default defineComponent({
|
|
164
164
|
name: 'AboutPage',
|
|
@@ -170,7 +170,7 @@ export default defineComponent({
|
|
|
170
170
|
</div>
|
|
171
171
|
\`,
|
|
172
172
|
})
|
|
173
|
-
`}function
|
|
173
|
+
`}function Te(){return`import { defineComponent } from '@lytjs/lytjs'
|
|
174
174
|
|
|
175
175
|
export default defineComponent({
|
|
176
176
|
name: 'Header',
|
|
@@ -184,7 +184,7 @@ export default defineComponent({
|
|
|
184
184
|
</header>
|
|
185
185
|
\`,
|
|
186
186
|
})
|
|
187
|
-
`}function
|
|
187
|
+
`}function Pe(){return`import { createRouter, createWebHistory } from '@lytjs/router'
|
|
188
188
|
import HomePage from '../pages/index'
|
|
189
189
|
import AboutPage from '../pages/about'
|
|
190
190
|
|
|
@@ -201,7 +201,7 @@ export const router = createRouter({
|
|
|
201
201
|
},
|
|
202
202
|
],
|
|
203
203
|
})
|
|
204
|
-
`}function
|
|
204
|
+
`}function Me(){return`import { createStore } from '@lytjs/store'
|
|
205
205
|
|
|
206
206
|
export const store = createStore({
|
|
207
207
|
state: {
|
|
@@ -229,7 +229,7 @@ export const store = createStore({
|
|
|
229
229
|
doubleCount: (state: any) => state.count * 2,
|
|
230
230
|
},
|
|
231
231
|
})
|
|
232
|
-
`}function
|
|
232
|
+
`}function Re(){return`/* \u5168\u5C40\u6837\u5F0F */
|
|
233
233
|
|
|
234
234
|
* {
|
|
235
235
|
margin: 0;
|
|
@@ -253,17 +253,17 @@ a {
|
|
|
253
253
|
a:hover {
|
|
254
254
|
text-decoration: underline;
|
|
255
255
|
}
|
|
256
|
-
`}function
|
|
256
|
+
`}function Ee(){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
|
257
257
|
<rect width="32" height="32" rx="6" fill="#42b883"/>
|
|
258
258
|
<text x="16" y="22" text-anchor="middle" fill="white" font-size="18" font-weight="bold">L</text>
|
|
259
259
|
</svg>
|
|
260
|
-
`}function
|
|
261
|
-
`}async function
|
|
260
|
+
`}function He(){return JSON.stringify({root:!0,env:{browser:!0,es2021:!0,node:!0},extends:["eslint:recommended"],parserOptions:{ecmaVersion:"latest",sourceType:"module"},rules:{"no-unused-vars":"warn","no-console":"warn"}},null,2)+`
|
|
261
|
+
`}async function D(e){let{name:t,template:o,ts:n,router:s,store:l,eslint:p}=e,a=L.resolve(process.cwd(),t);if(i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${r(t,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${r(o,"brightCyan")}`),A(a))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`);$(a);let c=[{filePath:"package.json",content:be(e)},{filePath:"index.html",content:ve(e)},{filePath:"lytx.config.ts",content:$e(e)},{filePath:"src/main.ts",content:we(e)},{filePath:"src/App.lyt",content:Se()},{filePath:"src/pages/index.ts",content:Ce()},{filePath:"src/pages/about.ts",content:je()},{filePath:"src/components/Header.ts",content:Te()},{filePath:"src/styles/main.css",content:Re()},{filePath:"public/favicon.svg",content:Ee()}];n&&c.push({filePath:"tsconfig.json",content:xe(e)}),s&&c.push({filePath:"src/router/index.ts",content:Pe()}),l&&c.push({filePath:"src/store/index.ts",content:Me()}),p&&c.push({filePath:".eslintrc.json",content:He()});for(let u of c){let d=L.join(a,u.filePath);S(d,u.content),i.success(` \u521B\u5EFA ${u.filePath}`)}i.success(`\u9879\u76EE ${r(t,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`)}var X=m(require("http")),B=m(require("fs")),T=m(require("path"));var J=m(require("http")),j=m(require("fs")),b=m(require("path")),V=m(require("crypto")),O=class{constructor(){this.clients=[]}handleUpgrade(t,o,n){let s=t.headers["sec-websocket-key"];if(!s){o.destroy();return}let l=V.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");o.write(`HTTP/1.1 101 Switching Protocols\r
|
|
262
262
|
Upgrade: websocket\r
|
|
263
263
|
Connection: Upgrade\r
|
|
264
|
-
Sec-WebSocket-Accept: ${
|
|
264
|
+
Sec-WebSocket-Accept: ${l}\r
|
|
265
265
|
\r
|
|
266
|
-
`);let p={socket:
|
|
266
|
+
`);let p={socket:o,isAlive:!0};o.on("close",()=>{this.clients=this.clients.filter(a=>a!==p)}),o.on("error",()=>{this.clients=this.clients.filter(a=>a!==p)}),this.clients.push(p)}broadcast(t){let o=[];for(let n of this.clients)try{if(!n.isAlive){o.push(n);continue}let s=Buffer.from(t,"utf-8"),l=this.createFrame(129,s);n.socket.write(l)}catch(s){o.push(n)}for(let n of o){this.clients=this.clients.filter(s=>s!==n);try{n.socket.destroy()}catch(s){}}}createFrame(t,o){let n=o.length,s;n<126?s=2:n<65536?s=4:s=10;let l=Buffer.alloc(s+n);return l[0]=t,n<126?l[1]=n:n<65536?(l[1]=126,l.writeUInt16BE(n,2)):(l[1]=127,l.writeUInt32BE(0,2),l.writeUInt32BE(n,6)),o.copy(l,s),l}getClientCount(){return this.clients.length}closeAll(){for(let t of this.clients)try{t.socket.destroy()}catch(o){}this.clients=[]}};function q(e){let t=new O,o=[],n=[],s=null,l=!1;function p(c){let u=b.extname(c).toLowerCase();if(u===".css")return"css";let d=b.basename(c);return d.startsWith("lytx.config")||d==="tsconfig.json"||d==="package.json"?"reload":u===".ts"||u===".tsx"||u===".lyt"||u===".js"||u===".jsx"?"update":"reload"}function a(c){try{let u=j.readdirSync(c,{withFileTypes:!0});for(let d of u){let f=b.join(c,d.name);if(d.isDirectory()){if(d.name==="node_modules"||d.name===".git"||d.name==="dist")continue;a(f)}else if(d.isFile()){let P=b.extname(d.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(P))try{let M=j.watch(f,{persistent:!1},W=>{if(W==="change"){let R=b.relative(e,f);for(let w of o)try{w(R)}catch(E){}let C=p(f),v={type:C,path:`/${R}`};if(C==="css")try{v.content=j.readFileSync(f,"utf-8")}catch(w){}t.broadcast(JSON.stringify(v))}});n.push(M)}catch(M){}}}}catch(u){}}return{start(c){l||(l=!0,s=J.createServer((u,d)=>{d.writeHead(426,{"Content-Type":"text/plain"}),d.end("Upgrade Required")}),s.on("upgrade",(u,d,f)=>{t.handleUpgrade(u,d,f)}),s.listen(c,()=>{}),a(e))},stop(){l=!1;for(let c of n)try{c.close()}catch(u){}if(n.length=0,t.closeAll(),s){try{s.close()}catch(c){}s=null}},onFileChange(c){o.push(c)},notifyClient(c){t.broadcast(JSON.stringify(c))}}}function I(e){let t=new O;return e.on("upgrade",(o,n,s)=>{t.handleUpgrade(o,n,s)}),{broadcast(o){t.broadcast(o)},getClientCount(){return t.getClientCount()}}}function G(){return`(function() {
|
|
267
267
|
'use strict';
|
|
268
268
|
|
|
269
269
|
var ws = null;
|
|
@@ -361,112 +361,112 @@ Sec-WebSocket-Accept: ${a}\r
|
|
|
361
361
|
|
|
362
362
|
// \u542F\u52A8\u8FDE\u63A5
|
|
363
363
|
connect();
|
|
364
|
-
})();`}var
|
|
365
|
-
</head>`)),{statusCode:200,headers:{"Content-Type":p},body:
|
|
366
|
-
${
|
|
364
|
+
})();`}var K;try{K=require("esbuild")}catch(e){i.error("\u7F3A\u5C11\u4F9D\u8D56: esbuild"),i.error(""),i.error(" Lyt CLI \u7684\u5F00\u53D1\u670D\u52A1\u5668\u9700\u8981 esbuild \u6765\u5B9E\u65F6\u7F16\u8BD1 TypeScript\u3002"),i.error(""),i.error(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5B89\u88C5:"),i.error(` ${r("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${r("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}function Ae(e,t){try{return K.transformSync(e,{loader:"ts",target:"es2018",format:"esm",sourcemap:"inline"}).code}catch(o){let n=o instanceof Error?o.message:String(o);return e}}function Fe(e,t){var c;let o=((c=e.url)==null?void 0:c.split("?")[0])||"/";o==="/"&&(o="/index.html");let n=T.join(t,o);if(!n.startsWith(t))return{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"};if(!B.existsSync(n)||!B.statSync(n).isFile())return{statusCode:404,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"404 Not Found"};let s=T.extname(n).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",a=F(n);return(s===".ts"||s===".tsx")&&(a=Ae(a,o)),s===".html"&&(a=a.replace("</head>",`<script>${G()}</script>
|
|
365
|
+
</head>`)),{statusCode:200,headers:{"Content-Type":p},body:a}}function N(e={}){let t=e.port||3e3,o=T.resolve(e.root||process.cwd()),n=e.hmr!==!1,s=X.createServer((a,c)=>{let u=Fe(a,o);c.writeHead(u.statusCode,u.headers),c.end(u.body)}),l=n?I(s):null;s.listen(t,()=>{}),s.on("error",a=>{a.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: ${a.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 h=m(require("fs")),g=m(require("path"));var Q;try{Q=require("esbuild")}catch(e){i.error("\u7F3A\u5C11\u4F9D\u8D56: esbuild"),i.error(""),i.error(" Lyt CLI \u7684\u6784\u5EFA\u529F\u80FD\u9700\u8981 esbuild\u3002"),i.error(""),i.error(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5B89\u88C5:"),i.error(` ${r("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${r("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}async function Z(e={}){let t=Date.now(),o=g.resolve(e.root||process.cwd()),n=g.resolve(o,e.outDir||"dist"),s=e.entry||"index.html",l=e.minify||!1;i.info("\u5F00\u59CB\u6784\u5EFA\u9879\u76EE..."),i.info(` \u6839\u76EE\u5F55: ${r(o,"brightCyan")}`),i.info(` \u8F93\u51FA\u76EE\u5F55: ${r(n,"brightCyan")}`),i.info(` \u538B\u7F29: ${r(l?"\u5F00\u542F":"\u5173\u95ED",l?"brightGreen":"brightYellow")}`);let p=g.join(o,s);h.existsSync(p)||(i.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${p}`),process.exit(1));let a=F(p),c=/<script\s+type="module"\s+src="([^"]+)"\s*><\/script>/g,u,d=[];for(;(u=c.exec(a))!==null;)d.push(u[1]);d.length===0&&i.warn("\u672A\u5728\u5165\u53E3 HTML \u4E2D\u627E\u5230\u6A21\u5757\u811A\u672C\u5F15\u7528");let f={inputFiles:0,outputFiles:0,totalSize:0,buildTime:0};$(n),$(g.join(n,"assets"));for(let x of d){let M=g.join(o,x);if(!h.existsSync(M)){i.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${x}`);continue}i.info(`\u6B63\u5728\u6253\u5305: ${r(x,"brightYellow")}`);let R=`${g.basename(x,g.extname(x))}.bundle.js`,C=g.join(n,"assets",R);try{await Q.build({entryPoints:[M],bundle:!0,minify:l,target:"es2018",format:"esm",outfile:C,sourcemap:!0,external:E=>E.startsWith("@lytjs/"),drop:l?["console"]:[],metafile:!0});let v=h.readFileSync(C,"utf-8");f.totalSize+=Buffer.byteLength(v,"utf-8"),f.outputFiles++;let w=C+".map";if(h.existsSync(w)){let E=h.readFileSync(w,"utf-8");f.totalSize+=Buffer.byteLength(E,"utf-8"),f.outputFiles++}a=a.replace(`<script type="module" src="${x}"></script>`,`<script src="/assets/${R}"></script>`),f.inputFiles++}catch(v){let w=v instanceof Error?v.message:String(v);i.error(`\u6253\u5305\u5931\u8D25 ${x}: ${w}`),process.exit(1)}}ke(o,n,f);let P=g.join(n,"index.html");S(P,a),f.outputFiles++,f.totalSize+=Buffer.byteLength(a,"utf-8"),f.buildTime=Date.now()-t,i.success("\u6784\u5EFA\u5B8C\u6210\uFF01")}function ke(e,t,o){let n=g.join(e,"src");if(!h.existsSync(n))return;function s(l,p){let a=h.readdirSync(l,{withFileTypes:!0});for(let c of a){let u=g.join(l,c.name);if(c.isDirectory()){if(c.name==="node_modules")continue;s(u,p)}else if(c.isFile()){let d=g.extname(c.name);if([".ts",".tsx",".js",".jsx"].includes(d))continue;let f=g.relative(p,u),P=g.join(t,f);S(P,h.readFileSync(u).toString("utf-8")),o.outputFiles++,o.totalSize+=h.statSync(u).size}}}s(n,n)}var Le="lytx",De="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",pt=`
|
|
366
|
+
${r(Le,"brightCyan")} - ${De}
|
|
367
367
|
|
|
368
|
-
${
|
|
368
|
+
${r("\u7528\u6CD5:","brightGreen")}
|
|
369
369
|
lytx <command> [options] [args]
|
|
370
370
|
|
|
371
|
-
${
|
|
372
|
-
${
|
|
373
|
-
${
|
|
374
|
-
${
|
|
375
|
-
${
|
|
376
|
-
|
|
377
|
-
${
|
|
378
|
-
${
|
|
379
|
-
${
|
|
380
|
-
|
|
381
|
-
${
|
|
382
|
-
${
|
|
383
|
-
${
|
|
384
|
-
${
|
|
385
|
-
${
|
|
386
|
-
${
|
|
387
|
-
${
|
|
388
|
-
${
|
|
389
|
-
|
|
390
|
-
`,
|
|
391
|
-
${
|
|
392
|
-
|
|
393
|
-
${
|
|
371
|
+
${r("\u547D\u4EE4:","brightGreen")}
|
|
372
|
+
${r("create","brightYellow")} <name> \u521B\u5EFA\u4E00\u4E2A\u65B0\u7684 Lyt \u9879\u76EE
|
|
373
|
+
${r("dev","brightYellow")} \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
374
|
+
${r("build","brightYellow")} \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
375
|
+
${r("preview","brightYellow")} \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
376
|
+
|
|
377
|
+
${r("\u5168\u5C40\u9009\u9879:","brightGreen")}
|
|
378
|
+
${r("-h, --help","brightYellow")} \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
|
|
379
|
+
${r("-v, --version","brightYellow")} \u663E\u793A\u7248\u672C\u53F7
|
|
380
|
+
|
|
381
|
+
${r("\u793A\u4F8B:","brightGreen")}
|
|
382
|
+
${r("$","dim")} lytx create my-app
|
|
383
|
+
${r("$","dim")} lytx create my-app --template spa --ts --router --store
|
|
384
|
+
${r("$","dim")} lytx dev
|
|
385
|
+
${r("$","dim")} lytx dev --port 8080 --hmr
|
|
386
|
+
${r("$","dim")} lytx build
|
|
387
|
+
${r("$","dim")} lytx build --mode ssr
|
|
388
|
+
${r("$","dim")} lytx preview --port 4173
|
|
389
|
+
|
|
390
|
+
`,ut=`
|
|
391
|
+
${r("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
|
|
392
|
+
|
|
393
|
+
${r("\u7528\u6CD5:","brightGreen")}
|
|
394
394
|
lytx create <name> [options]
|
|
395
395
|
|
|
396
|
-
${
|
|
397
|
-
${
|
|
396
|
+
${r("\u53C2\u6570:","brightGreen")}
|
|
397
|
+
${r("<name>","brightYellow")} \u9879\u76EE\u540D\u79F0\uFF08\u540C\u65F6\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF09
|
|
398
398
|
|
|
399
|
-
${
|
|
400
|
-
${
|
|
399
|
+
${r("\u9009\u9879:","brightGreen")}
|
|
400
|
+
${r("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
401
401
|
\u53EF\u9009\u503C: spa, ssr, ssg
|
|
402
|
-
${
|
|
403
|
-
${
|
|
404
|
-
${
|
|
405
|
-
${
|
|
402
|
+
${r("--ts","brightYellow")} \u4F7F\u7528 TypeScript
|
|
403
|
+
${r("--router","brightYellow")} \u5305\u542B\u8DEF\u7531
|
|
404
|
+
${r("--store","brightYellow")} \u5305\u542B\u72B6\u6001\u7BA1\u7406
|
|
405
|
+
${r("--eslint","brightYellow")} \u5305\u542B ESLint \u914D\u7F6E
|
|
406
406
|
|
|
407
|
-
${
|
|
408
|
-
${
|
|
409
|
-
${
|
|
410
|
-
${
|
|
407
|
+
${r("\u793A\u4F8B:","brightGreen")}
|
|
408
|
+
${r("$","dim")} lytx create my-app
|
|
409
|
+
${r("$","dim")} lytx create my-app --template spa --ts --router --store
|
|
410
|
+
${r("$","dim")} lytx create my-app --template ssr --ts
|
|
411
411
|
|
|
412
|
-
`,
|
|
413
|
-
${
|
|
412
|
+
`,dt=`
|
|
413
|
+
${r("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
414
414
|
|
|
415
|
-
${
|
|
415
|
+
${r("\u7528\u6CD5:","brightGreen")}
|
|
416
416
|
lytx dev [options]
|
|
417
417
|
|
|
418
|
-
${
|
|
419
|
-
${
|
|
420
|
-
${
|
|
421
|
-
${
|
|
418
|
+
${r("\u9009\u9879:","brightGreen")}
|
|
419
|
+
${r("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 3000\uFF09
|
|
420
|
+
${r("--hmr","brightYellow")} \u5F00\u542F\u70ED\u66F4\u65B0\uFF08\u9ED8\u8BA4: \u5F00\u542F\uFF09
|
|
421
|
+
${r("--no-hmr","brightYellow")} \u5173\u95ED\u70ED\u66F4\u65B0
|
|
422
422
|
|
|
423
|
-
${
|
|
423
|
+
${r("\u529F\u80FD:","brightGreen")}
|
|
424
424
|
- \u9759\u6001\u6587\u4EF6\u670D\u52A1
|
|
425
425
|
- TypeScript \u5373\u65F6\u7F16\u8BD1
|
|
426
426
|
- \u70ED\u6A21\u5757\u66FF\u6362\uFF08HMR\uFF09
|
|
427
427
|
- WebSocket \u5B9E\u65F6\u901A\u4FE1
|
|
428
428
|
|
|
429
|
-
${
|
|
430
|
-
${
|
|
431
|
-
${
|
|
432
|
-
${
|
|
429
|
+
${r("\u793A\u4F8B:","brightGreen")}
|
|
430
|
+
${r("$","dim")} lytx dev
|
|
431
|
+
${r("$","dim")} lytx dev --port 8080
|
|
432
|
+
${r("$","dim")} lytx dev --no-hmr
|
|
433
433
|
|
|
434
|
-
`,
|
|
435
|
-
${
|
|
434
|
+
`,ft=`
|
|
435
|
+
${r("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
436
436
|
|
|
437
|
-
${
|
|
437
|
+
${r("\u7528\u6CD5:","brightGreen")}
|
|
438
438
|
lytx build [options]
|
|
439
439
|
|
|
440
|
-
${
|
|
441
|
-
${
|
|
440
|
+
${r("\u9009\u9879:","brightGreen")}
|
|
441
|
+
${r("--mode <mode>","brightYellow")} \u6784\u5EFA\u6A21\u5F0F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
442
442
|
\u53EF\u9009\u503C: spa, ssr, ssg
|
|
443
|
-
${
|
|
444
|
-
${
|
|
445
|
-
${
|
|
443
|
+
${r("--minify","brightYellow")} \u538B\u7F29\u4EE3\u7801\uFF08\u53BB\u9664\u7A7A\u767D\u548C\u6CE8\u91CA\uFF09
|
|
444
|
+
${r("-o, --outDir <dir>","brightYellow")} \u8F93\u51FA\u76EE\u5F55\uFF08\u9ED8\u8BA4: dist\uFF09
|
|
445
|
+
${r("--entry <file>","brightYellow")} \u5165\u53E3\u6587\u4EF6\uFF08\u9ED8\u8BA4: index.html\uFF09
|
|
446
446
|
|
|
447
|
-
${
|
|
447
|
+
${r("\u529F\u80FD:","brightGreen")}
|
|
448
448
|
- TypeScript \u7F16\u8BD1
|
|
449
449
|
- \u6A21\u5757\u6253\u5305\uFF08\u5185\u8054\u4F9D\u8D56\uFF09
|
|
450
450
|
- \u53BB\u9664 console.log
|
|
451
451
|
- Source Map \u751F\u6210
|
|
452
452
|
- \u9759\u6001\u8D44\u6E90\u590D\u5236
|
|
453
453
|
|
|
454
|
-
${
|
|
455
|
-
${
|
|
456
|
-
${
|
|
457
|
-
${
|
|
454
|
+
${r("\u793A\u4F8B:","brightGreen")}
|
|
455
|
+
${r("$","dim")} lytx build
|
|
456
|
+
${r("$","dim")} lytx build --mode ssr
|
|
457
|
+
${r("$","dim")} lytx build --minify --outDir ./output
|
|
458
458
|
|
|
459
|
-
`,
|
|
460
|
-
${
|
|
459
|
+
`,gt=`
|
|
460
|
+
${r("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
461
461
|
|
|
462
|
-
${
|
|
462
|
+
${r("\u7528\u6CD5:","brightGreen")}
|
|
463
463
|
lytx preview [options]
|
|
464
464
|
|
|
465
|
-
${
|
|
466
|
-
${
|
|
465
|
+
${r("\u9009\u9879:","brightGreen")}
|
|
466
|
+
${r("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 4173\uFF09
|
|
467
467
|
|
|
468
|
-
${
|
|
469
|
-
${
|
|
470
|
-
${
|
|
468
|
+
${r("\u793A\u4F8B:","brightGreen")}
|
|
469
|
+
${r("$","dim")} lytx preview
|
|
470
|
+
${r("$","dim")} lytx preview --port 5000
|
|
471
471
|
|
|
472
|
-
`;function
|
|
472
|
+
`;function Oe(e){i.error(`\u672A\u77E5\u547D\u4EE4: ${r(e,"brightRed")}`)}function Ie(e){return typeof e=="string"&&["spa","ssr","ssg"].includes(e)?e:"spa"}async function Ge(e){if(e.options.help)return;e.args.length===0&&(i.error("\u8BF7\u63D0\u4F9B\u9879\u76EE\u540D\u79F0"),process.exit(1));let t=e.args[0];if(e.options.ts===!0||e.options.router===!0||e.options.store===!0||e.options.eslint===!0||typeof e.options.template=="string"&&["ssr","ssg"].includes(e.options.template)){let n={name:t,template:Ie(e.options.template),ts:e.options.ts===!0,router:e.options.router===!0,store:e.options.store===!0,eslint:e.options.eslint===!0};await D(n)}else{let n={template:typeof e.options.template=="string"?e.options.template:"spa"};await z(t,n)}}function Be(e){if(e.options.help)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)),N(t)}async function Ue(e){if(e.options.help)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 Z(t)}function Ne(e){if(e.options.help)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 o=te.resolve(process.cwd(),"dist");ee.existsSync(o)||(i.error("\u672A\u627E\u5230\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55 dist/\uFF0C\u8BF7\u5148\u8FD0\u884C lytx build"),process.exit(1)),N({port:t,root:o,hmr:!1})}async function We(){let e=_(process.argv);if(e.options.version){return}if(!(e.options.help&&!e.command)){e.command||process.exit(1);try{switch(e.command){case"create":await Ge(e);break;case"dev":Be(e);break;case"build":await Ue(e);break;case"preview":Ne(e);break;default:Oe(e.command),process.exit(1)}}catch(t){let o=t instanceof Error?t.message:String(t);i.error(`\u6267\u884C\u5931\u8D25: ${o}`),process.exit(1)}}}We();0&&(module.exports={createHMREndpoint,createHMRServer,createProject,getHMRClientScript});
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var N=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(
|
|
2
|
+
var N=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(t,r)=>(typeof require!="undefined"?require:t)[r]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import*as K from"fs";import*as Q from"path";import*as h from"fs";import*as D from"path";var Z="\x1B[0m",ee={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m",bgBlack:"\x1B[40m",bgRed:"\x1B[41m",bgGreen:"\x1B[42m",bgYellow:"\x1B[43m",bgBlue:"\x1B[44m",bgMagenta:"\x1B[45m",bgCyan:"\x1B[46m",bgWhite:"\x1B[47m",bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",strikethrough:"\x1B[9m"};function o(e,t){let r=ee[t];return r?`${r}${e}${Z}`:e}function W(e){let t=e.slice(2),r={command:"",args:[],options:{},raw:t},n=0;for(;n<t.length;){let s=t[n];if(s==="--help"||s==="-h")r.options.help=!0,n++;else if(s==="--version"||s==="-v")r.options.version=!0,n++;else if(s.startsWith("--")){let l=s.indexOf("=");if(l!==-1){let p=s.slice(2,l),a=s.slice(l+1);r.options[p]=a}else{let p=s.slice(2),a=t[n+1];a&&!a.startsWith("-")?(r.options[p]=a,n++):r.options[p]=!0}n++}else if(s.startsWith("-")&&s.length>1){let l=s.slice(1),p=t[n+1];p&&!p.startsWith("-")?(r.options[l]=p,n++):r.options[l]=!0,n++}else r.command?(r.args.push(s),n++):(r.command=s,n++)}return r}function v(e){h.existsSync(e)||h.mkdirSync(e,{recursive:!0})}function E(e){return h.existsSync(e)}function H(e){return h.readFileSync(e,"utf-8")}function w(e,t){let r=D.dirname(e);v(r),h.writeFileSync(e,t,"utf-8")}var i={info(e){},warn(e){},error(e){},success(e){}};import*as A from"path";function te(){return`<!DOCTYPE html>
|
|
3
3
|
<html lang="zh-CN">
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="UTF-8" />
|
|
@@ -11,7 +11,7 @@ var N=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Prox
|
|
|
11
11
|
<script type="module" src="/src/main.ts"></script>
|
|
12
12
|
</body>
|
|
13
13
|
</html>
|
|
14
|
-
`}function
|
|
14
|
+
`}function oe(){return`import { createApp } from '@lytjs/lytjs';
|
|
15
15
|
import App from './App';
|
|
16
16
|
|
|
17
17
|
// \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B
|
|
@@ -19,7 +19,7 @@ const app = createApp(App);
|
|
|
19
19
|
|
|
20
20
|
// \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20
|
|
21
21
|
app.mount('#app');
|
|
22
|
-
`}function
|
|
22
|
+
`}function re(){return`import { defineComponent } from '@lytjs/lytjs';
|
|
23
23
|
|
|
24
24
|
// \u5B9A\u4E49\u6839\u7EC4\u4EF6
|
|
25
25
|
const App = defineComponent({
|
|
@@ -44,7 +44,7 @@ const App = defineComponent({
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
export default App;
|
|
47
|
-
`}function
|
|
47
|
+
`}function ne(){return`/* Lyt \u5168\u5C40\u6837\u5F0F */
|
|
48
48
|
|
|
49
49
|
* {
|
|
50
50
|
margin: 0;
|
|
@@ -75,9 +75,9 @@ body {
|
|
|
75
75
|
font-size: 1.2rem;
|
|
76
76
|
color: #666;
|
|
77
77
|
}
|
|
78
|
-
`}function
|
|
79
|
-
`}function
|
|
80
|
-
`}function
|
|
78
|
+
`}function se(e){return JSON.stringify({name:e,version:"0.1.0",private:!0,type:"module",scripts:{dev:"lyt dev",build:"lyt build",preview:"lyt preview"},dependencies:{"@lytjs/lytjs":"latest"},devDependencies:{"@lytjs/cli":"latest",typescript:"^5.0.0"}},null,2)+`
|
|
79
|
+
`}function ie(){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)+`
|
|
80
|
+
`}function le(){return`# \u4F9D\u8D56
|
|
81
81
|
node_modules/
|
|
82
82
|
|
|
83
83
|
# \u6784\u5EFA\u8F93\u51FA
|
|
@@ -100,9 +100,9 @@ Thumbs.db
|
|
|
100
100
|
# \u65E5\u5FD7
|
|
101
101
|
*.log
|
|
102
102
|
npm-debug.log*
|
|
103
|
-
`}async function Y(e,
|
|
104
|
-
`}function
|
|
105
|
-
`}function
|
|
103
|
+
`}async function Y(e,t={}){let r=t.template||"spa",n=A.resolve(process.cwd(),e);i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(e,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(r,"brightCyan")}`),E(n)&&(i.error(`\u76EE\u5F55 "${e}" \u5DF2\u5B58\u5728\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u540D\u79F0\u6216\u5220\u9664\u5DF2\u6709\u76EE\u5F55`),process.exit(1)),v(n);let s=[{filePath:"index.html",content:te()},{filePath:"src/main.ts",content:oe()},{filePath:"src/App.ts",content:re()},{filePath:"src/style.css",content:ne()},{filePath:"package.json",content:se(e)},{filePath:"tsconfig.json",content:ie()},{filePath:".gitignore",content:le()}];for(let l of s){let p=A.join(n,l.filePath);w(p,l.content),i.success(` \u521B\u5EFA ${l.filePath}`)}i.success(`\u9879\u76EE ${o(e,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`)}import*as F from"path";function ae(e){let t={name:e.name,version:"0.1.0",private:!0,type:"module",scripts:{dev:"lytx dev",build:"lytx build",preview:"lytx preview"},dependencies:{"@lytjs/lytjs":"latest"}};return e.ts&&(t.devDependencies={"@lytjs/cli":"latest",typescript:"^5.0.0"}),e.eslint&&(t.devDependencies=t.devDependencies||{},t.devDependencies.eslint="^8.0.0",t.scripts=t.scripts||{},t.scripts.lint="eslint src --ext .ts,.js"),e.router&&(t.dependencies["@lytjs/router"]="latest"),e.store&&(t.dependencies["@lytjs/store"]="latest"),JSON.stringify(t,null,2)+`
|
|
104
|
+
`}function ce(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)+`
|
|
105
|
+
`}function pe(e){let t=e.ts?".ts":".js";return`<!DOCTYPE html>
|
|
106
106
|
<html lang="zh-CN">
|
|
107
107
|
<head>
|
|
108
108
|
<meta charset="UTF-8" />
|
|
@@ -112,13 +112,13 @@ npm-debug.log*
|
|
|
112
112
|
</head>
|
|
113
113
|
<body>
|
|
114
114
|
<div id="app"></div>
|
|
115
|
-
<script type="module" src="/src/main${
|
|
115
|
+
<script type="module" src="/src/main${t}"></script>
|
|
116
116
|
</body>
|
|
117
117
|
</html>
|
|
118
|
-
`}function
|
|
119
|
-
`)}function
|
|
118
|
+
`}function ue(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(`
|
|
119
|
+
`)}function de(e){let t=e.ts?".ts":".js",r=["import { createApp } from '@lytjs/lytjs'","import App from './App.lyt'","import './styles/main.css'"];return e.router&&r.push("import { router } from './router'"),e.store&&r.push("import { store } from './store'"),r.push(""),r.push("// \u521B\u5EFA\u5E94\u7528\u5B9E\u4F8B"),r.push("const app = createApp(App)"),e.router&&r.push("app.use(router)"),e.store&&r.push("app.use(store)"),r.push(""),r.push("// \u5C06\u5E94\u7528\u6302\u8F7D\u5230 #app \u5143\u7D20"),r.push("app.mount('#app')"),r.join(`
|
|
120
120
|
`)+`
|
|
121
|
-
`}function
|
|
121
|
+
`}function fe(){return`<template>
|
|
122
122
|
<div class="app">
|
|
123
123
|
<Header />
|
|
124
124
|
<main>
|
|
@@ -146,7 +146,7 @@ export default defineComponent({
|
|
|
146
146
|
padding: 20px;
|
|
147
147
|
}
|
|
148
148
|
</style>
|
|
149
|
-
`}function
|
|
149
|
+
`}function ge(){return`import { defineComponent } from '@lytjs/lytjs'
|
|
150
150
|
|
|
151
151
|
export default defineComponent({
|
|
152
152
|
name: 'HomePage',
|
|
@@ -158,7 +158,7 @@ export default defineComponent({
|
|
|
158
158
|
</div>
|
|
159
159
|
\`,
|
|
160
160
|
})
|
|
161
|
-
`}function
|
|
161
|
+
`}function me(){return`import { defineComponent } from '@lytjs/lytjs'
|
|
162
162
|
|
|
163
163
|
export default defineComponent({
|
|
164
164
|
name: 'AboutPage',
|
|
@@ -170,7 +170,7 @@ export default defineComponent({
|
|
|
170
170
|
</div>
|
|
171
171
|
\`,
|
|
172
172
|
})
|
|
173
|
-
`}function
|
|
173
|
+
`}function he(){return`import { defineComponent } from '@lytjs/lytjs'
|
|
174
174
|
|
|
175
175
|
export default defineComponent({
|
|
176
176
|
name: 'Header',
|
|
@@ -184,7 +184,7 @@ export default defineComponent({
|
|
|
184
184
|
</header>
|
|
185
185
|
\`,
|
|
186
186
|
})
|
|
187
|
-
`}function
|
|
187
|
+
`}function ye(){return`import { createRouter, createWebHistory } from '@lytjs/router'
|
|
188
188
|
import HomePage from '../pages/index'
|
|
189
189
|
import AboutPage from '../pages/about'
|
|
190
190
|
|
|
@@ -201,7 +201,7 @@ export const router = createRouter({
|
|
|
201
201
|
},
|
|
202
202
|
],
|
|
203
203
|
})
|
|
204
|
-
`}function
|
|
204
|
+
`}function be(){return`import { createStore } from '@lytjs/store'
|
|
205
205
|
|
|
206
206
|
export const store = createStore({
|
|
207
207
|
state: {
|
|
@@ -229,7 +229,7 @@ export const store = createStore({
|
|
|
229
229
|
doubleCount: (state: any) => state.count * 2,
|
|
230
230
|
},
|
|
231
231
|
})
|
|
232
|
-
`}function
|
|
232
|
+
`}function xe(){return`/* \u5168\u5C40\u6837\u5F0F */
|
|
233
233
|
|
|
234
234
|
* {
|
|
235
235
|
margin: 0;
|
|
@@ -253,17 +253,17 @@ a {
|
|
|
253
253
|
a:hover {
|
|
254
254
|
text-decoration: underline;
|
|
255
255
|
}
|
|
256
|
-
`}function
|
|
256
|
+
`}function ve(){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
|
257
257
|
<rect width="32" height="32" rx="6" fill="#42b883"/>
|
|
258
258
|
<text x="16" y="22" text-anchor="middle" fill="white" font-size="18" font-weight="bold">L</text>
|
|
259
259
|
</svg>
|
|
260
|
-
`}function
|
|
261
|
-
`}async function O(e){let{name:
|
|
260
|
+
`}function $e(){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)+`
|
|
261
|
+
`}async function O(e){let{name:t,template:r,ts:n,router:s,store:l,eslint:p}=e,a=F.resolve(process.cwd(),t);if(i.info(`\u6B63\u5728\u521B\u5EFA Lyt \u9879\u76EE: ${o(t,"brightCyan")}`),i.info(`\u4F7F\u7528\u6A21\u677F: ${o(r,"brightCyan")}`),E(a))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`);v(a);let c=[{filePath:"package.json",content:ae(e)},{filePath:"index.html",content:pe(e)},{filePath:"lytx.config.ts",content:ue(e)},{filePath:"src/main.ts",content:de(e)},{filePath:"src/App.lyt",content:fe()},{filePath:"src/pages/index.ts",content:ge()},{filePath:"src/pages/about.ts",content:me()},{filePath:"src/components/Header.ts",content:he()},{filePath:"src/styles/main.css",content:xe()},{filePath:"public/favicon.svg",content:ve()}];n&&c.push({filePath:"tsconfig.json",content:ce(e)}),s&&c.push({filePath:"src/router/index.ts",content:ye()}),l&&c.push({filePath:"src/store/index.ts",content:be()}),p&&c.push({filePath:".eslintrc.json",content:$e()});for(let u of c){let d=F.join(a,u.filePath);w(d,u.content),i.success(` \u521B\u5EFA ${u.filePath}`)}i.success(`\u9879\u76EE ${o(t,"brightCyan")} \u521B\u5EFA\u6210\u529F\uFF01`)}import*as J from"http";import*as L from"fs";import*as j from"path";import*as _ from"http";import*as C from"fs";import*as y from"path";import*as z from"crypto";var k=class{constructor(){this.clients=[]}handleUpgrade(t,r,n){let s=t.headers["sec-websocket-key"];if(!s){r.destroy();return}let l=z.createHash("sha1").update(s+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");r.write(`HTTP/1.1 101 Switching Protocols\r
|
|
262
262
|
Upgrade: websocket\r
|
|
263
263
|
Connection: Upgrade\r
|
|
264
|
-
Sec-WebSocket-Accept: ${
|
|
264
|
+
Sec-WebSocket-Accept: ${l}\r
|
|
265
265
|
\r
|
|
266
|
-
`);let p={socket:
|
|
266
|
+
`);let p={socket:r,isAlive:!0};r.on("close",()=>{this.clients=this.clients.filter(a=>a!==p)}),r.on("error",()=>{this.clients=this.clients.filter(a=>a!==p)}),this.clients.push(p)}broadcast(t){let r=[];for(let n of this.clients)try{if(!n.isAlive){r.push(n);continue}let s=Buffer.from(t,"utf-8"),l=this.createFrame(129,s);n.socket.write(l)}catch(s){r.push(n)}for(let n of r){this.clients=this.clients.filter(s=>s!==n);try{n.socket.destroy()}catch(s){}}}createFrame(t,r){let n=r.length,s;n<126?s=2:n<65536?s=4:s=10;let l=Buffer.alloc(s+n);return l[0]=t,n<126?l[1]=n:n<65536?(l[1]=126,l.writeUInt16BE(n,2)):(l[1]=127,l.writeUInt32BE(0,2),l.writeUInt32BE(n,6)),r.copy(l,s),l}getClientCount(){return this.clients.length}closeAll(){for(let t of this.clients)try{t.socket.destroy()}catch(r){}this.clients=[]}};function we(e){let t=new k,r=[],n=[],s=null,l=!1;function p(c){let u=y.extname(c).toLowerCase();if(u===".css")return"css";let d=y.basename(c);return d.startsWith("lytx.config")||d==="tsconfig.json"||d==="package.json"?"reload":u===".ts"||u===".tsx"||u===".lyt"||u===".js"||u===".jsx"?"update":"reload"}function a(c){try{let u=C.readdirSync(c,{withFileTypes:!0});for(let d of u){let f=y.join(c,d.name);if(d.isDirectory()){if(d.name==="node_modules"||d.name===".git"||d.name==="dist")continue;a(f)}else if(d.isFile()){let T=y.extname(d.name).toLowerCase();if(new Set([".ts",".tsx",".js",".jsx",".css",".html",".json",".lyt"]).has(T))try{let P=C.watch(f,{persistent:!1},U=>{if(U==="change"){let M=y.relative(e,f);for(let $ of r)try{$(M)}catch(R){}let S=p(f),x={type:S,path:`/${M}`};if(S==="css")try{x.content=C.readFileSync(f,"utf-8")}catch($){}t.broadcast(JSON.stringify(x))}});n.push(P)}catch(P){}}}}catch(u){}}return{start(c){l||(l=!0,s=_.createServer((u,d)=>{d.writeHead(426,{"Content-Type":"text/plain"}),d.end("Upgrade Required")}),s.on("upgrade",(u,d,f)=>{t.handleUpgrade(u,d,f)}),s.listen(c,()=>{}),a(e))},stop(){l=!1;for(let c of n)try{c.close()}catch(u){}if(n.length=0,t.closeAll(),s){try{s.close()}catch(c){}s=null}},onFileChange(c){r.push(c)},notifyClient(c){t.broadcast(JSON.stringify(c))}}}function I(e){let t=new k;return e.on("upgrade",(r,n,s)=>{t.handleUpgrade(r,n,s)}),{broadcast(r){t.broadcast(r)},getClientCount(){return t.getClientCount()}}}function G(){return`(function() {
|
|
267
267
|
'use strict';
|
|
268
268
|
|
|
269
269
|
var ws = null;
|
|
@@ -361,112 +361,112 @@ Sec-WebSocket-Accept: ${a}\r
|
|
|
361
361
|
|
|
362
362
|
// \u542F\u52A8\u8FDE\u63A5
|
|
363
363
|
connect();
|
|
364
|
-
})();`}var
|
|
365
|
-
</head>`)),{statusCode:200,headers:{"Content-Type":p},body:
|
|
366
|
-
${
|
|
364
|
+
})();`}var V;try{V=N("esbuild")}catch(e){i.error("\u7F3A\u5C11\u4F9D\u8D56: esbuild"),i.error(""),i.error(" Lyt CLI \u7684\u5F00\u53D1\u670D\u52A1\u5668\u9700\u8981 esbuild \u6765\u5B9E\u65F6\u7F16\u8BD1 TypeScript\u3002"),i.error(""),i.error(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5B89\u88C5:"),i.error(` ${o("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${o("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}function Se(e,t){try{return V.transformSync(e,{loader:"ts",target:"es2018",format:"esm",sourcemap:"inline"}).code}catch(r){let n=r instanceof Error?r.message:String(r);return e}}function Ce(e,t){var c;let r=((c=e.url)==null?void 0:c.split("?")[0])||"/";r==="/"&&(r="/index.html");let n=j.join(t,r);if(!n.startsWith(t))return{statusCode:403,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"403 Forbidden"};if(!L.existsSync(n)||!L.statSync(n).isFile())return{statusCode:404,headers:{"Content-Type":"text/plain; charset=utf-8"},body:"404 Not Found"};let s=j.extname(n).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",a=H(n);return(s===".ts"||s===".tsx")&&(a=Se(a,r)),s===".html"&&(a=a.replace("</head>",`<script>${G()}</script>
|
|
365
|
+
</head>`)),{statusCode:200,headers:{"Content-Type":p},body:a}}function B(e={}){let t=e.port||3e3,r=j.resolve(e.root||process.cwd()),n=e.hmr!==!1,s=J.createServer((a,c)=>{let u=Ce(a,r);c.writeHead(u.statusCode,u.headers),c.end(u.body)}),l=n?I(s):null;s.listen(t,()=>{}),s.on("error",a=>{a.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: ${a.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 m from"fs";import*as g from"path";var q;try{q=N("esbuild")}catch(e){i.error("\u7F3A\u5C11\u4F9D\u8D56: esbuild"),i.error(""),i.error(" Lyt CLI \u7684\u6784\u5EFA\u529F\u80FD\u9700\u8981 esbuild\u3002"),i.error(""),i.error(" \u8BF7\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5B89\u88C5:"),i.error(` ${o("npm install esbuild --save-dev","brightGreen")}`),i.error(""),i.error(" \u5982\u679C\u60A8\u4F7F\u7528 pnpm:"),i.error(` ${o("pnpm add esbuild -D","brightGreen")}`),i.error(""),process.exit(1)}async function X(e={}){let t=Date.now(),r=g.resolve(e.root||process.cwd()),n=g.resolve(r,e.outDir||"dist"),s=e.entry||"index.html",l=e.minify||!1;i.info("\u5F00\u59CB\u6784\u5EFA\u9879\u76EE..."),i.info(` \u6839\u76EE\u5F55: ${o(r,"brightCyan")}`),i.info(` \u8F93\u51FA\u76EE\u5F55: ${o(n,"brightCyan")}`),i.info(` \u538B\u7F29: ${o(l?"\u5F00\u542F":"\u5173\u95ED",l?"brightGreen":"brightYellow")}`);let p=g.join(r,s);m.existsSync(p)||(i.error(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${p}`),process.exit(1));let a=H(p),c=/<script\s+type="module"\s+src="([^"]+)"\s*><\/script>/g,u,d=[];for(;(u=c.exec(a))!==null;)d.push(u[1]);d.length===0&&i.warn("\u672A\u5728\u5165\u53E3 HTML \u4E2D\u627E\u5230\u6A21\u5757\u811A\u672C\u5F15\u7528");let f={inputFiles:0,outputFiles:0,totalSize:0,buildTime:0};v(n),v(g.join(n,"assets"));for(let b of d){let P=g.join(r,b);if(!m.existsSync(P)){i.warn(`\u811A\u672C\u6587\u4EF6\u4E0D\u5B58\u5728: ${b}`);continue}i.info(`\u6B63\u5728\u6253\u5305: ${o(b,"brightYellow")}`);let M=`${g.basename(b,g.extname(b))}.bundle.js`,S=g.join(n,"assets",M);try{await q.build({entryPoints:[P],bundle:!0,minify:l,target:"es2018",format:"esm",outfile:S,sourcemap:!0,external:R=>R.startsWith("@lytjs/"),drop:l?["console"]:[],metafile:!0});let x=m.readFileSync(S,"utf-8");f.totalSize+=Buffer.byteLength(x,"utf-8"),f.outputFiles++;let $=S+".map";if(m.existsSync($)){let R=m.readFileSync($,"utf-8");f.totalSize+=Buffer.byteLength(R,"utf-8"),f.outputFiles++}a=a.replace(`<script type="module" src="${b}"></script>`,`<script src="/assets/${M}"></script>`),f.inputFiles++}catch(x){let $=x instanceof Error?x.message:String(x);i.error(`\u6253\u5305\u5931\u8D25 ${b}: ${$}`),process.exit(1)}}je(r,n,f);let T=g.join(n,"index.html");w(T,a),f.outputFiles++,f.totalSize+=Buffer.byteLength(a,"utf-8"),f.buildTime=Date.now()-t,i.success("\u6784\u5EFA\u5B8C\u6210\uFF01")}function je(e,t,r){let n=g.join(e,"src");if(!m.existsSync(n))return;function s(l,p){let a=m.readdirSync(l,{withFileTypes:!0});for(let c of a){let u=g.join(l,c.name);if(c.isDirectory()){if(c.name==="node_modules")continue;s(u,p)}else if(c.isFile()){let d=g.extname(c.name);if([".ts",".tsx",".js",".jsx"].includes(d))continue;let f=g.relative(p,u),T=g.join(t,f);w(T,m.readFileSync(u).toString("utf-8")),r.outputFiles++,r.totalSize+=m.statSync(u).size}}}s(n,n)}var Te="lytx",Pe="Lyt.js \u6846\u67B6\u547D\u4EE4\u884C\u5DE5\u5177\uFF08\u589E\u5F3A\u7248\uFF09",et=`
|
|
366
|
+
${o(Te,"brightCyan")} - ${Pe}
|
|
367
367
|
|
|
368
|
-
${
|
|
368
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
369
369
|
lytx <command> [options] [args]
|
|
370
370
|
|
|
371
|
-
${
|
|
372
|
-
${
|
|
373
|
-
${
|
|
374
|
-
${
|
|
375
|
-
${
|
|
376
|
-
|
|
377
|
-
${
|
|
378
|
-
${
|
|
379
|
-
${
|
|
380
|
-
|
|
381
|
-
${
|
|
382
|
-
${
|
|
383
|
-
${
|
|
384
|
-
${
|
|
385
|
-
${
|
|
386
|
-
${
|
|
387
|
-
${
|
|
388
|
-
${
|
|
389
|
-
|
|
390
|
-
`,
|
|
391
|
-
${
|
|
392
|
-
|
|
393
|
-
${
|
|
371
|
+
${o("\u547D\u4EE4:","brightGreen")}
|
|
372
|
+
${o("create","brightYellow")} <name> \u521B\u5EFA\u4E00\u4E2A\u65B0\u7684 Lyt \u9879\u76EE
|
|
373
|
+
${o("dev","brightYellow")} \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
374
|
+
${o("build","brightYellow")} \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
375
|
+
${o("preview","brightYellow")} \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
376
|
+
|
|
377
|
+
${o("\u5168\u5C40\u9009\u9879:","brightGreen")}
|
|
378
|
+
${o("-h, --help","brightYellow")} \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
|
|
379
|
+
${o("-v, --version","brightYellow")} \u663E\u793A\u7248\u672C\u53F7
|
|
380
|
+
|
|
381
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
382
|
+
${o("$","dim")} lytx create my-app
|
|
383
|
+
${o("$","dim")} lytx create my-app --template spa --ts --router --store
|
|
384
|
+
${o("$","dim")} lytx dev
|
|
385
|
+
${o("$","dim")} lytx dev --port 8080 --hmr
|
|
386
|
+
${o("$","dim")} lytx build
|
|
387
|
+
${o("$","dim")} lytx build --mode ssr
|
|
388
|
+
${o("$","dim")} lytx preview --port 4173
|
|
389
|
+
|
|
390
|
+
`,tt=`
|
|
391
|
+
${o("lytx create","brightCyan")} - \u521B\u5EFA\u65B0\u7684 Lyt \u9879\u76EE
|
|
392
|
+
|
|
393
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
394
394
|
lytx create <name> [options]
|
|
395
395
|
|
|
396
|
-
${
|
|
397
|
-
${
|
|
396
|
+
${o("\u53C2\u6570:","brightGreen")}
|
|
397
|
+
${o("<name>","brightYellow")} \u9879\u76EE\u540D\u79F0\uFF08\u540C\u65F6\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF09
|
|
398
398
|
|
|
399
|
-
${
|
|
400
|
-
${
|
|
399
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
400
|
+
${o("--template <tpl>","brightYellow")} \u9879\u76EE\u6A21\u677F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
401
401
|
\u53EF\u9009\u503C: spa, ssr, ssg
|
|
402
|
-
${
|
|
403
|
-
${
|
|
404
|
-
${
|
|
405
|
-
${
|
|
402
|
+
${o("--ts","brightYellow")} \u4F7F\u7528 TypeScript
|
|
403
|
+
${o("--router","brightYellow")} \u5305\u542B\u8DEF\u7531
|
|
404
|
+
${o("--store","brightYellow")} \u5305\u542B\u72B6\u6001\u7BA1\u7406
|
|
405
|
+
${o("--eslint","brightYellow")} \u5305\u542B ESLint \u914D\u7F6E
|
|
406
406
|
|
|
407
|
-
${
|
|
408
|
-
${
|
|
409
|
-
${
|
|
410
|
-
${
|
|
407
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
408
|
+
${o("$","dim")} lytx create my-app
|
|
409
|
+
${o("$","dim")} lytx create my-app --template spa --ts --router --store
|
|
410
|
+
${o("$","dim")} lytx create my-app --template ssr --ts
|
|
411
411
|
|
|
412
|
-
`,
|
|
413
|
-
${
|
|
412
|
+
`,ot=`
|
|
413
|
+
${o("lytx dev","brightCyan")} - \u542F\u52A8\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5668
|
|
414
414
|
|
|
415
|
-
${
|
|
415
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
416
416
|
lytx dev [options]
|
|
417
417
|
|
|
418
|
-
${
|
|
419
|
-
${
|
|
420
|
-
${
|
|
421
|
-
${
|
|
418
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
419
|
+
${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 3000\uFF09
|
|
420
|
+
${o("--hmr","brightYellow")} \u5F00\u542F\u70ED\u66F4\u65B0\uFF08\u9ED8\u8BA4: \u5F00\u542F\uFF09
|
|
421
|
+
${o("--no-hmr","brightYellow")} \u5173\u95ED\u70ED\u66F4\u65B0
|
|
422
422
|
|
|
423
|
-
${
|
|
423
|
+
${o("\u529F\u80FD:","brightGreen")}
|
|
424
424
|
- \u9759\u6001\u6587\u4EF6\u670D\u52A1
|
|
425
425
|
- TypeScript \u5373\u65F6\u7F16\u8BD1
|
|
426
426
|
- \u70ED\u6A21\u5757\u66FF\u6362\uFF08HMR\uFF09
|
|
427
427
|
- WebSocket \u5B9E\u65F6\u901A\u4FE1
|
|
428
428
|
|
|
429
|
-
${
|
|
430
|
-
${
|
|
431
|
-
${
|
|
432
|
-
${
|
|
429
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
430
|
+
${o("$","dim")} lytx dev
|
|
431
|
+
${o("$","dim")} lytx dev --port 8080
|
|
432
|
+
${o("$","dim")} lytx dev --no-hmr
|
|
433
433
|
|
|
434
|
-
`,
|
|
435
|
-
${
|
|
434
|
+
`,rt=`
|
|
435
|
+
${o("lytx build","brightCyan")} - \u6784\u5EFA\u751F\u4EA7\u7248\u672C
|
|
436
436
|
|
|
437
|
-
${
|
|
437
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
438
438
|
lytx build [options]
|
|
439
439
|
|
|
440
|
-
${
|
|
441
|
-
${
|
|
440
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
441
|
+
${o("--mode <mode>","brightYellow")} \u6784\u5EFA\u6A21\u5F0F\uFF08\u9ED8\u8BA4: spa\uFF09
|
|
442
442
|
\u53EF\u9009\u503C: spa, ssr, ssg
|
|
443
|
-
${
|
|
444
|
-
${
|
|
445
|
-
${
|
|
443
|
+
${o("--minify","brightYellow")} \u538B\u7F29\u4EE3\u7801\uFF08\u53BB\u9664\u7A7A\u767D\u548C\u6CE8\u91CA\uFF09
|
|
444
|
+
${o("-o, --outDir <dir>","brightYellow")} \u8F93\u51FA\u76EE\u5F55\uFF08\u9ED8\u8BA4: dist\uFF09
|
|
445
|
+
${o("--entry <file>","brightYellow")} \u5165\u53E3\u6587\u4EF6\uFF08\u9ED8\u8BA4: index.html\uFF09
|
|
446
446
|
|
|
447
|
-
${
|
|
447
|
+
${o("\u529F\u80FD:","brightGreen")}
|
|
448
448
|
- TypeScript \u7F16\u8BD1
|
|
449
449
|
- \u6A21\u5757\u6253\u5305\uFF08\u5185\u8054\u4F9D\u8D56\uFF09
|
|
450
450
|
- \u53BB\u9664 console.log
|
|
451
451
|
- Source Map \u751F\u6210
|
|
452
452
|
- \u9759\u6001\u8D44\u6E90\u590D\u5236
|
|
453
453
|
|
|
454
|
-
${
|
|
455
|
-
${
|
|
456
|
-
${
|
|
457
|
-
${
|
|
454
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
455
|
+
${o("$","dim")} lytx build
|
|
456
|
+
${o("$","dim")} lytx build --mode ssr
|
|
457
|
+
${o("$","dim")} lytx build --minify --outDir ./output
|
|
458
458
|
|
|
459
|
-
`,
|
|
460
|
-
${
|
|
459
|
+
`,nt=`
|
|
460
|
+
${o("lytx preview","brightCyan")} - \u9884\u89C8\u6784\u5EFA\u7ED3\u679C
|
|
461
461
|
|
|
462
|
-
${
|
|
462
|
+
${o("\u7528\u6CD5:","brightGreen")}
|
|
463
463
|
lytx preview [options]
|
|
464
464
|
|
|
465
|
-
${
|
|
466
|
-
${
|
|
465
|
+
${o("\u9009\u9879:","brightGreen")}
|
|
466
|
+
${o("-p, --port <port>","brightYellow")} \u670D\u52A1\u7AEF\u53E3\uFF08\u9ED8\u8BA4: 4173\uFF09
|
|
467
467
|
|
|
468
|
-
${
|
|
469
|
-
${
|
|
470
|
-
${
|
|
468
|
+
${o("\u793A\u4F8B:","brightGreen")}
|
|
469
|
+
${o("$","dim")} lytx preview
|
|
470
|
+
${o("$","dim")} lytx preview --port 5000
|
|
471
471
|
|
|
472
|
-
`;function
|
|
472
|
+
`;function Me(e){i.error(`\u672A\u77E5\u547D\u4EE4: ${o(e,"brightRed")}`)}function Re(e){return typeof e=="string"&&["spa","ssr","ssg"].includes(e)?e:"spa"}async function Ee(e){if(e.options.help)return;e.args.length===0&&(i.error("\u8BF7\u63D0\u4F9B\u9879\u76EE\u540D\u79F0"),process.exit(1));let t=e.args[0];if(e.options.ts===!0||e.options.router===!0||e.options.store===!0||e.options.eslint===!0||typeof e.options.template=="string"&&["ssr","ssg"].includes(e.options.template)){let n={name:t,template:Re(e.options.template),ts:e.options.ts===!0,router:e.options.router===!0,store:e.options.store===!0,eslint:e.options.eslint===!0};await O(n)}else{let n={template:typeof e.options.template=="string"?e.options.template:"spa"};await Y(t,n)}}function He(e){if(e.options.help)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)),B(t)}async function Ae(e){if(e.options.help)return;let t={minify:e.options.minify===!0,outDir:typeof e.options.outDir=="string"?e.options.outDir:typeof e.options.o=="string"?e.options.o:"dist",entry:typeof e.options.entry=="string"?e.options.entry:"index.html"};await X(t)}function Fe(e){if(e.options.help)return;let t=typeof e.options.port=="string"?parseInt(e.options.port,10):typeof e.options.p=="string"?parseInt(e.options.p,10):4173;(isNaN(t)||t<1||t>65535)&&(i.error(`\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ${e.options.port||e.options.p}`),process.exit(1));let r=Q.resolve(process.cwd(),"dist");K.existsSync(r)||(i.error("\u672A\u627E\u5230\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55 dist/\uFF0C\u8BF7\u5148\u8FD0\u884C lytx build"),process.exit(1)),B({port:t,root:r,hmr:!1})}async function ke(){let e=W(process.argv);if(e.options.version){return}if(!(e.options.help&&!e.command)){e.command||process.exit(1);try{switch(e.command){case"create":await Ee(e);break;case"dev":He(e);break;case"build":await Ae(e);break;case"preview":Fe(e);break;default:Me(e.command),process.exit(1)}}catch(t){let r=t instanceof Error?t.message:String(t);i.error(`\u6267\u884C\u5931\u8D25: ${r}`),process.exit(1)}}}ke();export{I as createHMREndpoint,we as createHMRServer,O as createProject,G as getHMRClientScript};
|