UNPKG

@yeepay/yeepay-cli

Version:

易宝前端脚手架

67 lines (64 loc) 2.21 kB
import axios from 'axios'; import { $, cd } from 'zx'; import chalk from 'chalk' import Log from './log.js'; import ora from 'ora'; import config from '../../config/git.config.js'; const GITLAB_TOKEN = config.token; // 替换为你的 GitLab Token const GITLAB_API_URL = config.apiUrl; // 替换为你的 GitLab API URL export default class GitCreateProject { constructor() { this.axios = axios.create({ baseURL: GITLAB_API_URL, headers: { 'Private-Token': GITLAB_TOKEN, } }); } async createGitLabProject({projectName, description = '', nameSpaceId}) { const spinner = ora(`开始创建仓库...`).start(); try { const response = await this.axios.post('/push-readme', { projectName, description, nameSpaceId }); if(response.data.success){ spinner.succeed('仓库创建成功'); }else{ spinner.fail(`仓库创建失败:原因如下`); Log.red(response.data.message) process.exit(1) } } catch (error) { spinner.fail(`仓库创建500失败:原因如下`); Log.red(error); process.exit(1) } } async pushCode({projectName,group}) { const spinner = ora(`开始代码推送...`).start(); try { await $`git init`.quiet(); await $`git checkout -b feature/dev`.quiet(); await $`git add .`.quiet(); await $`git commit -m "Initial commit"`.quiet(); await $`git remote add origin ${config.requestUrl}${group}/${projectName}.git`.quiet(); await $`git pull origin master --allow-unrelated-histories`.quiet(); await $`git checkout --ours .`.quiet(); await $`git add .`.quiet(); await $`git commit -m "Merge readme.md"`.quiet(); await $`git push origin feature/dev`.quiet(); spinner.succeed('代码推送成功'); Log.enter() console.log('项目首次发布流程可参考:https://yeepay.feishu.cn/wiki/EJqmwgM52if48wkixyNca56unWf') Log.enter() console.log('~祝您开发愉快~') process.exit(0) } catch (error) { spinner.fail(`代码推送失败: ${error.message}`); Log.red('请手动推送代码') process.exit(1) } } }