@lntvow/vite-plugin 1.1.0 → 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/dist/index.cjs CHANGED
@@ -1,24 +1,24 @@
1
- "use strict";var w=Object.create;var c=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var E=(o,n)=>{for(var t in n)c(o,t,{get:n[t],enumerable:!0})},v=(o,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of R(n))!z.call(o,e)&&e!==t&&c(o,e,{get:()=>n[e],enumerable:!(r=P(n,e))||r.enumerable});return o};var m=(o,n,t)=>(t=o!=null?w(S(o)):{},v(n||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),q=o=>v(c({},"__esModule",{value:!0}),o);var H={};E(H,{vitePluginEnvRibbon:()=>k,vitePluginHtml:()=>j,vitePluginLog:()=>L});module.exports=q(H);var s=require("path"),h=require("fs"),l=m(require("dayjs"),1),x=m(require("dayjs/plugin/timezone.js"),1),$=m(require("dayjs/plugin/utc.js"),1);l.default.extend($.default);l.default.extend(x.default);function L(o={}){let{name:n="LNTVOW_VERSION"}=o,{version:t}=o;if(!t)try{let e=(0,h.readFileSync)((0,s.resolve)(process.cwd(),"package.json"),"utf8");t=JSON.parse(e).version}catch(e){t="version is missing",console.log("error: ",e)}let r=[(0,s.resolve)(process.cwd(),"src/main.ts"),(0,s.resolve)(process.cwd(),"src/main.js")];return{name:"vite-plugin-logs",transform(e,f){if(r.includes((0,s.normalize)(f))){let p=(0,l.default)().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");return{code:`
2
- ${e}
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}
3
3
 
4
- localStorage.setItem('${n}', JSON.stringify(['${p}', '${t}']))
5
- console.log('[Log] version: ', ['${p}', '${t}']);
6
- `}}}}}var b=require("vite");function j(){let o={};return{name:"vite-plugin-html",enforce:"pre",config(n,{mode:t}){o=(0,b.loadEnv)(t,process.cwd())},transformIndexHtml(n){return Object.keys(o).forEach(t=>{let r=new RegExp(`%${t}%`,"g");n=n.replace(r,o[t])}),n}}}function k(o={}){let{width:n=150,height:t=20,fontSize:r=12,backgroundColor:e="hsla(0, 100%, 33%, 0.733)",color:f="#fff",position:p="top-right",envMap:O={}}=o,i;return{name:"vite-plugin-env-ribbon",transformIndexHtml(a){if(console.log("mode: ",i),i==="production")return a;let d=O[i]||i;if(!d)return a;let g=p==="top-left",y=g?`translate(-${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${n/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${n/Math.sqrt(2)}px) rotate(45deg)`,M=`
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
7
  position: fixed;
8
- width: ${n}px;
9
- height: ${t}px;
10
- background: ${e};
11
- color: ${f};
8
+ width: ${e}px;
9
+ height: ${n}px;
10
+ background: ${o};
11
+ color: ${g};
12
12
  font-size: ${r}px;
13
- line-height: ${t}px;
14
- transform: ${y};
15
- transform-origin: ${g?"left top":"right top"};
13
+ line-height: ${n}px;
14
+ transform: ${M};
15
+ transform-origin: ${l?"left top":"right top"};
16
16
  top: 0;
17
- right: ${g?"auto":"0"};
18
- left: ${g?"0":"auto"};
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":i},children:d,injectTo:"body"}]}},configResolved(a){i=a.mode}}}0&&(module.exports={vitePluginEnvRibbon,vitePluginHtml,vitePluginLog});
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,31 +1,59 @@
1
1
  import { PluginOption } from 'vite';
2
+ import { Arrayable } from '@lntvow/utils';
2
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
+ */
3
22
  declare function vitePluginLog(options?: LogOptions): PluginOption;
4
23
  interface LogOptions {
5
24
  /**
6
- * localStorage key
25
+ * The key used for localStorage.
7
26
  * @default 'LNTVOW_VERSION'
8
27
  */
9
28
  name?: string;
10
29
  /**
11
- * 版本号
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
47
  declare function vitePluginHtml(): PluginOption;
18
48
 
19
49
  /**
20
50
  * 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.
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.
24
53
  *
25
54
  * The ribbon will NOT be injected when the current mode is 'production'.
26
55
  *
27
- * You can customize the ribbon's width, height, font size, background color, text color,
28
- * position, and environment label mapping via plugin options.
56
+ * You can customize the ribbon's width, height, font size, background color, text color, position, and environment label mapping via plugin options.
29
57
  *
30
58
  * @example
31
59
  * import { vitePluginEnvRibbon } from '@lntvow/vite-plugin'
package/dist/index.d.ts CHANGED
@@ -1,31 +1,59 @@
1
1
  import { PluginOption } from 'vite';
2
+ import { Arrayable } from '@lntvow/utils';
2
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
+ */
3
22
  declare function vitePluginLog(options?: LogOptions): PluginOption;
4
23
  interface LogOptions {
5
24
  /**
6
- * localStorage key
25
+ * The key used for localStorage.
7
26
  * @default 'LNTVOW_VERSION'
8
27
  */
9
28
  name?: string;
10
29
  /**
11
- * 版本号
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
47
  declare function vitePluginHtml(): PluginOption;
18
48
 
19
49
  /**
20
50
  * 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.
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.
24
53
  *
25
54
  * The ribbon will NOT be injected when the current mode is 'production'.
26
55
  *
27
- * You can customize the ribbon's width, height, font size, background color, text color,
28
- * position, and environment label mapping via plugin options.
56
+ * You can customize the ribbon's width, height, font size, background color, text color, position, and environment label mapping via plugin options.
29
57
  *
30
58
  * @example
31
59
  * import { vitePluginEnvRibbon } from '@lntvow/vite-plugin'
package/dist/index.mjs CHANGED
@@ -1,24 +1,24 @@
1
- import{normalize as x,resolve as c}from"path";import{readFileSync as $}from"fs";import m from"dayjs";import b from"dayjs/plugin/timezone.js";import O from"dayjs/plugin/utc.js";m.extend(O);m.extend(b);function L(n={}){let{name:o="LNTVOW_VERSION"}=n,{version:t}=n;if(!t)try{let e=$(c(process.cwd(),"package.json"),"utf8");t=JSON.parse(e).version}catch(e){t="version is missing",console.log("error: ",e)}let i=[c(process.cwd(),"src/main.ts"),c(process.cwd(),"src/main.js")];return{name:"vite-plugin-logs",transform(e,g){if(i.includes(x(g))){let a=m().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");return{code:`
2
- ${e}
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
3
 
4
- localStorage.setItem('${o}', JSON.stringify(['${a}', '${t}']))
5
- console.log('[Log] version: ', ['${a}', '${t}']);
6
- `}}}}}import{loadEnv as y}from"vite";function I(){let n={};return{name:"vite-plugin-html",enforce:"pre",config(o,{mode:t}){n=y(t,process.cwd())},transformIndexHtml(o){return Object.keys(n).forEach(t=>{let i=new RegExp(`%${t}%`,"g");o=o.replace(i,n[t])}),o}}}function C(n={}){let{width:o=150,height:t=20,fontSize:i=12,backgroundColor:e="hsla(0, 100%, 33%, 0.733)",color:g="#fff",position:a="top-right",envMap:d={}}=n,r;return{name:"vite-plugin-env-ribbon",transformIndexHtml(s){if(console.log("mode: ",r),r==="production")return s;let u=d[r]||r;if(!u)return s;let p=a==="top-left",v=p?`translate(-${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${o/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${o/Math.sqrt(2)}px) rotate(45deg)`,h=`
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
7
  position: fixed;
8
- width: ${o}px;
8
+ width: ${e}px;
9
9
  height: ${t}px;
10
- background: ${e};
11
- color: ${g};
12
- font-size: ${i}px;
10
+ background: ${i};
11
+ color: ${p};
12
+ font-size: ${r}px;
13
13
  line-height: ${t}px;
14
14
  transform: ${v};
15
- transform-origin: ${p?"left top":"right top"};
15
+ transform-origin: ${g?"left top":"right top"};
16
16
  top: 0;
17
- right: ${p?"auto":"0"};
18
- left: ${p?"0":"auto"};
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:s,tags:[{tag:"div",attrs:{style:h.replace(/\s+/g," ").trim(),class:"vite-plugin-env-ribbon","data-env-ribbon":r},children:u,injectTo:"body"}]}},configResolved(s){r=s.mode}}}export{C as vitePluginEnvRibbon,I as vitePluginHtml,L as vitePluginLog};
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@lntvow/vite-plugin",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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": {