@meng-xi/vite-plugin 0.0.5 → 0.0.7
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/README-en.md +404 -182
- package/README.md +403 -182
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +9 -1
- package/dist/common/index.d.mts +9 -1
- package/dist/common/index.d.ts +9 -1
- package/dist/common/index.mjs +1 -1
- package/dist/factory/index.cjs +1 -1
- package/dist/factory/index.d.cts +71 -6
- package/dist/factory/index.d.mts +71 -6
- package/dist/factory/index.d.ts +71 -6
- package/dist/factory/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.mjs +1 -1
- package/dist/logger/index.cjs +1 -1
- package/dist/logger/index.d.cts +1 -1
- package/dist/logger/index.d.mts +1 -1
- package/dist/logger/index.d.ts +1 -1
- package/dist/logger/index.mjs +1 -1
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +263 -8
- package/dist/plugins/index.d.mts +263 -8
- package/dist/plugins/index.d.ts +263 -8
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/vite-plugin.Ba9646wL.cjs +1 -0
- package/dist/shared/vite-plugin.C3ejdBNf.mjs +1 -0
- package/dist/shared/vite-plugin.CIahO6bu.mjs +37 -0
- package/dist/shared/{vite-plugin.B3PARlU9.d.cts → vite-plugin.CLr0ttuO.d.cts} +16 -0
- package/dist/shared/{vite-plugin.B3PARlU9.d.mts → vite-plugin.CLr0ttuO.d.mts} +16 -0
- package/dist/shared/{vite-plugin.B3PARlU9.d.ts → vite-plugin.CLr0ttuO.d.ts} +16 -0
- package/dist/shared/vite-plugin.CawoITTT.cjs +1 -0
- package/dist/shared/vite-plugin.DSb6XzBn.mjs +1 -0
- package/dist/shared/vite-plugin.DqgHJjxa.cjs +37 -0
- package/package.json +72 -72
- package/dist/shared/vite-plugin.BZsetDCm.cjs +0 -1
- package/dist/shared/vite-plugin.C7isVPKg.mjs +0 -1
- package/dist/shared/vite-plugin.CS9a5kjK.mjs +0 -36
- package/dist/shared/vite-plugin.CgnG5_UX.cjs +0 -36
- package/dist/shared/vite-plugin.DqWt65U-.cjs +0 -1
- package/dist/shared/vite-plugin.UkE7CdSe.d.cts +0 -43
- package/dist/shared/vite-plugin.UkE7CdSe.d.mts +0 -43
- package/dist/shared/vite-plugin.UkE7CdSe.d.ts +0 -43
- package/dist/shared/vite-plugin.YvjM8LxW.mjs +0 -1
package/package.json
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@meng-xi/vite-plugin",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"private": false,
|
|
6
|
-
"description": "一个为 Vite 提供的插件库",
|
|
7
|
-
"keywords": [
|
|
8
|
-
"@meng-xi/vite-plugin",
|
|
9
|
-
"meng-xi",
|
|
10
|
-
"vite",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
],
|
|
14
|
-
"main": "./dist/index.cjs",
|
|
15
|
-
"module": "./dist/index.mjs",
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
|
-
"exports": {
|
|
18
|
-
".": {
|
|
19
|
-
"require": "./dist/index.cjs",
|
|
20
|
-
"import": "./dist/index.mjs",
|
|
21
|
-
"types": "./dist/index.d.ts"
|
|
22
|
-
},
|
|
23
|
-
"./common": {
|
|
24
|
-
"require": "./dist/common/index.cjs",
|
|
25
|
-
"import": "./dist/common/index.mjs",
|
|
26
|
-
"types": "./dist/common/index.d.ts"
|
|
27
|
-
},
|
|
28
|
-
"./factory": {
|
|
29
|
-
"require": "./dist/factory/index.cjs",
|
|
30
|
-
"import": "./dist/factory/index.mjs",
|
|
31
|
-
"types": "./dist/factory/index.d.ts"
|
|
32
|
-
},
|
|
33
|
-
"./logger": {
|
|
34
|
-
"require": "./dist/logger/index.cjs",
|
|
35
|
-
"import": "./dist/logger/index.mjs",
|
|
36
|
-
"types": "./dist/logger/index.d.ts"
|
|
37
|
-
},
|
|
38
|
-
"./plugins": {
|
|
39
|
-
"require": "./dist/plugins/index.cjs",
|
|
40
|
-
"import": "./dist/plugins/index.mjs",
|
|
41
|
-
"types": "./dist/plugins/index.d.ts"
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
"files": [
|
|
45
|
-
"dist",
|
|
46
|
-
"README.md",
|
|
47
|
-
"README-en.md"
|
|
48
|
-
],
|
|
49
|
-
"scripts": {
|
|
50
|
-
"dev": "unbuild --watch",
|
|
51
|
-
"build": "unbuild"
|
|
52
|
-
},
|
|
53
|
-
"peerDependencies": {
|
|
54
|
-
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
55
|
-
},
|
|
56
|
-
"devDependencies": {
|
|
57
|
-
"@types/node": "^22.0.0",
|
|
58
|
-
"unbuild": "^3.6.0",
|
|
59
|
-
"typescript": "^5.9.3"
|
|
60
|
-
},
|
|
61
|
-
"author": {
|
|
62
|
-
"name": "PedroQue99",
|
|
63
|
-
"email": "ksmengfang@163.com"
|
|
64
|
-
},
|
|
65
|
-
"license": "MIT",
|
|
66
|
-
"homepage": "https://github.com/MengXi-Studio/vite-plugin#readme",
|
|
67
|
-
"repository": {
|
|
68
|
-
"type": "git",
|
|
69
|
-
"url": "git+https://github.com/MengXi-Studio/vite-plugin.git"
|
|
70
|
-
},
|
|
71
|
-
"bugs": "https://github.com/MengXi-Studio/vite-plugin/issues"
|
|
72
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@meng-xi/vite-plugin",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.7",
|
|
5
|
+
"private": false,
|
|
6
|
+
"description": "一个为 Vite 提供的插件库",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"@meng-xi/vite-plugin",
|
|
9
|
+
"meng-xi",
|
|
10
|
+
"vite-plugin",
|
|
11
|
+
"vite",
|
|
12
|
+
"plugin"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./common": {
|
|
24
|
+
"require": "./dist/common/index.cjs",
|
|
25
|
+
"import": "./dist/common/index.mjs",
|
|
26
|
+
"types": "./dist/common/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./factory": {
|
|
29
|
+
"require": "./dist/factory/index.cjs",
|
|
30
|
+
"import": "./dist/factory/index.mjs",
|
|
31
|
+
"types": "./dist/factory/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./logger": {
|
|
34
|
+
"require": "./dist/logger/index.cjs",
|
|
35
|
+
"import": "./dist/logger/index.mjs",
|
|
36
|
+
"types": "./dist/logger/index.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./plugins": {
|
|
39
|
+
"require": "./dist/plugins/index.cjs",
|
|
40
|
+
"import": "./dist/plugins/index.mjs",
|
|
41
|
+
"types": "./dist/plugins/index.d.ts"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"README.md",
|
|
47
|
+
"README-en.md"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"dev": "unbuild --watch",
|
|
51
|
+
"build": "unbuild"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^22.0.0",
|
|
58
|
+
"unbuild": "^3.6.0",
|
|
59
|
+
"typescript": "^5.9.3"
|
|
60
|
+
},
|
|
61
|
+
"author": {
|
|
62
|
+
"name": "PedroQue99",
|
|
63
|
+
"email": "ksmengfang@163.com"
|
|
64
|
+
},
|
|
65
|
+
"license": "MIT",
|
|
66
|
+
"homepage": "https://github.com/MengXi-Studio/vite-plugin#readme",
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "git+https://github.com/MengXi-Studio/vite-plugin.git"
|
|
70
|
+
},
|
|
71
|
+
"bugs": "https://github.com/MengXi-Studio/vite-plugin/issues"
|
|
72
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const o=require("fs"),u=require("path"),crypto=require("crypto");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const o__default=_interopDefaultCompat(o),u__default=_interopDefaultCompat(u),g=10;async function checkSourceExists(e){try{await o__default.promises.access(e,o__default.constants.F_OK)}catch(t){const r=t;throw r.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${e}`):r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${e}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function ensureTargetDir(e){try{await o__default.promises.mkdir(e,{recursive:!0})}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${e}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function readDirRecursive(e,t){const r=await o__default.promises.readdir(e,{withFileTypes:!0}),s=[];for(const n of r){const i=u__default.join(e,n.name),l=n.isFile(),F=n.isDirectory();if(s.push({path:i,isFile:l,isDirectory:F}),F&&t){const p=await readDirRecursive(i,t);s.push(...p)}}return s}async function shouldUpdateFile(e,t){try{const[r,s]=await Promise.all([o__default.promises.stat(e),o__default.promises.stat(t)]);return r.mtimeMs>s.mtimeMs||r.size!==s.size}catch{return!0}}async function fileExists(e){try{return await o__default.promises.access(e,o__default.constants.F_OK),!0}catch{return!1}}async function runWithConcurrency(e,t,r){const s=[];let n=0;async function i(){for(;n<e.length;){const F=n++,p=await t(e[F]);s[F]=p}}const l=Array(Math.min(r,e.length)).fill(null).map(()=>i());return await Promise.all(l),s}async function copySourceToTarget(e,t,r){const s=Date.now(),{recursive:n,overwrite:i,incremental:l=!1,parallelLimit:F=g}=r;let p=0,f=0,d=0;if((await o__default.promises.stat(e)).isDirectory()){await ensureTargetDir(t);const c=await readDirRecursive(e,n),D=c.filter(a=>a.isFile);d=c.filter(a=>a.isDirectory).length;const h=new Set;for(const a of D){const w=u__default.relative(e,a.path),m=u__default.dirname(u__default.join(t,w));h.add(m)}await Promise.all([...h].map(a=>ensureTargetDir(a)));const C=await runWithConcurrency(D,async a=>{const w=u__default.relative(e,a.path),m=u__default.join(t,w);let E=i;return E||(E=!await fileExists(m)),l&&E&&(E=await shouldUpdateFile(a.path,m)),E?(await o__default.promises.copyFile(a.path,m),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},F);for(const a of C)a.copied&&p++,a.skipped&&f++}else{await ensureTargetDir(u__default.dirname(t));let c=i;c||(c=!await fileExists(t)),l&&c&&(c=await shouldUpdateFile(e,t)),c?(await o__default.promises.copyFile(e,t),p++):f++}const y=Date.now()-s;return{copiedFiles:p,skippedFiles:f,copiedDirs:d,executionTime:y}}async function writeFileContent(e,t){try{await o__default.promises.writeFile(e,t,"utf-8")}catch(r){const s=r;throw s.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${e}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${s.message}`)}}function readFileSync(e){try{return o__default.readFileSync(e,"utf-8")}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${e}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}function padNumber(e,t=2){return e.toString().padStart(t,"0")}function generateRandomHash(e=8){const t=Math.max(1,Math.min(64,e));return crypto.randomBytes(Math.ceil(t/2)).toString("hex").slice(0,t)}function getDateFormatParams(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:padNumber(e.getMonth()+1),DD:padNumber(e.getDate()),HH:padNumber(e.getHours()),mm:padNumber(e.getMinutes()),ss:padNumber(e.getSeconds()),SSS:padNumber(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function formatDate(e,t){const r=getDateFormatParams(e);let s=t;for(const[n,i]of Object.entries(r))s=s.replace(new RegExp(`\\{${n}\\}`,"g"),i);return s}function parseTemplate(e,t){let r=e;for(const[s,n]of Object.entries(t))r=r.replace(new RegExp(`\\{${s}\\}`,"g"),n);return r}function toCamelCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map((r,s)=>s===0?r.toLowerCase():r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function toPascalCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function stripJsonComments(e){return e.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}exports.checkSourceExists=checkSourceExists,exports.copySourceToTarget=copySourceToTarget,exports.ensureTargetDir=ensureTargetDir,exports.fileExists=fileExists,exports.formatDate=formatDate,exports.generateRandomHash=generateRandomHash,exports.getDateFormatParams=getDateFormatParams,exports.padNumber=padNumber,exports.parseTemplate=parseTemplate,exports.readDirRecursive=readDirRecursive,exports.readFileSync=readFileSync,exports.runWithConcurrency=runWithConcurrency,exports.shouldUpdateFile=shouldUpdateFile,exports.stripJsonComments=stripJsonComments,exports.toCamelCase=toCamelCase,exports.toPascalCase=toPascalCase,exports.writeFileContent=writeFileContent;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Logger as s}from"../logger/index.mjs";import"fs";import"path";import"crypto";import{V as g,d as a}from"./vite-plugin.B88RyRN8.mjs";class u{options;logger;validator;viteConfig=null;constructor(t,e){this.options=this.mergeOptions(t),this.logger=this.initLogger(e),this.validator=new g(this.options),this.safeExecuteSync(()=>this.validateOptions(),"\u63D2\u4EF6\u914D\u7F6E\u9A8C\u8BC1")}mergeOptions(t){const e={enabled:!0,verbose:!0,errorStrategy:"throw"},r=this.getDefaultOptions();return a(e,r,t)}initLogger(t){return s.create({name:this.getPluginName(),enabled:this.options.verbose,...t}).createPluginLogger(this.getPluginName())}validateOptions(){}getEnforce(){}onConfigResolved(t){this.viteConfig=t,this.logger.info("\u914D\u7F6E\u89E3\u6790\u5B8C\u6210\uFF0C\u63D2\u4EF6\u5DF2\u521D\u59CB\u5316")}safeExecuteSync(t,e){try{return t()}catch(r){return this.handleError(r,e)}}async safeExecute(t,e){try{return await t()}catch(r){return this.handleError(r,e)}}handleError(t,e){let r=`${e}: `;switch(t instanceof Error?r+=t.message:typeof t=="string"?r+=t:r+=String(t),this.options.errorStrategy){case"throw":throw this.logger.error(r),t;case"log":case"ignore":this.logger.error(r);return;default:throw this.logger.error(r),t}}toPlugin(){const t={name:this.getPluginName(),enforce:this.getEnforce(),configResolved:e=>{this.options.enabled&&this.onConfigResolved(e)}};return this.addPluginHooks(t),t}}function l(o,t){return e=>{const r=t?t(e):e,i=new o(r),n=i.toPlugin();return n.pluginInstance=i,n}}export{u as B,l as c};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import{c as n,B as c}from"./vite-plugin.C7isVPKg.mjs";import{c as p,a as g,t as F,l as d,i as m,k as E,w as f,d as D,g as C,h as v}from"./vite-plugin.YvjM8LxW.mjs";import"crypto";import{resolve as h,join as y}from"path";import{existsSync as l,watch as b}from"fs";import{V as $}from"./vite-plugin.B88RyRN8.mjs";class w extends c{getDefaultOptions(){return{overwrite:!0,recursive:!0,incremental:!0}}validateOptions(){this.validator.field("sourceDir").required().string().custom(e=>e.trim()!=="","sourceDir \u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32").field("targetDir").required().string().custom(e=>e.trim()!=="","targetDir \u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32").field("overwrite").boolean().field("recursive").boolean().field("incremental").boolean().validate()}getPluginName(){return"copy-file"}getEnforce(){return"post"}async copyFiles(){const{sourceDir:e,targetDir:t,overwrite:s=!0,recursive:u=!0,incremental:i=!0,enabled:o=!0}=this.options;if(!o){this.logger.info(`\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6267\u884C\uFF1A\u4ECE ${e} \u590D\u5236\u5230 ${t}`);return}await p(e);const a=await g(e,t,{recursive:u,overwrite:s,incremental:i});this.logger.success(`\u590D\u5236\u6587\u4EF6\u6210\u529F\uFF1A\u4ECE ${e} \u5230 ${t}`,`\u590D\u5236\u4E86 ${a.copiedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8DF3\u8FC7\u4E86 ${a.skippedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8017\u65F6 ${a.executionTime}ms`)}addPluginHooks(e){e.writeBundle=async()=>{await this.safeExecute(()=>this.copyFiles(),"\u590D\u5236\u6587\u4EF6")}}}const B=n(w);class T extends c{projectRoot=process.cwd();tabBarPages=new Set;watcher=null;getDefaultOptions(){return{pagesJsonPath:"src/pages.json",outputPath:"src/router.config.ts",outputFormat:"ts",nameStrategy:"camelCase",includeSubPackages:!0,watch:!0,exportTypes:!0,preserveRouteChanges:!0,metaMapping:{navigationBarTitleText:"title",requireAuth:"requireAuth"}}}validateOptions(){if(this.validator.field("pagesJsonPath").string().field("outputPath").string().field("outputFormat").custom(e=>!e||["ts","js"].includes(e),"outputFormat \u5FC5\u987B\u662F ts \u6216 js").field("nameStrategy").custom(e=>!e||["path","camelCase","pascalCase","custom"].includes(e),"nameStrategy \u5FC5\u987B\u662F path, camelCase, pascalCase \u6216 custom").validate(),this.options.nameStrategy==="custom"&&!this.options.customNameGenerator)throw new Error("\u5F53 nameStrategy \u4E3A custom \u65F6\uFF0C\u5FC5\u987B\u63D0\u4F9B customNameGenerator")}getPluginName(){return"generate-router"}generateRouteName(e){switch(this.options.nameStrategy){case"path":return e.replace(/\//g,"_").replace(/^_/,"");case"camelCase":return F(e);case"pascalCase":return d(e);case"custom":return this.options.customNameGenerator(e);default:return F(e)}}extractMeta(e,t){const s={},u=e.style||{},i=this.options.metaMapping||{};for(const[o,a]of Object.entries(i))u[o]!==void 0&&(s[a]=u[o]);return this.tabBarPages.has(t)&&(s.isTab=!0),s}parsePageToRoute(e,t=""){const s=t?`/${t}/${e.path}`:`/${e.path}`,u=this.generateRouteName(s),i=this.extractMeta(e,s.replace(/^\//,"")),o={path:s,name:u};return Object.keys(i).length>0&&(o.meta=i),o}parsePagesJson(e){const t=[];if(!e.pages||!Array.isArray(e.pages)||e.pages.length===0)return this.logger.warn("pages.json \u4E2D\u6CA1\u6709\u6709\u6548\u7684\u9875\u9762\u914D\u7F6E"),t;if(this.tabBarPages.clear(),e.tabBar?.list)for(const s of e.tabBar.list)this.tabBarPages.add(s.pagePath);for(const s of e.pages)t.push(this.parsePageToRoute(s));if(this.options.includeSubPackages&&e.subPackages){for(const s of e.subPackages)if(s.pages&&Array.isArray(s.pages))for(const u of s.pages)t.push(this.parsePageToRoute(u,s.root))}return t}generateTypeDefinitions(){return!this.options.exportTypes||this.options.outputFormat==="js"?"":`
|
|
2
|
-
/**
|
|
3
|
-
* \u8DEF\u7531\u5143\u4FE1\u606F
|
|
4
|
-
*/
|
|
5
|
-
export interface RouteMeta {
|
|
6
|
-
/** \u9875\u9762\u6807\u9898 */
|
|
7
|
-
title?: string
|
|
8
|
-
/** \u662F\u5426\u4E3ATabBar\u9875\u9762 */
|
|
9
|
-
isTab?: boolean
|
|
10
|
-
/** \u662F\u5426\u9700\u8981\u767B\u5F55 */
|
|
11
|
-
requireAuth?: boolean
|
|
12
|
-
/** \u81EA\u5B9A\u4E49\u6269\u5C55\u5B57\u6BB5 */
|
|
13
|
-
[key: string]: unknown
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* \u8DEF\u7531\u914D\u7F6E\u9879
|
|
18
|
-
*/
|
|
19
|
-
export interface RouteConfig {
|
|
20
|
-
/** \u8DEF\u7531\u8DEF\u5F84 */
|
|
21
|
-
path: string
|
|
22
|
-
/** \u8DEF\u7531\u540D\u79F0\uFF08\u7528\u4E8E\u547D\u540D\u8DEF\u7531\u5BFC\u822A\uFF09 */
|
|
23
|
-
name?: string
|
|
24
|
-
/** \u8DEF\u7531\u5143\u4FE1\u606F */
|
|
25
|
-
meta?: RouteMeta
|
|
26
|
-
}
|
|
27
|
-
`}generateFileContent(e){const t=this.generateTypeDefinitions(),s=this.options.outputFormat==="ts",u=JSON.stringify(e,null," ").replace(/"(\w+)":/g,"$1:").replace(/: "([^"]+)"/g,": '$1'");return`${t}
|
|
28
|
-
/**
|
|
29
|
-
* \u8DEF\u7531\u914D\u7F6E\u5217\u8868
|
|
30
|
-
* @description \u7531 pages.json \u81EA\u52A8\u751F\u6210
|
|
31
|
-
*/
|
|
32
|
-
export const routes${s?": RouteConfig[]":""} = ${u}
|
|
33
|
-
|
|
34
|
-
export default routes
|
|
35
|
-
`}readPagesJson(){const e=h(this.projectRoot,this.options.pagesJsonPath);if(!l(e))return this.logger.warn(`pages.json \u6587\u4EF6\u4E0D\u5B58\u5728: ${e}`),null;try{const t=m(e),s=E(t);return JSON.parse(s)}catch(t){return this.logger.error(`\u89E3\u6790 pages.json \u5931\u8D25: ${t.message}`),null}}extractExistingRoutes(e){const t=new Map,s=e.match(/export const routes[^=]*=\s*(\[[\s\S]*?\](?=\s*\n|\s*$|\s*\/\/))/);if(!s)return t;try{let u=s[1].replace(/(\w+)(?=\s*:)/g,'"$1"').replace(/'([^']*)'/g,'"$1"').replace(/,\s*([\]\}])/g,"$1");const i=JSON.parse(u);for(const o of i)o.path&&t.set(o.path,o)}catch{this.logger.warn("\u89E3\u6790\u73B0\u6709 routes \u914D\u7F6E\u5931\u8D25\uFF0C\u5C06\u5B8C\u5168\u91CD\u65B0\u751F\u6210")}return t}mergeRoutes(e,t){return e.map(s=>{const u=t.get(s.path);if(!u)return s;const i={};return s.meta&&Object.assign(i,s.meta),u.meta&&Object.assign(i,u.meta),{...u,path:s.path,meta:Object.keys(i).length>0?i:void 0}})}async generateRouterConfig(){const e=this.readPagesJson();if(!e)return;let t=this.parsePagesJson(e);const s=h(this.projectRoot,this.options.outputPath);if(this.options.preserveRouteChanges&&l(s))try{const i=m(s),o=this.extractExistingRoutes(i);o.size>0&&(t=this.mergeRoutes(t,o),this.logger.info("\u5DF2\u5408\u5E76\u7528\u6237\u5BF9\u8DEF\u7531\u914D\u7F6E\u7684\u4FEE\u6539"))}catch{}const u=this.generateFileContent(t);await f(s,u),this.logger.success(`\u8DEF\u7531\u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210: ${s}`),this.logger.info(`\u5171\u751F\u6210 ${t.length} \u6761\u8DEF\u7531\u914D\u7F6E`)}startWatching(){if(!this.options.watch)return;const e=h(this.projectRoot,this.options.pagesJsonPath);l(e)&&(this.watcher=b(e,async t=>{t==="change"&&(this.logger.info("\u68C0\u6D4B\u5230 pages.json \u53D8\u5316\uFF0C\u91CD\u65B0\u751F\u6210\u8DEF\u7531\u914D\u7F6E..."),await this.safeExecute(()=>this.generateRouterConfig(),"\u91CD\u65B0\u751F\u6210\u8DEF\u7531\u914D\u7F6E"))}),this.logger.info(`\u6B63\u5728\u76D1\u542C pages.json \u53D8\u5316: ${e}`))}stopWatching(){this.watcher&&(this.watcher.close(),this.watcher=null)}addPluginHooks(e){e.configResolved=async t=>{this.options.enabled&&(this.projectRoot=t.root,await this.safeExecute(()=>this.generateRouterConfig(),"\u751F\u6210\u8DEF\u7531\u914D\u7F6E"),t.command==="serve"&&this.startWatching())},e.buildEnd=()=>{this.stopWatching()}}}const P=n(T);let x=class extends c{version="";buildTime=new Date;getDefaultOptions(){return{format:"timestamp",semverBase:"1.0.0",autoIncrement:!1,outputType:"file",outputFile:"version.json",defineName:"__APP_VERSION__",hashLength:8,prefix:"",suffix:""}}validateOptions(){if(this.validator.field("format").custom(e=>!e||["timestamp","date","datetime","semver","hash","custom"].includes(e),"format \u5FC5\u987B\u662F timestamp, date, datetime, semver, hash \u6216 custom").field("outputType").custom(e=>!e||["file","define","both"].includes(e),"outputType \u5FC5\u987B\u662F file, define \u6216 both").field("hashLength").number().custom(e=>!e||e>0&&e<=32,"hashLength \u5FC5\u987B\u5728 1-32 \u4E4B\u95F4").validate(),this.options.format==="custom"&&!this.options.customFormat)throw new Error("\u5F53 format \u4E3A custom \u65F6\uFF0C\u5FC5\u987B\u63D0\u4F9B customFormat")}getPluginName(){return"generate-version"}generateVersion(){const e=D(this.buildTime),t=C(this.options.hashLength);let s;switch(this.options.format){case"timestamp":s=`${e.YYYY}${e.MM}${e.DD}${e.HH}${e.mm}${e.ss}`;break;case"date":s=`${e.YYYY}.${e.MM}.${e.DD}`;break;case"datetime":s=`${e.YYYY}.${e.MM}.${e.DD}.${e.HH}${e.mm}${e.ss}`;break;case"semver":s=this.options.semverBase||"1.0.0";break;case"hash":s=t;break;case"custom":s=this.parseCustomFormat({...e,hash:t});break;default:s=e.timestamp}const u=this.options.prefix||"",i=this.options.suffix||"";return`${u}${s}${i}`}parseCustomFormat(e){const t={...e};if(this.options.semverBase){const[s,u,i]=this.options.semverBase.split(".");t.major=s||"1",t.minor=u||"0",t.patch=i||"0"}return v(this.options.customFormat||"",t)}generateVersionInfo(){return{version:this.version,buildTime:this.buildTime.toISOString(),timestamp:this.buildTime.getTime(),format:this.options.format,...this.options.extra}}async writeVersionFile(e){const t=y(e,this.options.outputFile||"version.json"),s=this.generateVersionInfo();await f(t,JSON.stringify(s,null,2)),this.logger.success(`\u7248\u672C\u6587\u4EF6\u5DF2\u751F\u6210: ${t}`)}addPluginHooks(e){const t=e.configResolved;e.configResolved=s=>{this.options.enabled&&(this.buildTime=new Date,this.version=this.generateVersion(),this.logger.info(`\u751F\u6210\u7248\u672C\u53F7: ${this.version}`)),typeof t=="function"&&t(s)},(this.options.outputType==="define"||this.options.outputType==="both")&&(e.config=()=>{if(!this.options.enabled)return{};this.version||(this.buildTime=new Date,this.version=this.generateVersion());const s=this.options.defineName||"__APP_VERSION__";return this.logger.info(`\u6CE8\u5165\u5168\u5C40\u53D8\u91CF: ${s} = "${this.version}"`),{define:{[s]:JSON.stringify(this.version),[`${s}_INFO`]:JSON.stringify(this.generateVersionInfo())}}}),(this.options.outputType==="file"||this.options.outputType==="both")&&(e.writeBundle=async()=>{!this.options.enabled||!this.viteConfig||await this.safeExecute(async()=>{const s=this.viteConfig.build.outDir;await this.writeVersionFile(s)},"\u5199\u5165\u7248\u672C\u6587\u4EF6")})}};const A=n(x);function j(r){const e=[];if(r.link)return[];if(r.icons&&r.icons.length>0)for(const t of r.icons){const s={rel:t.rel,href:t.href};t.sizes&&(s.sizes=t.sizes),t.type&&(s.type=t.type),e.push({tag:"link",attrs:s,injectTo:"head"})}else if(r.url)e.push({tag:"link",attrs:{rel:"icon",href:r.url},injectTo:"head"});else{const t=r.base||"/",s=t.endsWith("/")?`${t}favicon.ico`:`${t}/favicon.ico`;e.push({tag:"link",attrs:{rel:"icon",href:s},injectTo:"head"})}return e}class k extends c{getDefaultOptions(){return{base:"/"}}validateOptions(){this.validator.field("base").string().field("url").string().field("link").string().field("icons").array(),this.options?.copyOptions&&(this.validator.field("copyOptions").object(),new $(this.options.copyOptions).field("sourceDir").required().string().field("targetDir").required().string().field("overwrite").boolean().field("recursive").boolean().validate()),this.validator.validate()}getPluginName(){return"inject-ico"}getIconTagDescriptors(){if(!this.options.enabled)return this.logger.info("\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165"),[];const e=j(this.options);return e.length>0&&this.logger.success(`\u6210\u529F\u6CE8\u5165 ${e.length} \u4E2A\u56FE\u6807\u6807\u7B7E\u5230 HTML \u6587\u4EF6`),e}injectCustomLinkTag(e){if(!this.options.enabled||!this.options.link)return e;const t=this.options.link,s=/<\/head>/i,u=e.match(s);if(u&&u.index!==void 0){const i=e.slice(0,u.index)+t+`
|
|
36
|
-
`+e.slice(u.index);return this.logger.success("\u6210\u529F\u6CE8\u5165\u81EA\u5B9A\u4E49\u56FE\u6807\u6807\u7B7E\u5230 HTML \u6587\u4EF6"),this.logger.info(` - ${t}`),i}return this.logger.warn("\u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165"),e}async copyFiles(){if(!this.options.enabled){this.logger.info("\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6587\u4EF6\u590D\u5236");return}const{copyOptions:e}=this.options;if(!e)return;const{sourceDir:t,targetDir:s,overwrite:u=!0,recursive:i=!0}=e;await p(t);const o=await g(t,s,{recursive:i,overwrite:u,incremental:!0});this.logger.success(`\u56FE\u6807\u6587\u4EF6\u590D\u5236\u6210\u529F\uFF1A\u4ECE ${t} \u5230 ${s}`,`\u590D\u5236\u4E86 ${o.copiedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8DF3\u8FC7\u4E86 ${o.skippedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8017\u65F6 ${o.executionTime}ms`)}addPluginHooks(e){e.transformIndexHtml={order:"pre",handler:t=>{if(this.options.link)return this.injectCustomLinkTag(t);const s=this.getIconTagDescriptors();return s.length>0?{html:t,tags:s}:t}},e.writeBundle=async()=>{await this.safeExecute(()=>this.copyFiles(),"\u56FE\u6807\u6587\u4EF6\u590D\u5236")}}}const R=n(k,r=>typeof r=="string"?{base:r}:r||{});export{A as a,B as c,P as g,R as i};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";const index=require("./vite-plugin.DqWt65U-.cjs"),format=require("./vite-plugin.BZsetDCm.cjs");require("crypto");const u$2=require("path"),o=require("fs"),validation=require("./vite-plugin.IGZeStMa.cjs");class p extends index.BasePlugin{getDefaultOptions(){return{overwrite:!0,recursive:!0,incremental:!0}}validateOptions(){this.validator.field("sourceDir").required().string().custom(e=>e.trim()!=="","sourceDir \u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32").field("targetDir").required().string().custom(e=>e.trim()!=="","targetDir \u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32").field("overwrite").boolean().field("recursive").boolean().field("incremental").boolean().validate()}getPluginName(){return"copy-file"}getEnforce(){return"post"}async copyFiles(){const{sourceDir:e,targetDir:t,overwrite:s=!0,recursive:i=!0,incremental:r=!0,enabled:n=!0}=this.options;if(!n){this.logger.info(`\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6267\u884C\uFF1A\u4ECE ${e} \u590D\u5236\u5230 ${t}`);return}await format.checkSourceExists(e);const c=await format.copySourceToTarget(e,t,{recursive:i,overwrite:s,incremental:r});this.logger.success(`\u590D\u5236\u6587\u4EF6\u6210\u529F\uFF1A\u4ECE ${e} \u5230 ${t}`,`\u590D\u5236\u4E86 ${c.copiedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8DF3\u8FC7\u4E86 ${c.skippedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8017\u65F6 ${c.executionTime}ms`)}addPluginHooks(e){e.writeBundle=async()=>{await this.safeExecute(()=>this.copyFiles(),"\u590D\u5236\u6587\u4EF6")}}}const copyFile=index.createPluginFactory(p);class R extends index.BasePlugin{projectRoot=process.cwd();tabBarPages=new Set;watcher=null;getDefaultOptions(){return{pagesJsonPath:"src/pages.json",outputPath:"src/router.config.ts",outputFormat:"ts",nameStrategy:"camelCase",includeSubPackages:!0,watch:!0,exportTypes:!0,preserveRouteChanges:!0,metaMapping:{navigationBarTitleText:"title",requireAuth:"requireAuth"}}}validateOptions(){if(this.validator.field("pagesJsonPath").string().field("outputPath").string().field("outputFormat").custom(e=>!e||["ts","js"].includes(e),"outputFormat \u5FC5\u987B\u662F ts \u6216 js").field("nameStrategy").custom(e=>!e||["path","camelCase","pascalCase","custom"].includes(e),"nameStrategy \u5FC5\u987B\u662F path, camelCase, pascalCase \u6216 custom").validate(),this.options.nameStrategy==="custom"&&!this.options.customNameGenerator)throw new Error("\u5F53 nameStrategy \u4E3A custom \u65F6\uFF0C\u5FC5\u987B\u63D0\u4F9B customNameGenerator")}getPluginName(){return"generate-router"}generateRouteName(e){switch(this.options.nameStrategy){case"path":return e.replace(/\//g,"_").replace(/^_/,"");case"camelCase":return format.toCamelCase(e);case"pascalCase":return format.toPascalCase(e);case"custom":return this.options.customNameGenerator(e);default:return format.toCamelCase(e)}}extractMeta(e,t){const s={},i=e.style||{},r=this.options.metaMapping||{};for(const[n,c]of Object.entries(r))i[n]!==void 0&&(s[c]=i[n]);return this.tabBarPages.has(t)&&(s.isTab=!0),s}parsePageToRoute(e,t=""){const s=t?`/${t}/${e.path}`:`/${e.path}`,i=this.generateRouteName(s),r=this.extractMeta(e,s.replace(/^\//,"")),n={path:s,name:i};return Object.keys(r).length>0&&(n.meta=r),n}parsePagesJson(e){const t=[];if(!e.pages||!Array.isArray(e.pages)||e.pages.length===0)return this.logger.warn("pages.json \u4E2D\u6CA1\u6709\u6709\u6548\u7684\u9875\u9762\u914D\u7F6E"),t;if(this.tabBarPages.clear(),e.tabBar?.list)for(const s of e.tabBar.list)this.tabBarPages.add(s.pagePath);for(const s of e.pages)t.push(this.parsePageToRoute(s));if(this.options.includeSubPackages&&e.subPackages){for(const s of e.subPackages)if(s.pages&&Array.isArray(s.pages))for(const i of s.pages)t.push(this.parsePageToRoute(i,s.root))}return t}generateTypeDefinitions(){return!this.options.exportTypes||this.options.outputFormat==="js"?"":`
|
|
2
|
-
/**
|
|
3
|
-
* \u8DEF\u7531\u5143\u4FE1\u606F
|
|
4
|
-
*/
|
|
5
|
-
export interface RouteMeta {
|
|
6
|
-
/** \u9875\u9762\u6807\u9898 */
|
|
7
|
-
title?: string
|
|
8
|
-
/** \u662F\u5426\u4E3ATabBar\u9875\u9762 */
|
|
9
|
-
isTab?: boolean
|
|
10
|
-
/** \u662F\u5426\u9700\u8981\u767B\u5F55 */
|
|
11
|
-
requireAuth?: boolean
|
|
12
|
-
/** \u81EA\u5B9A\u4E49\u6269\u5C55\u5B57\u6BB5 */
|
|
13
|
-
[key: string]: unknown
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* \u8DEF\u7531\u914D\u7F6E\u9879
|
|
18
|
-
*/
|
|
19
|
-
export interface RouteConfig {
|
|
20
|
-
/** \u8DEF\u7531\u8DEF\u5F84 */
|
|
21
|
-
path: string
|
|
22
|
-
/** \u8DEF\u7531\u540D\u79F0\uFF08\u7528\u4E8E\u547D\u540D\u8DEF\u7531\u5BFC\u822A\uFF09 */
|
|
23
|
-
name?: string
|
|
24
|
-
/** \u8DEF\u7531\u5143\u4FE1\u606F */
|
|
25
|
-
meta?: RouteMeta
|
|
26
|
-
}
|
|
27
|
-
`}generateFileContent(e){const t=this.generateTypeDefinitions(),s=this.options.outputFormat==="ts",i=JSON.stringify(e,null," ").replace(/"(\w+)":/g,"$1:").replace(/: "([^"]+)"/g,": '$1'");return`${t}
|
|
28
|
-
/**
|
|
29
|
-
* \u8DEF\u7531\u914D\u7F6E\u5217\u8868
|
|
30
|
-
* @description \u7531 pages.json \u81EA\u52A8\u751F\u6210
|
|
31
|
-
*/
|
|
32
|
-
export const routes${s?": RouteConfig[]":""} = ${i}
|
|
33
|
-
|
|
34
|
-
export default routes
|
|
35
|
-
`}readPagesJson(){const e=u$2.resolve(this.projectRoot,this.options.pagesJsonPath);if(!o.existsSync(e))return this.logger.warn(`pages.json \u6587\u4EF6\u4E0D\u5B58\u5728: ${e}`),null;try{const t=format.readFileSync(e),s=format.stripJsonComments(t);return JSON.parse(s)}catch(t){return this.logger.error(`\u89E3\u6790 pages.json \u5931\u8D25: ${t.message}`),null}}extractExistingRoutes(e){const t=new Map,s=e.match(/export const routes[^=]*=\s*(\[[\s\S]*?\](?=\s*\n|\s*$|\s*\/\/))/);if(!s)return t;try{let i=s[1].replace(/(\w+)(?=\s*:)/g,'"$1"').replace(/'([^']*)'/g,'"$1"').replace(/,\s*([\]\}])/g,"$1");const r=JSON.parse(i);for(const n of r)n.path&&t.set(n.path,n)}catch{this.logger.warn("\u89E3\u6790\u73B0\u6709 routes \u914D\u7F6E\u5931\u8D25\uFF0C\u5C06\u5B8C\u5168\u91CD\u65B0\u751F\u6210")}return t}mergeRoutes(e,t){return e.map(s=>{const i=t.get(s.path);if(!i)return s;const r={};return s.meta&&Object.assign(r,s.meta),i.meta&&Object.assign(r,i.meta),{...i,path:s.path,meta:Object.keys(r).length>0?r:void 0}})}async generateRouterConfig(){const e=this.readPagesJson();if(!e)return;let t=this.parsePagesJson(e);const s=u$2.resolve(this.projectRoot,this.options.outputPath);if(this.options.preserveRouteChanges&&o.existsSync(s))try{const r=format.readFileSync(s),n=this.extractExistingRoutes(r);n.size>0&&(t=this.mergeRoutes(t,n),this.logger.info("\u5DF2\u5408\u5E76\u7528\u6237\u5BF9\u8DEF\u7531\u914D\u7F6E\u7684\u4FEE\u6539"))}catch{}const i=this.generateFileContent(t);await format.writeFileContent(s,i),this.logger.success(`\u8DEF\u7531\u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210: ${s}`),this.logger.info(`\u5171\u751F\u6210 ${t.length} \u6761\u8DEF\u7531\u914D\u7F6E`)}startWatching(){if(!this.options.watch)return;const e=u$2.resolve(this.projectRoot,this.options.pagesJsonPath);o.existsSync(e)&&(this.watcher=o.watch(e,async t=>{t==="change"&&(this.logger.info("\u68C0\u6D4B\u5230 pages.json \u53D8\u5316\uFF0C\u91CD\u65B0\u751F\u6210\u8DEF\u7531\u914D\u7F6E..."),await this.safeExecute(()=>this.generateRouterConfig(),"\u91CD\u65B0\u751F\u6210\u8DEF\u7531\u914D\u7F6E"))}),this.logger.info(`\u6B63\u5728\u76D1\u542C pages.json \u53D8\u5316: ${e}`))}stopWatching(){this.watcher&&(this.watcher.close(),this.watcher=null)}addPluginHooks(e){e.configResolved=async t=>{this.options.enabled&&(this.projectRoot=t.root,await this.safeExecute(()=>this.generateRouterConfig(),"\u751F\u6210\u8DEF\u7531\u914D\u7F6E"),t.command==="serve"&&this.startWatching())},e.buildEnd=()=>{this.stopWatching()}}}const generateRouter=index.createPluginFactory(R);let u$1=class extends index.BasePlugin{version="";buildTime=new Date;getDefaultOptions(){return{format:"timestamp",semverBase:"1.0.0",autoIncrement:!1,outputType:"file",outputFile:"version.json",defineName:"__APP_VERSION__",hashLength:8,prefix:"",suffix:""}}validateOptions(){if(this.validator.field("format").custom(e=>!e||["timestamp","date","datetime","semver","hash","custom"].includes(e),"format \u5FC5\u987B\u662F timestamp, date, datetime, semver, hash \u6216 custom").field("outputType").custom(e=>!e||["file","define","both"].includes(e),"outputType \u5FC5\u987B\u662F file, define \u6216 both").field("hashLength").number().custom(e=>!e||e>0&&e<=32,"hashLength \u5FC5\u987B\u5728 1-32 \u4E4B\u95F4").validate(),this.options.format==="custom"&&!this.options.customFormat)throw new Error("\u5F53 format \u4E3A custom \u65F6\uFF0C\u5FC5\u987B\u63D0\u4F9B customFormat")}getPluginName(){return"generate-version"}generateVersion(){const e=format.getDateFormatParams(this.buildTime),t=format.generateRandomHash(this.options.hashLength);let s;switch(this.options.format){case"timestamp":s=`${e.YYYY}${e.MM}${e.DD}${e.HH}${e.mm}${e.ss}`;break;case"date":s=`${e.YYYY}.${e.MM}.${e.DD}`;break;case"datetime":s=`${e.YYYY}.${e.MM}.${e.DD}.${e.HH}${e.mm}${e.ss}`;break;case"semver":s=this.options.semverBase||"1.0.0";break;case"hash":s=t;break;case"custom":s=this.parseCustomFormat({...e,hash:t});break;default:s=e.timestamp}const i=this.options.prefix||"",r=this.options.suffix||"";return`${i}${s}${r}`}parseCustomFormat(e){const t={...e};if(this.options.semverBase){const[s,i,r]=this.options.semverBase.split(".");t.major=s||"1",t.minor=i||"0",t.patch=r||"0"}return format.parseTemplate(this.options.customFormat||"",t)}generateVersionInfo(){return{version:this.version,buildTime:this.buildTime.toISOString(),timestamp:this.buildTime.getTime(),format:this.options.format,...this.options.extra}}async writeVersionFile(e){const t=u$2.join(e,this.options.outputFile||"version.json"),s=this.generateVersionInfo();await format.writeFileContent(t,JSON.stringify(s,null,2)),this.logger.success(`\u7248\u672C\u6587\u4EF6\u5DF2\u751F\u6210: ${t}`)}addPluginHooks(e){const t=e.configResolved;e.configResolved=s=>{this.options.enabled&&(this.buildTime=new Date,this.version=this.generateVersion(),this.logger.info(`\u751F\u6210\u7248\u672C\u53F7: ${this.version}`)),typeof t=="function"&&t(s)},(this.options.outputType==="define"||this.options.outputType==="both")&&(e.config=()=>{if(!this.options.enabled)return{};this.version||(this.buildTime=new Date,this.version=this.generateVersion());const s=this.options.defineName||"__APP_VERSION__";return this.logger.info(`\u6CE8\u5165\u5168\u5C40\u53D8\u91CF: ${s} = "${this.version}"`),{define:{[s]:JSON.stringify(this.version),[`${s}_INFO`]:JSON.stringify(this.generateVersionInfo())}}}),(this.options.outputType==="file"||this.options.outputType==="both")&&(e.writeBundle=async()=>{!this.options.enabled||!this.viteConfig||await this.safeExecute(async()=>{const s=this.viteConfig.build.outDir;await this.writeVersionFile(s)},"\u5199\u5165\u7248\u672C\u6587\u4EF6")})}};const generateVersion=index.createPluginFactory(u$1);function generateIconTagDescriptors(a){const e=[];if(a.link)return[];if(a.icons&&a.icons.length>0)for(const t of a.icons){const s={rel:t.rel,href:t.href};t.sizes&&(s.sizes=t.sizes),t.type&&(s.type=t.type),e.push({tag:"link",attrs:s,injectTo:"head"})}else if(a.url)e.push({tag:"link",attrs:{rel:"icon",href:a.url},injectTo:"head"});else{const t=a.base||"/",s=t.endsWith("/")?`${t}favicon.ico`:`${t}/favicon.ico`;e.push({tag:"link",attrs:{rel:"icon",href:s},injectTo:"head"})}return e}class u extends index.BasePlugin{getDefaultOptions(){return{base:"/"}}validateOptions(){this.validator.field("base").string().field("url").string().field("link").string().field("icons").array(),this.options?.copyOptions&&(this.validator.field("copyOptions").object(),new validation.Validator(this.options.copyOptions).field("sourceDir").required().string().field("targetDir").required().string().field("overwrite").boolean().field("recursive").boolean().validate()),this.validator.validate()}getPluginName(){return"inject-ico"}getIconTagDescriptors(){if(!this.options.enabled)return this.logger.info("\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165"),[];const e=generateIconTagDescriptors(this.options);return e.length>0&&this.logger.success(`\u6210\u529F\u6CE8\u5165 ${e.length} \u4E2A\u56FE\u6807\u6807\u7B7E\u5230 HTML \u6587\u4EF6`),e}injectCustomLinkTag(e){if(!this.options.enabled||!this.options.link)return e;const t=this.options.link,s=/<\/head>/i,i=e.match(s);if(i&&i.index!==void 0){const r=e.slice(0,i.index)+t+`
|
|
36
|
-
`+e.slice(i.index);return this.logger.success("\u6210\u529F\u6CE8\u5165\u81EA\u5B9A\u4E49\u56FE\u6807\u6807\u7B7E\u5230 HTML \u6587\u4EF6"),this.logger.info(` - ${t}`),r}return this.logger.warn("\u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165"),e}async copyFiles(){if(!this.options.enabled){this.logger.info("\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6587\u4EF6\u590D\u5236");return}const{copyOptions:e}=this.options;if(!e)return;const{sourceDir:t,targetDir:s,overwrite:i=!0,recursive:r=!0}=e;await format.checkSourceExists(t);const n=await format.copySourceToTarget(t,s,{recursive:r,overwrite:i,incremental:!0});this.logger.success(`\u56FE\u6807\u6587\u4EF6\u590D\u5236\u6210\u529F\uFF1A\u4ECE ${t} \u5230 ${s}`,`\u590D\u5236\u4E86 ${n.copiedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8DF3\u8FC7\u4E86 ${n.skippedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8017\u65F6 ${n.executionTime}ms`)}addPluginHooks(e){e.transformIndexHtml={order:"pre",handler:t=>{if(this.options.link)return this.injectCustomLinkTag(t);const s=this.getIconTagDescriptors();return s.length>0?{html:t,tags:s}:t}},e.writeBundle=async()=>{await this.safeExecute(()=>this.copyFiles(),"\u56FE\u6807\u6587\u4EF6\u590D\u5236")}}}const injectIco=index.createPluginFactory(u,a=>typeof a=="string"?{base:a}:a||{});exports.copyFile=copyFile,exports.generateRouter=generateRouter,exports.generateVersion=generateVersion,exports.injectIco=injectIco;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const logger_index=require("../logger/index.cjs");require("fs"),require("path"),require("crypto");const validation=require("./vite-plugin.IGZeStMa.cjs");class BasePlugin{options;logger;validator;viteConfig=null;constructor(e,t){this.options=this.mergeOptions(e),this.logger=this.initLogger(t),this.validator=new validation.Validator(this.options),this.safeExecuteSync(()=>this.validateOptions(),"\u63D2\u4EF6\u914D\u7F6E\u9A8C\u8BC1")}mergeOptions(e){const t={enabled:!0,verbose:!0,errorStrategy:"throw"},r=this.getDefaultOptions();return validation.deepMerge(t,r,e)}initLogger(e){return logger_index.Logger.create({name:this.getPluginName(),enabled:this.options.verbose,...e}).createPluginLogger(this.getPluginName())}validateOptions(){}getEnforce(){}onConfigResolved(e){this.viteConfig=e,this.logger.info("\u914D\u7F6E\u89E3\u6790\u5B8C\u6210\uFF0C\u63D2\u4EF6\u5DF2\u521D\u59CB\u5316")}safeExecuteSync(e,t){try{return e()}catch(r){return this.handleError(r,t)}}async safeExecute(e,t){try{return await e()}catch(r){return this.handleError(r,t)}}handleError(e,t){let r=`${t}: `;switch(e instanceof Error?r+=e.message:typeof e=="string"?r+=e:r+=String(e),this.options.errorStrategy){case"throw":throw this.logger.error(r),e;case"log":case"ignore":this.logger.error(r);return;default:throw this.logger.error(r),e}}toPlugin(){const e={name:this.getPluginName(),enforce:this.getEnforce(),configResolved:t=>{this.options.enabled&&this.onConfigResolved(t)}};return this.addPluginHooks(e),e}}function createPluginFactory(o,e){return t=>{const r=e?e(t):t,i=new o(r),n=i.toPlugin();return n.pluginInstance=i,n}}exports.BasePlugin=BasePlugin,exports.createPluginFactory=createPluginFactory;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 基础插件配置
|
|
5
|
-
*
|
|
6
|
-
* @interface BasePluginOptions
|
|
7
|
-
*/
|
|
8
|
-
interface BasePluginOptions {
|
|
9
|
-
/**
|
|
10
|
-
* 是否启用插件
|
|
11
|
-
*
|
|
12
|
-
* @default true
|
|
13
|
-
*/
|
|
14
|
-
enabled?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* 是否启用日志
|
|
17
|
-
*
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
verbose?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* 错误处理策略
|
|
23
|
-
*
|
|
24
|
-
* @default 'throw'
|
|
25
|
-
*/
|
|
26
|
-
errorStrategy?: 'throw' | 'log' | 'ignore';
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 插件选项标准化器类型
|
|
30
|
-
*
|
|
31
|
-
* @template T 目标选项类型
|
|
32
|
-
* @template R 原始选项类型
|
|
33
|
-
*/
|
|
34
|
-
type OptionsNormalizer<T, R = any> = (raw?: R) => T;
|
|
35
|
-
/**
|
|
36
|
-
* 插件工厂函数类型
|
|
37
|
-
*
|
|
38
|
-
* @template T 插件配置类型,默认继承自 BasePluginOptions
|
|
39
|
-
* @template R 原始配置类型,默认与 T 相同
|
|
40
|
-
*/
|
|
41
|
-
type PluginFactory<T extends BasePluginOptions = BasePluginOptions, R = T> = (options?: R) => Plugin;
|
|
42
|
-
|
|
43
|
-
export type { BasePluginOptions as B, OptionsNormalizer as O, PluginFactory as P };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 基础插件配置
|
|
5
|
-
*
|
|
6
|
-
* @interface BasePluginOptions
|
|
7
|
-
*/
|
|
8
|
-
interface BasePluginOptions {
|
|
9
|
-
/**
|
|
10
|
-
* 是否启用插件
|
|
11
|
-
*
|
|
12
|
-
* @default true
|
|
13
|
-
*/
|
|
14
|
-
enabled?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* 是否启用日志
|
|
17
|
-
*
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
verbose?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* 错误处理策略
|
|
23
|
-
*
|
|
24
|
-
* @default 'throw'
|
|
25
|
-
*/
|
|
26
|
-
errorStrategy?: 'throw' | 'log' | 'ignore';
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 插件选项标准化器类型
|
|
30
|
-
*
|
|
31
|
-
* @template T 目标选项类型
|
|
32
|
-
* @template R 原始选项类型
|
|
33
|
-
*/
|
|
34
|
-
type OptionsNormalizer<T, R = any> = (raw?: R) => T;
|
|
35
|
-
/**
|
|
36
|
-
* 插件工厂函数类型
|
|
37
|
-
*
|
|
38
|
-
* @template T 插件配置类型,默认继承自 BasePluginOptions
|
|
39
|
-
* @template R 原始配置类型,默认与 T 相同
|
|
40
|
-
*/
|
|
41
|
-
type PluginFactory<T extends BasePluginOptions = BasePluginOptions, R = T> = (options?: R) => Plugin;
|
|
42
|
-
|
|
43
|
-
export type { BasePluginOptions as B, OptionsNormalizer as O, PluginFactory as P };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 基础插件配置
|
|
5
|
-
*
|
|
6
|
-
* @interface BasePluginOptions
|
|
7
|
-
*/
|
|
8
|
-
interface BasePluginOptions {
|
|
9
|
-
/**
|
|
10
|
-
* 是否启用插件
|
|
11
|
-
*
|
|
12
|
-
* @default true
|
|
13
|
-
*/
|
|
14
|
-
enabled?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* 是否启用日志
|
|
17
|
-
*
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
verbose?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* 错误处理策略
|
|
23
|
-
*
|
|
24
|
-
* @default 'throw'
|
|
25
|
-
*/
|
|
26
|
-
errorStrategy?: 'throw' | 'log' | 'ignore';
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 插件选项标准化器类型
|
|
30
|
-
*
|
|
31
|
-
* @template T 目标选项类型
|
|
32
|
-
* @template R 原始选项类型
|
|
33
|
-
*/
|
|
34
|
-
type OptionsNormalizer<T, R = any> = (raw?: R) => T;
|
|
35
|
-
/**
|
|
36
|
-
* 插件工厂函数类型
|
|
37
|
-
*
|
|
38
|
-
* @template T 插件配置类型,默认继承自 BasePluginOptions
|
|
39
|
-
* @template R 原始配置类型,默认与 T 相同
|
|
40
|
-
*/
|
|
41
|
-
type PluginFactory<T extends BasePluginOptions = BasePluginOptions, R = T> = (options?: R) => Plugin;
|
|
42
|
-
|
|
43
|
-
export type { BasePluginOptions as B, OptionsNormalizer as O, PluginFactory as P };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import s from"fs";import l from"path";import{randomBytes as j}from"crypto";const T=10;async function Y(t){try{await s.promises.access(t,s.constants.F_OK)}catch(u){const e=u;throw e.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${t}`):e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${t}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function f(t){try{await s.promises.mkdir(t,{recursive:!0})}catch(u){const e=u;throw e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${t}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function D(t,u){const e=await s.promises.readdir(t,{withFileTypes:!0}),r=[];for(const i of e){const n=l.join(t,i.name),E=i.isFile(),c=i.isDirectory();if(r.push({path:n,isFile:E,isDirectory:c}),c&&u){const F=await D(n,u);r.push(...F)}}return r}async function g(t,u){try{const[e,r]=await Promise.all([s.promises.stat(t),s.promises.stat(u)]);return e.mtimeMs>r.mtimeMs||e.size!==r.size}catch{return!0}}async function y(t){try{return await s.promises.access(t,s.constants.F_OK),!0}catch{return!1}}async function B(t,u,e){const r=[];let i=0;async function n(){for(;i<t.length;){const c=i++,F=await u(t[c]);r[c]=F}}const E=Array(Math.min(e,t.length)).fill(null).map(()=>n());return await Promise.all(E),r}async function k(t,u,e){const r=Date.now(),{recursive:i,overwrite:n,incremental:E=!1,parallelLimit:c=T}=e;let F=0,d=0,A=0;if((await s.promises.stat(t)).isDirectory()){await f(u);const o=await D(t,i),C=o.filter(a=>a.isFile);A=o.filter(a=>a.isDirectory).length;const S=new Set;for(const a of C){const h=l.relative(t,a.path),m=l.dirname(l.join(u,h));S.add(m)}await Promise.all([...S].map(a=>f(a)));const x=await B(C,async a=>{const h=l.relative(t,a.path),m=l.join(u,h);let w=n;return w||(w=!await y(m)),E&&w&&(w=await g(a.path,m)),w?(await s.promises.copyFile(a.path,m),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},c);for(const a of x)a.copied&&F++,a.skipped&&d++}else{await f(l.dirname(u));let o=n;o||(o=!await y(u)),E&&o&&(o=await g(t,u)),o?(await s.promises.copyFile(t,u),F++):d++}const M=Date.now()-r;return{copiedFiles:F,skippedFiles:d,copiedDirs:A,executionTime:M}}async function v(t,u){try{await s.promises.writeFile(t,u,"utf-8")}catch(e){const r=e;throw r.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${t}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}function O(t){try{return s.readFileSync(t,"utf-8")}catch(u){const e=u;throw e.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${t}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}function p(t,u=2){return t.toString().padStart(u,"0")}function P(t=8){const u=Math.max(1,Math.min(64,t));return j(Math.ceil(u/2)).toString("hex").slice(0,u)}function $(t=new Date){return{YYYY:t.getFullYear().toString(),YY:t.getFullYear().toString().slice(-2),MM:p(t.getMonth()+1),DD:p(t.getDate()),HH:p(t.getHours()),mm:p(t.getMinutes()),ss:p(t.getSeconds()),SSS:p(t.getMilliseconds(),3),timestamp:t.getTime().toString()}}function b(t,u){const e=$(t);let r=u;for(const[i,n]of Object.entries(e))r=r.replace(new RegExp(`\\{${i}\\}`,"g"),n);return r}function H(t,u){let e=t;for(const[r,i]of Object.entries(u))e=e.replace(new RegExp(`\\{${r}\\}`,"g"),i);return e}function L(t,u=/[/-]/){return t.replace(/^\/+/,"").split(u).filter(Boolean).map((e,r)=>r===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function R(t,u=/[/-]/){return t.replace(/^\/+/,"").split(u).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function N(t){return t.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}export{k as a,b,Y as c,$ as d,f as e,y as f,P as g,H as h,O as i,B as j,N as k,R as l,p,D as r,g as s,L as t,v as w};
|