@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,16 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const esbuild = require("esbuild");
|
|
3
|
+
const { nodeExternalsPlugin } = require("esbuild-node-externals");
|
|
4
|
+
|
|
5
|
+
setImmediate(async () => {
|
|
6
|
+
await esbuild.build({
|
|
7
|
+
entryPoints: [path.resolve(process.cwd(), "./src/index.ts")],
|
|
8
|
+
bundle: true,
|
|
9
|
+
format: "cjs",
|
|
10
|
+
platform: "node",
|
|
11
|
+
outdir: path.resolve(process.cwd(), "./dist/"),
|
|
12
|
+
plugins: [nodeExternalsPlugin({
|
|
13
|
+
packagePath: path.resolve(process.cwd(), "./package.json")
|
|
14
|
+
})]
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const esbuild = require("esbuild");
|
|
4
|
+
const { promisify } = require("util");
|
|
5
|
+
const { nodeExternalsPlugin } = require("esbuild-node-externals");
|
|
6
|
+
|
|
7
|
+
setImmediate(async () => {
|
|
8
|
+
await promisify(fs.rm)(path.resolve(process.cwd(), "./dist/"), { recursive: true, force: true });
|
|
9
|
+
await esbuild.build({
|
|
10
|
+
entryPoints: [path.resolve(process.cwd(), "./src/index.ts")],
|
|
11
|
+
bundle: true,
|
|
12
|
+
format: "cjs",
|
|
13
|
+
platform: "node",
|
|
14
|
+
outdir: path.resolve(process.cwd(), "./dist/"),
|
|
15
|
+
plugins: [nodeExternalsPlugin({
|
|
16
|
+
packagePath: path.resolve(process.cwd(), "./package.json")
|
|
17
|
+
})]
|
|
18
|
+
});
|
|
19
|
+
require("../dist/index.js");
|
|
20
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cyber-tools/cyber-git",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "规范化git操作的相关的脚本和工具",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "node ./frameworks/development.js",
|
|
8
|
+
"build": "node ./frameworks/build.js",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"bin": "./dist/index.js",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"cli",
|
|
17
|
+
"node",
|
|
18
|
+
"cyber",
|
|
19
|
+
"shicheng.yu"
|
|
20
|
+
],
|
|
21
|
+
"author": "",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"cli-spinners": "^2.4.0",
|
|
25
|
+
"commander": "^6.0.0",
|
|
26
|
+
"esbuild-register": "^3.6.0",
|
|
27
|
+
"execa": "^4.0.3",
|
|
28
|
+
"git-remote-origin-url": "^3.1.0",
|
|
29
|
+
"inquirer": "^7.3.3",
|
|
30
|
+
"inversify": "^6.0.2",
|
|
31
|
+
"jsonfile": "^6.0.1",
|
|
32
|
+
"moment": "^2.29.1",
|
|
33
|
+
"open": "^7.3.0",
|
|
34
|
+
"ora": "^5.1.0",
|
|
35
|
+
"path-exists": "^4.0.0",
|
|
36
|
+
"prompt-promise": "^1.0.3",
|
|
37
|
+
"reflect-metadata": "^0.2.2",
|
|
38
|
+
"simple-git": "^2.20.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^25.5.0",
|
|
42
|
+
"esbuild": "^0.27.4",
|
|
43
|
+
"esbuild-node-externals": "^1.20.1",
|
|
44
|
+
"i": "^0.3.7",
|
|
45
|
+
"npm": "^11.12.1"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { injectable, inject } from "inversify";
|
|
2
|
+
|
|
3
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
4
|
+
import { ApplicationConfigManager } from "@/commons/ApplicationConfigManager";
|
|
5
|
+
|
|
6
|
+
import { ProjectSelfInspection } from "@/services/ProjectSelfInspection";
|
|
7
|
+
import { CommentPresetServices } from "@/services/CommentPresetServices";
|
|
8
|
+
|
|
9
|
+
import { ProjectJudgment } from "@/utils/ProjectJudgment";
|
|
10
|
+
import { CommandLineToast } from "@/utils/CommandLineToast";
|
|
11
|
+
import { SelectCommentType } from "@/utils/SelectCommentType";
|
|
12
|
+
import { ConfirmAndPushRemote } from "@/services/ConfirmAndPushRemote";
|
|
13
|
+
|
|
14
|
+
@injectable()
|
|
15
|
+
export class FastCommitAction {
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
@inject(ProjectJudgment) private readonly $ProjectJudgment: ProjectJudgment,
|
|
19
|
+
@inject(CommandLineToast) private readonly $CommandLineToast: CommandLineToast,
|
|
20
|
+
@inject(SelectCommentType) private readonly $SelectCommentType: SelectCommentType,
|
|
21
|
+
@inject(ConfirmAndPushRemote) private readonly $ConfirmAndPushRemote: ConfirmAndPushRemote,
|
|
22
|
+
@inject(CommentPresetServices) private readonly $CommentPresetServices: CommentPresetServices,
|
|
23
|
+
@inject(ProjectSelfInspection) private readonly $ProjectSelfInspection: ProjectSelfInspection,
|
|
24
|
+
@inject(ApplicationConfigManager) private readonly $ApplicationConfigManager: ApplicationConfigManager
|
|
25
|
+
) { };
|
|
26
|
+
|
|
27
|
+
public async execute() {
|
|
28
|
+
const git = this.$ApplicationConfigManager.getGitInstance();
|
|
29
|
+
const currentPreset = await this.$CommentPresetServices.getCommitPresets();
|
|
30
|
+
try {
|
|
31
|
+
await this.$ProjectSelfInspection.execute();
|
|
32
|
+
if (!await this.$ProjectJudgment.hasIgnoreFile()) {
|
|
33
|
+
return this.$CommandLineToast.warn("该项目下不存在.gitignore文件");
|
|
34
|
+
};
|
|
35
|
+
await git.add(".");
|
|
36
|
+
const commitType = await this.$SelectCommentType.execute();
|
|
37
|
+
const commitMessage = await currentPreset[commitType]();
|
|
38
|
+
this.$CommandLineToast.start("正在提交");
|
|
39
|
+
await git.commit(commitMessage);
|
|
40
|
+
this.$CommandLineToast.succeed("提交成功!");
|
|
41
|
+
await this.$ConfirmAndPushRemote.execute();
|
|
42
|
+
process.exit(0);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
this.$CommandLineToast.fail("提交失败!");
|
|
45
|
+
throw error;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
IOCContainer.bind(FastCommitAction).toSelf().inRequestScope();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import open from "open";
|
|
2
|
+
import { injectable, inject } from "inversify";
|
|
3
|
+
import gitRemoteOriginUrl from "git-remote-origin-url";
|
|
4
|
+
|
|
5
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
6
|
+
import { CommandLineToast } from "@/utils/CommandLineToast";
|
|
7
|
+
|
|
8
|
+
@injectable()
|
|
9
|
+
export class LaunchRemoteRepo {
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
@inject(CommandLineToast) private readonly $CommandLineToast: CommandLineToast
|
|
13
|
+
) { };
|
|
14
|
+
|
|
15
|
+
public async execute() {
|
|
16
|
+
try {
|
|
17
|
+
this.$CommandLineToast.start("查询git远程仓库,请稍后... ...");
|
|
18
|
+
const remoteURL = await gitRemoteOriginUrl();
|
|
19
|
+
await open(remoteURL);
|
|
20
|
+
this.$CommandLineToast.succeed("complate!");
|
|
21
|
+
} catch (error) {
|
|
22
|
+
this.$CommandLineToast.fail("error!");
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
IOCContainer.bind(LaunchRemoteRepo).toSelf().inRequestScope();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { injectable, inject } from "inversify";
|
|
2
|
+
|
|
3
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
4
|
+
import { FastCommitAction } from "@/actions/FastCommitAction";
|
|
5
|
+
|
|
6
|
+
import { UpdateRemoteURL } from "@/services/UpdateRemoteURL";
|
|
7
|
+
import { CreateIgnoreFile } from "@/services/CreateIgnoreFile";
|
|
8
|
+
import { ResetCommitWithIgnore } from "@/services/ResetCommitWithIgnore";
|
|
9
|
+
|
|
10
|
+
import { SelectScriptType } from "@/utils/SelectScriptType";
|
|
11
|
+
|
|
12
|
+
@injectable()
|
|
13
|
+
export class RunGitScripts {
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
@inject(SelectScriptType) private readonly $SelectScriptType: SelectScriptType,
|
|
17
|
+
@inject(UpdateRemoteURL) private readonly $UpdateRemoteURL: UpdateRemoteURL,
|
|
18
|
+
@inject(FastCommitAction) private readonly $FastCommitAction: FastCommitAction,
|
|
19
|
+
@inject(CreateIgnoreFile) private readonly $CreateIgnoreFile: CreateIgnoreFile,
|
|
20
|
+
@inject(ResetCommitWithIgnore) private readonly $ResetCommitWithIgnore: ResetCommitWithIgnore
|
|
21
|
+
) { };
|
|
22
|
+
|
|
23
|
+
public async execute() {
|
|
24
|
+
try {
|
|
25
|
+
const selectActionName = await this.$SelectScriptType.execute();
|
|
26
|
+
if (selectActionName === "fast_commit") {
|
|
27
|
+
await this.$FastCommitAction.execute();
|
|
28
|
+
};
|
|
29
|
+
if (selectActionName === "generate_gitignore_file") {
|
|
30
|
+
await this.$CreateIgnoreFile.execute();
|
|
31
|
+
};
|
|
32
|
+
if (selectActionName === "reset_with_gitignore_file") {
|
|
33
|
+
await this.$ResetCommitWithIgnore.execute();
|
|
34
|
+
};
|
|
35
|
+
if (selectActionName === "update_remote_repo") {
|
|
36
|
+
await this.$UpdateRemoteURL.execute();
|
|
37
|
+
};
|
|
38
|
+
console.log("未知的操作类型", selectActionName);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
throw error;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
IOCContainer.bind(RunGitScripts).toSelf().inRequestScope();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { merge } from "lodash";
|
|
4
|
+
import simpleGit from "simple-git";
|
|
5
|
+
import pathExists from "path-exists";
|
|
6
|
+
import { readFile } from "jsonfile";
|
|
7
|
+
import { injectable } from "inversify";
|
|
8
|
+
|
|
9
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
10
|
+
|
|
11
|
+
import type { SimpleGit } from "simple-git";
|
|
12
|
+
|
|
13
|
+
@injectable()
|
|
14
|
+
export class ApplicationConfigManager {
|
|
15
|
+
|
|
16
|
+
private git: SimpleGit = simpleGit();
|
|
17
|
+
|
|
18
|
+
/** 应用层内置的默认配置 **/
|
|
19
|
+
private defaultConfig: any = {};
|
|
20
|
+
|
|
21
|
+
/** 操作系统层的配置 **/
|
|
22
|
+
private systemConfig: any = {};
|
|
23
|
+
|
|
24
|
+
/** $HOME目录下的配置 **/
|
|
25
|
+
private custmerConfig: any = {};
|
|
26
|
+
|
|
27
|
+
/** 声明在操作系统层的配置文件路径 **/
|
|
28
|
+
get systemConfigPath() {
|
|
29
|
+
return path.join("/etc/", "/cyber-tools/", "./cyber-git-config.json");
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** 声明在$HOME目录下的配置文件路径 **/
|
|
33
|
+
get custmerConfigPath() {
|
|
34
|
+
return path.join(os.homedir(), "/.cyber-tools/", "./cyber-git-config.json");
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** 初始化并加载配置到运行时 **/
|
|
38
|
+
public async initialize() {
|
|
39
|
+
if (await pathExists(this.systemConfigPath)) {
|
|
40
|
+
this.systemConfig = await readFile(this.systemConfigPath);
|
|
41
|
+
};
|
|
42
|
+
if (await pathExists(this.custmerConfigPath)) {
|
|
43
|
+
this.custmerConfig = await readFile(this.custmerConfigPath);
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** 获取最终组合之后的运行时配置 **/
|
|
48
|
+
public getRuntimeConfig() {
|
|
49
|
+
const composeConfig = merge(this.defaultConfig, this.systemConfig, this.custmerConfig);
|
|
50
|
+
return composeConfig;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** 获取SimpleGit的操作示例 **/
|
|
54
|
+
public getGitInstance(): SimpleGit {
|
|
55
|
+
return this.git;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
IOCContainer.bind(ApplicationConfigManager).toSelf().inSingletonScope();
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
import packageJsonContent from "@@/package.json"
|
|
4
|
+
|
|
5
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
6
|
+
import { ApplicationConfigManager } from "@/commons/ApplicationConfigManager";
|
|
7
|
+
|
|
8
|
+
import { FastCommitAction } from "@/actions/FastCommitAction";
|
|
9
|
+
import { LaunchRemoteRepo } from "@/actions/LaunchRemoteRepo";
|
|
10
|
+
import { RunGitScripts } from "@/actions/RunGitScripts";
|
|
11
|
+
|
|
12
|
+
setImmediate(async () => {
|
|
13
|
+
await IOCContainer.get(ApplicationConfigManager).initialize();
|
|
14
|
+
program
|
|
15
|
+
.usage("cyber-git <command>")
|
|
16
|
+
.version(packageJsonContent.version);
|
|
17
|
+
|
|
18
|
+
program
|
|
19
|
+
.command("commit")
|
|
20
|
+
.description("提交文件并生成规范化命令")
|
|
21
|
+
.action(async () => {
|
|
22
|
+
await IOCContainer.get(FastCommitAction).execute();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
program
|
|
26
|
+
.command("open")
|
|
27
|
+
.description("在浏览器中打开远程的git仓库")
|
|
28
|
+
.action(async () => {
|
|
29
|
+
await IOCContainer.get(LaunchRemoteRepo).execute();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
program
|
|
33
|
+
.command("script", { isDefault: true })
|
|
34
|
+
.description("运行其他脚本")
|
|
35
|
+
.action(async () => {
|
|
36
|
+
await IOCContainer.get(RunGitScripts).execute();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
program.parse(process.argv);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { injectable, inject } from "inversify";
|
|
2
|
+
|
|
3
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
4
|
+
import { CommentMessageGenerater } from "@/utils/CommentMessageGenerater";
|
|
5
|
+
|
|
6
|
+
@injectable()
|
|
7
|
+
export class CommentPresetServices {
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
@inject(CommentMessageGenerater) private readonly $CommentMessageGenerater: CommentMessageGenerater
|
|
11
|
+
) { };
|
|
12
|
+
|
|
13
|
+
public async getCommitPresets() {
|
|
14
|
+
return {
|
|
15
|
+
"临时提交": async () => await this.$CommentMessageGenerater.createNormalMessage({
|
|
16
|
+
type: "temp",
|
|
17
|
+
title: "临时节点标记"
|
|
18
|
+
}),
|
|
19
|
+
"简单描述": async () => await this.$CommentMessageGenerater.createNormalMessage({
|
|
20
|
+
type: "description",
|
|
21
|
+
title: "简单描述"
|
|
22
|
+
}),
|
|
23
|
+
"重构功能": async () => await this.$CommentMessageGenerater.createNormalMessage({
|
|
24
|
+
type: "refactor",
|
|
25
|
+
title: "重构功能"
|
|
26
|
+
}),
|
|
27
|
+
"新功能": async () => await this.$CommentMessageGenerater.createNormalMessage({
|
|
28
|
+
type: "feat",
|
|
29
|
+
title: "开发新功能"
|
|
30
|
+
}),
|
|
31
|
+
"修复bug": async () => await this.$CommentMessageGenerater.createNormalMessage({
|
|
32
|
+
type: "fix",
|
|
33
|
+
title: "修复存在问题"
|
|
34
|
+
}),
|
|
35
|
+
"文档改变": async () => await this.$CommentMessageGenerater.createNormalMessage({
|
|
36
|
+
type: "docs",
|
|
37
|
+
title: "变更文档内容"
|
|
38
|
+
}),
|
|
39
|
+
"撤销commit": async () => await this.$CommentMessageGenerater.createNormalMessage({
|
|
40
|
+
type: "revert",
|
|
41
|
+
title: "回滚提交"
|
|
42
|
+
}),
|
|
43
|
+
"增加测试代码": async () => await this.$CommentMessageGenerater.createNormalMessage({
|
|
44
|
+
type: "test",
|
|
45
|
+
title: "新增测试代码"
|
|
46
|
+
})
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
IOCContainer.bind(CommentPresetServices).toSelf().inSingletonScope();
|
|
54
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { injectable, inject } from "inversify";
|
|
2
|
+
|
|
3
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
4
|
+
import { ApplicationConfigManager } from "@/commons/ApplicationConfigManager";
|
|
5
|
+
|
|
6
|
+
import { PopConfirmUtils } from "@/utils/PopConfirmUtils";
|
|
7
|
+
import { ProjectJudgment } from "@/utils/ProjectJudgment";
|
|
8
|
+
import { CommandLineToast } from "@/utils/CommandLineToast";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 确认是否需要推送到远程仓库
|
|
12
|
+
* **/
|
|
13
|
+
@injectable()
|
|
14
|
+
export class ConfirmAndPushRemote {
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
@inject(PopConfirmUtils) private readonly $PopConfirmUtils: PopConfirmUtils,
|
|
18
|
+
@inject(ProjectJudgment) private readonly $ProjectJudgment: ProjectJudgment,
|
|
19
|
+
@inject(CommandLineToast) private readonly $CommandLineToast: CommandLineToast,
|
|
20
|
+
@inject(ApplicationConfigManager) private readonly $ApplicationConfigManager: ApplicationConfigManager
|
|
21
|
+
) { };
|
|
22
|
+
|
|
23
|
+
public async execute() {
|
|
24
|
+
const git = this.$ApplicationConfigManager.getGitInstance();
|
|
25
|
+
if (await this.$ProjectJudgment.hasRemote()) {
|
|
26
|
+
try {
|
|
27
|
+
if (await this.$PopConfirmUtils.execute("是否推送到远程仓库?")) {
|
|
28
|
+
this.$CommandLineToast.start("正在推送,请稍后...");
|
|
29
|
+
await git.push();
|
|
30
|
+
this.$CommandLineToast.succeed("推送成功!");
|
|
31
|
+
};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
this.$CommandLineToast.warn("没有检测到远程仓库!");
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
IOCContainer.bind(ConfirmAndPushRemote).toSelf().inRequestScope();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { promisify } from "util";
|
|
4
|
+
import { injectable, inject } from "inversify";
|
|
5
|
+
|
|
6
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
7
|
+
import { ProjectJudgment } from "@/utils/ProjectJudgment";
|
|
8
|
+
import { CommandLineToast } from "@/utils/CommandLineToast";
|
|
9
|
+
|
|
10
|
+
@injectable()
|
|
11
|
+
export class CreateIgnoreFile {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* .gitignore文件的内容摸板
|
|
15
|
+
* **/
|
|
16
|
+
private ignoreFiletemplate = [
|
|
17
|
+
"/node_modules/",
|
|
18
|
+
"**/.DS_Store",
|
|
19
|
+
"package-lock.json"
|
|
20
|
+
].join("\n");
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
@inject(ProjectJudgment) private readonly $ProjectJudgment: ProjectJudgment,
|
|
24
|
+
@inject(CommandLineToast) private readonly $CommandLineToast: CommandLineToast
|
|
25
|
+
) { };
|
|
26
|
+
|
|
27
|
+
public async execute() {
|
|
28
|
+
if (await this.$ProjectJudgment.hasIgnoreFile()) {
|
|
29
|
+
this.$CommandLineToast.warn("该项目已存在.gitignore文件");
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
try {
|
|
33
|
+
this.$CommandLineToast.start("正在写入文件");
|
|
34
|
+
const writeFilePath = path.join(process.cwd(), ".gitignore");
|
|
35
|
+
await promisify(fs.writeFile)(writeFilePath, this.ignoreFiletemplate);
|
|
36
|
+
this.$CommandLineToast.succeed("写入成功!");
|
|
37
|
+
} catch (error) {
|
|
38
|
+
this.$CommandLineToast.fail("写入失败!");
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
IOCContainer.bind(CreateIgnoreFile).toSelf().inRequestScope();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { injectable, inject } from "inversify";
|
|
2
|
+
|
|
3
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
4
|
+
import { ApplicationConfigManager } from "@/commons/ApplicationConfigManager";
|
|
5
|
+
|
|
6
|
+
import { ConfirmAndPushRemote } from "@/services/ConfirmAndPushRemote";
|
|
7
|
+
|
|
8
|
+
import { CommentMessageGenerater } from "@/utils/CommentMessageGenerater";
|
|
9
|
+
import { CommandLineToast } from "@/utils/CommandLineToast";
|
|
10
|
+
|
|
11
|
+
@injectable()
|
|
12
|
+
export class FirstCommit {
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
@inject(ApplicationConfigManager) private readonly $ApplicationConfigManager: ApplicationConfigManager,
|
|
16
|
+
@inject(CommentMessageGenerater) private readonly $CommentMessageGenerater: CommentMessageGenerater,
|
|
17
|
+
@inject(ConfirmAndPushRemote) private readonly $ConfirmAndPushRemote: ConfirmAndPushRemote,
|
|
18
|
+
@inject(CommandLineToast) private readonly $CommandLineToast: CommandLineToast,
|
|
19
|
+
) { };
|
|
20
|
+
|
|
21
|
+
private async createInitMessage() {
|
|
22
|
+
try {
|
|
23
|
+
const comment_title = this.$CommentMessageGenerater.createCommentTitle({ type: "init", title: "项目初始化" });
|
|
24
|
+
const inputDescription = await this.$CommentMessageGenerater.inputDescriptionText("请输入");
|
|
25
|
+
return [comment_title, inputDescription || "项目初始化提交"].join("\n");
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw error;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
public async execute() {
|
|
32
|
+
try {
|
|
33
|
+
const git = this.$ApplicationConfigManager.getGitInstance();
|
|
34
|
+
await git.init();
|
|
35
|
+
await git.add(".");
|
|
36
|
+
const commitMessage = await this.createInitMessage();
|
|
37
|
+
this.$CommandLineToast.start("正在进行项目初始化提交");
|
|
38
|
+
await git.commit(commitMessage);
|
|
39
|
+
this.$CommandLineToast.succeed("项目初始化成功!");
|
|
40
|
+
await this.$ConfirmAndPushRemote.execute();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw error;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
IOCContainer.bind(FirstCommit).toSelf().inRequestScope();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { injectable, inject } from "inversify";
|
|
2
|
+
|
|
3
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
4
|
+
import { FirstCommit } from "@/services/FirstCommit";
|
|
5
|
+
|
|
6
|
+
import { CommandLineToast } from "@/utils/CommandLineToast";
|
|
7
|
+
import { PopConfirmUtils } from "@/utils/PopConfirmUtils";
|
|
8
|
+
import { ProjectJudgment } from "@/utils/ProjectJudgment";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 项目自检
|
|
12
|
+
* **/
|
|
13
|
+
@injectable()
|
|
14
|
+
export class ProjectSelfInspection {
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
@inject(FirstCommit) private readonly $FirstCommit: FirstCommit,
|
|
18
|
+
@inject(PopConfirmUtils) private readonly $PopConfirmUtils: PopConfirmUtils,
|
|
19
|
+
@inject(ProjectJudgment) private readonly $ProjectJudgment: ProjectJudgment,
|
|
20
|
+
@inject(CommandLineToast) private readonly $CommandLineToast: CommandLineToast
|
|
21
|
+
) { };
|
|
22
|
+
|
|
23
|
+
public async execute() {
|
|
24
|
+
/** 先检查项目文件夹中是否包含package.json **/
|
|
25
|
+
if (!await this.$ProjectJudgment.hasPackageJson()) {
|
|
26
|
+
this.$CommandLineToast.warn("当前项目文件没有package.json文件");
|
|
27
|
+
process.exit(0);
|
|
28
|
+
};
|
|
29
|
+
/** 判断项目是否已经进行了git init操作 **/
|
|
30
|
+
if (!await this.$ProjectJudgment.isInit()) {
|
|
31
|
+
const confirmToInitial = await this.$PopConfirmUtils.execute("检测到该项目没有被git初始化,是否进行初始化");
|
|
32
|
+
if (!confirmToInitial) {
|
|
33
|
+
process.exit(0);
|
|
34
|
+
} else {
|
|
35
|
+
await this.$FirstCommit.execute();
|
|
36
|
+
process.exit(0);
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/** 判断当前项目文件是否发生了变动 **/
|
|
40
|
+
if (!await this.$ProjectJudgment.isChange()) {
|
|
41
|
+
this.$CommandLineToast.warn("当前项目文件没有变动");
|
|
42
|
+
process.exit(0);
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
IOCContainer.bind(ProjectSelfInspection).toSelf().inRequestScope();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { injectable, inject } from "inversify";
|
|
2
|
+
|
|
3
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
4
|
+
import { ApplicationConfigManager } from "@/commons/ApplicationConfigManager";
|
|
5
|
+
|
|
6
|
+
import { FastCommitAction } from "@/actions/FastCommitAction";
|
|
7
|
+
import { CommandLineToast } from "@/utils/CommandLineToast";
|
|
8
|
+
import { ProjectJudgment } from "@/utils/ProjectJudgment";
|
|
9
|
+
|
|
10
|
+
@injectable()
|
|
11
|
+
export class ResetCommitWithIgnore {
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
@inject(ApplicationConfigManager) private readonly $ApplicationConfigManager: ApplicationConfigManager,
|
|
15
|
+
@inject(FastCommitAction) private readonly $FastCommitAction: FastCommitAction,
|
|
16
|
+
@inject(CommandLineToast) private readonly $CommandLineToast: CommandLineToast,
|
|
17
|
+
@inject(ProjectJudgment) private readonly $ProjectJudgment: ProjectJudgment
|
|
18
|
+
) { };
|
|
19
|
+
|
|
20
|
+
public async execute() {
|
|
21
|
+
const git = this.$ApplicationConfigManager.getGitInstance();
|
|
22
|
+
if (await this.$ProjectJudgment.hasIgnoreFile()) {
|
|
23
|
+
try {
|
|
24
|
+
this.$CommandLineToast.start("正在解除... ...");
|
|
25
|
+
await git.rm(["-r", "--cached", "."]);
|
|
26
|
+
this.$CommandLineToast.succeed("解除成功!");
|
|
27
|
+
await this.$FastCommitAction.execute();
|
|
28
|
+
} catch (error) {
|
|
29
|
+
this.$CommandLineToast.fail("重置失败!");
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
this.$CommandLineToast.warn("该项目下不存在.gitignore文件");
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
IOCContainer.bind(ResetCommitWithIgnore).toSelf().inRequestScope();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { injectable, inject } from "inversify";
|
|
2
|
+
|
|
3
|
+
import { IOCContainer } from "@/commons/IOCContainer";
|
|
4
|
+
import { ApplicationConfigManager } from "@/commons/ApplicationConfigManager";
|
|
5
|
+
|
|
6
|
+
import { CommandLineToast } from "@/utils/CommandLineToast";
|
|
7
|
+
import { ProjectJudgment } from "@/utils/ProjectJudgment";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@injectable()
|
|
11
|
+
export class UpdateRemoteURL {
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
@inject(ApplicationConfigManager) private readonly $ApplicationConfigManager: ApplicationConfigManager,
|
|
15
|
+
@inject(CommandLineToast) private readonly $CommandLineToast: CommandLineToast,
|
|
16
|
+
@inject(ProjectJudgment) private readonly $ProjectJudgment: ProjectJudgment
|
|
17
|
+
) { };
|
|
18
|
+
|
|
19
|
+
public async execute() {
|
|
20
|
+
const git = this.$ApplicationConfigManager.getGitInstance();
|
|
21
|
+
if (await this.$ProjectJudgment.hasRemote()) {
|
|
22
|
+
try {
|
|
23
|
+
await git.removeRemote("origin");
|
|
24
|
+
const repoUrl = await prompt("新的远程仓库url:");
|
|
25
|
+
await git.addRemote("origin", repoUrl);
|
|
26
|
+
this.$CommandLineToast.succeed("remote更新成功!");
|
|
27
|
+
// this.$CommandLineToast.start("正在推送,请稍后... ...");
|
|
28
|
+
// await git.push("origin", {
|
|
29
|
+
// "--all": true,
|
|
30
|
+
// "--set-upstream": true
|
|
31
|
+
// });
|
|
32
|
+
// await git.push(["-u", "origin", "master"]);
|
|
33
|
+
// this.$CommandLineToast.succeed("推送成功!");
|
|
34
|
+
} catch (error) {
|
|
35
|
+
this.$CommandLineToast.fail("更新失败!");
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
this.$CommandLineToast.warn("没有检测到远程仓库!");
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
IOCContainer.bind(UpdateRemoteURL).toSelf().inRequestScope();
|