@lntvow/vite-plugin 1.0.2 → 1.0.6

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,10 +1,103 @@
1
- "use strict";const m=require("node:path"),a=require("node:fs"),g=require("dayjs"),c=require("dayjs/plugin/utc"),f=require("dayjs/plugin/timezone"),utils=require("@lntvow/utils"),vite=require("vite");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const m__default=_interopDefaultCompat(m),a__default=_interopDefaultCompat(a),g__default=_interopDefaultCompat(g),c__default=_interopDefaultCompat(c),f__default=_interopDefaultCompat(f);g.extend(c__default),g.extend(f__default);function vitePluginLogs(t={}){const{name:n="LNTVOW_VERSION"}=t;let e=t.version;if(!e)try{const o=a__default.readFileSync(m__default.resolve(process.cwd(),"package.json"),"utf8");e=JSON.parse(o).version}catch{utils.throwError("vitePluginLogs","package.json not found")}return{name:"vite-plugin-logs",transform(o,s){if(s.endsWith("src/main.ts")||s.endsWith("src/main.js")){const r=g__default().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");return{code:`
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ vitePluginHtml: () => vitePluginHtml,
34
+ vitePluginLogs: () => vitePluginLogs
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // src/vite-plugin-logs.ts
39
+ var import_node_path = __toESM(require("path"), 1);
40
+ var import_node_fs = __toESM(require("fs"), 1);
41
+ var import_dayjs = __toESM(require("dayjs"), 1);
42
+ var import_utc = __toESM(require("dayjs/plugin/utc"), 1);
43
+ var import_timezone = __toESM(require("dayjs/plugin/timezone"), 1);
44
+ var import_utils = require("@lntvow/utils");
45
+ import_dayjs.default.extend(import_utc.default);
46
+ import_dayjs.default.extend(import_timezone.default);
47
+ function vitePluginLogs(options = {}) {
48
+ const { name = "LNTVOW_VERSION" } = options;
49
+ let { version } = options;
50
+ if (!version) {
51
+ try {
52
+ const packageJsonContent = import_node_fs.default.readFileSync(import_node_path.default.resolve(process.cwd(), "package.json"), "utf8");
53
+ version = JSON.parse(packageJsonContent).version;
54
+ } catch (e) {
55
+ (0, import_utils.throwError)("vitePluginLogs", "package.json not found");
56
+ }
57
+ }
58
+ return {
59
+ name: "vite-plugin-logs",
60
+ transform(code, id) {
61
+ if (id.endsWith("src/main.ts") || id.endsWith("src/main.js")) {
62
+ const time = (0, import_dayjs.default)().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");
63
+ return {
64
+ code: `
2
65
 
3
66
  import { log as vitePluginLogs } from '@lntvow/utils';
4
67
 
5
- ${o}
68
+ ${code}
69
+
70
+ localStorage.setItem('${name}', JSON.stringify(['${time}', '${version}']))
71
+ vitePluginLogs('version', '${time}', '${version}')
6
72
 
7
- localStorage.setItem('${n}', JSON.stringify(['${r}', '${e}']))
8
- vitePluginLogs('version', '${r}', '${e}')
73
+ `
74
+ };
75
+ }
76
+ }
77
+ };
78
+ }
9
79
 
10
- `}}}}}function vitePluginHtml(){let t={};return{name:"vite-plugin-html",enforce:"pre",config(n,{mode:e}){t=vite.loadEnv(e,process.cwd())},transformIndexHtml(n){return Object.keys(t).forEach(e=>{const o=new RegExp(`%${e}%`,"g");n=n.replace(o,t[e])}),n}}}exports.vitePluginHtml=vitePluginHtml,exports.vitePluginLogs=vitePluginLogs;
80
+ // src/vite-plugin-html.ts
81
+ var import_vite = require("vite");
82
+ function vitePluginHtml() {
83
+ let env = {};
84
+ return {
85
+ name: "vite-plugin-html",
86
+ enforce: "pre",
87
+ config(config, { mode }) {
88
+ env = (0, import_vite.loadEnv)(mode, process.cwd());
89
+ },
90
+ transformIndexHtml(html) {
91
+ Object.keys(env).forEach((key) => {
92
+ const regex = new RegExp(`%${key}%`, "g");
93
+ html = html.replace(regex, env[key]);
94
+ });
95
+ return html;
96
+ }
97
+ };
98
+ }
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ vitePluginHtml,
102
+ vitePluginLogs
103
+ });
package/dist/index.d.cts CHANGED
@@ -16,4 +16,4 @@ interface VitePluginLogsOptions {
16
16
 
17
17
  declare function vitePluginHtml(): Plugin;
18
18
 
19
- export { vitePluginHtml, vitePluginLogs };
19
+ export { type VitePluginLogsOptions, vitePluginHtml, vitePluginLogs };
package/dist/index.d.ts CHANGED
@@ -16,4 +16,4 @@ interface VitePluginLogsOptions {
16
16
 
17
17
  declare function vitePluginHtml(): Plugin;
18
18
 
19
- export { vitePluginHtml, vitePluginLogs };
19
+ export { type VitePluginLogsOptions, vitePluginHtml, vitePluginLogs };
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ // src/vite-plugin-logs.ts
2
+ import path from "path";
3
+ import fs from "fs";
4
+ import dayjs from "dayjs";
5
+ import utc from "dayjs/plugin/utc";
6
+ import timezone from "dayjs/plugin/timezone";
7
+ import { throwError } from "@lntvow/utils";
8
+ dayjs.extend(utc);
9
+ dayjs.extend(timezone);
10
+ function vitePluginLogs(options = {}) {
11
+ const { name = "LNTVOW_VERSION" } = options;
12
+ let { version } = options;
13
+ if (!version) {
14
+ try {
15
+ const packageJsonContent = fs.readFileSync(path.resolve(process.cwd(), "package.json"), "utf8");
16
+ version = JSON.parse(packageJsonContent).version;
17
+ } catch (e) {
18
+ throwError("vitePluginLogs", "package.json not found");
19
+ }
20
+ }
21
+ return {
22
+ name: "vite-plugin-logs",
23
+ transform(code, id) {
24
+ if (id.endsWith("src/main.ts") || id.endsWith("src/main.js")) {
25
+ const time = dayjs().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");
26
+ return {
27
+ code: `
28
+
29
+ import { log as vitePluginLogs } from '@lntvow/utils';
30
+
31
+ ${code}
32
+
33
+ localStorage.setItem('${name}', JSON.stringify(['${time}', '${version}']))
34
+ vitePluginLogs('version', '${time}', '${version}')
35
+
36
+ `
37
+ };
38
+ }
39
+ }
40
+ };
41
+ }
42
+
43
+ // src/vite-plugin-html.ts
44
+ import { loadEnv } from "vite";
45
+ function vitePluginHtml() {
46
+ let env = {};
47
+ return {
48
+ name: "vite-plugin-html",
49
+ enforce: "pre",
50
+ config(config, { mode }) {
51
+ env = loadEnv(mode, process.cwd());
52
+ },
53
+ transformIndexHtml(html) {
54
+ Object.keys(env).forEach((key) => {
55
+ const regex = new RegExp(`%${key}%`, "g");
56
+ html = html.replace(regex, env[key]);
57
+ });
58
+ return html;
59
+ }
60
+ };
61
+ }
62
+ export {
63
+ vitePluginHtml,
64
+ vitePluginLogs
65
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lntvow/vite-plugin",
3
- "version": "1.0.2",
3
+ "version": "1.0.6",
4
4
  "description": "vite插件",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -9,26 +9,25 @@
9
9
  "dist"
10
10
  ],
11
11
  "main": "dist/index.cjs",
12
- "module": "dist/index.mjs",
12
+ "module": "dist/index.js",
13
13
  "types": "dist/index.d.ts",
14
14
  "engines": {
15
15
  "node": ">=18.12.0",
16
16
  "pnpm": ">=9.0.0"
17
17
  },
18
18
  "dependencies": {
19
- "@lntvow/utils": "^3.0.2",
19
+ "@lntvow/utils": "^3.1.6",
20
20
  "dayjs": "^1.11.11"
21
21
  },
22
22
  "devDependencies": {
23
- "@lntvow/dev": "^1.0.1",
24
- "typescript": "^5.4.5",
25
- "unbuild": "^2.0.0"
23
+ "@lntvow/dev": "^1.1.10",
24
+ "tsup": "^8.1.0"
26
25
  },
27
26
  "peerDependencies": {
28
- "vite": ">=5.0.0"
27
+ "vite": ">=4.0.0"
29
28
  },
30
29
  "scripts": {
31
- "build": "unbuild",
30
+ "build": "tsup",
32
31
  "commit": "git add . && git-cz && git push",
33
32
  "rimraf": "rimraf ./node_modules/",
34
33
  "release": "git add . && bumpp package.json --all --commit --no-tag --push"
package/dist/index.d.mts DELETED
@@ -1,19 +0,0 @@
1
- import { Plugin } from 'vite';
2
-
3
- declare function vitePluginLogs(options?: VitePluginLogsOptions): Plugin;
4
- interface VitePluginLogsOptions {
5
- /**
6
- * @description localStorage key
7
- * @default LNTVOW_VERSION
8
- */
9
- name?: string;
10
- /**
11
- * @description 版本号
12
- * @default 默认读取package.json的version
13
- */
14
- version?: string;
15
- }
16
-
17
- declare function vitePluginHtml(): Plugin;
18
-
19
- export { vitePluginHtml, vitePluginLogs };
package/dist/index.mjs DELETED
@@ -1,10 +0,0 @@
1
- import m from"node:path";import a from"node:fs";import c,{extend as s}from"dayjs";import f from"dayjs/plugin/utc";import g from"dayjs/plugin/timezone";import{throwError as l}from"@lntvow/utils";import{loadEnv as p}from"vite";s(f),s(g);function u(r={}){const{name:t="LNTVOW_VERSION"}=r;let o=r.version;if(!o)try{const e=a.readFileSync(m.resolve(process.cwd(),"package.json"),"utf8");o=JSON.parse(e).version}catch{l("vitePluginLogs","package.json not found")}return{name:"vite-plugin-logs",transform(e,n){if(n.endsWith("src/main.ts")||n.endsWith("src/main.js")){const i=c().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");return{code:`
2
-
3
- import { log as vitePluginLogs } from '@lntvow/utils';
4
-
5
- ${e}
6
-
7
- localStorage.setItem('${t}', JSON.stringify(['${i}', '${o}']))
8
- vitePluginLogs('version', '${i}', '${o}')
9
-
10
- `}}}}}function v(){let r={};return{name:"vite-plugin-html",enforce:"pre",config(t,{mode:o}){r=p(o,process.cwd())},transformIndexHtml(t){return Object.keys(r).forEach(o=>{const e=new RegExp(`%${o}%`,"g");t=t.replace(e,r[o])}),t}}}export{v as vitePluginHtml,u as vitePluginLogs};