@lntvow/vite-plugin 1.1.13 → 1.2.0

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,15 +1,15 @@
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 a=require("path"),x=require("fs"),m=u(require("dayjs"),1),$=u(require("dayjs/plugin/timezone.js"),1),b=u(require("dayjs/plugin/utc.js"),1),O=require("@lntvow/utils");m.default.extend(b.default);m.default.extend($.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,a.resolve)(process.cwd(),n));let p=(0,m.default)().tz(o).format("YYYY-MM-DD HH:mm:ss");if(!e)try{let n=(0,x.readFileSync)((0,a.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,a.normalize)(f)))return{code:`
2
- ${n}
1
+ "use strict";var M=Object.create;var f=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var k=(t,n)=>{for(var o in n)f(t,o,{get:n[o],enumerable:!0})},v=(t,n,o,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of S(n))!E.call(t,r)&&r!==o&&f(t,r,{get:()=>n[r],enumerable:!(s=z(n,r))||s.enumerable});return t};var u=(t,n,o)=>(o=t!=null?M(w(t)):{},v(n||!t||!t.__esModule?f(o,"default",{value:t,enumerable:!0}):o,t)),q=t=>v(f({},"__esModule",{value:!0}),t);var R={};k(R,{vitePluginEnvRibbon:()=>P,vitePluginVersionLog:()=>L});module.exports=q(R);var a=require("path"),m=require("fs"),d=u(require("dayjs"),1),$=u(require("dayjs/plugin/timezone.js"),1),b=u(require("dayjs/plugin/utc.js"),1);d.default.extend(b.default);d.default.extend($.default);function L(t={}){let{name:n="LNTVOW_VERSION",timezone:o="Asia/Shanghai",entry:s}=t,{version:r}=t,g=["src/main.ts","src/main.js"].map(e=>(0,a.resolve)(process.cwd(),e)),p;s?p=(0,a.resolve)(process.cwd(),s):p=g.find(i=>(0,m.existsSync)(i))??g[0];let c=(0,d.default)().tz(o).format("YYYY-MM-DD HH:mm:ss");if(!r)try{let e=(0,m.readFileSync)((0,a.resolve)(process.cwd(),"package.json"),"utf8");r=JSON.parse(e).version}catch(e){r="unknown",console.log("error: ",e)}return{name:"vite-plugin-version-log",transform(e,i){if((0,a.normalize)(i)===(0,a.normalize)(p))return{code:`
2
+ ${e}
3
3
 
4
- localStorage.setItem('${r}', JSON.stringify(['${p}', '${e}']))
5
- console.log('[Log] version:', ['${p}', '${e}']);
6
- `}}}}function V(t={}){let{width:r=150,height:o=20,fontSize:i=12,backgroundColor:e="hsla(0, 100%, 33%, 0.733)",color:p="#fff",position:n="top-right",envMap:f={}}=t,g;return{name:"vite-plugin-env-ribbon",transformIndexHtml(s){if(g==="production")return s;let h=f[g]||g;if(!h)return s;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=`
4
+ localStorage.setItem('${n}', JSON.stringify(['${c}', '${r}']))
5
+ console.log('[Log] version:', ['${c}', '${r}']);
6
+ `}}}}function P(t={}){let{width:n=150,height:o=20,fontSize:s=12,backgroundColor:r="hsla(0, 100%, 33%, 0.733)",color:g="#fff",position:p="top-right",envMap:c={}}=t,e;return{name:"vite-plugin-env-ribbon",transformIndexHtml(i){if(e==="production")return i;let x=c[e]||e;if(!x)return i;let l=p==="top-left",y=l?`translate(-${o/Math.sqrt(2)}px, -${o/Math.sqrt(2)}px) translate(0, ${n/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${o/Math.sqrt(2)}px, -${o/Math.sqrt(2)}px) translate(0, ${n/Math.sqrt(2)}px) rotate(45deg)`,O=`
7
7
  position: fixed;
8
- width: ${r}px;
8
+ width: ${n}px;
9
9
  height: ${o}px;
10
- background: ${e};
11
- color: ${p};
12
- font-size: ${i}px;
10
+ background: ${r};
11
+ color: ${g};
12
+ font-size: ${s}px;
13
13
  line-height: ${o}px;
14
14
  transform: ${y};
15
15
  transform-origin: ${l?"left top":"right top"};
@@ -21,4 +21,4 @@
21
21
  pointer-events: none;
22
22
  user-select: none;
23
23
  overflow: hidden;
24
- `;return{html:s,tags:[{tag:"div",attrs:{style:M.replace(/\s+/g," ").trim(),id:"vite-plugin-env-ribbon"},children:h,injectTo:"body"}]}},configResolved(s){g=s.mode}}}0&&(module.exports={vitePluginEnvRibbon,vitePluginVersionLog});
24
+ `;return{html:i,tags:[{tag:"div",attrs:{style:O.replace(/\s+/g," ").trim(),id:"vite-plugin-env-ribbon"},children:x,injectTo:"body"}]}},configResolved(i){e=i.mode}}}0&&(module.exports={vitePluginEnvRibbon,vitePluginVersionLog});
package/dist/index.d.ts CHANGED
@@ -1,16 +1,14 @@
1
1
  import { PluginOption } from 'vite';
2
- import { Arrayable } from '@lntvow/utils';
3
2
 
4
3
  /**
5
- * This Vite plugin injects version and build time information into specified entry files.
4
+ * This Vite plugin injects version and build time information into a specified entry file.
6
5
  * It automatically writes the current build time and project version (read from package.json by default)
7
6
  * to localStorage and prints them to the console at runtime.
8
7
  *
9
8
  * This is useful for tracking deployment versions and build times in frontend projects,
10
9
  * making it easier to identify which version is currently deployed and when it was built.
11
10
  *
12
- *
13
- * You can customize the localStorage key, version, timezone, and the entry files to inject via plugin options.
11
+ * You can customize the localStorage key, version, timezone, and the entry file to inject via plugin options.
14
12
  *
15
13
  * @example
16
14
  * import { vitePluginVersionLog } from '@lntvow/vite-plugin'
@@ -25,7 +23,7 @@ import { Arrayable } from '@lntvow/utils';
25
23
  * - Automatically reads version from package.json if not provided
26
24
  * - Supports custom timezone for build time formatting
27
25
  * - Configurable localStorage key name
28
- * - Supports multiple entry files
26
+ * - Auto-detects entry file from 'src/main.ts' or 'src/main.js' if not specified
29
27
  */
30
28
  declare function vitePluginVersionLog(options?: VersionLogOptions): PluginOption;
31
29
  interface VersionLogOptions {
@@ -49,12 +47,13 @@ interface VersionLogOptions {
49
47
  */
50
48
  timezone?: string;
51
49
  /**
52
- * The entry files where version information will be injected.
53
- * Can be a single file path string or an array of file paths.
54
- * Paths are resolved from the command line working directory (process.cwd()).
55
- * @default ['src/main.ts', 'src/main.js']
50
+ * The entry file where version information will be injected.
51
+ * If not provided, the plugin will automatically find the main entry file
52
+ * by checking for the existence of 'src/main.ts' or 'src/main.js' in that order.
53
+ * Path is resolved from the command line working directory (process.cwd()).
54
+ * @default Auto-detected from ['src/main.ts', 'src/main.js']
56
55
  */
57
- entries?: Arrayable<string>;
56
+ entry?: string;
58
57
  }
59
58
 
60
59
  /**
package/dist/index.mjs CHANGED
@@ -1,24 +1,24 @@
1
- import{normalize as x,resolve as d}from"path";import{readFileSync as $}from"fs";import f from"dayjs";import b from"dayjs/plugin/timezone.js";import O from"dayjs/plugin/utc.js";import{castArray as y}from"@lntvow/utils";f.extend(O);f.extend(b);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 a=f().tz(r).format("YYYY-MM-DD HH:mm:ss");if(!o)try{let t=$(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:`
1
+ import{normalize as h,resolve as l}from"path";import{readFileSync as $,existsSync as b}from"fs";import d from"dayjs";import y from"dayjs/plugin/timezone.js";import O from"dayjs/plugin/utc.js";d.extend(O);d.extend(y);function P(s={}){let{name:e="LNTVOW_VERSION",timezone:o="Asia/Shanghai",entry:a}=s,{version:r}=s,p=["src/main.ts","src/main.js"].map(t=>l(process.cwd(),t)),i;a?i=l(process.cwd(),a):i=p.find(n=>b(n))??p[0];let g=d().tz(o).format("YYYY-MM-DD HH:mm:ss");if(!r)try{let t=$(l(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,n){if(h(n)===h(i))return{code:`
2
2
  ${t}
3
3
 
4
- localStorage.setItem('${n}', JSON.stringify(['${a}', '${o}']))
5
- console.log('[Log] version:', ['${a}', '${o}']);
6
- `}}}}function N(e={}){let{width:n=150,height:r=20,fontSize:i=12,backgroundColor:o="hsla(0, 100%, 33%, 0.733)",color:a="#fff",position:t="top-right",envMap:l={}}=e,p;return{name:"vite-plugin-env-ribbon",transformIndexHtml(s){if(p==="production")return s;let u=l[p]||p;if(!u)return s;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=`
4
+ localStorage.setItem('${e}', JSON.stringify(['${g}', '${r}']))
5
+ console.log('[Log] version:', ['${g}', '${r}']);
6
+ `}}}}function N(s={}){let{width:e=150,height:o=20,fontSize:a=12,backgroundColor:r="hsla(0, 100%, 33%, 0.733)",color:p="#fff",position:i="top-right",envMap:g={}}=s,t;return{name:"vite-plugin-env-ribbon",transformIndexHtml(n){if(t==="production")return n;let u=g[t]||t;if(!u)return n;let c=i==="top-left",x=c?`translate(-${o/Math.sqrt(2)}px, -${o/Math.sqrt(2)}px) translate(0, ${e/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${o/Math.sqrt(2)}px, -${o/Math.sqrt(2)}px) translate(0, ${e/Math.sqrt(2)}px) rotate(45deg)`,v=`
7
7
  position: fixed;
8
- width: ${n}px;
9
- height: ${r}px;
10
- background: ${o};
11
- color: ${a};
12
- font-size: ${i}px;
13
- line-height: ${r}px;
14
- transform: ${h};
15
- transform-origin: ${g?"left top":"right top"};
8
+ width: ${e}px;
9
+ height: ${o}px;
10
+ background: ${r};
11
+ color: ${p};
12
+ font-size: ${a}px;
13
+ line-height: ${o}px;
14
+ transform: ${x};
15
+ transform-origin: ${c?"left top":"right top"};
16
16
  top: 0;
17
- right: ${g?"auto":"0"};
18
- left: ${g?"0":"auto"};
17
+ right: ${c?"auto":"0"};
18
+ left: ${c?"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:v.replace(/\s+/g," ").trim(),id:"vite-plugin-env-ribbon"},children:u,injectTo:"body"}]}},configResolved(s){p=s.mode}}}export{N as vitePluginEnvRibbon,V as vitePluginVersionLog};
24
+ `;return{html:n,tags:[{tag:"div",attrs:{style:v.replace(/\s+/g," ").trim(),id:"vite-plugin-env-ribbon"},children:u,injectTo:"body"}]}},configResolved(n){t=n.mode}}}export{N as vitePluginEnvRibbon,P as vitePluginVersionLog};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lntvow/vite-plugin",
3
- "version": "1.1.13",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "description": "Collection of custom vite plugins",
6
6
  "keywords": [
@@ -23,23 +23,22 @@
23
23
  "import": "./dist/index.mjs"
24
24
  },
25
25
  "dependencies": {
26
- "@lntvow/utils": "^4.3.4",
27
26
  "dayjs": "^1.11.13"
28
27
  },
29
28
  "devDependencies": {
30
29
  "@commitlint/cli": "^19.8.1",
31
30
  "@commitlint/config-conventional": "^19.8.1",
32
- "@lntvow/eslint-config": "^9.29.1",
33
- "bumpp": "^10.2.0",
31
+ "@lntvow/eslint-config": "^9.30.3",
32
+ "bumpp": "^10.2.2",
34
33
  "commitizen": "^4.3.1",
35
34
  "cz-conventional-changelog": "^3.3.0",
36
- "eslint": "^9.32.0",
37
- "lint-staged": "^16.1.2",
35
+ "eslint": "^9.33.0",
36
+ "lint-staged": "^16.1.5",
38
37
  "npm-run-all": "^4.1.5",
39
38
  "prettier": "^3.6.2",
40
- "simple-git-hooks": "^2.13.0",
39
+ "simple-git-hooks": "^2.13.1",
41
40
  "tsup": "^8.5.0",
42
- "typescript": "^5.8.3"
41
+ "typescript": "^5.9.2"
43
42
  },
44
43
  "peerDependencies": {
45
44
  "vite": ">=5.0.0"