@cyber-tools/cyber-git 4.0.0
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/README.md +15 -0
- package/dist/index.js +6347 -0
- package/frameworks/build.js +16 -0
- package/frameworks/development.js +20 -0
- package/package.json +47 -0
- package/src/actions/FastCommitAction.ts +51 -0
- package/src/actions/LaunchRemoteRepo.ts +29 -0
- package/src/actions/RunGitScripts.ts +46 -0
- package/src/commons/ApplicationConfigManager.ts +60 -0
- package/src/commons/IOCContainer.ts +4 -0
- package/src/index.ts +46 -0
- package/src/services/CommentPresetServices.ts +54 -0
- package/src/services/ConfirmAndPushRemote.ts +42 -0
- package/src/services/CreateIgnoreFile.ts +45 -0
- package/src/services/FirstCommit.ts +48 -0
- package/src/services/ProjectSelfInspection.ts +48 -0
- package/src/services/ResetCommitWithIgnore.ts +39 -0
- package/src/services/UpdateRemoteURL.ts +45 -0
- package/src/utils/CommandLineToast.ts +31 -0
- package/src/utils/CommentMessageGenerater.ts +73 -0
- package/src/utils/PopConfirmUtils.ts +23 -0
- package/src/utils/ProjectJudgment.ts +83 -0
- package/src/utils/SelectCommentType.ts +34 -0
- package/src/utils/SelectScriptType.ts +38 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { dots } from "cli-spinners";
|
|
3
|
+
import { injectable } from "inversify";
|
|
4
|
+
|
|
5
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
6
|
+
|
|
7
|
+
@injectable()
|
|
8
|
+
export class CommandLineToast {
|
|
9
|
+
|
|
10
|
+
private toast = ora(dots);
|
|
11
|
+
|
|
12
|
+
public start(...params: any) {
|
|
13
|
+
this.toast.start(...arguments);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
public succeed(params: any) {
|
|
17
|
+
this.toast.succeed(...arguments);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
public warn(params: any) {
|
|
21
|
+
this.toast.warn(...arguments);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
public fail(params: any) {
|
|
25
|
+
this.toast.fail(...arguments);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
IOCContainer.bind(CommandLineToast).toSelf().inRequestScope();
|
|
31
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import { injectable, inject } from "inversify";
|
|
4
|
+
|
|
5
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
6
|
+
import { ApplicationConfigManager } from "@/commons/ApplicationConfigManager";
|
|
7
|
+
|
|
8
|
+
@injectable()
|
|
9
|
+
export class CommentMessageGenerater {
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
@inject(ApplicationConfigManager) private readonly $ApplicationConfigManager: ApplicationConfigManager
|
|
13
|
+
) { };
|
|
14
|
+
|
|
15
|
+
public async createNormalMessage({ type, title = "", message = "请输入提交的内容" }) {
|
|
16
|
+
const comment_title = this.createCommentTitle({ type, title });
|
|
17
|
+
const defaultDescription = await this.getFileStatus();
|
|
18
|
+
const inputDescription = await this.inputDescriptionText(message);
|
|
19
|
+
return [comment_title, inputDescription || defaultDescription].join("\n");
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
public async createCommentTitle({ type, title }) {
|
|
23
|
+
const title_description = [title, this.createTimeText()].join(" ");
|
|
24
|
+
const comment_title = [type, title_description].join(":");
|
|
25
|
+
return comment_title;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
public async getFileStatus() {
|
|
29
|
+
try {
|
|
30
|
+
const git = this.$ApplicationConfigManager.getGitInstance();
|
|
31
|
+
const { created, deleted, modified, conflicted } = await git.status();
|
|
32
|
+
return [
|
|
33
|
+
conflicted.length ? conflicted.map((path) => (`解决了 ${path} 的冲突`)).join("\n") : undefined,
|
|
34
|
+
created.length ? created.map((path) => (`创建了 ${path}`)).join("\n") : undefined,
|
|
35
|
+
modified.length ? modified.map((path) => (`修改了 ${path}`)).join("\n") : undefined,
|
|
36
|
+
deleted.length ? deleted.map((path) => (`删除了 ${path}`)).join("\n") : undefined
|
|
37
|
+
].filter(Boolean).join("\n");
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
public async inputDescriptionText(message) {
|
|
44
|
+
const history = [];
|
|
45
|
+
async function inputSingle() {
|
|
46
|
+
try {
|
|
47
|
+
const { content } = await inquirer.prompt({
|
|
48
|
+
type: "input",
|
|
49
|
+
name: "content",
|
|
50
|
+
message: `${message}(${history.length + 1}):`
|
|
51
|
+
});
|
|
52
|
+
if (content) {
|
|
53
|
+
history.push(content);
|
|
54
|
+
await inputSingle();
|
|
55
|
+
};
|
|
56
|
+
return history;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
throw error;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
await inputSingle();
|
|
62
|
+
return history.join("\n");
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
public createTimeText() {
|
|
66
|
+
const timeText = moment().locale("zh-cn").format("dddd a h:mm:ss MMMM Do YYYY");
|
|
67
|
+
console.log(["当前时间节点", timeText].join(":"));
|
|
68
|
+
return timeText;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
IOCContainer.bind(CommentMessageGenerater).toSelf().inRequestScope();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { injectable } from "inversify";
|
|
3
|
+
|
|
4
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@injectable()
|
|
8
|
+
export class PopConfirmUtils {
|
|
9
|
+
|
|
10
|
+
public async execute(message = "是否同意", defaultOption = true) {
|
|
11
|
+
const { confirm } = await inquirer.prompt({
|
|
12
|
+
type: "confirm",
|
|
13
|
+
name: "confirm",
|
|
14
|
+
default: defaultOption,
|
|
15
|
+
message: message
|
|
16
|
+
});
|
|
17
|
+
return confirm;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
IOCContainer.bind(PopConfirmUtils).toSelf().inRequestScope();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import pathExists from "path-exists";
|
|
3
|
+
import { injectable, inject } from "inversify";
|
|
4
|
+
|
|
5
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
6
|
+
import { ApplicationConfigManager } from "@/commons/ApplicationConfigManager";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@injectable()
|
|
10
|
+
export class ProjectJudgment {
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
@inject(ApplicationConfigManager) private readonly $ApplicationConfigManager: ApplicationConfigManager
|
|
14
|
+
) { };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 判断目录中是否含有.gitignore文件
|
|
18
|
+
* **/
|
|
19
|
+
public async hasIgnoreFile() {
|
|
20
|
+
try {
|
|
21
|
+
const ignoreFilePath = path.resolve(process.cwd(), ".gitignore");
|
|
22
|
+
const hasIgnoreFile = await pathExists(ignoreFilePath);
|
|
23
|
+
return hasIgnoreFile;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw error;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 判断目录中是否含有package.json文件
|
|
31
|
+
* **/
|
|
32
|
+
public async hasPackageJson() {
|
|
33
|
+
try {
|
|
34
|
+
const jsonFilePath = path.resolve(process.cwd(), "package.json");
|
|
35
|
+
const hasJsonFile = await pathExists(jsonFilePath);
|
|
36
|
+
return hasJsonFile;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw error;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 通过git status命令来判断项目内容是否发生了改变
|
|
44
|
+
* **/
|
|
45
|
+
public async isChange() {
|
|
46
|
+
try {
|
|
47
|
+
const git = this.$ApplicationConfigManager.getGitInstance();
|
|
48
|
+
const { files } = await git.status();
|
|
49
|
+
return Boolean(files.length);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw error;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 通过判断.git文件夹是否存在来判断项目是否已经被git init初始化了
|
|
57
|
+
* **/
|
|
58
|
+
public async isInit() {
|
|
59
|
+
try {
|
|
60
|
+
const result = await pathExists("./.git/");
|
|
61
|
+
return result;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw error;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 基于git remote命令来判断项目是否已经关联了远程仓库
|
|
69
|
+
* **/
|
|
70
|
+
public async hasRemote() {
|
|
71
|
+
try {
|
|
72
|
+
const git = this.$ApplicationConfigManager.getGitInstance();
|
|
73
|
+
const list = await git.getRemotes();
|
|
74
|
+
return list.length > 0;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throw error;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
IOCContainer.bind(ProjectJudgment).toSelf().inRequestScope();
|
|
83
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { injectable, inject } from "inversify";
|
|
3
|
+
|
|
4
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
5
|
+
import { CommentPresetServices } from "@/services/CommentPresetServices";
|
|
6
|
+
|
|
7
|
+
@injectable()
|
|
8
|
+
export class SelectCommentType {
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
@inject(CommentPresetServices) private readonly $CommentPresetServices: CommentPresetServices,
|
|
12
|
+
) { };
|
|
13
|
+
|
|
14
|
+
public async execute() {
|
|
15
|
+
try {
|
|
16
|
+
const currentPreset = await this.$CommentPresetServices.getCommitPresets();
|
|
17
|
+
const { commitType } = await inquirer.prompt({
|
|
18
|
+
loop: false,
|
|
19
|
+
type: "list",
|
|
20
|
+
name: "commitType",
|
|
21
|
+
default: Object.keys(currentPreset)[0],
|
|
22
|
+
message: "请选择提交生成的注释类型",
|
|
23
|
+
choices: Object.keys(currentPreset)
|
|
24
|
+
});
|
|
25
|
+
return commitType;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw error;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
IOCContainer.bind(SelectCommentType).toSelf().inRequestScope();
|
|
34
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { injectable } from "inversify";
|
|
3
|
+
|
|
4
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
5
|
+
|
|
6
|
+
@injectable()
|
|
7
|
+
export class SelectScriptType {
|
|
8
|
+
|
|
9
|
+
public async execute() {
|
|
10
|
+
try {
|
|
11
|
+
const { scriptType } = await inquirer.prompt({
|
|
12
|
+
loop: false,
|
|
13
|
+
type: "list",
|
|
14
|
+
name: "scriptType",
|
|
15
|
+
message: "请选择提交生成的注释类型",
|
|
16
|
+
choices: [{
|
|
17
|
+
name: "快速提交",
|
|
18
|
+
value: "fast_commit"
|
|
19
|
+
}, {
|
|
20
|
+
name: "生成.gitignore文件",
|
|
21
|
+
value: "generate_gitignore_file"
|
|
22
|
+
}, {
|
|
23
|
+
name: "基于.gitignore重置提交",
|
|
24
|
+
value: "reset_with_gitignore_file"
|
|
25
|
+
}, {
|
|
26
|
+
name: "更新远程仓库(origin)",
|
|
27
|
+
value: "update_remote_repo"
|
|
28
|
+
}]
|
|
29
|
+
});
|
|
30
|
+
return scriptType;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throw error;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
IOCContainer.bind(SelectScriptType).toSelf().inRequestScope();
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"emitDecoratorMetadata": true,
|
|
4
|
+
"experimentalDecorators": true,
|
|
5
|
+
"target": "es2016",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"baseUrl": "./",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"strict": false,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"paths": {
|
|
16
|
+
"@/*": [
|
|
17
|
+
"./src/*"
|
|
18
|
+
],
|
|
19
|
+
"@@/*": [
|
|
20
|
+
"./*"
|
|
21
|
+
],
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|