Skip to content

Commit

Permalink
fix: 修复publish Git包引用问题,以及修改生成token的参考文献
Browse files Browse the repository at this point in the history
  • Loading branch information
AKclown committed May 30, 2022
1 parent 8b68fd8 commit ee4c3c9
Show file tree
Hide file tree
Showing 8 changed files with 15,245 additions and 2,326 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

npm run lint-staged
yarn run lint-staged
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ ak-cli 工具
ak-cli init --targetPath /Users/ak/Desktop/project/ak-cli/commands/init --force --debug test-project
```

### publish 命令

```
ak-cli publish --targetPath E:/project/project/ak-cli/core/cli/commands/publish
```

### 提交规范

1. commitizen
Expand All @@ -18,7 +24,11 @@ ak-cli init --targetPath /Users/ak/Desktop/project/ak-cli/commands/init --force

3. @commitlint/cli (校验提交说明是否符合规范)
4. @commitlint/config-conventional (安装符合 Angular 风格的校验规则)
5. husky (git 钩子工具)
5. husky/lint-staged(git 钩子工具)

### git 命令

[git 命令](https://cloud.tencent.com/developer/section/1138701)

[commit 参考文献](https://godbasin.github.io/2019/11/10/change-log/)

Expand Down
10 changes: 5 additions & 5 deletions commands/publish/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('@ak-clown/command');
const Git = require('@ak-clown/command');
const Git = require('@ak-clown/git');
const log = require('@ak-clown/log');
const path = require('path');
const fse = require('fs-extra');
Expand All @@ -24,8 +24,7 @@ class PublishCommand extends Command {
this.prepare();
// 2. Git Flow自动化
const git = new Git(this.projectInfo, this.options);
git.prepare();
console.log('git: ', git);
await git.prepare();
// 3. 云构建 和 云发布
const endTime = new Date().getTime();
log.info(
Expand All @@ -44,6 +43,7 @@ class PublishCommand extends Command {
prepare() {
// 1. 确认项目是否为npm项目 (package.json是否存在)
const projectPath = process.cwd();
console.log('projectPath: ', projectPath);
const pkgPath = path.resolve(projectPath, 'package.json');
if (!fse.pathExistsSync(pkgPath)) {
throw new Error('package.json不存在');
Expand All @@ -61,10 +61,10 @@ class PublishCommand extends Command {
}
}

function init(args) {
function publish(args) {
// $ 这个args就是执行脚手架传入的参数
return new PublishCommand(args);
}

module.exports = init;
module.exports = publish;
module.exports.PublishCommand = PublishCommand;
2 changes: 1 addition & 1 deletion core/cli/lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const LOWEST_NODE_VERSION = '12.0.0';
const DEFAULT_CLI_HOME = 'ak-cli';
const DEFAULT_CLI_HOME = '.ak-cli';

module.exports = {
LOWEST_NODE_VERSION,
Expand Down
1 change: 1 addition & 0 deletions core/exec/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async function exec() {
const cmdName = cmdObj.name();
// 获取到对应的包名
const packageName = SETTINGS[cmdName];
console.log('packageName: ', packageName);
// 默认给定一个最新的版本号
const packageVersion = 'latest';
// $ 暂定
Expand Down
2 changes: 1 addition & 1 deletion models/git/lib/Github.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Github extends GitServer {

// 获取SSH KEY的帮助文档
getTokenHelpUrl() {
return 'https://docs.github.com/cn/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection';
return 'https://github.com/settings/tokens/new';
}
}

Expand Down
57 changes: 44 additions & 13 deletions models/git/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const path = require('path');
const userHome = require('user-home');
const fse = require('fs-extra');
const fs = require('fs');
const { spinnerStart, readFile, writeFile } = require('"@ak-clown/utils');
const { spinnerStart, readFile, writeFile } = require('@ak-clown/utils');
const inquirer = require('inquirer');
const terminalLink = require('terminal-link');
const Github = require('./Github');
const Gitee = require('./Gitee');

// 主目录
const DEFAULT_CLI_HOME = 'ak-cli';
const DEFAULT_CLI_HOME = '.ak-cli';
// git主目录
const GIT_ROOT_DIR = '.git';
// git server文件
Expand Down Expand Up @@ -112,7 +112,37 @@ class Git {
if (this.getRemote()) {
return;
}
// 初始化git仓库和add remote关联远程仓库
await this.initAndAddRemote();
// 初始化提交
await this.initCommit();
}

// 初始化提交
async initCommit() {
/**
* 1.检查代码冲突
* 2.检查是否有未提交的数据
* 3.检查是否存在master分支
*/
await this.checkConflicted();
await this.checkNotCommit();
}

// 检查代码冲突
async checkConflicted() {
log.info('代码冲突检查');
const status = await this.git.status();
if (status.conflicted.length > 0) {
throw new Error('当前代码存在冲突,请手动处理合并后再试!');
}
log.success('代码冲突检查通过');
}

// 检查是否有未提交的数据
async checkNotCommit() {
// const status = await this.git.status();
// if(status.no_added)
}

// 获取到远程
Expand Down Expand Up @@ -164,15 +194,17 @@ class Git {
// 不存在文件内容,提供选择 给 用户选择git平台
if (!gitServer || this.refreshServer) {
// 选择托管的git平台
const { gitServer } = await inquirer.prompt([
{
type: 'list',
name: 'gitServer',
message: '请选择你想要托管的Git平台',
default: GITHUB,
choices: GIT_SERVER_TYPE,
},
]);
gitServer = (
await inquirer.prompt([
{
type: 'list',
name: 'gitServer',
message: '请选择你想要托管的Git平台',
default: GITHUB,
choices: GIT_SERVER_TYPE,
},
])
).gitServer;
writeFile(gitServerPath, gitServer);
log.success('git server 写入成功', `${gitServer} --> ${gitServerPath}`);
} else {
Expand All @@ -195,8 +227,7 @@ class Git {
this.gitServer.type + 'token未生成',
'请先生成' +
this.gitServer.type +
'token,' +
terminalLink(this.gitServer.getTokenHelpUrl())
terminalLink('的token,参考文献:', this.gitServer.getTokenHelpUrl())
);
token = (
await inquirer.prompt({
Expand Down
Loading

0 comments on commit ee4c3c9

Please sign in to comment.