From 3a2fbfe95a063719c6229a6a4e8de4287ccbafe2 Mon Sep 17 00:00:00 2001 From: AKclown <13413629530@139.com> Date: Sun, 29 May 2022 15:02:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BAGitServe=E5=9F=BA?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 20 ++++++----------- models/git/lib/GitServer.js | 43 +++++++++++++++++++++++++++++++++++++ models/git/lib/Gitee.js | 9 ++++++++ models/git/lib/Github.js | 9 ++++++++ models/git/lib/index.js | 16 ++++++++++++++ 5 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 models/git/lib/GitServer.js create mode 100644 models/git/lib/Gitee.js create mode 100644 models/git/lib/Github.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b2b1e..d58a2d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - - - diff --git a/models/git/lib/GitServer.js b/models/git/lib/GitServer.js new file mode 100644 index 0000000..d98f32e --- /dev/null +++ b/models/git/lib/GitServer.js @@ -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; diff --git a/models/git/lib/Gitee.js b/models/git/lib/Gitee.js new file mode 100644 index 0000000..e06c8ce --- /dev/null +++ b/models/git/lib/Gitee.js @@ -0,0 +1,9 @@ +const GitServer = require('./GitServer'); + +class Gitee extends GitServer { + constructor() { + super('gitee'); + } +} + +module.exports = Gitee; diff --git a/models/git/lib/Github.js b/models/git/lib/Github.js new file mode 100644 index 0000000..edcd902 --- /dev/null +++ b/models/git/lib/Github.js @@ -0,0 +1,9 @@ +const GitServer = require('./GitServer'); + +class Github extends GitServer { + constructor() { + super('github'); + } +} + +module.exports = Github; diff --git a/models/git/lib/index.js b/models/git/lib/index.js index cb05594..1c64263 100644 --- a/models/git/lib/index.js +++ b/models/git/lib/index.js @@ -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'; @@ -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 的文件路径