Skip to content

Commit

Permalink
feat: 创建GitServe基类
Browse files Browse the repository at this point in the history
  • Loading branch information
AKclown committed May 29, 2022
1 parent 32656d8 commit 3a2fbfe
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 13 deletions.
20 changes: 7 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
# [1.0.0](https://github.com/AKclown/ak-cli/compare/v1.0.2...v1.0.0) (2022-05-29)


### Features

* 发布模块架构图、完善git提交规范 ([8ff4043](https://github.com/AKclown/ak-cli/commit/8ff40432f3334d2f47fd7d7997df99a8abbffd80))
* 添加publish模块 ([1a9dcf9](https://github.com/AKclown/ak-cli/commit/1a9dcf9f4f492e01b6c67e17d82aab61e0521b50))
* 项目发布前的检查流程 ([a890ece](https://github.com/AKclown/ak-cli/commit/a890ece362f53fe9d3a01c383de93168e6f01d1d))
* 新增Git package\检查缓存主目录 ([59b72a3](https://github.com/AKclown/ak-cli/commit/59b72a312f0ee7accaa0e7a8831fa2ca9a08ddac))
* **package.json:** 新增commit提交规范 ([e6c0227](https://github.com/AKclown/ak-cli/commit/e6c0227ec67b1e5f80b0da28707e3f340e3d9c7f))


- 发布模块架构图、完善 git 提交规范 ([8ff4043](https://github.com/AKclown/ak-cli/commit/8ff40432f3334d2f47fd7d7997df99a8abbffd80))
- 添加 publish 模块 ([1a9dcf9](https://github.com/AKclown/ak-cli/commit/1a9dcf9f4f492e01b6c67e17d82aab61e0521b50))
- 项目发布前的检查流程 ([a890ece](https://github.com/AKclown/ak-cli/commit/a890ece362f53fe9d3a01c383de93168e6f01d1d))
- 新增 Git package\检查缓存主目录 ([59b72a3](https://github.com/AKclown/ak-cli/commit/59b72a312f0ee7accaa0e7a8831fa2ca9a08ddac))
- 选择远程 Git 仓库逻辑 ([32656d8](https://github.com/AKclown/ak-cli/commit/32656d890ab16da68cc737f9a7bb956b17ae240e))
- **package.json:** 新增 commit 提交规范 ([e6c0227](https://github.com/AKclown/ak-cli/commit/e6c0227ec67b1e5f80b0da28707e3f340e3d9c7f))
- readme 追加 init 模板下载架构图 ([3a9d898](https://github.com/AKclown/ak-cli/commit/3a9d898ae8bd494da42b0a9894402a5a0db7f7d8))

## [1.0.2](https://github.com/AKclown/ak-cli/compare/v1.0.1...v1.0.2) (2022-01-13)



## 1.0.1 (2022-01-13)



43 changes: 43 additions & 0 deletions models/git/lib/GitServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function error(methodName) {
throw new Error(`${methodName} must be implemented !`);
}

class GitServer {
constructor(type, token) {
this.type = type;
this.token = token;
}

// 设置token
setToken() {
error('setToken');
}

// $ 定义子类必须实现方法
// 创建个人仓库
createRepo() {
error('createRepo');
}

// 创建组织仓库
createOrgRepo() {
error('createRepo');
}

// 获取仓库地址
getRemote() {
error('createRepo');
}

// 获取到用户信息
getUser() {
error('createRepo');
}

// 获取到组织信息
getOrg() {
error('createRepo');
}
}

module.exports = GitServer;
9 changes: 9 additions & 0 deletions models/git/lib/Gitee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const GitServer = require('./GitServer');

class Gitee extends GitServer {
constructor() {
super('gitee');
}
}

module.exports = Gitee;
9 changes: 9 additions & 0 deletions models/git/lib/Github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const GitServer = require('./GitServer');

class Github extends GitServer {
constructor() {
super('github');
}
}

module.exports = Github;
16 changes: 16 additions & 0 deletions models/git/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const fse = require('fs-extra');
const fs = require('fs');
const { readFile, writeFile } = require('"@ak-clown/utils');
const inquirer = require('inquirer');
const Github = require('./Github');
const Gitee = require('./Gitee');

// 主目录
const DEFAULT_CLI_HOME = 'ak-cli';
Expand Down Expand Up @@ -88,6 +90,20 @@ class Git {
} else {
log.success('git server 获取成功', gitServer);
}
this.gitServer = this.createGitServer(gitServer);
if (!this.gitServer) {
throw new Error('GitServer初始化失败!');
}
}

// 实例化git server
createGitServer(gitServer) {
if (gitServer === GITHUB) {
return new Github();
} else if (gitServer === GITEE) {
return new Gitee();
}
return null;
}

// 获取git server 的文件路径
Expand Down

0 comments on commit 3a2fbfe

Please sign in to comment.