@lntvow/vite-plugin 1.0.8 → 1.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 lntvow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1 +1,3 @@
1
- # vite-plugin
1
+ # @lntvow/vite-plugin
2
+
3
+ Collection of custom Vite plugins
package/dist/index.cjs CHANGED
@@ -1,103 +1,24 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";var z=Object.create;var c=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var k=(t,e)=>{for(var n in e)c(t,n,{get:e[n],enumerable:!0})},h=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of R(e))!E.call(t,o)&&o!==n&&c(t,o,{get:()=>e[o],enumerable:!(r=P(e,o))||r.enumerable});return t};var u=(t,e,n)=>(n=t!=null?z(S(t)):{},h(e||!t||!t.__esModule?c(n,"default",{value:t,enumerable:!0}):n,t)),q=t=>h(c({},"__esModule",{value:!0}),t);var A={};k(A,{vitePluginEnvRibbon:()=>H,vitePluginHtml:()=>j,vitePluginLog:()=>L});module.exports=q(A);var p=require("path"),x=require("fs"),m=u(require("dayjs"),1),b=u(require("dayjs/plugin/timezone.js"),1),$=u(require("dayjs/plugin/utc.js"),1),O=require("@lntvow/utils");m.default.extend($.default);m.default.extend(b.default);function L(t={}){let{name:e="LNTVOW_VERSION",timezone:n="Asia/Shanghai"}=t,{entries:r=["src/main.ts","src/main.js"]}=t,{version:o}=t;r=(0,O.castArray)(r).map(i=>(0,p.resolve)(process.cwd(),i));let g=(0,m.default)().tz(n).format("YYYY-MM-DD HH:mm:ss");if(!o)try{let i=(0,x.readFileSync)((0,p.resolve)(process.cwd(),"package.json"),"utf8");o=JSON.parse(i).version}catch(i){o="unknown",console.log("error: ",i)}return{name:"vite-plugin-logs",transform(i,f){if(r.includes((0,p.normalize)(f)))return{code:`
2
+ ${i}
29
3
 
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- vitePluginHtml: () => vitePluginHtml,
34
- vitePluginLog: () => vitePluginLog
35
- });
36
- module.exports = __toCommonJS(src_exports);
37
-
38
- // src/vite-plugin-logs.ts
39
- var import_node_path = __toESM(require("path"), 1);
40
- var import_node_fs = __toESM(require("fs"), 1);
41
- var import_dayjs = __toESM(require("dayjs"), 1);
42
- var import_utc = __toESM(require("dayjs/plugin/utc"), 1);
43
- var import_timezone = __toESM(require("dayjs/plugin/timezone"), 1);
44
- var import_utils = require("@lntvow/utils");
45
- import_dayjs.default.extend(import_utc.default);
46
- import_dayjs.default.extend(import_timezone.default);
47
- function vitePluginLog(options = {}) {
48
- const { name = "LNTVOW_VERSION" } = options;
49
- let { version } = options;
50
- if (!version) {
51
- try {
52
- const packageJsonContent = import_node_fs.default.readFileSync(import_node_path.default.resolve(process.cwd(), "package.json"), "utf8");
53
- version = JSON.parse(packageJsonContent).version;
54
- } catch (e) {
55
- (0, import_utils.throwError)("vitePluginLogs", "package.json not found");
56
- }
57
- }
58
- return {
59
- name: "vite-plugin-logs",
60
- transform(code, id) {
61
- if (id.endsWith("src/main.ts") || id.endsWith("src/main.js")) {
62
- const time = (0, import_dayjs.default)().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");
63
- return {
64
- code: `
65
-
66
- import { log as vitePluginLogs } from '@lntvow/utils';
67
-
68
- ${code}
69
-
70
- localStorage.setItem('${name}', JSON.stringify(['${time}', '${version}']))
71
- vitePluginLogs('version', '${time}', '${version}')
72
-
73
- `
74
- };
75
- }
76
- }
77
- };
78
- }
79
-
80
- // src/vite-plugin-html.ts
81
- var import_vite = require("vite");
82
- function vitePluginHtml() {
83
- let env = {};
84
- return {
85
- name: "vite-plugin-html",
86
- enforce: "pre",
87
- config(config, { mode }) {
88
- env = (0, import_vite.loadEnv)(mode, process.cwd());
89
- },
90
- transformIndexHtml(html) {
91
- Object.keys(env).forEach((key) => {
92
- const regex = new RegExp(`%${key}%`, "g");
93
- html = html.replace(regex, env[key]);
94
- });
95
- return html;
96
- }
97
- };
98
- }
99
- // Annotate the CommonJS export names for ESM import in node:
100
- 0 && (module.exports = {
101
- vitePluginHtml,
102
- vitePluginLog
103
- });
4
+ localStorage.setItem('${e}', JSON.stringify(['${g}', '${o}']))
5
+ console.log('[Log] version: ', ['${g}', '${o}']);
6
+ `}}}}var y=require("vite");function j(){let t={};return{name:"vite-plugin-html",enforce:"pre",config(e,{mode:n}){t=(0,y.loadEnv)(n,process.cwd())},transformIndexHtml(e){return Object.keys(t).forEach(n=>{let r=new RegExp(`%${n}%`,"g");e=e.replace(r,t[n])}),e}}}function H(t={}){let{width:e=150,height:n=20,fontSize:r=12,backgroundColor:o="hsla(0, 100%, 33%, 0.733)",color:g="#fff",position:i="top-right",envMap:f={}}=t,s;return{name:"vite-plugin-env-ribbon",transformIndexHtml(a){if(console.log("mode: ",s),s==="production")return a;let v=f[s]||s;if(!v)return a;let l=i==="top-left",M=l?`translate(-${n/Math.sqrt(2)}px, -${n/Math.sqrt(2)}px) translate(0, ${e/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${n/Math.sqrt(2)}px, -${n/Math.sqrt(2)}px) translate(0, ${e/Math.sqrt(2)}px) rotate(45deg)`,w=`
7
+ position: fixed;
8
+ width: ${e}px;
9
+ height: ${n}px;
10
+ background: ${o};
11
+ color: ${g};
12
+ font-size: ${r}px;
13
+ line-height: ${n}px;
14
+ transform: ${M};
15
+ transform-origin: ${l?"left top":"right top"};
16
+ top: 0;
17
+ right: ${l?"auto":"0"};
18
+ left: ${l?"0":"auto"};
19
+ z-index: 9999;
20
+ text-align: center;
21
+ pointer-events: none;
22
+ user-select: none;
23
+ overflow: hidden;
24
+ `;return{html:a,tags:[{tag:"div",attrs:{style:w.replace(/\s+/g," ").trim(),class:"vite-plugin-env-ribbon","data-env-ribbon":s},children:v,injectTo:"body"}]}},configResolved(a){s=a.mode}}}0&&(module.exports={vitePluginEnvRibbon,vitePluginHtml,vitePluginLog});
package/dist/index.d.cts CHANGED
@@ -1,19 +1,106 @@
1
- import { Plugin } from 'vite';
1
+ import { PluginOption } from 'vite';
2
+ import { Arrayable } from '@lntvow/utils';
2
3
 
3
- declare function vitePluginLog(options?: VitePluginLogOptions): Plugin;
4
- interface VitePluginLogOptions {
4
+ /**
5
+ * This Vite plugin injects version and build time information into specified entry files.
6
+ * It automatically writes the current build time and project version (read from package.json by default)
7
+ * to localStorage and prints them to the console at runtime.
8
+ *
9
+ * This is useful for tracking deployment versions and build times in frontend projects.
10
+ *
11
+ * You can customize the localStorage key, version, timezone, and the entry files to inject via plugin options.
12
+ *
13
+ * @example
14
+ * import { vitePluginLog } from '@lntvow/vite-plugin'
15
+ *
16
+ * export default defineConfig({
17
+ * plugins: [
18
+ * vitePluginLog(),
19
+ * ],
20
+ * })
21
+ */
22
+ declare function vitePluginLog(options?: LogOptions): PluginOption;
23
+ interface LogOptions {
5
24
  /**
6
- * @description localStorage key
7
- * @default LNTVOW_VERSION
25
+ * The key used for localStorage.
26
+ * @default 'LNTVOW_VERSION'
8
27
  */
9
28
  name?: string;
10
29
  /**
11
- * @description 版本号
12
- * @default 默认读取package.json的version
30
+ * Project version.
31
+ * @default Reads the version from package.json by default.
13
32
  */
14
33
  version?: string;
34
+ /**
35
+ * Timezone setting.
36
+ * @default 'Asia/Shanghai'
37
+ */
38
+ timezone?: string;
39
+ /**
40
+ * The entry files to log.
41
+ * The path is resolved from the command line working directory (process.cwd()).
42
+ * @default ['src/main.ts', 'src/main.js']
43
+ */
44
+ entries?: Arrayable<string>;
15
45
  }
16
46
 
17
- declare function vitePluginHtml(): Plugin;
47
+ declare function vitePluginHtml(): PluginOption;
48
+
49
+ /**
50
+ * This Vite plugin injects a diagonal environment ribbon into the built HTML page.
51
+ * The ribbon displays the current environment (such as development, test, uat, pre.)
52
+ * in the top-left or top-right corner of the page, similar to environment tags seen in some mobile app demos.
53
+ *
54
+ * The ribbon will NOT be injected when the current mode is 'production'.
55
+ *
56
+ * You can customize the ribbon's width, height, font size, background color, text color, position, and environment label mapping via plugin options.
57
+ *
58
+ * @example
59
+ * import { vitePluginEnvRibbon } from '@lntvow/vite-plugin'
60
+ *
61
+ * export default defineConfig({
62
+ * plugins: [
63
+ * vitePluginEnvRibbon(),
64
+ * ],
65
+ * })
66
+ */
67
+ declare function vitePluginEnvRibbon(options?: EnvRibbonOptions): PluginOption;
68
+ interface EnvRibbonOptions {
69
+ /**
70
+ * The height of the banner.
71
+ * @default 20
72
+ */
73
+ height?: number;
74
+ /**
75
+ * The width of the banner.
76
+ * @default 150
77
+ */
78
+ width?: number;
79
+ /**
80
+ * The font size of the banner text.
81
+ * @default 12
82
+ */
83
+ fontSize?: number;
84
+ /**
85
+ * The background color of the banner.
86
+ * @default 'hsla(0, 100%, 33%, 0.733)'
87
+ */
88
+ backgroundColor?: string;
89
+ /**
90
+ * The text color of the banner.
91
+ * @default '#fff'
92
+ */
93
+ color?: string;
94
+ /**
95
+ * The position of the banner on the screen.
96
+ * @default 'top-right'
97
+ */
98
+ position?: 'top-right' | 'top-left';
99
+ /**
100
+ * The mapping of environment modes to display labels.
101
+ * @default {}
102
+ */
103
+ envMap?: Record<string, string>;
104
+ }
18
105
 
19
- export { type VitePluginLogOptions, vitePluginHtml, vitePluginLog };
106
+ export { type EnvRibbonOptions, type LogOptions, vitePluginEnvRibbon, vitePluginHtml, vitePluginLog };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,106 @@
1
- import { Plugin } from 'vite';
1
+ import { PluginOption } from 'vite';
2
+ import { Arrayable } from '@lntvow/utils';
2
3
 
3
- declare function vitePluginLog(options?: VitePluginLogOptions): Plugin;
4
- interface VitePluginLogOptions {
4
+ /**
5
+ * This Vite plugin injects version and build time information into specified entry files.
6
+ * It automatically writes the current build time and project version (read from package.json by default)
7
+ * to localStorage and prints them to the console at runtime.
8
+ *
9
+ * This is useful for tracking deployment versions and build times in frontend projects.
10
+ *
11
+ * You can customize the localStorage key, version, timezone, and the entry files to inject via plugin options.
12
+ *
13
+ * @example
14
+ * import { vitePluginLog } from '@lntvow/vite-plugin'
15
+ *
16
+ * export default defineConfig({
17
+ * plugins: [
18
+ * vitePluginLog(),
19
+ * ],
20
+ * })
21
+ */
22
+ declare function vitePluginLog(options?: LogOptions): PluginOption;
23
+ interface LogOptions {
5
24
  /**
6
- * @description localStorage key
7
- * @default LNTVOW_VERSION
25
+ * The key used for localStorage.
26
+ * @default 'LNTVOW_VERSION'
8
27
  */
9
28
  name?: string;
10
29
  /**
11
- * @description 版本号
12
- * @default 默认读取package.json的version
30
+ * Project version.
31
+ * @default Reads the version from package.json by default.
13
32
  */
14
33
  version?: string;
34
+ /**
35
+ * Timezone setting.
36
+ * @default 'Asia/Shanghai'
37
+ */
38
+ timezone?: string;
39
+ /**
40
+ * The entry files to log.
41
+ * The path is resolved from the command line working directory (process.cwd()).
42
+ * @default ['src/main.ts', 'src/main.js']
43
+ */
44
+ entries?: Arrayable<string>;
15
45
  }
16
46
 
17
- declare function vitePluginHtml(): Plugin;
47
+ declare function vitePluginHtml(): PluginOption;
48
+
49
+ /**
50
+ * This Vite plugin injects a diagonal environment ribbon into the built HTML page.
51
+ * The ribbon displays the current environment (such as development, test, uat, pre.)
52
+ * in the top-left or top-right corner of the page, similar to environment tags seen in some mobile app demos.
53
+ *
54
+ * The ribbon will NOT be injected when the current mode is 'production'.
55
+ *
56
+ * You can customize the ribbon's width, height, font size, background color, text color, position, and environment label mapping via plugin options.
57
+ *
58
+ * @example
59
+ * import { vitePluginEnvRibbon } from '@lntvow/vite-plugin'
60
+ *
61
+ * export default defineConfig({
62
+ * plugins: [
63
+ * vitePluginEnvRibbon(),
64
+ * ],
65
+ * })
66
+ */
67
+ declare function vitePluginEnvRibbon(options?: EnvRibbonOptions): PluginOption;
68
+ interface EnvRibbonOptions {
69
+ /**
70
+ * The height of the banner.
71
+ * @default 20
72
+ */
73
+ height?: number;
74
+ /**
75
+ * The width of the banner.
76
+ * @default 150
77
+ */
78
+ width?: number;
79
+ /**
80
+ * The font size of the banner text.
81
+ * @default 12
82
+ */
83
+ fontSize?: number;
84
+ /**
85
+ * The background color of the banner.
86
+ * @default 'hsla(0, 100%, 33%, 0.733)'
87
+ */
88
+ backgroundColor?: string;
89
+ /**
90
+ * The text color of the banner.
91
+ * @default '#fff'
92
+ */
93
+ color?: string;
94
+ /**
95
+ * The position of the banner on the screen.
96
+ * @default 'top-right'
97
+ */
98
+ position?: 'top-right' | 'top-left';
99
+ /**
100
+ * The mapping of environment modes to display labels.
101
+ * @default {}
102
+ */
103
+ envMap?: Record<string, string>;
104
+ }
18
105
 
19
- export { type VitePluginLogOptions, vitePluginHtml, vitePluginLog };
106
+ export { type EnvRibbonOptions, type LogOptions, vitePluginEnvRibbon, vitePluginHtml, vitePluginLog };
package/dist/index.mjs ADDED
@@ -0,0 +1,24 @@
1
+ import{normalize as x,resolve as d}from"path";import{readFileSync as b}from"fs";import f from"dayjs";import $ from"dayjs/plugin/timezone.js";import O from"dayjs/plugin/utc.js";import{castArray as y}from"@lntvow/utils";f.extend(O);f.extend($);function j(n={}){let{name:e="LNTVOW_VERSION",timezone:t="Asia/Shanghai"}=n,{entries:r=["src/main.ts","src/main.js"]}=n,{version:i}=n;r=y(r).map(o=>d(process.cwd(),o));let p=f().tz(t).format("YYYY-MM-DD HH:mm:ss");if(!i)try{let o=b(d(process.cwd(),"package.json"),"utf8");i=JSON.parse(o).version}catch(o){i="unknown",console.log("error: ",o)}return{name:"vite-plugin-logs",transform(o,l){if(r.includes(x(l)))return{code:`
2
+ ${o}
3
+
4
+ localStorage.setItem('${e}', JSON.stringify(['${p}', '${i}']))
5
+ console.log('[Log] version: ', ['${p}', '${i}']);
6
+ `}}}}import{loadEnv as M}from"vite";function N(){let n={};return{name:"vite-plugin-html",enforce:"pre",config(e,{mode:t}){n=M(t,process.cwd())},transformIndexHtml(e){return Object.keys(n).forEach(t=>{let r=new RegExp(`%${t}%`,"g");e=e.replace(r,n[t])}),e}}}function J(n={}){let{width:e=150,height:t=20,fontSize:r=12,backgroundColor:i="hsla(0, 100%, 33%, 0.733)",color:p="#fff",position:o="top-right",envMap:l={}}=n,s;return{name:"vite-plugin-env-ribbon",transformIndexHtml(a){if(console.log("mode: ",s),s==="production")return a;let u=l[s]||s;if(!u)return a;let g=o==="top-left",v=g?`translate(-${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${e/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${e/Math.sqrt(2)}px) rotate(45deg)`,h=`
7
+ position: fixed;
8
+ width: ${e}px;
9
+ height: ${t}px;
10
+ background: ${i};
11
+ color: ${p};
12
+ font-size: ${r}px;
13
+ line-height: ${t}px;
14
+ transform: ${v};
15
+ transform-origin: ${g?"left top":"right top"};
16
+ top: 0;
17
+ right: ${g?"auto":"0"};
18
+ left: ${g?"0":"auto"};
19
+ z-index: 9999;
20
+ text-align: center;
21
+ pointer-events: none;
22
+ user-select: none;
23
+ overflow: hidden;
24
+ `;return{html:a,tags:[{tag:"div",attrs:{style:h.replace(/\s+/g," ").trim(),class:"vite-plugin-env-ribbon","data-env-ribbon":s},children:u,injectTo:"body"}]}},configResolved(a){s=a.mode}}}export{J as vitePluginEnvRibbon,N as vitePluginHtml,j as vitePluginLog};
package/package.json CHANGED
@@ -1,31 +1,58 @@
1
1
  {
2
2
  "name": "@lntvow/vite-plugin",
3
- "version": "1.0.8",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
- "description": "vite插件",
5
+ "description": "Collection of custom vite plugins",
6
+ "keywords": [
7
+ "vite-plugin"
8
+ ],
6
9
  "license": "MIT",
7
- "author": "lntvow",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/lntvow/vite-plugin.git"
13
+ },
8
14
  "files": [
9
15
  "dist"
10
16
  ],
11
- "main": "dist/index.cjs",
12
- "module": "dist/index.js",
13
17
  "types": "dist/index.d.ts",
18
+ "main": "dist/index.cjs",
19
+ "module": "dist/index.mjs",
20
+ "exports": {
21
+ "types": "./dist/index.d.ts",
22
+ "require": "./dist/index.cjs",
23
+ "import": "./dist/index.mjs"
24
+ },
14
25
  "dependencies": {
15
- "@lntvow/utils": "^3.1.7",
16
- "dayjs": "^1.11.11"
26
+ "@lntvow/utils": "^4.0.25",
27
+ "dayjs": "^1.11.13"
17
28
  },
18
29
  "devDependencies": {
19
- "@lntvow/dev": "^2.1.1",
20
- "tsup": "^8.1.0"
30
+ "@commitlint/cli": "^19.8.1",
31
+ "@commitlint/config-conventional": "^19.8.1",
32
+ "@lntvow/eslint-config": "^9.26.6",
33
+ "bumpp": "^10.2.0",
34
+ "commitizen": "^4.3.1",
35
+ "cz-conventional-changelog": "^3.3.0",
36
+ "eslint": "^9.29.0",
37
+ "lint-staged": "^16.1.2",
38
+ "npm-run-all": "^4.1.5",
39
+ "prettier": "^3.6.1",
40
+ "simple-git-hooks": "^2.13.0",
41
+ "tsup": "^8.5.0",
42
+ "typescript": "^5.8.3"
21
43
  },
22
44
  "peerDependencies": {
23
- "vite": ">=4.0.0"
45
+ "vite": ">=5.0.0"
24
46
  },
25
47
  "scripts": {
26
- "build": "tsup",
27
- "commit": "git add . && git-cz && git push",
48
+ "postinstall": "simple-git-hooks",
28
49
  "rimraf": "rimraf ./node_modules/",
29
- "release": "git add . && bumpp package.json --all --commit --no-tag --push"
50
+ "ncu": "ncu -u --reject @types/node && pnpm install",
51
+ "commit": "git add . && git-cz && pnpm release -y",
52
+ "release": "git add . && bumpp package.json --all --no-tag --no-print-commits",
53
+ "lint:eslint": "eslint \"src/**/*.{js,jsx,ts,tsx,vue}\" --fix",
54
+ "lint:tsc": "tsc --noEmit",
55
+ "lint": "run-p lint:eslint lint:tsc",
56
+ "build": "tsup"
30
57
  }
31
58
  }
package/dist/index.js DELETED
@@ -1,65 +0,0 @@
1
- // src/vite-plugin-logs.ts
2
- import path from "path";
3
- import fs from "fs";
4
- import dayjs from "dayjs";
5
- import utc from "dayjs/plugin/utc";
6
- import timezone from "dayjs/plugin/timezone";
7
- import { throwError } from "@lntvow/utils";
8
- dayjs.extend(utc);
9
- dayjs.extend(timezone);
10
- function vitePluginLog(options = {}) {
11
- const { name = "LNTVOW_VERSION" } = options;
12
- let { version } = options;
13
- if (!version) {
14
- try {
15
- const packageJsonContent = fs.readFileSync(path.resolve(process.cwd(), "package.json"), "utf8");
16
- version = JSON.parse(packageJsonContent).version;
17
- } catch (e) {
18
- throwError("vitePluginLogs", "package.json not found");
19
- }
20
- }
21
- return {
22
- name: "vite-plugin-logs",
23
- transform(code, id) {
24
- if (id.endsWith("src/main.ts") || id.endsWith("src/main.js")) {
25
- const time = dayjs().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");
26
- return {
27
- code: `
28
-
29
- import { log as vitePluginLogs } from '@lntvow/utils';
30
-
31
- ${code}
32
-
33
- localStorage.setItem('${name}', JSON.stringify(['${time}', '${version}']))
34
- vitePluginLogs('version', '${time}', '${version}')
35
-
36
- `
37
- };
38
- }
39
- }
40
- };
41
- }
42
-
43
- // src/vite-plugin-html.ts
44
- import { loadEnv } from "vite";
45
- function vitePluginHtml() {
46
- let env = {};
47
- return {
48
- name: "vite-plugin-html",
49
- enforce: "pre",
50
- config(config, { mode }) {
51
- env = loadEnv(mode, process.cwd());
52
- },
53
- transformIndexHtml(html) {
54
- Object.keys(env).forEach((key) => {
55
- const regex = new RegExp(`%${key}%`, "g");
56
- html = html.replace(regex, env[key]);
57
- });
58
- return html;
59
- }
60
- };
61
- }
62
- export {
63
- vitePluginHtml,
64
- vitePluginLog
65
- };