@lntvow/vite-plugin 1.2.7 → 1.3.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.d.ts CHANGED
@@ -1,61 +1,5 @@
1
1
  import { PluginOption } from 'vite';
2
2
 
3
- /**
4
- * This Vite plugin injects version and build time information into a specified entry file.
5
- * It automatically writes the current build time and project version (read from package.json by default)
6
- * to localStorage and prints them to the console at runtime.
7
- *
8
- * This is useful for tracking deployment versions and build times in frontend projects,
9
- * making it easier to identify which version is currently deployed and when it was built.
10
- *
11
- * You can customize the localStorage key, version, timezone, and the entry file 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
- * @remarks
23
- * - Automatically reads version from package.json if not provided
24
- * - Supports custom timezone for build time formatting
25
- * - Configurable localStorage key name
26
- * - Auto-detects entry file from 'src/main.ts' or 'src/main.js' if not specified
27
- */
28
- declare function vitePluginVersionLog(options?: VersionLogOptions): PluginOption;
29
- interface VersionLogOptions {
30
- /**
31
- * The key used for localStorage to store version information.
32
- * The stored value will be a JSON array: [buildTime, version]
33
- * @default 'LNTVOW_VERSION'
34
- */
35
- name?: string;
36
- /**
37
- * Project version string.
38
- * If not provided, the plugin will automatically read the version from package.json.
39
- * If package.json is not found or doesn't contain a version, 'unknown' will be used.
40
- * @default Reads the version from package.json by default.
41
- */
42
- version?: string;
43
- /**
44
- * Timezone setting for formatting the build time.
45
- * Supports all timezone identifiers (e.g., 'UTC', 'America/New_York', 'Europe/London').
46
- * @default 'Asia/Shanghai'
47
- */
48
- timezone?: string;
49
- /**
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']
55
- */
56
- entry?: string;
57
- }
58
-
59
3
  /**
60
4
  * This Vite plugin injects a diagonal environment ribbon into the built HTML page.
61
5
  * The ribbon displays the current environment (such as development, uat, pre.)
@@ -130,4 +74,61 @@ interface EnvRibbonOptions {
130
74
  envMap?: Record<string, string>;
131
75
  }
132
76
 
77
+ /**
78
+ * This Vite plugin injects version and build time information into a specified entry file.
79
+ * It automatically writes the current build time and project version (read from package.json by default)
80
+ * to localStorage and prints them to the console at runtime.
81
+ *
82
+ * This is useful for tracking deployment versions and build times in frontend projects,
83
+ * making it easier to identify which version is currently deployed and when it was built.
84
+ *
85
+ * You can customize the localStorage key, version, timezone, and provide a custom entry file path via plugin options.
86
+ *
87
+ * @example
88
+ * import { vitePluginVersionLog } from '@lntvow/vite-plugin'
89
+ *
90
+ * export default {
91
+ * plugins: [
92
+ * vitePluginVersionLog(),
93
+ * ],
94
+ * }
95
+ *
96
+ * @remarks
97
+ * - Automatically reads version from package.json if not provided
98
+ * - Supports custom timezone for build time formatting
99
+ * - Configurable localStorage key name
100
+ * - Auto-detects entry file from 'src/main.ts' or 'src/main.js' if not specified
101
+ */
102
+ declare function vitePluginVersionLog(options?: VersionLogOptions): PluginOption;
103
+ interface VersionLogOptions {
104
+ /**
105
+ * The key used for localStorage to store version information.
106
+ * The stored value will be a JSON array: [buildTime, version]
107
+ * @default 'LNTVOW_VERSION'
108
+ */
109
+ name?: string;
110
+ /**
111
+ * Project version string.
112
+ * If not provided, the plugin will automatically read the version from package.json.
113
+ * If package.json is not found or doesn't contain a version, 'unknown' will be used.
114
+ * @default reads the version from package.json by default.
115
+ */
116
+ version?: string;
117
+ /**
118
+ * Only the time zone may be changed — the format itself is hard‑coded as
119
+ * `YYYY-MM-DD HH:mm:ss`. This option tells the formatter which local
120
+ * clock should be used (e.g. 'Asia/Shanghai', 'UTC', etc.).
121
+ * @default system local time zone (Intl.DateTimeFormat().resolvedOptions().timeZone)
122
+ */
123
+ timezone?: string;
124
+ /**
125
+ * Custom entry file path to inject version/build info into.
126
+ * If an absolute path is given it will be used directly; otherwise the path
127
+ * is resolved relative to `process.cwd()`.
128
+ * When omitted the plugin will look for `src/main.ts` or `src/main.js` in
129
+ * @default auto-detected from ['src/main.ts', 'src/main.js']
130
+ */
131
+ entry?: string;
132
+ }
133
+
133
134
  export { type EnvRibbonOptions, type VersionLogOptions, vitePluginEnvRibbon, vitePluginVersionLog };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ function k(a={}){let g="vite-plugin-env-ribbon",{width:i=150,height:o=20,fontSize:t=12,backgroundColor:c="hsla(0, 100%, 33%, 0.733)",color:n="#fff",position:p="top-right",envMap:r={}}=a,s;return{name:g,transformIndexHtml(e){if(s==="production")return e;let m=r[s]||s;if(!m)return e;let l=p==="top-left",w=l?`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)`,b=l?"left top":"right top",y=l?"auto":"0",O=l?"0":"auto",S=["position: fixed",`width: ${i}px`,`height: ${o}px`,`background: ${c}`,`color: ${n}`,`font-size: ${t}px`,`line-height: ${o}px`,`transform: ${w}`,`transform-origin: ${b}`,"top: 0",`right: ${y}`,`left: ${O}`,"z-index: 9999","text-align: center","pointer-events: none","user-select: none","overflow: hidden"].join(";");return{html:e,tags:[{tag:"div",attrs:{style:S,id:g},children:m,injectTo:"body"}]}},configResolved(e){s=e.mode}}}import{existsSync as $,readFileSync as j}from"fs";import{isAbsolute as M,normalize as x,resolve as h}from"path";import f from"picocolors";function v(a){let g=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"}),i=t=>g.format(t);return{info:t=>console.log(o("info",t)),warn:t=>console.log(o("warn",t)),error:t=>console.log(o("error",t))};function o(t,c){let n={info:f.cyan,warn:f.yellow,error:f.red};return`${f.dim(i(new Date))} ${n[t](f.bold(`[${a}]`))} ${n[t](c)}`}}function N(a={}){let{name:g="LNTVOW_VERSION",timezone:i=Intl.DateTimeFormat().resolvedOptions().timeZone,entry:o}=a,{version:t}=a,c="vite-plugin-version-log",n=v(c),p=["src/main.ts","src/main.js"].map(e=>h(process.cwd(),e)),r;if(o){if(r=M(o)?o:h(process.cwd(),o),!$(r)){n.error(`Entry file not found: ${r}`);return}}else if(r=p.find(e=>$(e)),!r){n.error(`Default entry files (${p.join(", ")}) were not found.`),n.error('Specify a custom path via the "entry" option to use a different file.');return}let s=new Intl.DateTimeFormat("sv-SE",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).format(new Date);if(!t)try{let e=j(h(process.cwd(),"package.json"),"utf8");t=JSON.parse(e).version}catch(e){t="unknown",console.log("error: ",e),n.warn("Failed to read version from package.json. Using 'unknown' as version.")}return{name:c,transform(e,m){if(x(m)===x(r))return{code:[e,`localStorage.setItem('${g}', JSON.stringify(['${s}', '${t}']))`,`console.log('[Log] version:', ['${s}', '${t}']);`].join(";")}}}}export{k as vitePluginEnvRibbon,N as vitePluginVersionLog};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lntvow/vite-plugin",
3
- "version": "1.2.7",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "Collection of custom vite plugins",
6
6
  "keywords": [
@@ -15,25 +15,24 @@
15
15
  "dist"
16
16
  ],
17
17
  "types": "dist/index.d.ts",
18
- "main": "dist/index.cjs",
19
- "module": "dist/index.mjs",
18
+ "main": "dist/index.js",
20
19
  "exports": {
21
20
  "types": "./dist/index.d.ts",
22
- "require": "./dist/index.cjs",
23
- "import": "./dist/index.mjs"
21
+ "import": "./dist/index.js",
22
+ "default": "./dist/index.js"
24
23
  },
25
24
  "dependencies": {
26
- "dayjs": "^1.11.19"
25
+ "picocolors": "^1.1.1"
27
26
  },
28
27
  "devDependencies": {
29
- "@commitlint/cli": "^20.4.2",
30
- "@commitlint/config-conventional": "^20.4.2",
31
- "@lntvow/eslint-config": "^10.0.1",
28
+ "@commitlint/cli": "^20.4.3",
29
+ "@commitlint/config-conventional": "^20.4.3",
30
+ "@lntvow/eslint-config": "^10.1.2",
32
31
  "bumpp": "^10.4.1",
33
32
  "commitizen": "^4.3.1",
34
33
  "cz-conventional-changelog": "^3.3.0",
35
- "eslint": "^10.0.2",
36
- "lint-staged": "^16.2.7",
34
+ "eslint": "^10.0.3",
35
+ "lint-staged": "^16.3.2",
37
36
  "npm-run-all": "^4.1.5",
38
37
  "prettier": "^3.8.1",
39
38
  "simple-git-hooks": "^2.13.1",
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";var j=Object.create;var l=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var L=(t,n)=>{for(var o in n)l(t,o,{get:n[o],enumerable:!0})},v=(t,n,o,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of E(n))!q.call(t,e)&&e!==o&&l(t,e,{get:()=>n[e],enumerable:!(s=w(n,e))||s.enumerable});return t};var h=(t,n,o)=>(o=t!=null?j(k(t)):{},v(n||!t||!t.__esModule?l(o,"default",{value:t,enumerable:!0}):o,t)),P=t=>v(l({},"__esModule",{value:!0}),t);var V={};L(V,{vitePluginEnvRibbon:()=>C,vitePluginVersionLog:()=>R});module.exports=P(V);var a=require("path"),m=require("fs"),d=h(require("dayjs"),1),$=h(require("dayjs/plugin/timezone.js"),1),b=h(require("dayjs/plugin/utc.js"),1);d.default.extend(b.default);d.default.extend($.default);function R(t={}){let{name:n="LNTVOW_VERSION",timezone:o="Asia/Shanghai",entry:s}=t,{version:e}=t,c=["src/main.ts","src/main.js"].map(r=>(0,a.resolve)(process.cwd(),r)),p;s?p=(0,a.resolve)(process.cwd(),s):p=c.find(i=>(0,m.existsSync)(i))??c[0];let g=(0,d.default)().tz(o).format("YYYY-MM-DD HH:mm:ss");if(!e)try{let r=(0,m.readFileSync)((0,a.resolve)(process.cwd(),"package.json"),"utf8");e=JSON.parse(r).version}catch(r){e="unknown",console.log("error: ",r)}return{name:"vite-plugin-version-log",transform(r,i){if((0,a.normalize)(i)===(0,a.normalize)(p))return{code:[r,`localStorage.setItem('${n}', JSON.stringify(['${g}', '${e}']))`,`console.log('[Log] version:', ['${g}', '${e}']);`].join(";")}}}}function C(t={}){let{width:n=150,height:o=20,fontSize:s=12,backgroundColor:e="hsla(0, 100%, 33%, 0.733)",color:c="#fff",position:p="top-right",envMap:g={}}=t,r;return{name:"vite-plugin-env-ribbon",transformIndexHtml(i){if(r==="production")return i;let u=g[r]||r;if(!u)return i;let f=p==="top-left",y=f?`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=f?"left top":"right top",M=f?"auto":"0",z=f?"0":"auto",S=["position: fixed",`width: ${n}px`,`height: ${o}px`,`background: ${e}`,`color: ${c}`,`font-size: ${s}px`,`line-height: ${o}px`,`transform: ${y}`,`transform-origin: ${O}`,"top: 0",`right: ${M}`,`left: ${z}`,"z-index: 9999","text-align: center","pointer-events: none","user-select: none","overflow: hidden"].join(";");return{html:i,tags:[{tag:"div",attrs:{style:S,id:"vite-plugin-env-ribbon"},children:u,injectTo:"body"}]}},configResolved(i){r=i.mode}}}0&&(module.exports={vitePluginEnvRibbon,vitePluginVersionLog});
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- import{normalize as h,resolve as l}from"path";import{readFileSync as O,existsSync as M}from"fs";import u from"dayjs";import z from"dayjs/plugin/timezone.js";import S from"dayjs/plugin/utc.js";u.extend(S);u.extend(z);function L(s={}){let{name:r="LNTVOW_VERSION",timezone:o="Asia/Shanghai",entry:a}=s,{version:e}=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=>M(n))??p[0];let c=u().tz(o).format("YYYY-MM-DD HH:mm:ss");if(!e)try{let t=O(l(process.cwd(),"package.json"),"utf8");e=JSON.parse(t).version}catch(t){e="unknown",console.log("error: ",t)}return{name:"vite-plugin-version-log",transform(t,n){if(h(n)===h(i))return{code:[t,`localStorage.setItem('${r}', JSON.stringify(['${c}', '${e}']))`,`console.log('[Log] version:', ['${c}', '${e}']);`].join(";")}}}}function V(s={}){let{width:r=150,height:o=20,fontSize:a=12,backgroundColor:e="hsla(0, 100%, 33%, 0.733)",color:p="#fff",position:i="top-right",envMap:c={}}=s,t;return{name:"vite-plugin-env-ribbon",transformIndexHtml(n){if(t==="production")return n;let f=c[t]||t;if(!f)return n;let g=i==="top-left",x=g?`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)`,v=g?"left top":"right top",$=g?"auto":"0",b=g?"0":"auto",y=["position: fixed",`width: ${r}px`,`height: ${o}px`,`background: ${e}`,`color: ${p}`,`font-size: ${a}px`,`line-height: ${o}px`,`transform: ${x}`,`transform-origin: ${v}`,"top: 0",`right: ${$}`,`left: ${b}`,"z-index: 9999","text-align: center","pointer-events: none","user-select: none","overflow: hidden"].join(";");return{html:n,tags:[{tag:"div",attrs:{style:y,id:"vite-plugin-env-ribbon"},children:f,injectTo:"body"}]}},configResolved(n){t=n.mode}}}export{V as vitePluginEnvRibbon,L as vitePluginVersionLog};