UNPKG

bia

Version:

a tool for download git repository

314 lines (309 loc) 18.5 kB
/* * @Author: hzxulin@yeah.net * @Date: 2018-02-01 14:04:04 * @Last Modified by: hzxulin * @Last Modified time: 2020-12-30 11:09:19 */ const path = require('path') const utils = require('./utils') const question = require('./question') const colors = require('colors') const BASE_CONFIG = require('../../config/base.json') module.exports = (cmd, opts) => { switch (cmd) { case 'act': case 'act2': { // 新版活动相关 if (opts.file) { utils.cloneGit(BASE_CONFIG.repo.bia2act, 'ver-0.9.0', '项目更新中...').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess() }).catch(err => { console.log(err) }) } else { let answer = {} question.askActBusinessId().then(businessId => { answer = Object.assign(answer, { businessId, }) return question.askTplCategory().then(tplCategory => { answer = Object.assign(answer, { tplCategory: tplCategory.cvalue, tplPlatform: tplCategory.platform, }) if (answer.tplPlatform) { return question.askPlatform().then(platform => { answer = Object.assign(answer, { platform, }) return utils.getCateList().then(list => { return question.askCateList(list).then(cateList => { answer = Object.assign(answer, { cateList, }) return question.askPageInfo() }) }) }) } else { answer = Object.assign(answer, { platform: 2, }) return utils.getCateList().then(list => { return question.askCateList(list).then(cateList => { answer = Object.assign(answer, { cateList, }) return question.askPageInfo() }) }) } }) }).then((res) => { answer = Object.assign(answer, res) return utils.cloneGit(BASE_CONFIG.repo.bia2act, 'ver-0.9.0') }).then(tpl => { const distFolder = path.resolve(process.cwd()) utils.moveFiles('', tpl, distFolder) utils.renderPageInfoJson(answer, path.resolve(distFolder, 'pageInfo/pageInfo.tpl'), path.resolve(distFolder, 'pageInfo/pageInfo.json')) utils.renderFloorListJson(answer, path.resolve(distFolder, 'pageInfo/floorList.tpl'), path.resolve(distFolder, 'pageInfo/floorList.json')) return utils.cloneGit(BASE_CONFIG.repo.bia_tpl, answer.tplCategory) }).then(tpl => { const srcFolder = path.resolve(tpl, answer.tplCategory) const distFolder = path.resolve(process.cwd(), 'src') return utils.renderTpl(answer.platform, srcFolder, distFolder) }).then(() => { utils.showSuccess(() => { console.log(colors.green('┌───────────────────────────────┐')) console.log(colors.green('│ Bia success. │')) console.log(colors.green('│ │')) console.log(colors.green('│ cnpm i │')) console.log(colors.green('│ npm run dev │')) console.log(colors.green('└───────────────────────────────┘')) }) }).catch(err => { console.log(err) }) } break } case 'newact': { utils.cloneGit(BASE_CONFIG.repo.bia2act, 'ver-0.9.1', '正在升级中,该功能主要起辅助作用...').then(tpl => { return utils.moveFiles('./', tpl, path.resolve(process.cwd())) }).then(() => { return utils.updateAct() }).then(() => { utils.showSuccess() }).catch(err => { console.log(err) }) break } case 'eris': case 'eris2': { question.askErisCategory().then(category => { return utils.cloneGit(category, 'dev-2.7.0', opts.file ? '项目更新中...' : '') }).then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess(() => { console.log(colors.green('┌───────────────────────────────┐')) console.log(colors.green('│ Bia success. │')) console.log(colors.green('│ │')) console.log(colors.green('│ cnpm i │')) console.log(colors.green('│ npm run init │')) console.log(colors.green('│ npm run dev │')) console.log(colors.green('└───────────────────────────────┘')) }) }).catch(err => { console.log(err) }) break } case 'eris3': { question.askErisCategory().then(category => { return utils.cloneGit(category, 'dev-3.0.0', opts.file ? '项目更新中...' : '') }).then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess(() => { console.log(colors.green('┌───────────────────────────────┐')) console.log(colors.green('│ Bia success. │')) console.log(colors.green('│ │')) console.log(colors.green('│ cnpm i │')) console.log(colors.green('│ npm run init │')) console.log(colors.green('│ npm run dev │')) console.log(colors.green('└───────────────────────────────┘')) }) }).catch(err => { console.log(err) }) break } case 'eos': { utils.cloneGit(BASE_CONFIG.repo.bia2eos, 'master', opts.file ? '项目更新中...' : '').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess(() => { console.log(colors.green('┌───────────────────────────────┐')) console.log(colors.green('│ Bia success. │')) console.log(colors.green('│ │')) console.log(colors.green('│ cnpm i │')) console.log(colors.green('│ npm run dev │')) console.log(colors.green('└───────────────────────────────┘')) }) }).catch(err => { console.log(err) }) break } case 'vue': { utils.cloneGit(BASE_CONFIG.repo.bia2vue, 'master', opts.file ? '项目更新中...' : '').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess(() => { console.log(colors.green('┌───────────────────────────────┐')) console.log(colors.green('│ Bia success. │')) console.log(colors.green('│ │')) console.log(colors.green('│ cnpm i │')) console.log(colors.green('│ npm run dev │')) console.log(colors.green('└───────────────────────────────┘')) }) }).catch(err => { console.log(err) }) break } case 'react': { utils.cloneGit(BASE_CONFIG.repo.bia2react, 'master', opts.file ? '项目更新中...' : '').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess() }).catch(err => { console.log(err) }) break } case 'angular': { utils.cloneGit(BASE_CONFIG.repo.bia2angular, 'master', opts.file ? '项目更新中...' : '').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess() }).catch(err => { console.log(err) }) break } case 'mini': { utils.cloneGit(BASE_CONFIG.repo.bia2mini, 'master', opts.file ? '项目更新中...' : '').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess() }).catch(err => { console.log(err) }) break } case 'weex': { utils.cloneGit(BASE_CONFIG.repo.bia2weex, 'master', opts.file ? '项目更新中...' : '').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess() }).catch(err => { console.log(err) }) break } case 'taro': { question.askTaroType().then(res => { switch (res.type) { case 'component': { if (opts.file) { utils.cloneGit(res.repo, 'master', opts.file ? '项目更新中...' : '').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess(() => { console.log(colors.green('┌────────────────────────────────────────────────────┐')) console.log(colors.green('│ Bia success. │')) console.log(colors.green('│ nrm use ppnpm │')) console.log(colors.green('│ http://yx.mail.netease.com/wiki/#/doc/319334 │')) console.log(colors.green('│ │')) console.log(colors.green('│ npm install │')) console.log(colors.green('│ npm run dev:h5 │')) console.log(colors.green('└────────────────────────────────────────────────────┘')) }) }).catch(err => { console.log(err) }) } else { let newInfo = {} question.askTaroComponentInfo().then(info => { newInfo = Object.assign({}, info) return utils.cloneGit(res.repo, 'master', opts.file ? '项目更新中...' : '') }).then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { return utils.updateComponentFramework(newInfo) }).then(() => { utils.showSuccess(() => { console.log(colors.green('┌────────────────────────────────────────────────────┐')) console.log(colors.green('│ Bia success. │')) console.log(colors.green('│ nrm use ppnpm │')) console.log(colors.green('│ http://yx.mail.netease.com/wiki/#/doc/319334 │')) console.log(colors.green('│ │')) console.log(colors.green('│ npm install │')) console.log(colors.green('│ npm run dev:h5 │')) console.log(colors.green('└────────────────────────────────────────────────────┘')) }) }).catch(err => { console.log(err) }) } break } case 'page': default: { utils.cloneGit(res.repo, 'master', opts.file ? '项目更新中...' : '').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { utils.showSuccess(() => { console.log(colors.green('┌────────────────────────────────────────────────────┐')) console.log(colors.green('│ Bia success. │')) console.log(colors.green('│ nrm use ppnpm │')) console.log(colors.green('│ http://yx.mail.netease.com/wiki/#/doc/319334 │')) console.log(colors.green('│ │')) console.log(colors.green('│ npm install │')) console.log(colors.green('│ npm run dev:h5 │')) console.log(colors.green('└────────────────────────────────────────────────────┘')) }) }).catch(err => { console.log(err) }) break } } }) } case 'ops': { question.askOpsType().then(res => { utils.cloneGit(res.repo, 'master', '项目更新中...').then(tpl => { return utils.moveFiles(opts.file, tpl, path.resolve(process.cwd())) }).then(() => { console.log(colors.green('┌────────────────────────────────────────────────────┐')) console.log(colors.green('│ Bia success. │')) console.log(colors.green('│ │')) console.log(colors.green('│ npm install │')) console.log(colors.green('│ npm run dev │')) console.log(colors.green('└────────────────────────────────────────────────────┘')) }).catch(err => { console.log(err) }) }) } default: { break } } }