@lntvow/vite-plugin 1.1.1 → 1.1.4
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.cjs +12 -12
- package/dist/index.d.ts +9 -11
- package/dist/index.mjs +12 -12
- package/package.json +1 -1
- package/dist/index.d.cts +0 -106
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";var z=Object.create;var c=Object.defineProperty;var
|
|
2
|
-
${
|
|
1
|
+
"use strict";var z=Object.create;var c=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var L=(t,r)=>{for(var o in r)c(t,o,{get:r[o],enumerable:!0})},v=(t,r,o,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of w(r))!q.call(t,e)&&e!==o&&c(t,e,{get:()=>r[e],enumerable:!(i=S(r,e))||i.enumerable});return t};var u=(t,r,o)=>(o=t!=null?z(k(t)):{},v(r||!t||!t.__esModule?c(o,"default",{value:t,enumerable:!0}):o,t)),P=t=>v(c({},"__esModule",{value:!0}),t);var j={};L(j,{vitePluginEnvRibbon:()=>V,vitePluginVersionLog:()=>R});module.exports=P(j);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 R(t={}){let{name:r="LNTVOW_VERSION",timezone:o="Asia/Shanghai"}=t,{entries:i=["src/main.ts","src/main.js"]}=t,{version:e}=t;i=(0,O.castArray)(i).map(n=>(0,p.resolve)(process.cwd(),n));let g=(0,m.default)().tz(o).format("YYYY-MM-DD HH:mm:ss");if(!e)try{let n=(0,x.readFileSync)((0,p.resolve)(process.cwd(),"package.json"),"utf8");e=JSON.parse(n).version}catch(n){e="unknown",console.log("error: ",n)}return{name:"vite-plugin-version-log",transform(n,f){if(i.includes((0,p.normalize)(f)))return{code:`
|
|
2
|
+
${n}
|
|
3
3
|
|
|
4
|
-
localStorage.setItem('${
|
|
5
|
-
console.log('[Log] version: ', ['${g}', '${
|
|
6
|
-
`}}}}
|
|
4
|
+
localStorage.setItem('${r}', JSON.stringify(['${g}', '${e}']))
|
|
5
|
+
console.log('[Log] version: ', ['${g}', '${e}']);
|
|
6
|
+
`}}}}function V(t={}){let{width:r=150,height:o=20,fontSize:i=12,backgroundColor:e="hsla(0, 100%, 33%, 0.733)",color:g="#fff",position:n="top-right",envMap:f={}}=t,s;return{name:"vite-plugin-env-ribbon",transformIndexHtml(a){if(s==="production")return a;let h=f[s]||s;if(!h)return a;let l=n==="top-left",y=l?`translate(-${o/Math.sqrt(2)}px, -${o/Math.sqrt(2)}px) translate(0, ${r/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${o/Math.sqrt(2)}px, -${o/Math.sqrt(2)}px) translate(0, ${r/Math.sqrt(2)}px) rotate(45deg)`,M=`
|
|
7
7
|
position: fixed;
|
|
8
|
-
width: ${
|
|
9
|
-
height: ${
|
|
10
|
-
background: ${
|
|
8
|
+
width: ${r}px;
|
|
9
|
+
height: ${o}px;
|
|
10
|
+
background: ${e};
|
|
11
11
|
color: ${g};
|
|
12
|
-
font-size: ${
|
|
13
|
-
line-height: ${
|
|
14
|
-
transform: ${
|
|
12
|
+
font-size: ${i}px;
|
|
13
|
+
line-height: ${o}px;
|
|
14
|
+
transform: ${y};
|
|
15
15
|
transform-origin: ${l?"left top":"right top"};
|
|
16
16
|
top: 0;
|
|
17
17
|
right: ${l?"auto":"0"};
|
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
pointer-events: none;
|
|
22
22
|
user-select: none;
|
|
23
23
|
overflow: hidden;
|
|
24
|
-
`;return{html:a,tags:[{tag:"div",attrs:{style:
|
|
24
|
+
`;return{html:a,tags:[{tag:"div",attrs:{style:M.replace(/\s+/g," ").trim(),class:"vite-plugin-env-ribbon","data-env-ribbon":s},children:h,injectTo:"body"}]}},configResolved(a){s=a.mode}}}0&&(module.exports={vitePluginEnvRibbon,vitePluginVersionLog});
|
package/dist/index.d.ts
CHANGED
|
@@ -11,16 +11,16 @@ import { Arrayable } from '@lntvow/utils';
|
|
|
11
11
|
* You can customize the localStorage key, version, timezone, and the entry files to inject via plugin options.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
* import {
|
|
14
|
+
* import { vitePluginVersionLog } from '@lntvow/vite-plugin'
|
|
15
15
|
*
|
|
16
|
-
* export default
|
|
16
|
+
* export default {
|
|
17
17
|
* plugins: [
|
|
18
|
-
*
|
|
18
|
+
* vitePluginVersionLog(),
|
|
19
19
|
* ],
|
|
20
|
-
* }
|
|
20
|
+
* }
|
|
21
21
|
*/
|
|
22
|
-
declare function
|
|
23
|
-
interface
|
|
22
|
+
declare function vitePluginVersionLog(options?: VersionLogOptions): PluginOption;
|
|
23
|
+
interface VersionLogOptions {
|
|
24
24
|
/**
|
|
25
25
|
* The key used for localStorage.
|
|
26
26
|
* @default 'LNTVOW_VERSION'
|
|
@@ -44,8 +44,6 @@ interface LogOptions {
|
|
|
44
44
|
entries?: Arrayable<string>;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
declare function vitePluginHtml(): PluginOption;
|
|
48
|
-
|
|
49
47
|
/**
|
|
50
48
|
* This Vite plugin injects a diagonal environment ribbon into the built HTML page.
|
|
51
49
|
* The ribbon displays the current environment (such as development, test, uat, pre.)
|
|
@@ -58,11 +56,11 @@ declare function vitePluginHtml(): PluginOption;
|
|
|
58
56
|
* @example
|
|
59
57
|
* import { vitePluginEnvRibbon } from '@lntvow/vite-plugin'
|
|
60
58
|
*
|
|
61
|
-
* export default
|
|
59
|
+
* export default {
|
|
62
60
|
* plugins: [
|
|
63
61
|
* vitePluginEnvRibbon(),
|
|
64
62
|
* ],
|
|
65
|
-
* }
|
|
63
|
+
* }
|
|
66
64
|
*/
|
|
67
65
|
declare function vitePluginEnvRibbon(options?: EnvRibbonOptions): PluginOption;
|
|
68
66
|
interface EnvRibbonOptions {
|
|
@@ -103,4 +101,4 @@ interface EnvRibbonOptions {
|
|
|
103
101
|
envMap?: Record<string, string>;
|
|
104
102
|
}
|
|
105
103
|
|
|
106
|
-
export { type EnvRibbonOptions, type
|
|
104
|
+
export { type EnvRibbonOptions, type VersionLogOptions, vitePluginEnvRibbon, vitePluginVersionLog };
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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
|
|
2
|
-
${
|
|
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 V(e={}){let{name:n="LNTVOW_VERSION",timezone:r="Asia/Shanghai"}=e,{entries:i=["src/main.ts","src/main.js"]}=e,{version:o}=e;i=y(i).map(t=>d(process.cwd(),t));let p=f().tz(r).format("YYYY-MM-DD HH:mm:ss");if(!o)try{let t=b(d(process.cwd(),"package.json"),"utf8");o=JSON.parse(t).version}catch(t){o="unknown",console.log("error: ",t)}return{name:"vite-plugin-version-log",transform(t,l){if(i.includes(x(l)))return{code:`
|
|
2
|
+
${t}
|
|
3
3
|
|
|
4
|
-
localStorage.setItem('${
|
|
5
|
-
console.log('[Log] version: ', ['${p}', '${
|
|
6
|
-
`}}}}
|
|
4
|
+
localStorage.setItem('${n}', JSON.stringify(['${p}', '${o}']))
|
|
5
|
+
console.log('[Log] version: ', ['${p}', '${o}']);
|
|
6
|
+
`}}}}function N(e={}){let{width:n=150,height:r=20,fontSize:i=12,backgroundColor:o="hsla(0, 100%, 33%, 0.733)",color:p="#fff",position:t="top-right",envMap:l={}}=e,s;return{name:"vite-plugin-env-ribbon",transformIndexHtml(a){if(s==="production")return a;let u=l[s]||s;if(!u)return a;let g=t==="top-left",h=g?`translate(-${r/Math.sqrt(2)}px, -${r/Math.sqrt(2)}px) translate(0, ${n/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${r/Math.sqrt(2)}px, -${r/Math.sqrt(2)}px) translate(0, ${n/Math.sqrt(2)}px) rotate(45deg)`,v=`
|
|
7
7
|
position: fixed;
|
|
8
|
-
width: ${
|
|
9
|
-
height: ${
|
|
10
|
-
background: ${
|
|
8
|
+
width: ${n}px;
|
|
9
|
+
height: ${r}px;
|
|
10
|
+
background: ${o};
|
|
11
11
|
color: ${p};
|
|
12
|
-
font-size: ${
|
|
13
|
-
line-height: ${
|
|
14
|
-
transform: ${
|
|
12
|
+
font-size: ${i}px;
|
|
13
|
+
line-height: ${r}px;
|
|
14
|
+
transform: ${h};
|
|
15
15
|
transform-origin: ${g?"left top":"right top"};
|
|
16
16
|
top: 0;
|
|
17
17
|
right: ${g?"auto":"0"};
|
|
@@ -21,4 +21,4 @@ import{normalize as x,resolve as d}from"path";import{readFileSync as b}from"fs";
|
|
|
21
21
|
pointer-events: none;
|
|
22
22
|
user-select: none;
|
|
23
23
|
overflow: hidden;
|
|
24
|
-
`;return{html:a,tags:[{tag:"div",attrs:{style:
|
|
24
|
+
`;return{html:a,tags:[{tag:"div",attrs:{style:v.replace(/\s+/g," ").trim(),class:"vite-plugin-env-ribbon","data-env-ribbon":s},children:u,injectTo:"body"}]}},configResolved(a){s=a.mode}}}export{N as vitePluginEnvRibbon,V as vitePluginVersionLog};
|
package/package.json
CHANGED
package/dist/index.d.cts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { PluginOption } from 'vite';
|
|
2
|
-
import { Arrayable } from '@lntvow/utils';
|
|
3
|
-
|
|
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 {
|
|
24
|
-
/**
|
|
25
|
-
* The key used for localStorage.
|
|
26
|
-
* @default 'LNTVOW_VERSION'
|
|
27
|
-
*/
|
|
28
|
-
name?: string;
|
|
29
|
-
/**
|
|
30
|
-
* Project version.
|
|
31
|
-
* @default Reads the version from package.json by default.
|
|
32
|
-
*/
|
|
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>;
|
|
45
|
-
}
|
|
46
|
-
|
|
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
|
-
}
|
|
105
|
-
|
|
106
|
-
export { type EnvRibbonOptions, type LogOptions, vitePluginEnvRibbon, vitePluginHtml, vitePluginLog };
|