@lntvow/vite-plugin 1.1.0 → 1.1.3
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 +14 -14
- package/dist/index.d.ts +41 -15
- package/dist/index.mjs +16 -16
- package/package.json +2 -1
- package/dist/index.d.cts +0 -78
package/dist/index.cjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";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,o)=>{for(var r in o)c(t,r,{get:o[r],enumerable:!0})},v=(t,o,r,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of w(o))!q.call(t,e)&&e!==r&&c(t,e,{get:()=>o[e],enumerable:!(i=S(o,e))||i.enumerable});return t};var d=(t,o,r)=>(r=t!=null?z(k(t)):{},v(o||!t||!t.__esModule?c(r,"default",{value:t,enumerable:!0}):r,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=d(require("dayjs"),1),b=d(require("dayjs/plugin/timezone.js"),1),$=d(require("dayjs/plugin/utc.js"),1),O=require("@lntvow/utils");m.default.extend($.default);m.default.extend(b.default);function R(t={}){let{name:o="LNTVOW_VERSION",timezone:r="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(r).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: ', ['${
|
|
6
|
-
`}}}}
|
|
4
|
+
localStorage.setItem('${o}', JSON.stringify(['${g}', '${e}']))
|
|
5
|
+
console.log('[Log] version: ', ['${g}', '${e}']);
|
|
6
|
+
`}}}}function V(t={}){let{width:o=150,height:r=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(console.log("mode: ",s),s==="production")return a;let h=f[s]||s;if(!h)return a;let l=n==="top-left",y=l?`translate(-${r/Math.sqrt(2)}px, -${r/Math.sqrt(2)}px) translate(0, ${o/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${r/Math.sqrt(2)}px, -${r/Math.sqrt(2)}px) translate(0, ${o/Math.sqrt(2)}px) rotate(45deg)`,M=`
|
|
7
7
|
position: fixed;
|
|
8
|
-
width: ${
|
|
9
|
-
height: ${
|
|
8
|
+
width: ${o}px;
|
|
9
|
+
height: ${r}px;
|
|
10
10
|
background: ${e};
|
|
11
|
-
color: ${
|
|
12
|
-
font-size: ${
|
|
13
|
-
line-height: ${
|
|
11
|
+
color: ${g};
|
|
12
|
+
font-size: ${i}px;
|
|
13
|
+
line-height: ${r}px;
|
|
14
14
|
transform: ${y};
|
|
15
|
-
transform-origin: ${
|
|
15
|
+
transform-origin: ${l?"left top":"right top"};
|
|
16
16
|
top: 0;
|
|
17
|
-
right: ${
|
|
18
|
-
left: ${
|
|
17
|
+
right: ${l?"auto":"0"};
|
|
18
|
+
left: ${l?"0":"auto"};
|
|
19
19
|
z-index: 9999;
|
|
20
20
|
text-align: center;
|
|
21
21
|
pointer-events: none;
|
|
22
22
|
user-select: none;
|
|
23
23
|
overflow: hidden;
|
|
24
|
-
`;return{html:a,tags:[{tag:"div",attrs:{style:M.replace(/\s+/g," ").trim(),class:"vite-plugin-env-ribbon","data-env-ribbon":
|
|
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
|
@@ -1,40 +1,66 @@
|
|
|
1
1
|
import { PluginOption } from 'vite';
|
|
2
|
+
import { Arrayable } from '@lntvow/utils';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
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 { vitePluginVersionLog } from '@lntvow/vite-plugin'
|
|
15
|
+
*
|
|
16
|
+
* export default {
|
|
17
|
+
* plugins: [
|
|
18
|
+
* vitePluginVersionLog(),
|
|
19
|
+
* ],
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
declare function vitePluginVersionLog(options?: VersionLogOptions): PluginOption;
|
|
23
|
+
interface VersionLogOptions {
|
|
5
24
|
/**
|
|
6
|
-
*
|
|
25
|
+
* The key used for localStorage.
|
|
7
26
|
* @default 'LNTVOW_VERSION'
|
|
8
27
|
*/
|
|
9
28
|
name?: string;
|
|
10
29
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @default
|
|
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(): PluginOption;
|
|
18
|
-
|
|
19
47
|
/**
|
|
20
48
|
* This Vite plugin injects a diagonal environment ribbon into the built HTML page.
|
|
21
|
-
* The ribbon displays the current environment (such as development, uat, pre
|
|
22
|
-
* in the top-left or top-right corner of the page, similar to environment tags
|
|
23
|
-
* seen in some mobile app demos.
|
|
49
|
+
* The ribbon displays the current environment (such as development, test, uat, pre.)
|
|
50
|
+
* in the top-left or top-right corner of the page, similar to environment tags seen in some mobile app demos.
|
|
24
51
|
*
|
|
25
52
|
* The ribbon will NOT be injected when the current mode is 'production'.
|
|
26
53
|
*
|
|
27
|
-
* You can customize the ribbon's width, height, font size, background color, text color,
|
|
28
|
-
* position, and environment label mapping via plugin options.
|
|
54
|
+
* You can customize the ribbon's width, height, font size, background color, text color, position, and environment label mapping via plugin options.
|
|
29
55
|
*
|
|
30
56
|
* @example
|
|
31
57
|
* import { vitePluginEnvRibbon } from '@lntvow/vite-plugin'
|
|
32
58
|
*
|
|
33
|
-
* export default
|
|
59
|
+
* export default {
|
|
34
60
|
* plugins: [
|
|
35
61
|
* vitePluginEnvRibbon(),
|
|
36
62
|
* ],
|
|
37
|
-
* }
|
|
63
|
+
* }
|
|
38
64
|
*/
|
|
39
65
|
declare function vitePluginEnvRibbon(options?: EnvRibbonOptions): PluginOption;
|
|
40
66
|
interface EnvRibbonOptions {
|
|
@@ -75,4 +101,4 @@ interface EnvRibbonOptions {
|
|
|
75
101
|
envMap?: Record<string, string>;
|
|
76
102
|
}
|
|
77
103
|
|
|
78
|
-
export { type EnvRibbonOptions, type
|
|
104
|
+
export { type EnvRibbonOptions, type VersionLogOptions, vitePluginEnvRibbon, vitePluginVersionLog };
|
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import{normalize as x,resolve as
|
|
2
|
-
${
|
|
1
|
+
import{normalize as x,resolve as u}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(n={}){let{name:i="LNTVOW_VERSION",timezone:o="Asia/Shanghai"}=n,{entries:s=["src/main.ts","src/main.js"]}=n,{version:r}=n;s=y(s).map(t=>u(process.cwd(),t));let p=f().tz(o).format("YYYY-MM-DD HH:mm:ss");if(!r)try{let t=b(u(process.cwd(),"package.json"),"utf8");r=JSON.parse(t).version}catch(t){r="unknown",console.log("error: ",t)}return{name:"vite-plugin-version-log",transform(t,l){if(s.includes(x(l)))return{code:`
|
|
2
|
+
${t}
|
|
3
3
|
|
|
4
|
-
localStorage.setItem('${
|
|
5
|
-
console.log('[Log] version: ', ['${
|
|
6
|
-
`}}}}
|
|
4
|
+
localStorage.setItem('${i}', JSON.stringify(['${p}', '${r}']))
|
|
5
|
+
console.log('[Log] version: ', ['${p}', '${r}']);
|
|
6
|
+
`}}}}function N(n={}){let{width:i=150,height:o=20,fontSize:s=12,backgroundColor:r="hsla(0, 100%, 33%, 0.733)",color:p="#fff",position:t="top-right",envMap:l={}}=n,e;return{name:"vite-plugin-env-ribbon",transformIndexHtml(a){if(console.log("mode: ",e),e==="production")return a;let d=l[e]||e;if(!d)return a;let g=t==="top-left",h=g?`translate(-${o/Math.sqrt(2)}px, -${o/Math.sqrt(2)}px) translate(0, ${i/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${o/Math.sqrt(2)}px, -${o/Math.sqrt(2)}px) translate(0, ${i/Math.sqrt(2)}px) rotate(45deg)`,v=`
|
|
7
7
|
position: fixed;
|
|
8
|
-
width: ${
|
|
9
|
-
height: ${
|
|
10
|
-
background: ${
|
|
11
|
-
color: ${
|
|
12
|
-
font-size: ${
|
|
13
|
-
line-height: ${
|
|
14
|
-
transform: ${
|
|
15
|
-
transform-origin: ${
|
|
8
|
+
width: ${i}px;
|
|
9
|
+
height: ${o}px;
|
|
10
|
+
background: ${r};
|
|
11
|
+
color: ${p};
|
|
12
|
+
font-size: ${s}px;
|
|
13
|
+
line-height: ${o}px;
|
|
14
|
+
transform: ${h};
|
|
15
|
+
transform-origin: ${g?"left top":"right top"};
|
|
16
16
|
top: 0;
|
|
17
|
-
right: ${
|
|
18
|
-
left: ${
|
|
17
|
+
right: ${g?"auto":"0"};
|
|
18
|
+
left: ${g?"0":"auto"};
|
|
19
19
|
z-index: 9999;
|
|
20
20
|
text-align: center;
|
|
21
21
|
pointer-events: none;
|
|
22
22
|
user-select: none;
|
|
23
23
|
overflow: hidden;
|
|
24
|
-
`;return{html:
|
|
24
|
+
`;return{html:a,tags:[{tag:"div",attrs:{style:v.replace(/\s+/g," ").trim(),class:"vite-plugin-env-ribbon","data-env-ribbon":e},children:d,injectTo:"body"}]}},configResolved(a){e=a.mode}}}export{N as vitePluginEnvRibbon,V as vitePluginVersionLog};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/vite-plugin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Collection of custom vite plugins",
|
|
6
6
|
"keywords": [
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"import": "./dist/index.mjs"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@lntvow/utils": "^4.0.25",
|
|
26
27
|
"dayjs": "^1.11.13"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
package/dist/index.d.cts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { PluginOption } from 'vite';
|
|
2
|
-
|
|
3
|
-
declare function vitePluginLog(options?: LogOptions): PluginOption;
|
|
4
|
-
interface LogOptions {
|
|
5
|
-
/**
|
|
6
|
-
* localStorage key
|
|
7
|
-
* @default 'LNTVOW_VERSION'
|
|
8
|
-
*/
|
|
9
|
-
name?: string;
|
|
10
|
-
/**
|
|
11
|
-
* 版本号
|
|
12
|
-
* @default 默认读取package.json的version
|
|
13
|
-
*/
|
|
14
|
-
version?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
declare function vitePluginHtml(): PluginOption;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* This Vite plugin injects a diagonal environment ribbon into the built HTML page.
|
|
21
|
-
* The ribbon displays the current environment (such as development, uat, pre, etc.)
|
|
22
|
-
* in the top-left or top-right corner of the page, similar to environment tags
|
|
23
|
-
* seen in some mobile app demos.
|
|
24
|
-
*
|
|
25
|
-
* The ribbon will NOT be injected when the current mode is 'production'.
|
|
26
|
-
*
|
|
27
|
-
* You can customize the ribbon's width, height, font size, background color, text color,
|
|
28
|
-
* position, and environment label mapping via plugin options.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* import { vitePluginEnvRibbon } from '@lntvow/vite-plugin'
|
|
32
|
-
*
|
|
33
|
-
* export default defineConfig({
|
|
34
|
-
* plugins: [
|
|
35
|
-
* vitePluginEnvRibbon(),
|
|
36
|
-
* ],
|
|
37
|
-
* })
|
|
38
|
-
*/
|
|
39
|
-
declare function vitePluginEnvRibbon(options?: EnvRibbonOptions): PluginOption;
|
|
40
|
-
interface EnvRibbonOptions {
|
|
41
|
-
/**
|
|
42
|
-
* The height of the banner.
|
|
43
|
-
* @default 20
|
|
44
|
-
*/
|
|
45
|
-
height?: number;
|
|
46
|
-
/**
|
|
47
|
-
* The width of the banner.
|
|
48
|
-
* @default 150
|
|
49
|
-
*/
|
|
50
|
-
width?: number;
|
|
51
|
-
/**
|
|
52
|
-
* The font size of the banner text.
|
|
53
|
-
* @default 12
|
|
54
|
-
*/
|
|
55
|
-
fontSize?: number;
|
|
56
|
-
/**
|
|
57
|
-
* The background color of the banner.
|
|
58
|
-
* @default 'hsla(0, 100%, 33%, 0.733)'
|
|
59
|
-
*/
|
|
60
|
-
backgroundColor?: string;
|
|
61
|
-
/**
|
|
62
|
-
* The text color of the banner.
|
|
63
|
-
* @default '#fff'
|
|
64
|
-
*/
|
|
65
|
-
color?: string;
|
|
66
|
-
/**
|
|
67
|
-
* The position of the banner on the screen.
|
|
68
|
-
* @default 'top-right'
|
|
69
|
-
*/
|
|
70
|
-
position?: 'top-right' | 'top-left';
|
|
71
|
-
/**
|
|
72
|
-
* The mapping of environment modes to display labels.
|
|
73
|
-
* @default {}
|
|
74
|
-
*/
|
|
75
|
-
envMap?: Record<string, string>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export { type EnvRibbonOptions, type LogOptions, vitePluginEnvRibbon, vitePluginHtml, vitePluginLog };
|