@sybz-components/utils 1.0.4 → 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/base.cjs +1 -1
- 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 +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/{utils.C2MJOkBA.mjs → utils.Cwn0z-Ga.mjs} +1 -1
- package/dist/shared/{utils.D-aYhNvS.cjs → utils.x_syVt5c.cjs} +1 -1
- package/dist/vite.cjs +21 -0
- package/dist/vite.d.cts +16 -0
- package/dist/vite.d.mts +16 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.mjs +19 -0
- package/package.json +27 -1
package/dist/base.cjs
CHANGED
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 confirm, d as copy, e as debounce, f as delay, g as getStorage, h as getType, i as getUtilsBuildTime, j as getVariable, k as isEmpty, l as log, m as merge, n as mockValue, p as processWidth, r as random, s as setStorage, t as test, o as throttle, q as toLine, u as tryCatch, v as validate, w as validateForm, x as validateOnSubmit } from './shared/utils.
|
|
4
|
+
export { $ as $toast, c as clearStorage, a as clone, b as confirm, d as copy, e as debounce, f as delay, g as getStorage, h as getType, i as getUtilsBuildTime, j as getVariable, k as isEmpty, l as log, m as merge, n as mockValue, p as processWidth, r as random, s as setStorage, t as test, o as throttle, q as toLine, u as tryCatch, v as validate, w as validateForm, x as validateOnSubmit } from './shared/utils.Cwn0z-Ga.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 { y as formatBytes, z as formatBytesConvert, A as formatDurationTime, B as formatTextToHtml, C as formatThousands, D as formatTime, E as formatToFixed } from './shared/utils.
|
|
1
|
+
export { y as formatBytes, z as formatBytesConvert, A as formatDurationTime, B as formatTextToHtml, C as formatThousands, D as formatTime, E as formatToFixed } from './shared/utils.Cwn0z-Ga.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
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { $ as $toast, c as clearStorage, a as clone, b as confirm, d as copy, e as debounce, f as delay, y as formatBytes, z as formatBytesConvert, A as formatDurationTime, B as formatTextToHtml, C as formatThousands, D as formatTime, E as formatToFixed, g as getStorage, h as getType, i as getUtilsBuildTime, j as getVariable, k as isEmpty, l as log, m as merge, n as mockValue, p as processWidth, r as random, s as setStorage, t as test, o as throttle, q as toLine, u as tryCatch, v as validate, w as validateForm, x as validateOnSubmit } from './shared/utils.
|
|
1
|
+
export { $ as $toast, c as clearStorage, a as clone, b as confirm, d as copy, e as debounce, f as delay, y as formatBytes, z as formatBytesConvert, A as formatDurationTime, B as formatTextToHtml, C as formatThousands, D as formatTime, E as formatToFixed, g as getStorage, h as getType, i as getUtilsBuildTime, j as getVariable, k as isEmpty, l as log, m as merge, n as mockValue, p as processWidth, r as random, s as setStorage, t as test, o as throttle, q as toLine, u as tryCatch, v as validate, w as validateForm, x as validateOnSubmit } from './shared/utils.Cwn0z-Ga.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';
|
|
@@ -1056,7 +1056,7 @@ function getVariable(propertyName, fallback = "") {
|
|
|
1056
1056
|
const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
|
|
1057
1057
|
function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
|
|
1058
1058
|
{
|
|
1059
|
-
return "2026-08-
|
|
1059
|
+
return "2026-08-17 14:41:44";
|
|
1060
1060
|
}
|
|
1061
1061
|
}
|
|
1062
1062
|
function test() {
|
|
@@ -1058,7 +1058,7 @@ function getVariable(propertyName, fallback = "") {
|
|
|
1058
1058
|
const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
|
|
1059
1059
|
function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
|
|
1060
1060
|
{
|
|
1061
|
-
return "2026-08-
|
|
1061
|
+
return "2026-08-17 14:41:44";
|
|
1062
1062
|
}
|
|
1063
1063
|
}
|
|
1064
1064
|
function test() {
|
package/dist/vite.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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 sybzVitePlugins = (options = {}) => {
|
|
11
|
+
const plugins = [];
|
|
12
|
+
if (options.codeInspector !== false) {
|
|
13
|
+
plugins.push(createCodeInspector(typeof options.codeInspector === "object" ? options.codeInspector : {}));
|
|
14
|
+
}
|
|
15
|
+
if (options.gitCommitLog !== false) {
|
|
16
|
+
plugins.push(gitCommitLog.gitCommitLog(typeof options.gitCommitLog === "object" ? options.gitCommitLog : {}));
|
|
17
|
+
}
|
|
18
|
+
return plugins;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.sybzVitePlugins = sybzVitePlugins;
|
package/dist/vite.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CodeInspectorPluginOptions } from 'code-inspector-plugin';
|
|
2
|
+
import { Plugin } from 'vite';
|
|
3
|
+
import { GitCommitLogOptions } from './gitCommitLog.cjs';
|
|
4
|
+
|
|
5
|
+
type SybzCodeInspectorOptions = Omit<CodeInspectorPluginOptions, 'bundler'>;
|
|
6
|
+
interface SybzVitePluginsOptions {
|
|
7
|
+
/** 代码定位插件配置;默认启用,设为 false 时关闭。 */
|
|
8
|
+
codeInspector?: boolean | SybzCodeInspectorOptions;
|
|
9
|
+
/** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
|
|
10
|
+
gitCommitLog?: boolean | GitCommitLogOptions;
|
|
11
|
+
}
|
|
12
|
+
/** 创建 sybz 项目的 Vite 插件预设,默认包含代码定位和 Git 提交信息。 */
|
|
13
|
+
declare const sybzVitePlugins: (options?: SybzVitePluginsOptions) => Plugin[];
|
|
14
|
+
|
|
15
|
+
export { sybzVitePlugins };
|
|
16
|
+
export type { SybzCodeInspectorOptions, SybzVitePluginsOptions };
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CodeInspectorPluginOptions } from 'code-inspector-plugin';
|
|
2
|
+
import { Plugin } from 'vite';
|
|
3
|
+
import { GitCommitLogOptions } from './gitCommitLog.mjs';
|
|
4
|
+
|
|
5
|
+
type SybzCodeInspectorOptions = Omit<CodeInspectorPluginOptions, 'bundler'>;
|
|
6
|
+
interface SybzVitePluginsOptions {
|
|
7
|
+
/** 代码定位插件配置;默认启用,设为 false 时关闭。 */
|
|
8
|
+
codeInspector?: boolean | SybzCodeInspectorOptions;
|
|
9
|
+
/** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
|
|
10
|
+
gitCommitLog?: boolean | GitCommitLogOptions;
|
|
11
|
+
}
|
|
12
|
+
/** 创建 sybz 项目的 Vite 插件预设,默认包含代码定位和 Git 提交信息。 */
|
|
13
|
+
declare const sybzVitePlugins: (options?: SybzVitePluginsOptions) => Plugin[];
|
|
14
|
+
|
|
15
|
+
export { sybzVitePlugins };
|
|
16
|
+
export type { SybzCodeInspectorOptions, SybzVitePluginsOptions };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CodeInspectorPluginOptions } from 'code-inspector-plugin';
|
|
2
|
+
import { Plugin } from 'vite';
|
|
3
|
+
import { GitCommitLogOptions } from './gitCommitLog.js';
|
|
4
|
+
|
|
5
|
+
type SybzCodeInspectorOptions = Omit<CodeInspectorPluginOptions, 'bundler'>;
|
|
6
|
+
interface SybzVitePluginsOptions {
|
|
7
|
+
/** 代码定位插件配置;默认启用,设为 false 时关闭。 */
|
|
8
|
+
codeInspector?: boolean | SybzCodeInspectorOptions;
|
|
9
|
+
/** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
|
|
10
|
+
gitCommitLog?: boolean | GitCommitLogOptions;
|
|
11
|
+
}
|
|
12
|
+
/** 创建 sybz 项目的 Vite 插件预设,默认包含代码定位和 Git 提交信息。 */
|
|
13
|
+
declare const sybzVitePlugins: (options?: SybzVitePluginsOptions) => Plugin[];
|
|
14
|
+
|
|
15
|
+
export { sybzVitePlugins };
|
|
16
|
+
export type { SybzCodeInspectorOptions, SybzVitePluginsOptions };
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 sybzVitePlugins = (options = {}) => {
|
|
9
|
+
const plugins = [];
|
|
10
|
+
if (options.codeInspector !== false) {
|
|
11
|
+
plugins.push(createCodeInspector(typeof options.codeInspector === "object" ? options.codeInspector : {}));
|
|
12
|
+
}
|
|
13
|
+
if (options.gitCommitLog !== false) {
|
|
14
|
+
plugins.push(gitCommitLog(typeof options.gitCommitLog === "object" ? options.gitCommitLog : {}));
|
|
15
|
+
}
|
|
16
|
+
return plugins;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
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.6",
|
|
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
|
}
|