@peiyanlu/cli-utils 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1237 -0
- package/dist/index.d.cts +523 -0
- package/dist/index.d.mts +523 -0
- package/dist/index.mjs +1133 -0
- package/package.json +9 -5
- package/dist/cjs/index.cjs +0 -308
- package/dist/cjs/index.d.cts +0 -94
- package/dist/esm/index.d.mts +0 -94
- package/dist/esm/index.mjs +0 -275
package/package.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peiyanlu/cli-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Shared utils for building interactive Node.js CLI applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"private": false,
|
|
8
|
-
"main": "./dist/cjs/index.cjs",
|
|
9
|
-
"types": "./dist/cjs/index.d.cts",
|
|
10
8
|
"exports": {
|
|
11
9
|
".": {
|
|
12
|
-
"import":
|
|
13
|
-
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
14
18
|
},
|
|
15
19
|
"./package.json": "./package.json"
|
|
16
20
|
},
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
let node_child_process = require("node:child_process");
|
|
2
|
-
let node_fs = require("node:fs");
|
|
3
|
-
let node_fs_promises = require("node:fs/promises");
|
|
4
|
-
let node_os = require("node:os");
|
|
5
|
-
let node_path = require("node:path");
|
|
6
|
-
let node_util = require("node:util");
|
|
7
|
-
|
|
8
|
-
//#region src/enums.ts
|
|
9
|
-
let PkgManager = /* @__PURE__ */ function(PkgManager$1) {
|
|
10
|
-
PkgManager$1["NPM"] = "npm";
|
|
11
|
-
PkgManager$1["YARN"] = "yarn";
|
|
12
|
-
PkgManager$1["PNPM"] = "pnpm";
|
|
13
|
-
return PkgManager$1;
|
|
14
|
-
}({});
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated Use `ConfirmResult` instead.
|
|
17
|
-
*/
|
|
18
|
-
let YesOrNo = /* @__PURE__ */ function(YesOrNo$1) {
|
|
19
|
-
YesOrNo$1["Yes"] = "yes";
|
|
20
|
-
YesOrNo$1["No"] = "no";
|
|
21
|
-
YesOrNo$1["Ignore"] = "ignore";
|
|
22
|
-
return YesOrNo$1;
|
|
23
|
-
}({});
|
|
24
|
-
let ConfirmResult = /* @__PURE__ */ function(ConfirmResult$1) {
|
|
25
|
-
ConfirmResult$1["YES"] = "yes";
|
|
26
|
-
ConfirmResult$1["NO"] = "no";
|
|
27
|
-
ConfirmResult$1["IGNORE"] = "ignore";
|
|
28
|
-
return ConfirmResult$1;
|
|
29
|
-
}({});
|
|
30
|
-
let HttpLibrary = /* @__PURE__ */ function(HttpLibrary$1) {
|
|
31
|
-
HttpLibrary$1["EXPRESS"] = "express";
|
|
32
|
-
HttpLibrary$1["FASTIFY"] = "fastify";
|
|
33
|
-
HttpLibrary$1["KOA"] = "koa";
|
|
34
|
-
HttpLibrary$1["HONO"] = "hono";
|
|
35
|
-
return HttpLibrary$1;
|
|
36
|
-
}({});
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/utils.ts
|
|
40
|
-
const isValidPackageName = (packageName) => {
|
|
41
|
-
return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(packageName);
|
|
42
|
-
};
|
|
43
|
-
const toValidPackageName = (packageName) => packageName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z\d\-~]+/g, "-");
|
|
44
|
-
const toValidProjectName = (projectName) => projectName.trim().replace(/\/+$/g, "");
|
|
45
|
-
const emptyDir = async (dir, ignore = []) => {
|
|
46
|
-
if (!(0, node_fs.existsSync)(dir)) return false;
|
|
47
|
-
for (const file of await (0, node_fs_promises.readdir)(dir)) {
|
|
48
|
-
if (ignore.includes(file)) continue;
|
|
49
|
-
await (0, node_fs_promises.rm)((0, node_path.resolve)(dir, file), {
|
|
50
|
-
recursive: true,
|
|
51
|
-
force: true
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
};
|
|
56
|
-
const isEmpty = async (path, ignore = []) => {
|
|
57
|
-
return (await (0, node_fs_promises.readdir)(path)).filter((f) => !ignore.includes(f)).length === 0;
|
|
58
|
-
};
|
|
59
|
-
const editFile = async (file, callback) => {
|
|
60
|
-
if (!(0, node_fs.existsSync)(file)) return;
|
|
61
|
-
return (0, node_fs_promises.writeFile)(file, callback(await (0, node_fs_promises.readFile)(file, "utf-8")), "utf-8");
|
|
62
|
-
};
|
|
63
|
-
const editJsonFile = (file, callback) => {
|
|
64
|
-
return editFile(file, (str) => {
|
|
65
|
-
try {
|
|
66
|
-
const json = JSON.parse(str);
|
|
67
|
-
callback(json);
|
|
68
|
-
return JSON.stringify(json, null, 2);
|
|
69
|
-
} catch (e) {
|
|
70
|
-
console.error(e);
|
|
71
|
-
return str;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
const readSubDirs = async (source, ignore = []) => {
|
|
76
|
-
return (await (0, node_fs_promises.readdir)(source, { withFileTypes: true })).filter((k) => k.isDirectory() && !ignore.includes(k.name)).map((dir) => dir.name);
|
|
77
|
-
};
|
|
78
|
-
const copyDirAsync = async (src, dest, options) => {
|
|
79
|
-
await (0, node_fs_promises.mkdir)(dest, { recursive: true });
|
|
80
|
-
const entries = await (0, node_fs_promises.readdir)(src, { withFileTypes: true });
|
|
81
|
-
for (const entry of entries) {
|
|
82
|
-
const name = entry.name;
|
|
83
|
-
const isDir = entry.isDirectory();
|
|
84
|
-
const { rename = {}, skips = [] } = options;
|
|
85
|
-
const relName = rename[name] ?? name;
|
|
86
|
-
if (skips.some((rule) => rule(name, isDir))) continue;
|
|
87
|
-
const from = (0, node_path.join)(src, name);
|
|
88
|
-
const to = (0, node_path.join)(dest, relName);
|
|
89
|
-
if (isDir) await copyDirAsync(from, to, options);
|
|
90
|
-
else await (0, node_fs_promises.copyFile)(from, to);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const readJsonFile = (file) => {
|
|
94
|
-
if (!(0, node_fs.existsSync)(file)) return {};
|
|
95
|
-
try {
|
|
96
|
-
return JSON.parse((0, node_fs.readFileSync)(file, "utf-8"));
|
|
97
|
-
} catch (e) {
|
|
98
|
-
return {};
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
/** 通过包管理器执行脚本时生效 UserAgent: `process.env.npm_config_user_agent` */
|
|
102
|
-
const pkgFromUserAgent = (userAgent) => {
|
|
103
|
-
if (!userAgent) return void 0;
|
|
104
|
-
const [name, version] = userAgent.split(" ")[0].split("/");
|
|
105
|
-
return {
|
|
106
|
-
name,
|
|
107
|
-
version
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
/** 同步执行 Node CLI(用于测试环境) */
|
|
111
|
-
const runCliForTest = (path, args, options) => {
|
|
112
|
-
return (0, node_child_process.spawnSync)("node", [path, ...args], {
|
|
113
|
-
env: {
|
|
114
|
-
...process.env,
|
|
115
|
-
_VITE_TEST_CLI: "true"
|
|
116
|
-
},
|
|
117
|
-
encoding: "utf-8",
|
|
118
|
-
...options
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
/** 判断测试文件(夹) */
|
|
122
|
-
const isTestFile = (name) => {
|
|
123
|
-
return [
|
|
124
|
-
/(^|[\\/])(test(s?)|__test(s?)__)([\\/]|$)/,
|
|
125
|
-
/\.([a-zA-Z0-9]+-)?(test|spec)\.m?(ts|js)$/,
|
|
126
|
-
/^vitest([-.])(.*)\.m?(ts|js)$/
|
|
127
|
-
].some((reg) => reg.test(name));
|
|
128
|
-
};
|
|
129
|
-
/** 解析 Github 链接获取 owner 和 repo */
|
|
130
|
-
const parseGitHubRepo = (url) => {
|
|
131
|
-
const match = url.trim().match(/github(?:\.com)?[:/](.+?)\/(.+?)(?:[#/?].+?)?(?:\.git)?$/);
|
|
132
|
-
return match ? match.slice(1, 3) : [];
|
|
133
|
-
};
|
|
134
|
-
/** 基于 EOL 的可多换行函数 */
|
|
135
|
-
const eol = (n = 1) => node_os.EOL.repeat(n);
|
|
136
|
-
|
|
137
|
-
//#endregion
|
|
138
|
-
//#region src/shell.ts
|
|
139
|
-
const dim = (text) => (0, node_util.styleText)(["dim"], text);
|
|
140
|
-
const red = (text) => (0, node_util.styleText)(["red"], text);
|
|
141
|
-
const yellow = (text) => (0, node_util.styleText)(["yellow"], text);
|
|
142
|
-
const underline = (text) => (0, node_util.styleText)(["underline"], text);
|
|
143
|
-
const spawnAsync = (cmd, args, options) => {
|
|
144
|
-
return new Promise((resolve$1) => {
|
|
145
|
-
const { trim, error, dryRun, ...others } = options ?? {};
|
|
146
|
-
const fullCmd = [cmd, ...args].join(" ");
|
|
147
|
-
if (dryRun) {
|
|
148
|
-
console.log(`${dim("[dry-run]")} ${fullCmd}`);
|
|
149
|
-
return resolve$1(void 0);
|
|
150
|
-
}
|
|
151
|
-
const child = (0, node_child_process.spawn)(cmd, args, { ...others });
|
|
152
|
-
let stdout = "";
|
|
153
|
-
child.stdout?.setEncoding("utf-8");
|
|
154
|
-
child.stdout?.on("data", (data) => stdout += trim ? data.trim() : data);
|
|
155
|
-
let stderr = "";
|
|
156
|
-
child.stderr?.setEncoding("utf-8");
|
|
157
|
-
child.stderr?.on("data", (data) => stderr += trim ? data.trim() : data);
|
|
158
|
-
child.on("close", (code) => {
|
|
159
|
-
if (stderr) {
|
|
160
|
-
const err = `${red("spawnAsync")} ${dim(fullCmd)} ${stderr}`;
|
|
161
|
-
switch (error) {
|
|
162
|
-
case "log":
|
|
163
|
-
console.error(err);
|
|
164
|
-
break;
|
|
165
|
-
case "throw": throw new Error(err);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
resolve$1(0 === code ? stdout : void 0);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
const execAsync = (cmd, options) => {
|
|
173
|
-
return new Promise((resolve$1) => {
|
|
174
|
-
const { trim, dryRun, error, ...others } = options ?? {};
|
|
175
|
-
if (dryRun) {
|
|
176
|
-
console.log(`${dim("[dry-run]")} ${cmd}`);
|
|
177
|
-
return resolve$1(void 0);
|
|
178
|
-
}
|
|
179
|
-
(0, node_child_process.exec)(cmd, { ...others }, (err, stdout) => {
|
|
180
|
-
if (err) {
|
|
181
|
-
const msg = `${red("execAsync")} ${dim(cmd)} ${err.message}`;
|
|
182
|
-
switch (error) {
|
|
183
|
-
case "log":
|
|
184
|
-
console.error(msg);
|
|
185
|
-
break;
|
|
186
|
-
case "throw": throw new Error(msg);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
resolve$1(err ? void 0 : trim ? stdout.trim() : stdout);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
const runGit = async (args, options = { trim: true }) => {
|
|
194
|
-
return spawnAsync("git", args, options);
|
|
195
|
-
};
|
|
196
|
-
const runNpm = (args, options = { trim: true }) => {
|
|
197
|
-
return execAsync(["npm", ...args].join(" "), options);
|
|
198
|
-
};
|
|
199
|
-
const fixArgs = (args) => args.trim() ? args.trim().split(" ") : [];
|
|
200
|
-
const checkVersion = async (cmd) => {
|
|
201
|
-
return execAsync(`${cmd} --version`);
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
//#endregion
|
|
205
|
-
//#region src/joinUrl.ts
|
|
206
|
-
function joinUrl(input) {
|
|
207
|
-
const temps = Array.isArray(input) ? input : [...arguments];
|
|
208
|
-
if (temps.length === 0) return "";
|
|
209
|
-
const result = [];
|
|
210
|
-
const parts = [...temps];
|
|
211
|
-
/** 协议正则 */
|
|
212
|
-
const PROTOCOL_RE = /^[^/:]+:\/*$/;
|
|
213
|
-
const FILE_PROTOCOL_RE = /^file:\/\/\//;
|
|
214
|
-
if (PROTOCOL_RE.test(parts[0]) && parts.length > 1) {
|
|
215
|
-
parts[1] = parts[0] + parts[1];
|
|
216
|
-
parts.shift();
|
|
217
|
-
}
|
|
218
|
-
if (FILE_PROTOCOL_RE.test(parts[0])) parts[0] = parts[0].replace(/^([^/:]+):\/*/, "$1:///");
|
|
219
|
-
else parts[0] = parts[0].replace(/^([^/:]+):\/*/, "$1://");
|
|
220
|
-
parts.forEach((part, index) => {
|
|
221
|
-
if (!part) return;
|
|
222
|
-
let segment = part;
|
|
223
|
-
if (index > 0) segment = segment.replace(/^\/+/, "");
|
|
224
|
-
if (index < parts.length - 1) segment = segment.replace(/\/+$/, "");
|
|
225
|
-
else segment = segment.replace(/\/+$/, "/");
|
|
226
|
-
result.push(segment);
|
|
227
|
-
});
|
|
228
|
-
let url = result.join("/");
|
|
229
|
-
url = url.replace(/\/(\?|&|#[^!])/g, "$1");
|
|
230
|
-
const [base, ...queryParts] = url.split("?");
|
|
231
|
-
url = base + (queryParts.length ? "?" + queryParts.join("&") : "");
|
|
232
|
-
return url;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/git.ts
|
|
237
|
-
const isGitRepo = async (dir) => {
|
|
238
|
-
return !!await runGit([
|
|
239
|
-
"-C",
|
|
240
|
-
dir ? `./${dir}` : ".",
|
|
241
|
-
"rev-parse",
|
|
242
|
-
"--is-inside-work-tree"
|
|
243
|
-
]);
|
|
244
|
-
};
|
|
245
|
-
const getGitConfig = (key, global = true) => {
|
|
246
|
-
return runGit([
|
|
247
|
-
"config",
|
|
248
|
-
...global ? ["--global"] : [],
|
|
249
|
-
key
|
|
250
|
-
]);
|
|
251
|
-
};
|
|
252
|
-
const getGitRemoteUrl = async (remoteName = "origin") => {
|
|
253
|
-
return runGit([
|
|
254
|
-
"remote",
|
|
255
|
-
"get-url",
|
|
256
|
-
remoteName
|
|
257
|
-
]).catch((_) => runGit([
|
|
258
|
-
"config",
|
|
259
|
-
"--get",
|
|
260
|
-
`remote.${remoteName}.url`
|
|
261
|
-
]));
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/npm.ts
|
|
266
|
-
const pkgVersion = (pkg) => {
|
|
267
|
-
return runNpm([
|
|
268
|
-
"view",
|
|
269
|
-
pkg,
|
|
270
|
-
"version"
|
|
271
|
-
]);
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
//#endregion
|
|
275
|
-
exports.ConfirmResult = ConfirmResult;
|
|
276
|
-
exports.HttpLibrary = HttpLibrary;
|
|
277
|
-
exports.PkgManager = PkgManager;
|
|
278
|
-
exports.YesOrNo = YesOrNo;
|
|
279
|
-
exports.checkVersion = checkVersion;
|
|
280
|
-
exports.copyDirAsync = copyDirAsync;
|
|
281
|
-
exports.dim = dim;
|
|
282
|
-
exports.editFile = editFile;
|
|
283
|
-
exports.editJsonFile = editJsonFile;
|
|
284
|
-
exports.emptyDir = emptyDir;
|
|
285
|
-
exports.eol = eol;
|
|
286
|
-
exports.execAsync = execAsync;
|
|
287
|
-
exports.fixArgs = fixArgs;
|
|
288
|
-
exports.getGitConfig = getGitConfig;
|
|
289
|
-
exports.getGitRemoteUrl = getGitRemoteUrl;
|
|
290
|
-
exports.isEmpty = isEmpty;
|
|
291
|
-
exports.isGitRepo = isGitRepo;
|
|
292
|
-
exports.isTestFile = isTestFile;
|
|
293
|
-
exports.isValidPackageName = isValidPackageName;
|
|
294
|
-
exports.joinUrl = joinUrl;
|
|
295
|
-
exports.parseGitHubRepo = parseGitHubRepo;
|
|
296
|
-
exports.pkgFromUserAgent = pkgFromUserAgent;
|
|
297
|
-
exports.pkgVersion = pkgVersion;
|
|
298
|
-
exports.readJsonFile = readJsonFile;
|
|
299
|
-
exports.readSubDirs = readSubDirs;
|
|
300
|
-
exports.red = red;
|
|
301
|
-
exports.runCliForTest = runCliForTest;
|
|
302
|
-
exports.runGit = runGit;
|
|
303
|
-
exports.runNpm = runNpm;
|
|
304
|
-
exports.spawnAsync = spawnAsync;
|
|
305
|
-
exports.toValidPackageName = toValidPackageName;
|
|
306
|
-
exports.toValidProjectName = toValidProjectName;
|
|
307
|
-
exports.underline = underline;
|
|
308
|
-
exports.yellow = yellow;
|
package/dist/cjs/index.d.cts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import * as child_process0 from "child_process";
|
|
2
|
-
import { ExecOptions, SpawnOptions, SpawnSyncOptionsWithStringEncoding } from "child_process";
|
|
3
|
-
|
|
4
|
-
//#region src/enums.d.ts
|
|
5
|
-
declare enum PkgManager {
|
|
6
|
-
NPM = "npm",
|
|
7
|
-
YARN = "yarn",
|
|
8
|
-
PNPM = "pnpm",
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Use `ConfirmResult` instead.
|
|
12
|
-
*/
|
|
13
|
-
declare enum YesOrNo {
|
|
14
|
-
Yes = "yes",
|
|
15
|
-
No = "no",
|
|
16
|
-
Ignore = "ignore",
|
|
17
|
-
}
|
|
18
|
-
declare enum ConfirmResult {
|
|
19
|
-
YES = "yes",
|
|
20
|
-
NO = "no",
|
|
21
|
-
IGNORE = "ignore",
|
|
22
|
-
}
|
|
23
|
-
declare enum HttpLibrary {
|
|
24
|
-
EXPRESS = "express",
|
|
25
|
-
FASTIFY = "fastify",
|
|
26
|
-
KOA = "koa",
|
|
27
|
-
HONO = "hono",
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/types.d.ts
|
|
31
|
-
interface CopyOptions {
|
|
32
|
-
rename?: Record<string, string>;
|
|
33
|
-
skips?: ((name: string, isDir: boolean) => boolean)[];
|
|
34
|
-
}
|
|
35
|
-
type CliOptions<T = string | boolean> = Record<string, T>;
|
|
36
|
-
interface PkgInfo {
|
|
37
|
-
name: string;
|
|
38
|
-
version: string;
|
|
39
|
-
}
|
|
40
|
-
interface ExecResultOptions {
|
|
41
|
-
trim?: boolean;
|
|
42
|
-
dryRun?: boolean;
|
|
43
|
-
error?: 'log' | 'throw' | 'ignore';
|
|
44
|
-
}
|
|
45
|
-
type SpawnAsyncOptions<T = SpawnOptions> = T & ExecResultOptions;
|
|
46
|
-
type ExecAsyncOptions<T = ExecOptions> = T & ExecResultOptions;
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/utils.d.ts
|
|
49
|
-
declare const isValidPackageName: (packageName: string) => boolean;
|
|
50
|
-
declare const toValidPackageName: (packageName: string) => string;
|
|
51
|
-
declare const toValidProjectName: (projectName: string) => string;
|
|
52
|
-
declare const emptyDir: (dir: string, ignore?: string[]) => Promise<boolean>;
|
|
53
|
-
declare const isEmpty: (path: string, ignore?: string[]) => Promise<boolean>;
|
|
54
|
-
declare const editFile: (file: string, callback: (content: string) => string) => Promise<void>;
|
|
55
|
-
declare const editJsonFile: <T extends Record<string, any>>(file: string, callback: (json: T) => void) => Promise<void>;
|
|
56
|
-
declare const readSubDirs: (source: string, ignore?: string[]) => Promise<string[]>;
|
|
57
|
-
declare const copyDirAsync: (src: string, dest: string, options: CopyOptions) => Promise<void>;
|
|
58
|
-
declare const readJsonFile: <T extends Record<string, any>>(file: string) => T;
|
|
59
|
-
/** 通过包管理器执行脚本时生效 UserAgent: `process.env.npm_config_user_agent` */
|
|
60
|
-
declare const pkgFromUserAgent: (userAgent: string | undefined) => PkgInfo | undefined;
|
|
61
|
-
/** 同步执行 Node CLI(用于测试环境) */
|
|
62
|
-
declare const runCliForTest: (path: string, args: string[], options?: SpawnSyncOptionsWithStringEncoding) => child_process0.SpawnSyncReturns<string>;
|
|
63
|
-
/** 判断测试文件(夹) */
|
|
64
|
-
declare const isTestFile: (name: string) => boolean;
|
|
65
|
-
/** 解析 Github 链接获取 owner 和 repo */
|
|
66
|
-
declare const parseGitHubRepo: (url: string) => string[];
|
|
67
|
-
/** 基于 EOL 的可多换行函数 */
|
|
68
|
-
declare const eol: (n?: number) => string;
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/shell.d.ts
|
|
71
|
-
declare const dim: (text: string) => string;
|
|
72
|
-
declare const red: (text: string) => string;
|
|
73
|
-
declare const yellow: (text: string) => string;
|
|
74
|
-
declare const underline: (text: string) => string;
|
|
75
|
-
declare const spawnAsync: <T = SpawnOptions>(cmd: string, args: string[], options?: SpawnAsyncOptions<T>) => Promise<string | undefined>;
|
|
76
|
-
declare const execAsync: <T = ExecOptions>(cmd: string, options?: ExecAsyncOptions<T>) => Promise<string | undefined>;
|
|
77
|
-
declare const runGit: (args: string[], options?: SpawnAsyncOptions) => Promise<string | undefined>;
|
|
78
|
-
declare const runNpm: (args: string[], options?: ExecAsyncOptions) => Promise<string | undefined>;
|
|
79
|
-
declare const fixArgs: (args: string) => string[];
|
|
80
|
-
declare const checkVersion: (cmd: string) => Promise<string | undefined>;
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/joinUrl.d.ts
|
|
83
|
-
declare function joinUrl(...args: string[]): string;
|
|
84
|
-
declare function joinUrl(input: readonly string[]): string;
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region src/git.d.ts
|
|
87
|
-
declare const isGitRepo: (dir?: string) => Promise<boolean>;
|
|
88
|
-
declare const getGitConfig: (key: string, global?: boolean) => Promise<string | undefined>;
|
|
89
|
-
declare const getGitRemoteUrl: (remoteName?: string) => Promise<string | undefined>;
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/npm.d.ts
|
|
92
|
-
declare const pkgVersion: (pkg: string) => Promise<string | undefined>;
|
|
93
|
-
//#endregion
|
|
94
|
-
export { CliOptions, ConfirmResult, CopyOptions, ExecAsyncOptions, ExecResultOptions, HttpLibrary, PkgInfo, PkgManager, SpawnAsyncOptions, YesOrNo, checkVersion, copyDirAsync, dim, editFile, editJsonFile, emptyDir, eol, execAsync, fixArgs, getGitConfig, getGitRemoteUrl, isEmpty, isGitRepo, isTestFile, isValidPackageName, joinUrl, parseGitHubRepo, pkgFromUserAgent, pkgVersion, readJsonFile, readSubDirs, red, runCliForTest, runGit, runNpm, spawnAsync, toValidPackageName, toValidProjectName, underline, yellow };
|
package/dist/esm/index.d.mts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import * as child_process0 from "child_process";
|
|
2
|
-
import { ExecOptions, SpawnOptions, SpawnSyncOptionsWithStringEncoding } from "child_process";
|
|
3
|
-
|
|
4
|
-
//#region src/enums.d.ts
|
|
5
|
-
declare enum PkgManager {
|
|
6
|
-
NPM = "npm",
|
|
7
|
-
YARN = "yarn",
|
|
8
|
-
PNPM = "pnpm",
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Use `ConfirmResult` instead.
|
|
12
|
-
*/
|
|
13
|
-
declare enum YesOrNo {
|
|
14
|
-
Yes = "yes",
|
|
15
|
-
No = "no",
|
|
16
|
-
Ignore = "ignore",
|
|
17
|
-
}
|
|
18
|
-
declare enum ConfirmResult {
|
|
19
|
-
YES = "yes",
|
|
20
|
-
NO = "no",
|
|
21
|
-
IGNORE = "ignore",
|
|
22
|
-
}
|
|
23
|
-
declare enum HttpLibrary {
|
|
24
|
-
EXPRESS = "express",
|
|
25
|
-
FASTIFY = "fastify",
|
|
26
|
-
KOA = "koa",
|
|
27
|
-
HONO = "hono",
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/types.d.ts
|
|
31
|
-
interface CopyOptions {
|
|
32
|
-
rename?: Record<string, string>;
|
|
33
|
-
skips?: ((name: string, isDir: boolean) => boolean)[];
|
|
34
|
-
}
|
|
35
|
-
type CliOptions<T = string | boolean> = Record<string, T>;
|
|
36
|
-
interface PkgInfo {
|
|
37
|
-
name: string;
|
|
38
|
-
version: string;
|
|
39
|
-
}
|
|
40
|
-
interface ExecResultOptions {
|
|
41
|
-
trim?: boolean;
|
|
42
|
-
dryRun?: boolean;
|
|
43
|
-
error?: 'log' | 'throw' | 'ignore';
|
|
44
|
-
}
|
|
45
|
-
type SpawnAsyncOptions<T = SpawnOptions> = T & ExecResultOptions;
|
|
46
|
-
type ExecAsyncOptions<T = ExecOptions> = T & ExecResultOptions;
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/utils.d.ts
|
|
49
|
-
declare const isValidPackageName: (packageName: string) => boolean;
|
|
50
|
-
declare const toValidPackageName: (packageName: string) => string;
|
|
51
|
-
declare const toValidProjectName: (projectName: string) => string;
|
|
52
|
-
declare const emptyDir: (dir: string, ignore?: string[]) => Promise<boolean>;
|
|
53
|
-
declare const isEmpty: (path: string, ignore?: string[]) => Promise<boolean>;
|
|
54
|
-
declare const editFile: (file: string, callback: (content: string) => string) => Promise<void>;
|
|
55
|
-
declare const editJsonFile: <T extends Record<string, any>>(file: string, callback: (json: T) => void) => Promise<void>;
|
|
56
|
-
declare const readSubDirs: (source: string, ignore?: string[]) => Promise<string[]>;
|
|
57
|
-
declare const copyDirAsync: (src: string, dest: string, options: CopyOptions) => Promise<void>;
|
|
58
|
-
declare const readJsonFile: <T extends Record<string, any>>(file: string) => T;
|
|
59
|
-
/** 通过包管理器执行脚本时生效 UserAgent: `process.env.npm_config_user_agent` */
|
|
60
|
-
declare const pkgFromUserAgent: (userAgent: string | undefined) => PkgInfo | undefined;
|
|
61
|
-
/** 同步执行 Node CLI(用于测试环境) */
|
|
62
|
-
declare const runCliForTest: (path: string, args: string[], options?: SpawnSyncOptionsWithStringEncoding) => child_process0.SpawnSyncReturns<string>;
|
|
63
|
-
/** 判断测试文件(夹) */
|
|
64
|
-
declare const isTestFile: (name: string) => boolean;
|
|
65
|
-
/** 解析 Github 链接获取 owner 和 repo */
|
|
66
|
-
declare const parseGitHubRepo: (url: string) => string[];
|
|
67
|
-
/** 基于 EOL 的可多换行函数 */
|
|
68
|
-
declare const eol: (n?: number) => string;
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/shell.d.ts
|
|
71
|
-
declare const dim: (text: string) => string;
|
|
72
|
-
declare const red: (text: string) => string;
|
|
73
|
-
declare const yellow: (text: string) => string;
|
|
74
|
-
declare const underline: (text: string) => string;
|
|
75
|
-
declare const spawnAsync: <T = SpawnOptions>(cmd: string, args: string[], options?: SpawnAsyncOptions<T>) => Promise<string | undefined>;
|
|
76
|
-
declare const execAsync: <T = ExecOptions>(cmd: string, options?: ExecAsyncOptions<T>) => Promise<string | undefined>;
|
|
77
|
-
declare const runGit: (args: string[], options?: SpawnAsyncOptions) => Promise<string | undefined>;
|
|
78
|
-
declare const runNpm: (args: string[], options?: ExecAsyncOptions) => Promise<string | undefined>;
|
|
79
|
-
declare const fixArgs: (args: string) => string[];
|
|
80
|
-
declare const checkVersion: (cmd: string) => Promise<string | undefined>;
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/joinUrl.d.ts
|
|
83
|
-
declare function joinUrl(...args: string[]): string;
|
|
84
|
-
declare function joinUrl(input: readonly string[]): string;
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region src/git.d.ts
|
|
87
|
-
declare const isGitRepo: (dir?: string) => Promise<boolean>;
|
|
88
|
-
declare const getGitConfig: (key: string, global?: boolean) => Promise<string | undefined>;
|
|
89
|
-
declare const getGitRemoteUrl: (remoteName?: string) => Promise<string | undefined>;
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/npm.d.ts
|
|
92
|
-
declare const pkgVersion: (pkg: string) => Promise<string | undefined>;
|
|
93
|
-
//#endregion
|
|
94
|
-
export { CliOptions, ConfirmResult, CopyOptions, ExecAsyncOptions, ExecResultOptions, HttpLibrary, PkgInfo, PkgManager, SpawnAsyncOptions, YesOrNo, checkVersion, copyDirAsync, dim, editFile, editJsonFile, emptyDir, eol, execAsync, fixArgs, getGitConfig, getGitRemoteUrl, isEmpty, isGitRepo, isTestFile, isValidPackageName, joinUrl, parseGitHubRepo, pkgFromUserAgent, pkgVersion, readJsonFile, readSubDirs, red, runCliForTest, runGit, runNpm, spawnAsync, toValidPackageName, toValidProjectName, underline, yellow };
|