@sybz-components/utils 1.0.5 → 1.0.7
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/base.cjs +2 -1
- package/dist/base.d.cts +24 -4
- package/dist/base.d.mts +24 -4
- package/dist/base.d.ts +24 -4
- package/dist/base.mjs +1 -1
- package/dist/format.cjs +1 -1
- package/dist/format.mjs +1 -1
- package/dist/gitCommitLog.cjs +144 -0
- package/dist/gitCommitLog.d.cts +54 -0
- package/dist/gitCommitLog.d.mts +54 -0
- package/dist/gitCommitLog.d.ts +54 -0
- package/dist/gitCommitLog.mjs +142 -0
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/{utils.3tjAW8jl.cjs → utils.CQ_8FikI.cjs} +26 -17
- package/dist/shared/{utils.DaaLd-vj.mjs → utils.DvUjmqr2.mjs} +27 -19
- package/dist/vite.cjs +53 -0
- package/dist/vite.d.cts +25 -0
- package/dist/vite.d.mts +25 -0
- package/dist/vite.d.ts +25 -0
- package/dist/vite.mjs +51 -0
- package/package.json +27 -1
package/dist/base.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require('vue');
|
|
4
4
|
require('consola');
|
|
5
5
|
require('es-toolkit');
|
|
6
|
-
const format = require('./shared/utils.
|
|
6
|
+
const format = require('./shared/utils.CQ_8FikI.cjs');
|
|
7
7
|
require('element-plus');
|
|
8
8
|
require('./is.cjs');
|
|
9
9
|
|
|
@@ -12,6 +12,7 @@ require('./is.cjs');
|
|
|
12
12
|
exports.$toast = format.$toast;
|
|
13
13
|
exports.clearStorage = format.clearStorage;
|
|
14
14
|
exports.clone = format.clone;
|
|
15
|
+
exports.configureUtils = format.configureUtils;
|
|
15
16
|
exports.confirm = format.confirm;
|
|
16
17
|
exports.copy = format.copy;
|
|
17
18
|
exports.debounce = format.debounce;
|
package/dist/base.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { VNode, AppContext, Ref } from 'vue';
|
|
3
|
-
import {
|
|
3
|
+
import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
|
|
4
4
|
|
|
5
5
|
type Func<Args extends any[] = any[], Return = any> = (...args: Args) => Return;
|
|
6
6
|
type StorageValue = unknown;
|
|
@@ -25,11 +25,22 @@ type MockValueOptionItem<T = any> = {
|
|
|
25
25
|
label: string;
|
|
26
26
|
value: T;
|
|
27
27
|
};
|
|
28
|
+
type UtilsTheme = 'default' | 'chenghua' | 'shijingshan';
|
|
29
|
+
interface SybzUtilsConfig {
|
|
30
|
+
/**
|
|
31
|
+
* 工具函数的默认主题。
|
|
32
|
+
*/
|
|
33
|
+
theme?: UtilsTheme;
|
|
34
|
+
}
|
|
28
35
|
interface ToastOptions extends Partial<MessageOptions> {
|
|
29
36
|
/**
|
|
30
37
|
* 调用前是否先关闭全部消息提示。
|
|
31
38
|
*/
|
|
32
39
|
closeAll?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 当前消息的主题;未传时使用 utils 全局主题。
|
|
42
|
+
*/
|
|
43
|
+
theme?: UtilsTheme;
|
|
33
44
|
}
|
|
34
45
|
interface ClearStorageExcludeOptions {
|
|
35
46
|
/**
|
|
@@ -116,7 +127,7 @@ interface CopyOptions extends ToastOptions {
|
|
|
116
127
|
type WidthInput = string | number | Ref<string | number>;
|
|
117
128
|
type ConfirmMessage = string | VNode | (() => VNode);
|
|
118
129
|
type ConfirmVariant = 'default' | 'delete' | 'warning';
|
|
119
|
-
type ConfirmTheme =
|
|
130
|
+
type ConfirmTheme = UtilsTheme;
|
|
120
131
|
type ConfirmTarget = string | number;
|
|
121
132
|
interface ConfirmCustomOptions {
|
|
122
133
|
/**
|
|
@@ -147,6 +158,15 @@ interface TryCatchResult<T> {
|
|
|
147
158
|
*/
|
|
148
159
|
error: any;
|
|
149
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* 配置 `@sybz-components/utils` 的全局默认行为。
|
|
163
|
+
*
|
|
164
|
+
* 单次函数调用中传入的配置优先级高于这里的全局配置。
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* configureUtils({ theme: 'shijingshan' })
|
|
168
|
+
*/
|
|
169
|
+
declare function configureUtils(config: SybzUtilsConfig): Readonly<Required<SybzUtilsConfig>>;
|
|
150
170
|
type MessageType = 'success' | 'info' | 'error' | 'warning';
|
|
151
171
|
type ShortType = 's' | 'i' | 'e' | 'w';
|
|
152
172
|
type ToastType = MessageType | ShortType;
|
|
@@ -623,5 +643,5 @@ declare function getUtilsBuildTime(fallback?: string): string;
|
|
|
623
643
|
*/
|
|
624
644
|
declare function test(): string;
|
|
625
645
|
|
|
626
|
-
export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit };
|
|
627
|
-
export type { ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant };
|
|
646
|
+
export { $toast, clearStorage, clone, configureUtils, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit };
|
|
647
|
+
export type { ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant, SybzUtilsConfig, ToastOptions, UtilsTheme };
|
package/dist/base.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { VNode, AppContext, Ref } from 'vue';
|
|
3
|
-
import {
|
|
3
|
+
import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
|
|
4
4
|
|
|
5
5
|
type Func<Args extends any[] = any[], Return = any> = (...args: Args) => Return;
|
|
6
6
|
type StorageValue = unknown;
|
|
@@ -25,11 +25,22 @@ type MockValueOptionItem<T = any> = {
|
|
|
25
25
|
label: string;
|
|
26
26
|
value: T;
|
|
27
27
|
};
|
|
28
|
+
type UtilsTheme = 'default' | 'chenghua' | 'shijingshan';
|
|
29
|
+
interface SybzUtilsConfig {
|
|
30
|
+
/**
|
|
31
|
+
* 工具函数的默认主题。
|
|
32
|
+
*/
|
|
33
|
+
theme?: UtilsTheme;
|
|
34
|
+
}
|
|
28
35
|
interface ToastOptions extends Partial<MessageOptions> {
|
|
29
36
|
/**
|
|
30
37
|
* 调用前是否先关闭全部消息提示。
|
|
31
38
|
*/
|
|
32
39
|
closeAll?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 当前消息的主题;未传时使用 utils 全局主题。
|
|
42
|
+
*/
|
|
43
|
+
theme?: UtilsTheme;
|
|
33
44
|
}
|
|
34
45
|
interface ClearStorageExcludeOptions {
|
|
35
46
|
/**
|
|
@@ -116,7 +127,7 @@ interface CopyOptions extends ToastOptions {
|
|
|
116
127
|
type WidthInput = string | number | Ref<string | number>;
|
|
117
128
|
type ConfirmMessage = string | VNode | (() => VNode);
|
|
118
129
|
type ConfirmVariant = 'default' | 'delete' | 'warning';
|
|
119
|
-
type ConfirmTheme =
|
|
130
|
+
type ConfirmTheme = UtilsTheme;
|
|
120
131
|
type ConfirmTarget = string | number;
|
|
121
132
|
interface ConfirmCustomOptions {
|
|
122
133
|
/**
|
|
@@ -147,6 +158,15 @@ interface TryCatchResult<T> {
|
|
|
147
158
|
*/
|
|
148
159
|
error: any;
|
|
149
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* 配置 `@sybz-components/utils` 的全局默认行为。
|
|
163
|
+
*
|
|
164
|
+
* 单次函数调用中传入的配置优先级高于这里的全局配置。
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* configureUtils({ theme: 'shijingshan' })
|
|
168
|
+
*/
|
|
169
|
+
declare function configureUtils(config: SybzUtilsConfig): Readonly<Required<SybzUtilsConfig>>;
|
|
150
170
|
type MessageType = 'success' | 'info' | 'error' | 'warning';
|
|
151
171
|
type ShortType = 's' | 'i' | 'e' | 'w';
|
|
152
172
|
type ToastType = MessageType | ShortType;
|
|
@@ -623,5 +643,5 @@ declare function getUtilsBuildTime(fallback?: string): string;
|
|
|
623
643
|
*/
|
|
624
644
|
declare function test(): string;
|
|
625
645
|
|
|
626
|
-
export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit };
|
|
627
|
-
export type { ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant };
|
|
646
|
+
export { $toast, clearStorage, clone, configureUtils, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit };
|
|
647
|
+
export type { ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant, SybzUtilsConfig, ToastOptions, UtilsTheme };
|
package/dist/base.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { VNode, AppContext, Ref } from 'vue';
|
|
3
|
-
import {
|
|
3
|
+
import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
|
|
4
4
|
|
|
5
5
|
type Func<Args extends any[] = any[], Return = any> = (...args: Args) => Return;
|
|
6
6
|
type StorageValue = unknown;
|
|
@@ -25,11 +25,22 @@ type MockValueOptionItem<T = any> = {
|
|
|
25
25
|
label: string;
|
|
26
26
|
value: T;
|
|
27
27
|
};
|
|
28
|
+
type UtilsTheme = 'default' | 'chenghua' | 'shijingshan';
|
|
29
|
+
interface SybzUtilsConfig {
|
|
30
|
+
/**
|
|
31
|
+
* 工具函数的默认主题。
|
|
32
|
+
*/
|
|
33
|
+
theme?: UtilsTheme;
|
|
34
|
+
}
|
|
28
35
|
interface ToastOptions extends Partial<MessageOptions> {
|
|
29
36
|
/**
|
|
30
37
|
* 调用前是否先关闭全部消息提示。
|
|
31
38
|
*/
|
|
32
39
|
closeAll?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 当前消息的主题;未传时使用 utils 全局主题。
|
|
42
|
+
*/
|
|
43
|
+
theme?: UtilsTheme;
|
|
33
44
|
}
|
|
34
45
|
interface ClearStorageExcludeOptions {
|
|
35
46
|
/**
|
|
@@ -116,7 +127,7 @@ interface CopyOptions extends ToastOptions {
|
|
|
116
127
|
type WidthInput = string | number | Ref<string | number>;
|
|
117
128
|
type ConfirmMessage = string | VNode | (() => VNode);
|
|
118
129
|
type ConfirmVariant = 'default' | 'delete' | 'warning';
|
|
119
|
-
type ConfirmTheme =
|
|
130
|
+
type ConfirmTheme = UtilsTheme;
|
|
120
131
|
type ConfirmTarget = string | number;
|
|
121
132
|
interface ConfirmCustomOptions {
|
|
122
133
|
/**
|
|
@@ -147,6 +158,15 @@ interface TryCatchResult<T> {
|
|
|
147
158
|
*/
|
|
148
159
|
error: any;
|
|
149
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* 配置 `@sybz-components/utils` 的全局默认行为。
|
|
163
|
+
*
|
|
164
|
+
* 单次函数调用中传入的配置优先级高于这里的全局配置。
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* configureUtils({ theme: 'shijingshan' })
|
|
168
|
+
*/
|
|
169
|
+
declare function configureUtils(config: SybzUtilsConfig): Readonly<Required<SybzUtilsConfig>>;
|
|
150
170
|
type MessageType = 'success' | 'info' | 'error' | 'warning';
|
|
151
171
|
type ShortType = 's' | 'i' | 'e' | 'w';
|
|
152
172
|
type ToastType = MessageType | ShortType;
|
|
@@ -623,5 +643,5 @@ declare function getUtilsBuildTime(fallback?: string): string;
|
|
|
623
643
|
*/
|
|
624
644
|
declare function test(): string;
|
|
625
645
|
|
|
626
|
-
export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit };
|
|
627
|
-
export type { ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant };
|
|
646
|
+
export { $toast, clearStorage, clone, configureUtils, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit };
|
|
647
|
+
export type { ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant, SybzUtilsConfig, ToastOptions, UtilsTheme };
|
package/dist/base.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'vue';
|
|
2
2
|
import 'consola';
|
|
3
3
|
import 'es-toolkit';
|
|
4
|
-
export { $ as $toast, c as clearStorage, a as clone, b as
|
|
4
|
+
export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.DvUjmqr2.mjs';
|
|
5
5
|
import 'element-plus';
|
|
6
6
|
import './is.mjs';
|
package/dist/format.cjs
CHANGED
package/dist/format.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.DvUjmqr2.mjs';
|
|
2
2
|
import './is.mjs';
|
|
3
3
|
import 'consola';
|
|
4
4
|
import 'vue';
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_child_process = require('node:child_process');
|
|
4
|
+
const node_fs = require('node:fs');
|
|
5
|
+
const node_path = require('node:path');
|
|
6
|
+
|
|
7
|
+
const normalizePositiveInteger = (value, fallback) => {
|
|
8
|
+
const number = Number(value);
|
|
9
|
+
return Number.isFinite(number) && number > 0 ? Math.floor(number) : fallback;
|
|
10
|
+
};
|
|
11
|
+
const runGit = (cwd, args) => {
|
|
12
|
+
try {
|
|
13
|
+
return node_child_process.execFileSync("git", args, {
|
|
14
|
+
cwd,
|
|
15
|
+
encoding: "utf8",
|
|
16
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
17
|
+
}).trim();
|
|
18
|
+
} catch {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const normalizeRepositoryUrl = (url) => url.trim().replace(/^git\+/, "").replace(/^git@([^:]+):/, "https://$1/").replace(/\.git$/, "");
|
|
23
|
+
const getCommitUrl = (repository, hash) => {
|
|
24
|
+
if (!repository || !hash) return "";
|
|
25
|
+
return `${repository}${/github\.com/i.test(repository) ? "/commit/" : "/-/commit/"}${hash}`;
|
|
26
|
+
};
|
|
27
|
+
const readProjectPackage = (cwd) => {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(node_fs.readFileSync(node_path.resolve(cwd, "package.json"), "utf8"));
|
|
30
|
+
} catch {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const createGitCommitLogInfo = (cwd, maxCommits, mode) => {
|
|
35
|
+
const packageInfo = readProjectPackage(cwd);
|
|
36
|
+
const packageRepository = typeof packageInfo.repository === "string" ? packageInfo.repository : packageInfo.repository?.url || "";
|
|
37
|
+
const repository = normalizeRepositoryUrl(packageRepository || runGit(cwd, ["remote", "get-url", "origin"]));
|
|
38
|
+
const output = runGit(cwd, ["log", `-${maxCommits}`, "--pretty=format:%H%x1f%h%x1f%an%x1f%ae%x1f%aI%x1f%s"]);
|
|
39
|
+
const commits = output.split("\n").filter(Boolean).map((line) => {
|
|
40
|
+
const [hash = "", shortHash = "", authorName = "", authorEmail = "", committedAt = "", message = ""] = line.split("");
|
|
41
|
+
return {
|
|
42
|
+
hash,
|
|
43
|
+
shortHash,
|
|
44
|
+
authorName,
|
|
45
|
+
authorEmail,
|
|
46
|
+
committedAt,
|
|
47
|
+
message,
|
|
48
|
+
url: getCommitUrl(repository, hash)
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
const upstream = runGit(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]);
|
|
52
|
+
const [ahead = "0", behind = "0"] = upstream ? runGit(cwd, ["rev-list", "--left-right", "--count", `HEAD...${upstream}`]).split(/\s+/) : [];
|
|
53
|
+
const changedFiles = runGit(cwd, ["status", "--porcelain"]).split("\n").filter(Boolean).length;
|
|
54
|
+
return {
|
|
55
|
+
project: packageInfo.name || node_path.resolve(cwd).split("/").pop() || "",
|
|
56
|
+
version: packageInfo.version || "",
|
|
57
|
+
repository,
|
|
58
|
+
branch: process.env.GITHUB_REF_NAME || process.env.GITHUB_HEAD_REF || runGit(cwd, ["branch", "--show-current"]),
|
|
59
|
+
tag: runGit(cwd, ["describe", "--tags", "--exact-match"]) || "-",
|
|
60
|
+
describe: runGit(cwd, ["describe", "--tags", "--always", "--dirty"]) || "-",
|
|
61
|
+
upstream: upstream || "-",
|
|
62
|
+
sync: upstream ? `ahead ${ahead || 0} / behind ${behind || 0}` : "-",
|
|
63
|
+
workspace: changedFiles ? `${changedFiles} changed` : "clean",
|
|
64
|
+
mode,
|
|
65
|
+
node: process.version,
|
|
66
|
+
platform: `${process.platform}/${process.arch}`,
|
|
67
|
+
buildTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
68
|
+
body: runGit(cwd, ["log", "-1", "--pretty=format:%B"]),
|
|
69
|
+
commits
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const serialize = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
|
73
|
+
const createClientCode = (info, defaultLimit, autoPrint, expanded) => `
|
|
74
|
+
(() => {
|
|
75
|
+
const info = ${serialize(info)};
|
|
76
|
+
const formatDateTime = (value) => {
|
|
77
|
+
if (!value) return '';
|
|
78
|
+
const date = new Date(value);
|
|
79
|
+
return Number.isNaN(date.getTime()) ? value : date.toLocaleString('zh-CN', { hour12: false });
|
|
80
|
+
};
|
|
81
|
+
const normalizeLimit = (value) => {
|
|
82
|
+
const number = Number(value);
|
|
83
|
+
return Number.isFinite(number) && number > 0 ? Math.min(Math.floor(number), info.commits.length) : ${defaultLimit};
|
|
84
|
+
};
|
|
85
|
+
window.__SYBZ_GIT_COMMIT_LOG__ = info;
|
|
86
|
+
window.b = (limit = ${defaultLimit}) => {
|
|
87
|
+
const commits = info.commits.slice(0, normalizeLimit(limit));
|
|
88
|
+
const latestCommit = commits[0] || info.commits[0] || {};
|
|
89
|
+
console.${expanded ? "group" : "groupCollapsed"}('[build git info]');
|
|
90
|
+
console.table({
|
|
91
|
+
authorName: latestCommit.authorName || '-',
|
|
92
|
+
buildTime: formatDateTime(info.buildTime),
|
|
93
|
+
mode: info.mode,
|
|
94
|
+
subject: latestCommit.message || '-',
|
|
95
|
+
branch: info.branch || '-',
|
|
96
|
+
tag: info.tag,
|
|
97
|
+
describe: info.describe,
|
|
98
|
+
shortHash: latestCommit.shortHash || '-',
|
|
99
|
+
authorDate: formatDateTime(latestCommit.committedAt),
|
|
100
|
+
upstream: info.upstream,
|
|
101
|
+
sync: info.sync,
|
|
102
|
+
workspace: info.workspace,
|
|
103
|
+
node: info.node,
|
|
104
|
+
platform: info.platform,
|
|
105
|
+
});
|
|
106
|
+
console.log('repository:', info.repository || '-');
|
|
107
|
+
console.log('body:\\n' + (info.body || '-'));
|
|
108
|
+
console.log('recentCommits:\\n' + commits.map((commit, index) =>
|
|
109
|
+
String(index + 1).padStart(2, '0') + '. ' + formatDateTime(commit.committedAt) + ' [' + commit.shortHash + '] ' + commit.authorName + ': ' + commit.message
|
|
110
|
+
).join('\\n'));
|
|
111
|
+
console.groupEnd();
|
|
112
|
+
return info;
|
|
113
|
+
};
|
|
114
|
+
${autoPrint ? `window.b(${typeof autoPrint === "number" ? autoPrint : defaultLimit});` : ""}
|
|
115
|
+
})();`;
|
|
116
|
+
const gitCommitLog = (options = {}) => {
|
|
117
|
+
const maxCommits = normalizePositiveInteger(options.maxCommits, 20);
|
|
118
|
+
const defaultLimit = Math.min(normalizePositiveInteger(options.defaultLimit, 10), maxCommits);
|
|
119
|
+
let viteRoot = process.cwd();
|
|
120
|
+
let viteMode = "development";
|
|
121
|
+
return {
|
|
122
|
+
name: "sybz-git-commit-log",
|
|
123
|
+
configResolved(config) {
|
|
124
|
+
viteRoot = config.root;
|
|
125
|
+
viteMode = config.mode;
|
|
126
|
+
},
|
|
127
|
+
transformIndexHtml: {
|
|
128
|
+
order: "pre",
|
|
129
|
+
handler() {
|
|
130
|
+
const cwd = node_path.resolve(options.cwd || viteRoot);
|
|
131
|
+
const info = createGitCommitLogInfo(cwd, maxCommits, viteMode);
|
|
132
|
+
return [
|
|
133
|
+
{
|
|
134
|
+
tag: "script",
|
|
135
|
+
children: createClientCode(info, defaultLimit, options.autoPrint ?? false, options.expanded ?? false),
|
|
136
|
+
injectTo: "head-prepend"
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
exports.gitCommitLog = gitCommitLog;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface GitCommitLogItem {
|
|
4
|
+
hash: string;
|
|
5
|
+
shortHash: string;
|
|
6
|
+
authorName: string;
|
|
7
|
+
authorEmail: string;
|
|
8
|
+
committedAt: string;
|
|
9
|
+
message: string;
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
interface GitCommitLogInfo {
|
|
13
|
+
project: string;
|
|
14
|
+
version: string;
|
|
15
|
+
repository: string;
|
|
16
|
+
branch: string;
|
|
17
|
+
tag: string;
|
|
18
|
+
describe: string;
|
|
19
|
+
upstream: string;
|
|
20
|
+
sync: string;
|
|
21
|
+
workspace: string;
|
|
22
|
+
mode: string;
|
|
23
|
+
node: string;
|
|
24
|
+
platform: string;
|
|
25
|
+
buildTime: string;
|
|
26
|
+
body: string;
|
|
27
|
+
commits: GitCommitLogItem[];
|
|
28
|
+
}
|
|
29
|
+
interface GitCommitLogOptions {
|
|
30
|
+
/** Git 仓库目录,默认使用 Vite 的 root。 */
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/** 构建时最多读取的提交数量,默认 20。 */
|
|
33
|
+
maxCommits?: number;
|
|
34
|
+
/** 调用 b() 时默认展示的提交数量,默认 10。 */
|
|
35
|
+
defaultLimit?: number;
|
|
36
|
+
/** 页面加载后自动打印;传数字时同时指定打印条数,默认 false。 */
|
|
37
|
+
autoPrint?: boolean | number;
|
|
38
|
+
/** 打印后是否默认展开控制台分组,默认 false。 */
|
|
39
|
+
expanded?: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare global {
|
|
42
|
+
function b(limit?: number): GitCommitLogInfo;
|
|
43
|
+
interface Window {
|
|
44
|
+
b: (limit?: number) => GitCommitLogInfo;
|
|
45
|
+
__SYBZ_GIT_COMMIT_LOG__: GitCommitLogInfo;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 为 Vite 项目注册 Git 提交记录调试工具。页面加载后可在控制台调用 `b()` 查看。
|
|
50
|
+
*/
|
|
51
|
+
declare const gitCommitLog: (options?: GitCommitLogOptions) => Plugin;
|
|
52
|
+
|
|
53
|
+
export { gitCommitLog };
|
|
54
|
+
export type { GitCommitLogInfo, GitCommitLogItem, GitCommitLogOptions };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface GitCommitLogItem {
|
|
4
|
+
hash: string;
|
|
5
|
+
shortHash: string;
|
|
6
|
+
authorName: string;
|
|
7
|
+
authorEmail: string;
|
|
8
|
+
committedAt: string;
|
|
9
|
+
message: string;
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
interface GitCommitLogInfo {
|
|
13
|
+
project: string;
|
|
14
|
+
version: string;
|
|
15
|
+
repository: string;
|
|
16
|
+
branch: string;
|
|
17
|
+
tag: string;
|
|
18
|
+
describe: string;
|
|
19
|
+
upstream: string;
|
|
20
|
+
sync: string;
|
|
21
|
+
workspace: string;
|
|
22
|
+
mode: string;
|
|
23
|
+
node: string;
|
|
24
|
+
platform: string;
|
|
25
|
+
buildTime: string;
|
|
26
|
+
body: string;
|
|
27
|
+
commits: GitCommitLogItem[];
|
|
28
|
+
}
|
|
29
|
+
interface GitCommitLogOptions {
|
|
30
|
+
/** Git 仓库目录,默认使用 Vite 的 root。 */
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/** 构建时最多读取的提交数量,默认 20。 */
|
|
33
|
+
maxCommits?: number;
|
|
34
|
+
/** 调用 b() 时默认展示的提交数量,默认 10。 */
|
|
35
|
+
defaultLimit?: number;
|
|
36
|
+
/** 页面加载后自动打印;传数字时同时指定打印条数,默认 false。 */
|
|
37
|
+
autoPrint?: boolean | number;
|
|
38
|
+
/** 打印后是否默认展开控制台分组,默认 false。 */
|
|
39
|
+
expanded?: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare global {
|
|
42
|
+
function b(limit?: number): GitCommitLogInfo;
|
|
43
|
+
interface Window {
|
|
44
|
+
b: (limit?: number) => GitCommitLogInfo;
|
|
45
|
+
__SYBZ_GIT_COMMIT_LOG__: GitCommitLogInfo;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 为 Vite 项目注册 Git 提交记录调试工具。页面加载后可在控制台调用 `b()` 查看。
|
|
50
|
+
*/
|
|
51
|
+
declare const gitCommitLog: (options?: GitCommitLogOptions) => Plugin;
|
|
52
|
+
|
|
53
|
+
export { gitCommitLog };
|
|
54
|
+
export type { GitCommitLogInfo, GitCommitLogItem, GitCommitLogOptions };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface GitCommitLogItem {
|
|
4
|
+
hash: string;
|
|
5
|
+
shortHash: string;
|
|
6
|
+
authorName: string;
|
|
7
|
+
authorEmail: string;
|
|
8
|
+
committedAt: string;
|
|
9
|
+
message: string;
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
interface GitCommitLogInfo {
|
|
13
|
+
project: string;
|
|
14
|
+
version: string;
|
|
15
|
+
repository: string;
|
|
16
|
+
branch: string;
|
|
17
|
+
tag: string;
|
|
18
|
+
describe: string;
|
|
19
|
+
upstream: string;
|
|
20
|
+
sync: string;
|
|
21
|
+
workspace: string;
|
|
22
|
+
mode: string;
|
|
23
|
+
node: string;
|
|
24
|
+
platform: string;
|
|
25
|
+
buildTime: string;
|
|
26
|
+
body: string;
|
|
27
|
+
commits: GitCommitLogItem[];
|
|
28
|
+
}
|
|
29
|
+
interface GitCommitLogOptions {
|
|
30
|
+
/** Git 仓库目录,默认使用 Vite 的 root。 */
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/** 构建时最多读取的提交数量,默认 20。 */
|
|
33
|
+
maxCommits?: number;
|
|
34
|
+
/** 调用 b() 时默认展示的提交数量,默认 10。 */
|
|
35
|
+
defaultLimit?: number;
|
|
36
|
+
/** 页面加载后自动打印;传数字时同时指定打印条数,默认 false。 */
|
|
37
|
+
autoPrint?: boolean | number;
|
|
38
|
+
/** 打印后是否默认展开控制台分组,默认 false。 */
|
|
39
|
+
expanded?: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare global {
|
|
42
|
+
function b(limit?: number): GitCommitLogInfo;
|
|
43
|
+
interface Window {
|
|
44
|
+
b: (limit?: number) => GitCommitLogInfo;
|
|
45
|
+
__SYBZ_GIT_COMMIT_LOG__: GitCommitLogInfo;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 为 Vite 项目注册 Git 提交记录调试工具。页面加载后可在控制台调用 `b()` 查看。
|
|
50
|
+
*/
|
|
51
|
+
declare const gitCommitLog: (options?: GitCommitLogOptions) => Plugin;
|
|
52
|
+
|
|
53
|
+
export { gitCommitLog };
|
|
54
|
+
export type { GitCommitLogInfo, GitCommitLogItem, GitCommitLogOptions };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const normalizePositiveInteger = (value, fallback) => {
|
|
6
|
+
const number = Number(value);
|
|
7
|
+
return Number.isFinite(number) && number > 0 ? Math.floor(number) : fallback;
|
|
8
|
+
};
|
|
9
|
+
const runGit = (cwd, args) => {
|
|
10
|
+
try {
|
|
11
|
+
return execFileSync("git", args, {
|
|
12
|
+
cwd,
|
|
13
|
+
encoding: "utf8",
|
|
14
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
15
|
+
}).trim();
|
|
16
|
+
} catch {
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const normalizeRepositoryUrl = (url) => url.trim().replace(/^git\+/, "").replace(/^git@([^:]+):/, "https://$1/").replace(/\.git$/, "");
|
|
21
|
+
const getCommitUrl = (repository, hash) => {
|
|
22
|
+
if (!repository || !hash) return "";
|
|
23
|
+
return `${repository}${/github\.com/i.test(repository) ? "/commit/" : "/-/commit/"}${hash}`;
|
|
24
|
+
};
|
|
25
|
+
const readProjectPackage = (cwd) => {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(readFileSync(resolve(cwd, "package.json"), "utf8"));
|
|
28
|
+
} catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const createGitCommitLogInfo = (cwd, maxCommits, mode) => {
|
|
33
|
+
const packageInfo = readProjectPackage(cwd);
|
|
34
|
+
const packageRepository = typeof packageInfo.repository === "string" ? packageInfo.repository : packageInfo.repository?.url || "";
|
|
35
|
+
const repository = normalizeRepositoryUrl(packageRepository || runGit(cwd, ["remote", "get-url", "origin"]));
|
|
36
|
+
const output = runGit(cwd, ["log", `-${maxCommits}`, "--pretty=format:%H%x1f%h%x1f%an%x1f%ae%x1f%aI%x1f%s"]);
|
|
37
|
+
const commits = output.split("\n").filter(Boolean).map((line) => {
|
|
38
|
+
const [hash = "", shortHash = "", authorName = "", authorEmail = "", committedAt = "", message = ""] = line.split("");
|
|
39
|
+
return {
|
|
40
|
+
hash,
|
|
41
|
+
shortHash,
|
|
42
|
+
authorName,
|
|
43
|
+
authorEmail,
|
|
44
|
+
committedAt,
|
|
45
|
+
message,
|
|
46
|
+
url: getCommitUrl(repository, hash)
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
const upstream = runGit(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]);
|
|
50
|
+
const [ahead = "0", behind = "0"] = upstream ? runGit(cwd, ["rev-list", "--left-right", "--count", `HEAD...${upstream}`]).split(/\s+/) : [];
|
|
51
|
+
const changedFiles = runGit(cwd, ["status", "--porcelain"]).split("\n").filter(Boolean).length;
|
|
52
|
+
return {
|
|
53
|
+
project: packageInfo.name || resolve(cwd).split("/").pop() || "",
|
|
54
|
+
version: packageInfo.version || "",
|
|
55
|
+
repository,
|
|
56
|
+
branch: process.env.GITHUB_REF_NAME || process.env.GITHUB_HEAD_REF || runGit(cwd, ["branch", "--show-current"]),
|
|
57
|
+
tag: runGit(cwd, ["describe", "--tags", "--exact-match"]) || "-",
|
|
58
|
+
describe: runGit(cwd, ["describe", "--tags", "--always", "--dirty"]) || "-",
|
|
59
|
+
upstream: upstream || "-",
|
|
60
|
+
sync: upstream ? `ahead ${ahead || 0} / behind ${behind || 0}` : "-",
|
|
61
|
+
workspace: changedFiles ? `${changedFiles} changed` : "clean",
|
|
62
|
+
mode,
|
|
63
|
+
node: process.version,
|
|
64
|
+
platform: `${process.platform}/${process.arch}`,
|
|
65
|
+
buildTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
66
|
+
body: runGit(cwd, ["log", "-1", "--pretty=format:%B"]),
|
|
67
|
+
commits
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const serialize = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
|
71
|
+
const createClientCode = (info, defaultLimit, autoPrint, expanded) => `
|
|
72
|
+
(() => {
|
|
73
|
+
const info = ${serialize(info)};
|
|
74
|
+
const formatDateTime = (value) => {
|
|
75
|
+
if (!value) return '';
|
|
76
|
+
const date = new Date(value);
|
|
77
|
+
return Number.isNaN(date.getTime()) ? value : date.toLocaleString('zh-CN', { hour12: false });
|
|
78
|
+
};
|
|
79
|
+
const normalizeLimit = (value) => {
|
|
80
|
+
const number = Number(value);
|
|
81
|
+
return Number.isFinite(number) && number > 0 ? Math.min(Math.floor(number), info.commits.length) : ${defaultLimit};
|
|
82
|
+
};
|
|
83
|
+
window.__SYBZ_GIT_COMMIT_LOG__ = info;
|
|
84
|
+
window.b = (limit = ${defaultLimit}) => {
|
|
85
|
+
const commits = info.commits.slice(0, normalizeLimit(limit));
|
|
86
|
+
const latestCommit = commits[0] || info.commits[0] || {};
|
|
87
|
+
console.${expanded ? "group" : "groupCollapsed"}('[build git info]');
|
|
88
|
+
console.table({
|
|
89
|
+
authorName: latestCommit.authorName || '-',
|
|
90
|
+
buildTime: formatDateTime(info.buildTime),
|
|
91
|
+
mode: info.mode,
|
|
92
|
+
subject: latestCommit.message || '-',
|
|
93
|
+
branch: info.branch || '-',
|
|
94
|
+
tag: info.tag,
|
|
95
|
+
describe: info.describe,
|
|
96
|
+
shortHash: latestCommit.shortHash || '-',
|
|
97
|
+
authorDate: formatDateTime(latestCommit.committedAt),
|
|
98
|
+
upstream: info.upstream,
|
|
99
|
+
sync: info.sync,
|
|
100
|
+
workspace: info.workspace,
|
|
101
|
+
node: info.node,
|
|
102
|
+
platform: info.platform,
|
|
103
|
+
});
|
|
104
|
+
console.log('repository:', info.repository || '-');
|
|
105
|
+
console.log('body:\\n' + (info.body || '-'));
|
|
106
|
+
console.log('recentCommits:\\n' + commits.map((commit, index) =>
|
|
107
|
+
String(index + 1).padStart(2, '0') + '. ' + formatDateTime(commit.committedAt) + ' [' + commit.shortHash + '] ' + commit.authorName + ': ' + commit.message
|
|
108
|
+
).join('\\n'));
|
|
109
|
+
console.groupEnd();
|
|
110
|
+
return info;
|
|
111
|
+
};
|
|
112
|
+
${autoPrint ? `window.b(${typeof autoPrint === "number" ? autoPrint : defaultLimit});` : ""}
|
|
113
|
+
})();`;
|
|
114
|
+
const gitCommitLog = (options = {}) => {
|
|
115
|
+
const maxCommits = normalizePositiveInteger(options.maxCommits, 20);
|
|
116
|
+
const defaultLimit = Math.min(normalizePositiveInteger(options.defaultLimit, 10), maxCommits);
|
|
117
|
+
let viteRoot = process.cwd();
|
|
118
|
+
let viteMode = "development";
|
|
119
|
+
return {
|
|
120
|
+
name: "sybz-git-commit-log",
|
|
121
|
+
configResolved(config) {
|
|
122
|
+
viteRoot = config.root;
|
|
123
|
+
viteMode = config.mode;
|
|
124
|
+
},
|
|
125
|
+
transformIndexHtml: {
|
|
126
|
+
order: "pre",
|
|
127
|
+
handler() {
|
|
128
|
+
const cwd = resolve(options.cwd || viteRoot);
|
|
129
|
+
const info = createGitCommitLogInfo(cwd, maxCommits, viteMode);
|
|
130
|
+
return [
|
|
131
|
+
{
|
|
132
|
+
tag: "script",
|
|
133
|
+
children: createClientCode(info, defaultLimit, options.autoPrint ?? false, options.expanded ?? false),
|
|
134
|
+
injectTo: "head-prepend"
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export { gitCommitLog };
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const format = require('./shared/utils.
|
|
3
|
+
const format = require('./shared/utils.CQ_8FikI.cjs');
|
|
4
4
|
const is = require('./is.cjs');
|
|
5
5
|
require('vue');
|
|
6
6
|
require('consola');
|
|
@@ -12,6 +12,7 @@ require('element-plus');
|
|
|
12
12
|
exports.$toast = format.$toast;
|
|
13
13
|
exports.clearStorage = format.clearStorage;
|
|
14
14
|
exports.clone = format.clone;
|
|
15
|
+
exports.configureUtils = format.configureUtils;
|
|
15
16
|
exports.confirm = format.confirm;
|
|
16
17
|
exports.copy = format.copy;
|
|
17
18
|
exports.debounce = format.debounce;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit } from './base.cjs';
|
|
1
|
+
export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant, SybzUtilsConfig, ToastOptions, UtilsTheme, clearStorage, clone, configureUtils, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit } from './base.cjs';
|
|
2
2
|
export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.cjs';
|
|
3
3
|
export { FormatBytesConvertOptions, FormatBytesOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions, formatBytes, formatBytesConvert, formatDurationTime, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.cjs';
|
|
4
4
|
import 'vue';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit } from './base.mjs';
|
|
1
|
+
export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant, SybzUtilsConfig, ToastOptions, UtilsTheme, clearStorage, clone, configureUtils, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit } from './base.mjs';
|
|
2
2
|
export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.mjs';
|
|
3
3
|
export { FormatBytesConvertOptions, FormatBytesOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions, formatBytes, formatBytesConvert, formatDurationTime, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.mjs';
|
|
4
4
|
import 'vue';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit } from './base.js';
|
|
1
|
+
export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTarget, ConfirmTheme, ConfirmVariant, SybzUtilsConfig, ToastOptions, UtilsTheme, clearStorage, clone, configureUtils, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit } from './base.js';
|
|
2
2
|
export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.js';
|
|
3
3
|
export { FormatBytesConvertOptions, FormatBytesOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions, formatBytes, formatBytesConvert, formatDurationTime, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.js';
|
|
4
4
|
import 'vue';
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { $ as $toast, c as clearStorage, a as clone, b as
|
|
1
|
+
export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.DvUjmqr2.mjs';
|
|
2
2
|
export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.mjs';
|
|
3
3
|
import 'vue';
|
|
4
4
|
import 'consola';
|
|
@@ -227,6 +227,15 @@ const CHENGHUA_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--chenghua";
|
|
|
227
227
|
const SHIJINGSHAN_CONFIRM_BOX_CLASS = "s-message-box--shijingshan";
|
|
228
228
|
const SHIJINGSHAN_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--shijingshan";
|
|
229
229
|
const SHIJINGSHAN_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--shijingshan";
|
|
230
|
+
const utilsConfig = {
|
|
231
|
+
theme: "default"
|
|
232
|
+
};
|
|
233
|
+
function configureUtils(config) {
|
|
234
|
+
if (config.theme !== void 0) {
|
|
235
|
+
utilsConfig.theme = config.theme;
|
|
236
|
+
}
|
|
237
|
+
return { ...utilsConfig };
|
|
238
|
+
}
|
|
230
239
|
function _getBrowserStorage(isSession = false) {
|
|
231
240
|
if (typeof window === "undefined") {
|
|
232
241
|
return null;
|
|
@@ -263,32 +272,31 @@ function $toast(message, type = "success", otherParams = {}) {
|
|
|
263
272
|
function isToastOptions(obj) {
|
|
264
273
|
return typeof obj === "object" && obj !== null;
|
|
265
274
|
}
|
|
266
|
-
|
|
267
|
-
|
|
275
|
+
function showToast(options) {
|
|
276
|
+
const { theme = utilsConfig.theme, customClass, ...messageOptions } = options;
|
|
277
|
+
if (options.closeAll) {
|
|
268
278
|
elementPlus.ElMessage.closeAll();
|
|
269
279
|
}
|
|
270
|
-
|
|
271
|
-
elementPlus.ElMessage(
|
|
280
|
+
const resolvedCustomClass = customClass === "el" ? "" : _mergeClassNames("s-antd-message", theme !== "default" && `s-antd-message--${theme}`, customClass);
|
|
281
|
+
elementPlus.ElMessage({
|
|
282
|
+
...messageOptions,
|
|
283
|
+
customClass: resolvedCustomClass
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
if (isToastOptions(message)) {
|
|
287
|
+
showToast(message);
|
|
272
288
|
return;
|
|
273
289
|
}
|
|
274
290
|
if (isToastOptions(type)) {
|
|
275
|
-
|
|
276
|
-
elementPlus.ElMessage.closeAll();
|
|
277
|
-
}
|
|
278
|
-
type.customClass = type.customClass === "el" ? "" : "s-antd-message";
|
|
279
|
-
elementPlus.ElMessage({
|
|
291
|
+
showToast({
|
|
280
292
|
message,
|
|
281
293
|
type: "success",
|
|
282
294
|
...type
|
|
283
295
|
});
|
|
284
296
|
return;
|
|
285
297
|
}
|
|
286
|
-
if (otherParams.closeAll) {
|
|
287
|
-
elementPlus.ElMessage.closeAll();
|
|
288
|
-
}
|
|
289
298
|
const resolvedType = isShortType(type) ? typeMap[type] : type;
|
|
290
|
-
|
|
291
|
-
elementPlus.ElMessage({
|
|
299
|
+
showToast({
|
|
292
300
|
message,
|
|
293
301
|
type: resolvedType,
|
|
294
302
|
...otherParams
|
|
@@ -944,7 +952,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
944
952
|
const argumentAppContext = isOptionsCall ? optionsOrAppContext : appContext;
|
|
945
953
|
const {
|
|
946
954
|
message: _message,
|
|
947
|
-
theme,
|
|
955
|
+
theme = utilsConfig.theme,
|
|
948
956
|
variant = "default",
|
|
949
957
|
target,
|
|
950
958
|
customClass,
|
|
@@ -955,7 +963,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
955
963
|
...messageBoxOptions
|
|
956
964
|
} = options;
|
|
957
965
|
const inputMessage = typeof message === "function" ? message() : message;
|
|
958
|
-
const resolvedMessage = variant === "delete" && target !== void 0 && !inputMessage ? `\u786E\u8BA4\u8981\u5220\u9664<code type="danger">${_escapeHtml(target)}</code>\u5417
|
|
966
|
+
const resolvedMessage = variant === "delete" && target !== void 0 && !inputMessage ? `\u786E\u8BA4\u8981\u5220\u9664<code type="danger">${_escapeHtml(target)}</code>\u5417\uFF1F\u5220\u9664\u540E\u4E0D\u53EF\u6062\u590D\u3002` : inputMessage;
|
|
959
967
|
const resolvedAppendTo = _resolveAppendTarget(appendTo);
|
|
960
968
|
const resolvedAppContext = _resolveAppContext(optionAppContext || argumentAppContext);
|
|
961
969
|
const isChenghuaTheme = theme === "chenghua";
|
|
@@ -1058,7 +1066,7 @@ function getVariable(propertyName, fallback = "") {
|
|
|
1058
1066
|
const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
|
|
1059
1067
|
function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
|
|
1060
1068
|
{
|
|
1061
|
-
return "2026-08-
|
|
1069
|
+
return "2026-08-18 17:59:46";
|
|
1062
1070
|
}
|
|
1063
1071
|
}
|
|
1064
1072
|
function test() {
|
|
@@ -1068,6 +1076,7 @@ function test() {
|
|
|
1068
1076
|
exports.$toast = $toast;
|
|
1069
1077
|
exports.clearStorage = clearStorage;
|
|
1070
1078
|
exports.clone = clone;
|
|
1079
|
+
exports.configureUtils = configureUtils;
|
|
1071
1080
|
exports.confirm = confirm;
|
|
1072
1081
|
exports.copy = copy;
|
|
1073
1082
|
exports.debounce = debounce;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isRef, unref, isVNode, toRaw } from 'vue';
|
|
2
2
|
import { consola } from 'consola';
|
|
3
3
|
import { cloneDeep } from 'es-toolkit';
|
|
4
|
-
import {
|
|
4
|
+
import { ElMessageBox, ElMessage } from 'element-plus';
|
|
5
5
|
import { isStringNumber, isNumber } from '../is.mjs';
|
|
6
6
|
|
|
7
7
|
function formatBytes(bytes, options = {}) {
|
|
@@ -225,6 +225,15 @@ const CHENGHUA_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--chenghua";
|
|
|
225
225
|
const SHIJINGSHAN_CONFIRM_BOX_CLASS = "s-message-box--shijingshan";
|
|
226
226
|
const SHIJINGSHAN_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--shijingshan";
|
|
227
227
|
const SHIJINGSHAN_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--shijingshan";
|
|
228
|
+
const utilsConfig = {
|
|
229
|
+
theme: "default"
|
|
230
|
+
};
|
|
231
|
+
function configureUtils(config) {
|
|
232
|
+
if (config.theme !== void 0) {
|
|
233
|
+
utilsConfig.theme = config.theme;
|
|
234
|
+
}
|
|
235
|
+
return { ...utilsConfig };
|
|
236
|
+
}
|
|
228
237
|
function _getBrowserStorage(isSession = false) {
|
|
229
238
|
if (typeof window === "undefined") {
|
|
230
239
|
return null;
|
|
@@ -261,32 +270,31 @@ function $toast(message, type = "success", otherParams = {}) {
|
|
|
261
270
|
function isToastOptions(obj) {
|
|
262
271
|
return typeof obj === "object" && obj !== null;
|
|
263
272
|
}
|
|
264
|
-
|
|
265
|
-
|
|
273
|
+
function showToast(options) {
|
|
274
|
+
const { theme = utilsConfig.theme, customClass, ...messageOptions } = options;
|
|
275
|
+
if (options.closeAll) {
|
|
266
276
|
ElMessage.closeAll();
|
|
267
277
|
}
|
|
268
|
-
|
|
269
|
-
ElMessage(
|
|
278
|
+
const resolvedCustomClass = customClass === "el" ? "" : _mergeClassNames("s-antd-message", theme !== "default" && `s-antd-message--${theme}`, customClass);
|
|
279
|
+
ElMessage({
|
|
280
|
+
...messageOptions,
|
|
281
|
+
customClass: resolvedCustomClass
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if (isToastOptions(message)) {
|
|
285
|
+
showToast(message);
|
|
270
286
|
return;
|
|
271
287
|
}
|
|
272
288
|
if (isToastOptions(type)) {
|
|
273
|
-
|
|
274
|
-
ElMessage.closeAll();
|
|
275
|
-
}
|
|
276
|
-
type.customClass = type.customClass === "el" ? "" : "s-antd-message";
|
|
277
|
-
ElMessage({
|
|
289
|
+
showToast({
|
|
278
290
|
message,
|
|
279
291
|
type: "success",
|
|
280
292
|
...type
|
|
281
293
|
});
|
|
282
294
|
return;
|
|
283
295
|
}
|
|
284
|
-
if (otherParams.closeAll) {
|
|
285
|
-
ElMessage.closeAll();
|
|
286
|
-
}
|
|
287
296
|
const resolvedType = isShortType(type) ? typeMap[type] : type;
|
|
288
|
-
|
|
289
|
-
ElMessage({
|
|
297
|
+
showToast({
|
|
290
298
|
message,
|
|
291
299
|
type: resolvedType,
|
|
292
300
|
...otherParams
|
|
@@ -942,7 +950,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
942
950
|
const argumentAppContext = isOptionsCall ? optionsOrAppContext : appContext;
|
|
943
951
|
const {
|
|
944
952
|
message: _message,
|
|
945
|
-
theme,
|
|
953
|
+
theme = utilsConfig.theme,
|
|
946
954
|
variant = "default",
|
|
947
955
|
target,
|
|
948
956
|
customClass,
|
|
@@ -953,7 +961,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
953
961
|
...messageBoxOptions
|
|
954
962
|
} = options;
|
|
955
963
|
const inputMessage = typeof message === "function" ? message() : message;
|
|
956
|
-
const resolvedMessage = variant === "delete" && target !== void 0 && !inputMessage ? `\u786E\u8BA4\u8981\u5220\u9664<code type="danger">${_escapeHtml(target)}</code>\u5417
|
|
964
|
+
const resolvedMessage = variant === "delete" && target !== void 0 && !inputMessage ? `\u786E\u8BA4\u8981\u5220\u9664<code type="danger">${_escapeHtml(target)}</code>\u5417\uFF1F\u5220\u9664\u540E\u4E0D\u53EF\u6062\u590D\u3002` : inputMessage;
|
|
957
965
|
const resolvedAppendTo = _resolveAppendTarget(appendTo);
|
|
958
966
|
const resolvedAppContext = _resolveAppContext(optionAppContext || argumentAppContext);
|
|
959
967
|
const isChenghuaTheme = theme === "chenghua";
|
|
@@ -1056,11 +1064,11 @@ function getVariable(propertyName, fallback = "") {
|
|
|
1056
1064
|
const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
|
|
1057
1065
|
function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
|
|
1058
1066
|
{
|
|
1059
|
-
return "2026-08-
|
|
1067
|
+
return "2026-08-18 17:59:46";
|
|
1060
1068
|
}
|
|
1061
1069
|
}
|
|
1062
1070
|
function test() {
|
|
1063
1071
|
return `build time: ${getUtilsBuildTime()}`;
|
|
1064
1072
|
}
|
|
1065
1073
|
|
|
1066
|
-
export { $toast as $,
|
|
1074
|
+
export { $toast as $, formatBytesConvert as A, formatDurationTime as B, formatTextToHtml as C, formatThousands as D, formatTime as E, formatToFixed as F, clone as a, configureUtils as b, clearStorage as c, confirm as d, copy as e, debounce as f, delay as g, getStorage as h, getType as i, getUtilsBuildTime as j, getVariable as k, isEmpty as l, log as m, merge as n, mockValue as o, processWidth as p, throttle as q, random as r, setStorage as s, test as t, toLine as u, tryCatch as v, validate as w, validateForm as x, validateOnSubmit as y, formatBytes as z };
|
package/dist/vite.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const codeInspectorPlugin = require('code-inspector-plugin');
|
|
4
|
+
const gitCommitLog = require('./gitCommitLog.cjs');
|
|
5
|
+
require('node:child_process');
|
|
6
|
+
require('node:fs');
|
|
7
|
+
require('node:path');
|
|
8
|
+
|
|
9
|
+
const createCodeInspector = (options = {}) => codeInspectorPlugin.codeInspectorPlugin({ ...options, bundler: "vite" });
|
|
10
|
+
const formatBuildTime = (date) => {
|
|
11
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
12
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(
|
|
13
|
+
date.getMinutes()
|
|
14
|
+
)}:${pad(date.getSeconds())}`;
|
|
15
|
+
};
|
|
16
|
+
const createBuildTime = (metaName = "buildTime") => {
|
|
17
|
+
const buildTime = formatBuildTime(/* @__PURE__ */ new Date());
|
|
18
|
+
return {
|
|
19
|
+
name: "sybz-build-time",
|
|
20
|
+
transformIndexHtml: {
|
|
21
|
+
order: "pre",
|
|
22
|
+
handler() {
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
tag: "meta",
|
|
26
|
+
attrs: { name: metaName, content: buildTime },
|
|
27
|
+
injectTo: "head-prepend"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
tag: "script",
|
|
31
|
+
children: `window.__SYBZ_BUILD_TIME__ = ${JSON.stringify(buildTime)};`,
|
|
32
|
+
injectTo: "head-prepend"
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const sybzVitePlugins = (options = {}) => {
|
|
40
|
+
const plugins = [];
|
|
41
|
+
if (options.codeInspector !== false) {
|
|
42
|
+
plugins.push(createCodeInspector(typeof options.codeInspector === "object" ? options.codeInspector : {}));
|
|
43
|
+
}
|
|
44
|
+
if (options.gitCommitLog !== false) {
|
|
45
|
+
plugins.push(gitCommitLog.gitCommitLog(typeof options.gitCommitLog === "object" ? options.gitCommitLog : {}));
|
|
46
|
+
}
|
|
47
|
+
if (options.buildTime !== false) {
|
|
48
|
+
plugins.push(createBuildTime(typeof options.buildTime === "object" ? options.buildTime.metaName : void 0));
|
|
49
|
+
}
|
|
50
|
+
return plugins;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.sybzVitePlugins = sybzVitePlugins;
|
package/dist/vite.d.cts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CodeInspectorPluginOptions } from 'code-inspector-plugin';
|
|
2
|
+
import { Plugin } from 'vite';
|
|
3
|
+
import { GitCommitLogOptions } from './gitCommitLog.cjs';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
__SYBZ_BUILD_TIME__: string;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
type SybzCodeInspectorOptions = Omit<CodeInspectorPluginOptions, 'bundler'>;
|
|
11
|
+
interface SybzVitePluginsOptions {
|
|
12
|
+
/** 代码定位插件配置;默认启用,设为 false 时关闭。 */
|
|
13
|
+
codeInspector?: boolean | SybzCodeInspectorOptions;
|
|
14
|
+
/** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
|
|
15
|
+
gitCommitLog?: boolean | GitCommitLogOptions;
|
|
16
|
+
/** 打包时间注入配置;默认启用,设为 false 时关闭。 */
|
|
17
|
+
buildTime?: boolean | {
|
|
18
|
+
metaName?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** 创建 sybz 项目的 Vite 插件预设,默认包含代码定位和 Git 提交信息。 */
|
|
22
|
+
declare const sybzVitePlugins: (options?: SybzVitePluginsOptions) => Plugin[];
|
|
23
|
+
|
|
24
|
+
export { sybzVitePlugins };
|
|
25
|
+
export type { SybzCodeInspectorOptions, SybzVitePluginsOptions };
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CodeInspectorPluginOptions } from 'code-inspector-plugin';
|
|
2
|
+
import { Plugin } from 'vite';
|
|
3
|
+
import { GitCommitLogOptions } from './gitCommitLog.mjs';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
__SYBZ_BUILD_TIME__: string;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
type SybzCodeInspectorOptions = Omit<CodeInspectorPluginOptions, 'bundler'>;
|
|
11
|
+
interface SybzVitePluginsOptions {
|
|
12
|
+
/** 代码定位插件配置;默认启用,设为 false 时关闭。 */
|
|
13
|
+
codeInspector?: boolean | SybzCodeInspectorOptions;
|
|
14
|
+
/** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
|
|
15
|
+
gitCommitLog?: boolean | GitCommitLogOptions;
|
|
16
|
+
/** 打包时间注入配置;默认启用,设为 false 时关闭。 */
|
|
17
|
+
buildTime?: boolean | {
|
|
18
|
+
metaName?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** 创建 sybz 项目的 Vite 插件预设,默认包含代码定位和 Git 提交信息。 */
|
|
22
|
+
declare const sybzVitePlugins: (options?: SybzVitePluginsOptions) => Plugin[];
|
|
23
|
+
|
|
24
|
+
export { sybzVitePlugins };
|
|
25
|
+
export type { SybzCodeInspectorOptions, SybzVitePluginsOptions };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CodeInspectorPluginOptions } from 'code-inspector-plugin';
|
|
2
|
+
import { Plugin } from 'vite';
|
|
3
|
+
import { GitCommitLogOptions } from './gitCommitLog.js';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
__SYBZ_BUILD_TIME__: string;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
type SybzCodeInspectorOptions = Omit<CodeInspectorPluginOptions, 'bundler'>;
|
|
11
|
+
interface SybzVitePluginsOptions {
|
|
12
|
+
/** 代码定位插件配置;默认启用,设为 false 时关闭。 */
|
|
13
|
+
codeInspector?: boolean | SybzCodeInspectorOptions;
|
|
14
|
+
/** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
|
|
15
|
+
gitCommitLog?: boolean | GitCommitLogOptions;
|
|
16
|
+
/** 打包时间注入配置;默认启用,设为 false 时关闭。 */
|
|
17
|
+
buildTime?: boolean | {
|
|
18
|
+
metaName?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** 创建 sybz 项目的 Vite 插件预设,默认包含代码定位和 Git 提交信息。 */
|
|
22
|
+
declare const sybzVitePlugins: (options?: SybzVitePluginsOptions) => Plugin[];
|
|
23
|
+
|
|
24
|
+
export { sybzVitePlugins };
|
|
25
|
+
export type { SybzCodeInspectorOptions, SybzVitePluginsOptions };
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { codeInspectorPlugin } from 'code-inspector-plugin';
|
|
2
|
+
import { gitCommitLog } from './gitCommitLog.mjs';
|
|
3
|
+
import 'node:child_process';
|
|
4
|
+
import 'node:fs';
|
|
5
|
+
import 'node:path';
|
|
6
|
+
|
|
7
|
+
const createCodeInspector = (options = {}) => codeInspectorPlugin({ ...options, bundler: "vite" });
|
|
8
|
+
const formatBuildTime = (date) => {
|
|
9
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
10
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(
|
|
11
|
+
date.getMinutes()
|
|
12
|
+
)}:${pad(date.getSeconds())}`;
|
|
13
|
+
};
|
|
14
|
+
const createBuildTime = (metaName = "buildTime") => {
|
|
15
|
+
const buildTime = formatBuildTime(/* @__PURE__ */ new Date());
|
|
16
|
+
return {
|
|
17
|
+
name: "sybz-build-time",
|
|
18
|
+
transformIndexHtml: {
|
|
19
|
+
order: "pre",
|
|
20
|
+
handler() {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
tag: "meta",
|
|
24
|
+
attrs: { name: metaName, content: buildTime },
|
|
25
|
+
injectTo: "head-prepend"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
tag: "script",
|
|
29
|
+
children: `window.__SYBZ_BUILD_TIME__ = ${JSON.stringify(buildTime)};`,
|
|
30
|
+
injectTo: "head-prepend"
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const sybzVitePlugins = (options = {}) => {
|
|
38
|
+
const plugins = [];
|
|
39
|
+
if (options.codeInspector !== false) {
|
|
40
|
+
plugins.push(createCodeInspector(typeof options.codeInspector === "object" ? options.codeInspector : {}));
|
|
41
|
+
}
|
|
42
|
+
if (options.gitCommitLog !== false) {
|
|
43
|
+
plugins.push(gitCommitLog(typeof options.gitCommitLog === "object" ? options.gitCommitLog : {}));
|
|
44
|
+
}
|
|
45
|
+
if (options.buildTime !== false) {
|
|
46
|
+
plugins.push(createBuildTime(typeof options.buildTime === "object" ? options.buildTime.metaName : void 0));
|
|
47
|
+
}
|
|
48
|
+
return plugins;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { sybzVitePlugins };
|
package/package.json
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sybz-components/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "utils of sybz-components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./gitCommitLog": {
|
|
17
|
+
"types": "./dist/gitCommitLog.d.ts",
|
|
18
|
+
"import": "./dist/gitCommitLog.mjs",
|
|
19
|
+
"require": "./dist/gitCommitLog.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./vite": {
|
|
22
|
+
"types": "./dist/vite.d.ts",
|
|
23
|
+
"import": "./dist/vite.mjs",
|
|
24
|
+
"require": "./dist/vite.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./*": {
|
|
27
|
+
"types": "./dist/*.d.ts",
|
|
28
|
+
"import": "./dist/*.mjs",
|
|
29
|
+
"require": "./dist/*.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
10
32
|
"files": [
|
|
11
33
|
"dist"
|
|
12
34
|
],
|
|
@@ -26,10 +48,14 @@
|
|
|
26
48
|
"dependencies": {
|
|
27
49
|
"@vue/reactivity": "^3.5.18",
|
|
28
50
|
"@vue/shared": "^3.5.18",
|
|
51
|
+
"code-inspector-plugin": "^0.10.1",
|
|
29
52
|
"consola": "^3.4.2",
|
|
30
53
|
"element-plus": "^2.11.5",
|
|
31
54
|
"es-toolkit": "^1.39.10",
|
|
32
55
|
"lodash-es": "^4.17.21",
|
|
33
56
|
"vue": "3.4.15"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"vite": ">=5 <8"
|
|
34
60
|
}
|
|
35
61
|
}
|