@peiyanlu/cli-utils 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1219 -0
- package/dist/index.d.cts +525 -0
- package/dist/index.d.mts +525 -0
- package/dist/index.mjs +1115 -0
- package/package.json +9 -5
- package/dist/cjs/index.cjs +0 -344
- package/dist/cjs/index.d.cts +0 -114
- package/dist/esm/index.d.mts +0 -114
- package/dist/esm/index.mjs +0 -312
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import { ExecOptions, ExecSyncOptions, SpawnOptions, SpawnSyncOptions } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
//#region src/enums.d.ts
|
|
4
|
+
declare enum PkgManager {
|
|
5
|
+
NPM = "npm",
|
|
6
|
+
YARN = "yarn",
|
|
7
|
+
PNPM = "pnpm",
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `ConfirmResult` instead.
|
|
11
|
+
*/
|
|
12
|
+
declare enum YesOrNo {
|
|
13
|
+
Yes = "yes",
|
|
14
|
+
No = "no",
|
|
15
|
+
Ignore = "ignore",
|
|
16
|
+
}
|
|
17
|
+
declare enum ConfirmResult {
|
|
18
|
+
YES = "yes",
|
|
19
|
+
NO = "no",
|
|
20
|
+
IGNORE = "ignore",
|
|
21
|
+
}
|
|
22
|
+
declare enum HttpLibrary {
|
|
23
|
+
EXPRESS = "express",
|
|
24
|
+
FASTIFY = "fastify",
|
|
25
|
+
KOA = "koa",
|
|
26
|
+
HONO = "hono",
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/types.d.ts
|
|
30
|
+
interface CopyOptions {
|
|
31
|
+
rename?: Record<string, string>;
|
|
32
|
+
skips?: ((name: string, isDir: boolean) => boolean)[];
|
|
33
|
+
}
|
|
34
|
+
type CliOptions<T = string | boolean> = Record<string, T>;
|
|
35
|
+
interface PkgInfo {
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
}
|
|
39
|
+
interface ExecResultOptions {
|
|
40
|
+
/** 去掉结果的首尾空格 */
|
|
41
|
+
trim?: boolean;
|
|
42
|
+
/** 仅打印命令,不实际执行命令 */
|
|
43
|
+
dryRun?: boolean;
|
|
44
|
+
/** log: 打印错误信息,返回 undefined; throw: 抛出错误; ignore: 返回 undefined */
|
|
45
|
+
error?: 'log' | 'throw' | 'ignore';
|
|
46
|
+
}
|
|
47
|
+
type SpawnAsyncWithStringOptions = SpawnOptions & ExecResultOptions;
|
|
48
|
+
type ExecAsyncWithStringOptions = Omit<ExecOptions, 'encoding'> & ExecResultOptions;
|
|
49
|
+
type SpawnSyncWithStringOptions = Omit<SpawnSyncOptions, 'encoding'> & ExecResultOptions;
|
|
50
|
+
type ExecSyncWithStringOptions = Omit<ExecSyncOptions, 'encoding'> & ExecResultOptions;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/utils.d.ts
|
|
53
|
+
declare const isValidPackageName: (packageName: string) => boolean;
|
|
54
|
+
declare const toValidPackageName: (packageName: string) => string;
|
|
55
|
+
declare const toValidProjectName: (projectName: string) => string;
|
|
56
|
+
declare const emptyDir: (dir: string, ignore?: string[]) => Promise<boolean>;
|
|
57
|
+
declare const isEmpty: (path: string, ignore?: string[]) => Promise<boolean>;
|
|
58
|
+
declare const editFile: (file: string, callback: (content: string) => string) => Promise<void>;
|
|
59
|
+
declare const editJsonFile: <T extends Record<string, any>>(file: string, callback: (json: T) => void) => Promise<void>;
|
|
60
|
+
declare const readSubDirs: (source: string, ignore?: string[]) => Promise<string[]>;
|
|
61
|
+
declare const copyDirAsync: (src: string, dest: string, options: CopyOptions) => Promise<void>;
|
|
62
|
+
declare const readJsonFile: <T extends Record<string, any>>(file: string) => T;
|
|
63
|
+
declare const getPackageInfo: (pkgName: string, getPkgDir: (pkg: string) => string) => {
|
|
64
|
+
pkg: {
|
|
65
|
+
name: string;
|
|
66
|
+
version: string;
|
|
67
|
+
private?: boolean;
|
|
68
|
+
publishConfig?: {
|
|
69
|
+
access: string;
|
|
70
|
+
registry: string;
|
|
71
|
+
[key: string]: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
pkgDir: string;
|
|
75
|
+
pkgPath: string;
|
|
76
|
+
};
|
|
77
|
+
/** 通过包管理器执行脚本时生效 UserAgent: `process.env.npm_config_user_agent` */
|
|
78
|
+
declare const pkgFromUserAgent: (userAgent: string | undefined) => PkgInfo | undefined;
|
|
79
|
+
/** 同步执行 Node CLI(用于测试环境) */
|
|
80
|
+
declare const runCliForTest: (path: string, args?: string[], options?: SpawnSyncWithStringOptions) => string | undefined;
|
|
81
|
+
/** 判断测试文件(夹) */
|
|
82
|
+
declare const isTestFile: (name: string) => boolean;
|
|
83
|
+
/** 解析 Github 链接获取 owner 和 repo */
|
|
84
|
+
declare const parseGitHubRepo: (url: string) => string[];
|
|
85
|
+
/** 基于 EOL 的可多换行函数 */
|
|
86
|
+
declare const eol: (n?: number) => string;
|
|
87
|
+
/** 多空格函数 */
|
|
88
|
+
declare const space: (n?: number) => string;
|
|
89
|
+
/** 将字符串以空格分割为数组 */
|
|
90
|
+
declare const parseArgs: (args: string) => string[];
|
|
91
|
+
/** 将数组以空格拼接为字符串 */
|
|
92
|
+
declare const stringifyArgs: (args: string[]) => string;
|
|
93
|
+
/** 去掉模板字符串首尾换行 */
|
|
94
|
+
declare const trimTemplate: (str: string) => string;
|
|
95
|
+
/** 生成 GitHub 仓库主页地址 */
|
|
96
|
+
declare const getGithubUrl: (owner: string, repo: string) => string;
|
|
97
|
+
/** 生成 GitHub Release 页面地址 */
|
|
98
|
+
declare const getGithubReleaseUrl: (owner: string, repo: string, tag: string) => string;
|
|
99
|
+
/** 生成 npm 包指定版本的详情页地址 */
|
|
100
|
+
declare const getPackageUrl: (pkg: string, version: string) => string;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/shell.d.ts
|
|
103
|
+
/** 异步执行 `spawn` 获取字符串类型的结果 */
|
|
104
|
+
declare const spawnAsync: (cmd: string, args: string[], options?: SpawnAsyncWithStringOptions) => Promise<string | undefined>;
|
|
105
|
+
type ExecAsync = {
|
|
106
|
+
(cmd: string, options?: ExecAsyncWithStringOptions): Promise<string | undefined>;
|
|
107
|
+
(cmd: string, args: string[], options?: ExecAsyncWithStringOptions): Promise<string | undefined>;
|
|
108
|
+
};
|
|
109
|
+
/** 异步执行 `exec` 获取字符串类型的结果 */
|
|
110
|
+
declare const execAsync: ExecAsync;
|
|
111
|
+
/** 执行 `spawnSync` 获取字符串类型的结果 */
|
|
112
|
+
declare const spawnSyncWithString: (cmd: string, args: string[], options?: SpawnSyncWithStringOptions) => string | undefined;
|
|
113
|
+
type ExecSync = {
|
|
114
|
+
(cmd: string, options?: ExecAsyncWithStringOptions): string | undefined;
|
|
115
|
+
(cmd: string, args: string[], options?: ExecAsyncWithStringOptions): string | undefined;
|
|
116
|
+
};
|
|
117
|
+
/** 执行 `execSync` 获取字符串类型的结果 */
|
|
118
|
+
declare const execSyncWithString: ExecSync;
|
|
119
|
+
/** 基于 {@link spawnAsync} 实现 */
|
|
120
|
+
declare const runGit: (args: string[], options?: SpawnAsyncWithStringOptions) => Promise<string | undefined>;
|
|
121
|
+
/** 基于 {@link spawnSyncWithString} 实现 */
|
|
122
|
+
declare const runGitSync: (args: string[], options?: SpawnSyncWithStringOptions) => string | undefined;
|
|
123
|
+
/** 基于 {@link execAsync} 实现 */
|
|
124
|
+
declare const runNpm: (args: string[], options?: ExecAsyncWithStringOptions) => Promise<string | undefined>;
|
|
125
|
+
/** 基于 {@link execSyncWithString} 实现 */
|
|
126
|
+
declare const runNpmSync: (args: string[], options?: ExecSyncWithStringOptions) => string | undefined;
|
|
127
|
+
/** 基于 {@link spawnAsync} 实现 */
|
|
128
|
+
declare const runNode: (args: string[], options: SpawnAsyncWithStringOptions) => Promise<string | undefined>;
|
|
129
|
+
/** 基于 {@link spawnSyncWithString} 实现 */
|
|
130
|
+
declare const runNodeSync: (args: string[], options: SpawnSyncWithStringOptions) => string | undefined;
|
|
131
|
+
/** 支持所有支持 `--version` 命令的脚本查看版本 */
|
|
132
|
+
declare const checkVersion: (cmd: string) => Promise<string | undefined>;
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/joinUrl.d.ts
|
|
135
|
+
declare function joinUrl(...args: string[]): string;
|
|
136
|
+
declare function joinUrl(input: readonly string[]): string;
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/git.d.ts
|
|
139
|
+
/** 判断指定目录是否是 git 仓库 */
|
|
140
|
+
declare const isGitRepo: (dir?: string) => Promise<boolean>;
|
|
141
|
+
/** 获取指定的 git 配置 */
|
|
142
|
+
declare const getGitConfig: (key: string, global?: boolean) => Promise<string | undefined>;
|
|
143
|
+
/** 获取 git 远程地址 */
|
|
144
|
+
declare const getGitRemoteUrl: (remoteName?: string) => Promise<string | undefined>;
|
|
145
|
+
/** 获取当前分支 */
|
|
146
|
+
declare const getCurrentBranch: () => Promise<string | undefined>;
|
|
147
|
+
/** 获取分支关联的远程地址 */
|
|
148
|
+
declare const getRemoteForBranch: (branch: string) => Promise<string | undefined>;
|
|
149
|
+
/** 获取关联的所有远程地址 */
|
|
150
|
+
declare const getAllRemotes: () => Promise<string[]>;
|
|
151
|
+
/** 获取默认的远程地址 */
|
|
152
|
+
declare const getDefaultRemote: (branch?: string) => Promise<string | undefined>;
|
|
153
|
+
/** 获取默认远程地址之外的远程地址 */
|
|
154
|
+
declare const getOtherRemotes: (branch?: string) => Promise<string[]>;
|
|
155
|
+
/** 提取所有分支 */
|
|
156
|
+
declare const fetchAllBranch: (remoteName?: string) => Promise<string | undefined>;
|
|
157
|
+
/**
|
|
158
|
+
* 获取本地所有 tag
|
|
159
|
+
* @returns {Promise<string[]>}
|
|
160
|
+
* @defaults git tag --list
|
|
161
|
+
*/
|
|
162
|
+
declare const getLocalTags: () => Promise<string[]>;
|
|
163
|
+
/** 获取远程 tags */
|
|
164
|
+
declare const getSortedTags: (match?: string, exclude?: string, sort?: "v:refname" | "creatordate", count?: number) => Promise<string[]>;
|
|
165
|
+
/**
|
|
166
|
+
* 获取远程(或所有 refs)中的 tag
|
|
167
|
+
* 使用 for-each-ref 以支持版本号排序
|
|
168
|
+
* @param {string} match 默认 *
|
|
169
|
+
* @param {string} exclude 默认 beta
|
|
170
|
+
* @returns {Promise<string[]>}
|
|
171
|
+
* @defaults git for-each-ref --sort=-v:refname --format=%(refname:short) refs/tags/<match>
|
|
172
|
+
*/
|
|
173
|
+
declare const getRemoteTags: (match?: string, exclude?: string) => Promise<string[]>;
|
|
174
|
+
/**
|
|
175
|
+
* 获取当前工作区状态(不包含未跟踪文件)
|
|
176
|
+
* @returns {Promise<string | undefined>}
|
|
177
|
+
* @defaults git status --short --untracked-files=no
|
|
178
|
+
*/
|
|
179
|
+
declare const getStatus: () => Promise<string | undefined>;
|
|
180
|
+
/**
|
|
181
|
+
* 为 git status / changeset 输出添加颜色
|
|
182
|
+
*
|
|
183
|
+
* M -> 黄色(修改)
|
|
184
|
+
* A -> 绿色(新增)
|
|
185
|
+
* D -> 红色(删除)
|
|
186
|
+
* @param {string} log git status --short 输出
|
|
187
|
+
* @returns {string}
|
|
188
|
+
*/
|
|
189
|
+
declare const coloredChangeset: (log: string) => string;
|
|
190
|
+
/**
|
|
191
|
+
* 获取当前分支对应的远程信息
|
|
192
|
+
* @returns {Promise<{remoteName: string, remoteUrl: string | undefined}>}
|
|
193
|
+
*/
|
|
194
|
+
declare const getRemote: () => Promise<{
|
|
195
|
+
remoteName: string;
|
|
196
|
+
remoteUrl: string | undefined;
|
|
197
|
+
}>;
|
|
198
|
+
/**
|
|
199
|
+
* 获取最新 tag
|
|
200
|
+
*
|
|
201
|
+
* 默认:
|
|
202
|
+
* - 匹配所有 tag
|
|
203
|
+
* - 排除 beta 版本
|
|
204
|
+
* @param {string} match 默认 *
|
|
205
|
+
* @param {string} exclude 默认 beta
|
|
206
|
+
* @returns {Promise<string | undefined>}
|
|
207
|
+
*/
|
|
208
|
+
declare const getLatestTag: (match?: string, exclude?: string) => Promise<string | undefined>;
|
|
209
|
+
/**
|
|
210
|
+
* 获取上一个 tag
|
|
211
|
+
*
|
|
212
|
+
* 默认:
|
|
213
|
+
* - 匹配所有 tag
|
|
214
|
+
* - 排除 beta 版本
|
|
215
|
+
* @param {string} latestTag
|
|
216
|
+
* @param {string} match 默认 *
|
|
217
|
+
* @param {string} exclude 默认 beta
|
|
218
|
+
* @returns {Promise<string | undefined>}
|
|
219
|
+
*/
|
|
220
|
+
declare const getPreviousTag: (latestTag: string, match?: string, exclude?: string) => Promise<string | undefined>;
|
|
221
|
+
/**
|
|
222
|
+
* 计算 changelog 的 commit 范围
|
|
223
|
+
* @param {boolean} isIncrement 是否为版本递增发布
|
|
224
|
+
* @param {string} match tag match
|
|
225
|
+
* @param {string} exclude tag exclude
|
|
226
|
+
* @returns {Promise<{from: string, to: string}>}
|
|
227
|
+
*/
|
|
228
|
+
declare const resolveChangelogRange: (isIncrement?: boolean, match?: string, exclude?: string) => Promise<{
|
|
229
|
+
from: string;
|
|
230
|
+
to: string;
|
|
231
|
+
}>;
|
|
232
|
+
/**
|
|
233
|
+
* 将短 hash 解析为完整 hash
|
|
234
|
+
* @param {string} short
|
|
235
|
+
* @returns {Promise<string | undefined>}
|
|
236
|
+
*/
|
|
237
|
+
declare const getFullHash: (short: string) => Promise<string | undefined>;
|
|
238
|
+
/**
|
|
239
|
+
* 获取指定范围内的 commit 日志
|
|
240
|
+
* @param {string} from
|
|
241
|
+
* @param {string} to
|
|
242
|
+
* @param {string} scope 文件或目录范围
|
|
243
|
+
* @returns {Promise<string | undefined>}
|
|
244
|
+
*/
|
|
245
|
+
declare const getLog: (from?: string, to?: string, scope?: string) => Promise<string | undefined>;
|
|
246
|
+
/**
|
|
247
|
+
* 判断工作区是否干净(无未提交修改)
|
|
248
|
+
* @returns {Promise<boolean>}
|
|
249
|
+
*/
|
|
250
|
+
declare const isWorkingDirClean: () => Promise<boolean>;
|
|
251
|
+
/** 判断字符串是否为合法 remote 名称 */
|
|
252
|
+
declare const isRemoteName: (remoteName: string) => boolean | "";
|
|
253
|
+
/** 判断当前分支是否已设置 upstream */
|
|
254
|
+
declare const hasUpstreamBranch: () => Promise<boolean>;
|
|
255
|
+
/** 获取 push 所需的 upstream 参数 */
|
|
256
|
+
declare const getUpstreamArgs: (remoteName: string, branch?: string) => Promise<string[]>;
|
|
257
|
+
/** 统计自最新 tag 以来的提交数量 */
|
|
258
|
+
declare const countCommitsSinceLatestTag: () => Promise<number>;
|
|
259
|
+
/** git add(包含未追踪文件) */
|
|
260
|
+
declare const gitAddAll: (args?: string[]) => Promise<void>;
|
|
261
|
+
/** git add(仅已追踪文件) */
|
|
262
|
+
declare const gitAddTracked: (args?: string[]) => Promise<void>;
|
|
263
|
+
/** git commit */
|
|
264
|
+
declare const gitCommit: (message: string, args?: string[]) => Promise<void>;
|
|
265
|
+
/** git commit amend */
|
|
266
|
+
declare const gitCommitAmend: (message: string, args?: string[]) => Promise<void>;
|
|
267
|
+
/** 创建 annotated tag */
|
|
268
|
+
declare const gitTagAnnotated: (tag: string, message?: string, args?: string[]) => Promise<void>;
|
|
269
|
+
/** 创建 lightweight tag */
|
|
270
|
+
declare const gitTagLightweight: (tag: string, message?: string, args?: string[]) => Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* 推送 tag 到远程
|
|
273
|
+
* @param {string} remoteName
|
|
274
|
+
* @param {string} tag
|
|
275
|
+
* @param {string[]} args
|
|
276
|
+
* @returns {Promise<string | undefined>}
|
|
277
|
+
* @defaults git push <remoteName> refs/tags/<tag>
|
|
278
|
+
*/
|
|
279
|
+
declare const pushTag: (remoteName: string, tag: string, args?: string[]) => Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* 推送分支到远程
|
|
282
|
+
* 自动处理 upstream 设置
|
|
283
|
+
* @param {string} remoteName
|
|
284
|
+
* @param {string} branch
|
|
285
|
+
* @param {string[]} args
|
|
286
|
+
* @returns {Promise<string | undefined>}
|
|
287
|
+
*/
|
|
288
|
+
declare const pushBranch: (remoteName: string, branch?: string, args?: string[]) => Promise<void>;
|
|
289
|
+
/**
|
|
290
|
+
* 撤销【工作区】中某个文件的修改(未暂存的改动)
|
|
291
|
+
* - 不影响暂存区
|
|
292
|
+
* - 不影响提交历史
|
|
293
|
+
* - ⚠️ 会丢弃该文件当前未暂存的修改
|
|
294
|
+
*
|
|
295
|
+
* 等价命令:git restore <file>
|
|
296
|
+
*/
|
|
297
|
+
declare const restoreFile: (file: string) => Promise<void>;
|
|
298
|
+
/**
|
|
299
|
+
* 撤销【工作区】中所有未暂存的修改
|
|
300
|
+
* - 不影响暂存区
|
|
301
|
+
* - 不影响提交历史
|
|
302
|
+
* - ⚠️ 会丢弃所有未暂存的修改
|
|
303
|
+
*
|
|
304
|
+
* 等价命令:git restore .
|
|
305
|
+
*/
|
|
306
|
+
declare const restoreAll: () => Promise<void>;
|
|
307
|
+
/**
|
|
308
|
+
* 将某个文件从【暂存区】移回【工作区】
|
|
309
|
+
* - 保留文件修改
|
|
310
|
+
* - 仅取消 git add 的效果
|
|
311
|
+
*
|
|
312
|
+
* 等价命令:git restore --staged <file>
|
|
313
|
+
*/
|
|
314
|
+
declare const unstageFile: (file: string) => Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* 取消所有文件的暂存状态
|
|
317
|
+
* - 保留所有文件修改
|
|
318
|
+
* - 清空暂存区
|
|
319
|
+
*
|
|
320
|
+
* 等价命令:git restore --staged .
|
|
321
|
+
*/
|
|
322
|
+
declare const unstageAll: () => Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* 丢弃某个文件的所有修改(暂存 + 未暂存)
|
|
325
|
+
* - 先取消暂存
|
|
326
|
+
* - 再撤销工作区修改
|
|
327
|
+
* - ⚠️ 修改内容将彻底丢失
|
|
328
|
+
*
|
|
329
|
+
* 等价操作:
|
|
330
|
+
* git restore --staged <file>
|
|
331
|
+
* git restore <file>
|
|
332
|
+
*/
|
|
333
|
+
declare const discardFile: (file: string) => Promise<void>;
|
|
334
|
+
/**
|
|
335
|
+
* 丢弃所有修改(包括暂存和未暂存的文件)
|
|
336
|
+
*
|
|
337
|
+
* 作用:
|
|
338
|
+
* - 将暂存区和工作区全部重置到当前 HEAD 提交状态
|
|
339
|
+
* - 丢弃所有未提交的更改,无法恢复(除非使用 reflog)
|
|
340
|
+
*
|
|
341
|
+
* ⚠️ 高风险操作,请确保已备份重要修改
|
|
342
|
+
*
|
|
343
|
+
* 等价命令:
|
|
344
|
+
* git reset --hard HEAD
|
|
345
|
+
*/
|
|
346
|
+
declare const discardAll: () => Promise<void>;
|
|
347
|
+
/**
|
|
348
|
+
* 撤销最近的 commit(软回退)
|
|
349
|
+
* - 提交历史回退
|
|
350
|
+
* - 修改内容保留
|
|
351
|
+
* - 修改仍在【暂存区】
|
|
352
|
+
*
|
|
353
|
+
* 常用于:刚提交但还想改点东西
|
|
354
|
+
*
|
|
355
|
+
* 等价命令:git reset --soft HEAD~<count>
|
|
356
|
+
*/
|
|
357
|
+
declare const resetSoft: (count?: number) => Promise<void>;
|
|
358
|
+
/**
|
|
359
|
+
* 撤销最近的 commit(混合回退,默认行为)
|
|
360
|
+
* - 提交历史回退
|
|
361
|
+
* - 修改内容保留
|
|
362
|
+
* - 修改回到【工作区】,不再暂存
|
|
363
|
+
*
|
|
364
|
+
* 等价命令:git reset --mixed HEAD~<count>
|
|
365
|
+
*/
|
|
366
|
+
declare const resetMixed: (count?: number) => Promise<void>;
|
|
367
|
+
/**
|
|
368
|
+
* 撤销最近的 commit(强制回退)
|
|
369
|
+
* - 提交历史回退
|
|
370
|
+
* - ⚠️ 所有修改全部丢弃
|
|
371
|
+
*
|
|
372
|
+
* ⚠️ 高危操作,请谨慎使用
|
|
373
|
+
*
|
|
374
|
+
* 等价命令:git reset --hard HEAD~<count>
|
|
375
|
+
*/
|
|
376
|
+
declare const resetHard: (count?: number) => Promise<void>;
|
|
377
|
+
/**
|
|
378
|
+
* 安全撤销一个已提交(并可能已 push)的 commit
|
|
379
|
+
* - 不改写提交历史
|
|
380
|
+
* - 生成一个新的反向提交
|
|
381
|
+
*
|
|
382
|
+
* 适用于:公共分支 / 已推送到远端
|
|
383
|
+
*
|
|
384
|
+
* 等价命令:git revert <commit>
|
|
385
|
+
*/
|
|
386
|
+
declare const revertCommit: (hash: string) => Promise<void>;
|
|
387
|
+
/**
|
|
388
|
+
* 将某个文件恢复到指定 commit 的状态
|
|
389
|
+
* - 仅影响该文件
|
|
390
|
+
* - 会覆盖当前工作区中的该文件
|
|
391
|
+
* - 不自动提交
|
|
392
|
+
*
|
|
393
|
+
* 等价命令:git restore --source=<commit> <file>
|
|
394
|
+
*/
|
|
395
|
+
declare const restoreFileFromCommit: (file: string, commit: string) => Promise<void>;
|
|
396
|
+
/**
|
|
397
|
+
* 将当前目录下的所有文件恢复到指定 commit 的状态
|
|
398
|
+
*
|
|
399
|
+
* 行为说明:
|
|
400
|
+
* - 仅影响【工作区(Working Tree)】
|
|
401
|
+
* - 不影响暂存区(Index)
|
|
402
|
+
* - 不修改提交历史
|
|
403
|
+
*
|
|
404
|
+
* ⚠️ 风险提示:
|
|
405
|
+
* - 会覆盖当前工作区中的所有文件
|
|
406
|
+
* - 所有未暂存的修改将被永久丢弃
|
|
407
|
+
*
|
|
408
|
+
* 适用场景:
|
|
409
|
+
* - 批量回退文件内容到某个历史版本
|
|
410
|
+
* - 修复误操作、误格式化、误生成文件等情况
|
|
411
|
+
*
|
|
412
|
+
* 等价命令:
|
|
413
|
+
* git restore --source=<commit> .
|
|
414
|
+
*/
|
|
415
|
+
declare const restoreFromCommit: (commit: string) => Promise<void>;
|
|
416
|
+
declare const deleteTag: (tag: string) => Promise<void>;
|
|
417
|
+
/** {@link restoreAll} 的同步版本 */
|
|
418
|
+
declare const restoreAllSync: () => Promise<void>;
|
|
419
|
+
declare const deleteTagSync: (tag: string) => Promise<void>;
|
|
420
|
+
declare const discardAllSync: () => Promise<void>;
|
|
421
|
+
declare const resetHardSync: (count?: number) => Promise<void>;
|
|
422
|
+
declare const gitUndo: {
|
|
423
|
+
file: {
|
|
424
|
+
restore: (file: string) => Promise<void>;
|
|
425
|
+
unstage: (file: string) => Promise<void>;
|
|
426
|
+
discard: (file: string) => Promise<void>;
|
|
427
|
+
};
|
|
428
|
+
all: {
|
|
429
|
+
restore: () => Promise<void>;
|
|
430
|
+
unstage: () => Promise<void>;
|
|
431
|
+
discard: () => Promise<void>;
|
|
432
|
+
};
|
|
433
|
+
reset: {
|
|
434
|
+
soft: (count?: number) => Promise<void>;
|
|
435
|
+
mixed: (count?: number) => Promise<void>;
|
|
436
|
+
hard: (count?: number) => Promise<void>;
|
|
437
|
+
};
|
|
438
|
+
revert: (hash: string) => Promise<void>;
|
|
439
|
+
};
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/npm.d.ts
|
|
442
|
+
declare const DEFAULT_TAG: string;
|
|
443
|
+
declare const DEFAULT_ACCESS: string;
|
|
444
|
+
declare const DEFAULT_REGISTRY: string;
|
|
445
|
+
declare const accessArg: (access?: string) => string[];
|
|
446
|
+
declare const registryArg: (registry?: string) => string[];
|
|
447
|
+
declare const tagArg: (tag?: string) => string[];
|
|
448
|
+
/**
|
|
449
|
+
* 获取 npm registry
|
|
450
|
+
* @param {string} pkgDir
|
|
451
|
+
* @returns {Promise<string>}
|
|
452
|
+
* @defaults https://registry.npmjs.org/
|
|
453
|
+
*/
|
|
454
|
+
declare const getRegistry: (pkgDir: string) => Promise<string>;
|
|
455
|
+
/**
|
|
456
|
+
* 获取 publish access
|
|
457
|
+
* @param {string} pkgDir
|
|
458
|
+
* @returns {Promise<string>}
|
|
459
|
+
* @defaults scoped: restricted; unscoped: public
|
|
460
|
+
*/
|
|
461
|
+
declare const getAccess: (pkgDir: string) => Promise<"restricted" | "public">;
|
|
462
|
+
/**
|
|
463
|
+
* 检查与仓库的连接
|
|
464
|
+
* @param {string} registry
|
|
465
|
+
* @returns {Promise<boolean>}
|
|
466
|
+
* @defaults npm ping --registry https://registry.npmjs.org/
|
|
467
|
+
*/
|
|
468
|
+
declare const pingRegistry: (registry?: string) => Promise<boolean>;
|
|
469
|
+
/**
|
|
470
|
+
* 获取已登录用户
|
|
471
|
+
* @param {string} registry
|
|
472
|
+
* @returns {Promise<string | undefined>}
|
|
473
|
+
* @defaults npm whoami --registry https://registry.npmjs.org/
|
|
474
|
+
*/
|
|
475
|
+
declare const getAuthenticatedUser: (registry?: string) => Promise<string | undefined>;
|
|
476
|
+
/**
|
|
477
|
+
* 用户是否拥有写入权限
|
|
478
|
+
* @param {string} pkg
|
|
479
|
+
* @param {string} user
|
|
480
|
+
* @param {string} registry
|
|
481
|
+
* @returns {Promise<boolean>}
|
|
482
|
+
* @defaults npm access list collaborators <pkg> --json
|
|
483
|
+
* npm access ls-collaborators <pkg> --json
|
|
484
|
+
*/
|
|
485
|
+
declare const hasWriteAccess: (pkg: string, user: string, registry?: string) => Promise<boolean>;
|
|
486
|
+
/**
|
|
487
|
+
* 获取指定包的版本
|
|
488
|
+
* @param {string} pkg pkgName pkgName@tag
|
|
489
|
+
* @param {string} registry
|
|
490
|
+
* @returns {Promise<string | undefined>}
|
|
491
|
+
* @defaults npm view <pkg> version
|
|
492
|
+
*/
|
|
493
|
+
declare const getPublishedVersion: (pkg: string, registry?: string) => Promise<string | undefined>;
|
|
494
|
+
/**
|
|
495
|
+
* 获取所有已发布的 dist-tags
|
|
496
|
+
* @param {string} pkg
|
|
497
|
+
* @param {string} registry
|
|
498
|
+
* @returns {Promise<string[]>}
|
|
499
|
+
* @defaults npm view <pkg> dist-tags --json
|
|
500
|
+
*/
|
|
501
|
+
declare const getDistTags: (pkg: string, registry?: string) => Promise<string[]>;
|
|
502
|
+
/**
|
|
503
|
+
* 更新包版本号
|
|
504
|
+
* @param {string} version
|
|
505
|
+
* @param {string[]} args
|
|
506
|
+
* @param {string} cwd
|
|
507
|
+
* @returns {Promise<string | undefined>}
|
|
508
|
+
* @defaults npm version <version> --workspaces=false --no-git-tag-version --allow-same-version
|
|
509
|
+
*/
|
|
510
|
+
declare const bumpPackageVersion: (version: string, args?: string[], cwd?: string) => Promise<string | undefined>;
|
|
511
|
+
/**
|
|
512
|
+
* 发布
|
|
513
|
+
* @param {{access?: string, registry?: string, tag?: string, args?: string[], cwd?: string}} options
|
|
514
|
+
* @returns {Promise<string | undefined>}
|
|
515
|
+
* @defaults npm publish --tag latest --access public --registry https://registry.npmjs.org/ --workspaces=false
|
|
516
|
+
*/
|
|
517
|
+
declare const publishPackage: (options?: {
|
|
518
|
+
access?: string;
|
|
519
|
+
registry?: string;
|
|
520
|
+
tag?: string;
|
|
521
|
+
args?: string[];
|
|
522
|
+
cwd?: string;
|
|
523
|
+
}) => Promise<string | undefined>;
|
|
524
|
+
//#endregion
|
|
525
|
+
export { CliOptions, ConfirmResult, CopyOptions, DEFAULT_ACCESS, DEFAULT_REGISTRY, DEFAULT_TAG, ExecAsyncWithStringOptions, ExecResultOptions, ExecSyncWithStringOptions, HttpLibrary, PkgInfo, PkgManager, SpawnAsyncWithStringOptions, SpawnSyncWithStringOptions, YesOrNo, accessArg, bumpPackageVersion, checkVersion, coloredChangeset, copyDirAsync, countCommitsSinceLatestTag, deleteTag, deleteTagSync, discardAll, discardAllSync, discardFile, editFile, editJsonFile, emptyDir, eol, execAsync, execSyncWithString, fetchAllBranch, getAccess, getAllRemotes, getAuthenticatedUser, getCurrentBranch, getDefaultRemote, getDistTags, getFullHash, getGitConfig, getGitRemoteUrl, getGithubReleaseUrl, getGithubUrl, getLatestTag, getLocalTags, getLog, getOtherRemotes, getPackageInfo, getPackageUrl, getPreviousTag, getPublishedVersion, getRegistry, getRemote, getRemoteForBranch, getRemoteTags, getSortedTags, getStatus, getUpstreamArgs, gitAddAll, gitAddTracked, gitCommit, gitCommitAmend, gitTagAnnotated, gitTagLightweight, gitUndo, hasUpstreamBranch, hasWriteAccess, isEmpty, isGitRepo, isRemoteName, isTestFile, isValidPackageName, isWorkingDirClean, joinUrl, parseArgs, parseGitHubRepo, pingRegistry, pkgFromUserAgent, publishPackage, pushBranch, pushTag, readJsonFile, readSubDirs, registryArg, resetHard, resetHardSync, resetMixed, resetSoft, resolveChangelogRange, restoreAll, restoreAllSync, restoreFile, restoreFileFromCommit, restoreFromCommit, revertCommit, runCliForTest, runGit, runGitSync, runNode, runNodeSync, runNpm, runNpmSync, space, spawnAsync, spawnSyncWithString, stringifyArgs, tagArg, toValidPackageName, toValidProjectName, trimTemplate, unstageAll, unstageFile };
|