@umijs/utils 4.0.0-canary.20230309.4 → 4.0.0-canary.20230314.1
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/getFileGitIno.d.ts +47 -0
- package/dist/getFileGitIno.js +130 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/dist/zod/zod2string.d.ts +0 -2
- package/dist/zod/zod2string.js +0 -49
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface ICreateInfo {
|
|
2
|
+
createTime?: string;
|
|
3
|
+
creator?: string;
|
|
4
|
+
creatorEmail?: string;
|
|
5
|
+
createSince?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IModifyInfo {
|
|
8
|
+
modifyTime?: string;
|
|
9
|
+
modifier?: string;
|
|
10
|
+
modifierEmail?: string;
|
|
11
|
+
modifySince?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 获取文件创建信息
|
|
15
|
+
* @param filePath 文件路径,绝对或相对 .git
|
|
16
|
+
* @param gitDirPath .git路径
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare const getFileCreateInfo: (filePath: string, gitDirPath?: string) => Promise<{
|
|
20
|
+
createTime: string | undefined;
|
|
21
|
+
creator: string | undefined;
|
|
22
|
+
creatorEmail: string | undefined;
|
|
23
|
+
createSince: string | undefined;
|
|
24
|
+
} | {
|
|
25
|
+
createTime?: undefined;
|
|
26
|
+
creator?: undefined;
|
|
27
|
+
creatorEmail?: undefined;
|
|
28
|
+
createSince?: undefined;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* 获取文件最新修改信息
|
|
32
|
+
* @param filePath 文件路径,绝对或相对 .git
|
|
33
|
+
* @param gitDirPath .git路径
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export declare const getFileLastModifyInfo: (filePath: string, gitDirPath?: string) => Promise<{
|
|
37
|
+
modifyTime: string | undefined;
|
|
38
|
+
modifier: string | undefined;
|
|
39
|
+
modifierEmail: string | undefined;
|
|
40
|
+
modifySince: string | undefined;
|
|
41
|
+
} | {
|
|
42
|
+
modifyTime?: undefined;
|
|
43
|
+
modifier?: undefined;
|
|
44
|
+
modifierEmail?: undefined;
|
|
45
|
+
modifySince?: undefined;
|
|
46
|
+
}>;
|
|
47
|
+
export declare const isGitRepo: () => Promise<boolean>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/getFileGitIno.ts
|
|
30
|
+
var getFileGitIno_exports = {};
|
|
31
|
+
__export(getFileGitIno_exports, {
|
|
32
|
+
getFileCreateInfo: () => getFileCreateInfo,
|
|
33
|
+
getFileLastModifyInfo: () => getFileLastModifyInfo,
|
|
34
|
+
isGitRepo: () => isGitRepo
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(getFileGitIno_exports);
|
|
37
|
+
var import_cross_spawn = __toESM(require("cross-spawn"));
|
|
38
|
+
var import_execa = require("../compiled/execa");
|
|
39
|
+
var promisifySpawn = (cmd, args, {
|
|
40
|
+
onlyOnce,
|
|
41
|
+
...rest
|
|
42
|
+
}) => new Promise((resolve, reject) => {
|
|
43
|
+
var _a;
|
|
44
|
+
const cp = (0, import_cross_spawn.default)(cmd, args, rest);
|
|
45
|
+
const error = [];
|
|
46
|
+
const stdout = [];
|
|
47
|
+
(_a = cp.stdout) == null ? void 0 : _a.on("data", (data) => {
|
|
48
|
+
stdout.push(data.toString());
|
|
49
|
+
if (onlyOnce) {
|
|
50
|
+
cp.kill("SIGKILL");
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
cp.on("error", (e) => {
|
|
54
|
+
error.push(e.toString());
|
|
55
|
+
});
|
|
56
|
+
cp.on("close", () => {
|
|
57
|
+
if (error.length) {
|
|
58
|
+
reject(error.join(""));
|
|
59
|
+
} else {
|
|
60
|
+
resolve(stdout);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
var getFileCreateInfo = async (filePath, gitDirPath) => {
|
|
65
|
+
try {
|
|
66
|
+
const info = await promisifySpawn(
|
|
67
|
+
"git",
|
|
68
|
+
// time|name|email|since
|
|
69
|
+
["log", "--reverse", "-1000000", "--pretty='%ad|%an|%ae|%ar'", filePath],
|
|
70
|
+
{
|
|
71
|
+
cwd: gitDirPath,
|
|
72
|
+
onlyOnce: true,
|
|
73
|
+
shell: true
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
if (info.length && info[0]) {
|
|
77
|
+
const firstCommit = info[0].slice(0, info[0].indexOf("\n")).split("|");
|
|
78
|
+
return {
|
|
79
|
+
createTime: firstCommit.at(0),
|
|
80
|
+
creator: firstCommit.at(1),
|
|
81
|
+
creatorEmail: firstCommit.at(2),
|
|
82
|
+
createSince: firstCommit.at(3)
|
|
83
|
+
};
|
|
84
|
+
} else {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
} catch (err) {
|
|
88
|
+
throw new Error(`get file ${filePath} git info failed`);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var getFileLastModifyInfo = async (filePath, gitDirPath) => {
|
|
92
|
+
try {
|
|
93
|
+
const info = await promisifySpawn(
|
|
94
|
+
"git",
|
|
95
|
+
["log", "-1", "--pretty='%ad|%an|%ae|%ar'", filePath],
|
|
96
|
+
{
|
|
97
|
+
cwd: gitDirPath,
|
|
98
|
+
onlyOnce: true,
|
|
99
|
+
shell: true
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
if (info.length && info[0]) {
|
|
103
|
+
const firstCommit = info[0].slice(0, info[0].indexOf("\n")).split("|");
|
|
104
|
+
return {
|
|
105
|
+
modifyTime: firstCommit.at(0),
|
|
106
|
+
modifier: firstCommit.at(1),
|
|
107
|
+
modifierEmail: firstCommit.at(2),
|
|
108
|
+
modifySince: firstCommit.at(3)
|
|
109
|
+
};
|
|
110
|
+
} else {
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {
|
|
114
|
+
throw new Error(`get file ${filePath} git info failed`);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var isGitRepo = async () => {
|
|
118
|
+
try {
|
|
119
|
+
const res = await (0, import_execa.execa)("git", ["rev-parse", "--is-inside-work-tree"]);
|
|
120
|
+
return res.stdout.includes("true");
|
|
121
|
+
} catch (e) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
getFileCreateInfo,
|
|
128
|
+
getFileLastModifyInfo,
|
|
129
|
+
isGitRepo
|
|
130
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ import updatePackageJSON from './updatePackageJSON';
|
|
|
38
38
|
export * as aliasUtils from './aliasUtils';
|
|
39
39
|
export * from './getCorejsVersion';
|
|
40
40
|
export * from './getDevBanner';
|
|
41
|
+
export * as git from './getFileGitIno';
|
|
41
42
|
export * from './importLazy';
|
|
42
43
|
export * from './isLocalDev';
|
|
43
44
|
export * from './isMonorepo';
|
|
@@ -50,5 +51,4 @@ export * from './setNoDeprecation';
|
|
|
50
51
|
export * from './tryPaths';
|
|
51
52
|
export * from './winPath';
|
|
52
53
|
export * from './zod/isZodSchema';
|
|
53
|
-
export * from './zod/zod2string';
|
|
54
54
|
export { address, axios, chalk, cheerio, chokidar, crossSpawn, debug, deepmerge, execa, fsExtra, glob, Generator, BaseGenerator, generateFile, installDeps, lodash, logger, Mustache, pkgUp, portfinder, prompts, resolve, rimraf, semver, stripAnsi, updatePackageJSON, yParser, getGitInfo, printHelp, filesize, gzipSize, fastestLevenshtein, clackPrompts, MagicString, remapping, tsconfigPaths, z as zod, };
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ __export(src_exports, {
|
|
|
50
50
|
fsExtra: () => import_fs_extra.default,
|
|
51
51
|
generateFile: () => import_generateFile.default,
|
|
52
52
|
getGitInfo: () => import_getGitInfo.default,
|
|
53
|
+
git: () => git,
|
|
53
54
|
glob: () => import_glob.default,
|
|
54
55
|
gzipSize: () => gzipSize,
|
|
55
56
|
installDeps: () => import_installDeps.default,
|
|
@@ -111,6 +112,7 @@ var import_updatePackageJSON = __toESM(require("./updatePackageJSON"));
|
|
|
111
112
|
var aliasUtils = __toESM(require("./aliasUtils"));
|
|
112
113
|
__reExport(src_exports, require("./getCorejsVersion"), module.exports);
|
|
113
114
|
__reExport(src_exports, require("./getDevBanner"), module.exports);
|
|
115
|
+
var git = __toESM(require("./getFileGitIno"));
|
|
114
116
|
__reExport(src_exports, require("./importLazy"), module.exports);
|
|
115
117
|
__reExport(src_exports, require("./isLocalDev"), module.exports);
|
|
116
118
|
__reExport(src_exports, require("./isMonorepo"), module.exports);
|
|
@@ -123,7 +125,6 @@ __reExport(src_exports, require("./setNoDeprecation"), module.exports);
|
|
|
123
125
|
__reExport(src_exports, require("./tryPaths"), module.exports);
|
|
124
126
|
__reExport(src_exports, require("./winPath"), module.exports);
|
|
125
127
|
__reExport(src_exports, require("./zod/isZodSchema"), module.exports);
|
|
126
|
-
__reExport(src_exports, require("./zod/zod2string"), module.exports);
|
|
127
128
|
// Annotate the CommonJS export names for ESM import in node:
|
|
128
129
|
0 && (module.exports = {
|
|
129
130
|
BaseGenerator,
|
|
@@ -146,6 +147,7 @@ __reExport(src_exports, require("./zod/zod2string"), module.exports);
|
|
|
146
147
|
fsExtra,
|
|
147
148
|
generateFile,
|
|
148
149
|
getGitInfo,
|
|
150
|
+
git,
|
|
149
151
|
glob,
|
|
150
152
|
gzipSize,
|
|
151
153
|
installDeps,
|
package/package.json
CHANGED
package/dist/zod/zod2string.d.ts
DELETED
package/dist/zod/zod2string.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/zod/zod2string.ts
|
|
20
|
-
var zod2string_exports = {};
|
|
21
|
-
__export(zod2string_exports, {
|
|
22
|
-
zod2string: () => zod2string
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(zod2string_exports);
|
|
25
|
-
var import_zod = require("../../compiled/zod");
|
|
26
|
-
function zod2string(schema) {
|
|
27
|
-
if (schema instanceof import_zod.z.ZodObject) {
|
|
28
|
-
const keys = Object.keys(schema.shape);
|
|
29
|
-
const properties = keys.map((key) => `${key}: ${zod2string(schema.shape[key])}`).join(", ");
|
|
30
|
-
return `z.object({${properties}})`;
|
|
31
|
-
} else if (schema instanceof import_zod.z.ZodArray) {
|
|
32
|
-
return `z.array(${zod2string(schema._def.type)})`;
|
|
33
|
-
} else if (schema instanceof import_zod.z.ZodOptional) {
|
|
34
|
-
return `z.optional(${zod2string(schema._def.innerType)})`;
|
|
35
|
-
} else {
|
|
36
|
-
const { typeName, checks } = schema._def;
|
|
37
|
-
let str = `z.${typeName.replace("Zod", "").toLowerCase()}()`;
|
|
38
|
-
if (checks && checks.length > 0) {
|
|
39
|
-
checks.forEach((i) => {
|
|
40
|
-
str += `.${i.kind}(${(i == null ? void 0 : i.value) || ""})`;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return str;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
-
0 && (module.exports = {
|
|
48
|
-
zod2string
|
|
49
|
-
});
|