Skip to content

Commit

Permalink
feat: added version command
Browse files Browse the repository at this point in the history
  • Loading branch information
baiwusanyu-c committed Jan 17, 2023
1 parent 996a72c commit 63ef0b3
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 96 deletions.
3 changes: 3 additions & 0 deletions build-script/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const config = [
copy({
targets: [
{ src: 'template', dest: 'dist/' },
{ src: 'entry', dest: 'dist/' },
{ src: './package.json', dest: 'dist/' },
{ src: './README.md', dest: 'dist/' },
],
}),
],
Expand Down
104 changes: 53 additions & 51 deletions core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,63 @@ import {
} from '../utils'
import { run } from './rumtime/runtime'

export function BeCLIRun() {
// 获取package 文件配置信息
const configInfo = getConfigFile()
const configInfo = getConfigFile()

const program = new Command()
program
.name(configInfo.name)
.description(configInfo.description)
.version(configInfo.version)
const program = new Command()
program
.name(configInfo.name)
.description(configInfo.description)
.version(configInfo.version)

program.action(async() => {
// 输入项目名称
const nameRes = await promptsRun(projectNameOptions)
// 选择项目模板类型
const typeRes = await promptsRun(projectTypeOptions)
program.action(async() => {
// 输入项目名称
const nameRes = await promptsRun(projectNameOptions)
// 选择项目模板类型
const typeRes = await promptsRun(projectTypeOptions)

let componentUiRes = {}
let cssUiRes = {}
let buildRes = {}
let runEnvRes = {}
let otherRes = {}
if (typeRes.projectType === PROJECTTYPE.LIB) {
// 选择使用那个打包库
buildRes = await promptsRun(buildLibTypeOptions)
// 选择使用那个运行环境
runEnvRes = await promptsRun(envTypeOptions)
} else if (typeRes.projectType === PROJECTTYPE.OTHER) {
otherRes = await promptsRun(otherTypeOptions)
} else {
// 选择使用那个组件库
componentUiRes = await promptsRun(typeRes.projectType === PROJECTTYPE.REACT ? uiLibTypeReactOptions : uiLibTypeOptions)
// 选择使用那个css原子样式库
cssUiRes = await promptsRun(cssLibTypeOptions)
}
let componentUiRes = {}
let cssUiRes = {}
let buildRes = {}
let runEnvRes = {}
let otherRes = {}
if (typeRes.projectType === PROJECTTYPE.LIB) {
// 选择使用那个打包库
buildRes = await promptsRun(buildLibTypeOptions)
// 选择使用那个运行环境
runEnvRes = await promptsRun(envTypeOptions)
} else if (typeRes.projectType === PROJECTTYPE.OTHER) {
otherRes = await promptsRun(otherTypeOptions)
} else {
// 选择使用那个组件库
componentUiRes = await promptsRun(typeRes.projectType === PROJECTTYPE.REACT ? uiLibTypeReactOptions : uiLibTypeOptions)
// 选择使用那个css原子样式库
cssUiRes = await promptsRun(cssLibTypeOptions)
}

// 选择使用单元测试
const unitTestRes = await promptsRun(unitTestTypeOptions)
// 选择使用单元测试
const unitTestRes = await promptsRun(unitTestTypeOptions)

// 项目存储路径
const rootPath = process.cwd()
const projectPath = path.resolve(rootPath, nameRes.projectName)
// 组装配置对象
const options = {
projectPath,
...componentUiRes,
...cssUiRes,
...buildRes,
...runEnvRes,
...nameRes,
...typeRes,
...unitTestRes,
...otherRes,
} as any
console.log(options)
// 开始运行命令
await run(options)
})
// 项目存储路径
const rootPath = process.cwd()
const projectPath = path.resolve(rootPath, nameRes.projectName)
// 组装配置对象
const options = {
projectPath,
...componentUiRes,
...cssUiRes,
...buildRes,
...runEnvRes,
...nameRes,
...typeRes,
...unitTestRes,
...otherRes,
} as any
console.log(options)
// 开始运行命令
await run(options)
})

program.parse()
program.parse()
}
4 changes: 2 additions & 2 deletions core/rumtime/add-unit-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra'
import chalk from 'chalk'
import {IOtherOption, templatePath} from '../../utils'
import type { ILibOption, IViteProjOption } from '../../utils'
import { templatePath } from '../../utils'
import type { ILibOption, IOtherOption, IViteProjOption } from '../../utils'

export async function addBaseUnitTest(
packageJson: any,
Expand Down
2 changes: 1 addition & 1 deletion core/rumtime/read-write-package.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import fs from 'fs-extra'
import chalk from 'chalk'
import type {ILibOption, IOtherOption, IViteProjOption} from '../../utils'
import type { ILibOption, IOtherOption, IViteProjOption } from '../../utils'

export async function readPackageJson(option: ILibOption | IViteProjOption | IOtherOption) {
const { projectPath } = option
Expand Down
19 changes: 10 additions & 9 deletions core/rumtime/runtime-other/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {filterFile, IOtherOption, templatePath} from "../../../utils";
import ora from "ora";
import chalk from "chalk";
import fs from "fs-extra";
import {readPackageJson, writePackageJson} from "../read-write-package";
import {addBaseUnitTest} from "../add-unit-test";
import ora from 'ora'
import chalk from 'chalk'
import fs from 'fs-extra'
import { filterFile, templatePath } from '../../../utils'
import { readPackageJson, writePackageJson } from '../read-write-package'
import { addBaseUnitTest } from '../add-unit-test'
import type { IOtherOption } from '../../../utils'

export async function runRuntimeOther(option: IOtherOption){
export async function runRuntimeOther(option: IOtherOption) {
const {
projectName,
projectPath,
unitTestLibType,
otherType
otherType,
} = option
const spinner = ora('Loading').start()
try {
Expand Down Expand Up @@ -44,4 +45,4 @@ export async function runRuntimeOther(option: IOtherOption){
spinner.fail()
console.log(chalk.redBright.bold(e))
}
}
}
4 changes: 2 additions & 2 deletions core/rumtime/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import chalk from 'chalk'
import { PROJECTTYPE} from '../../utils'
import { PROJECTTYPE } from '../../utils'
import { runRuntimeVue } from './runtime-vue'
import { runRuntimeLib } from './runtime-lib'
import { runRuntimeReact } from './runtime-react'
import { runRuntimeOther } from './runtime-other'
import type { ILibOption, IViteProjOption, IOtherOption } from '../../utils'
import type { ILibOption, IOtherOption, IViteProjOption } from '../../utils'
export async function run(option: IViteProjOption & ILibOption & IOtherOption) {
const {
projectName,
Expand Down
13 changes: 12 additions & 1 deletion entry/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
import '../dist/index.js'
import fs from 'fs-extra'
import { BeCLIRun } from '../index.js'
async function start() {
const pkg = await fs.readJson('../package.json')
const argv = process.argv
const len = argv.length
if (argv[len - 1] === '--v')
console.log(`Be ClI: v${pkg.version}`)
else
BeCLIRun()
}
start()
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
"init": "pnpm i",
"lint:fix": "eslint . --fix",
"dev": "cross-env ENV=BECLIDEV esno core/index.ts",
"build": "rollup -c build-script/rollup.config.js",
"build": "pnpm run clean && rollup -c build-script/rollup.config.js",
"prepublishOnly": "pnpm run build",
"release": "bumpp package.json --commit --push --tag",
"publish": "pnpm publish --no-git-checks --access public",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"clean": "rimraf dist"
},
"dependencies": {
"chalk": "5.2.0",
Expand Down Expand Up @@ -65,6 +66,7 @@
"cross-env": "^7.0.3",
"eslint": "^8.32.0",
"esno": "^0.16.3",
"rimraf": "^4.1.0",
"rollup": "^3.10.0",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-copy": "^3.4.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions template/other/bms/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"name": "other-bms",
"version": "0.0.0",
"description": "XXX平台管理后台",
"author": "chabaidao",
"version": "0.0.0",
"license": "MIT",
"author": "chabaidao",
"repository": {
"type": "git",
"url": "http://192.168.110.101:8081/bigdata/frontend/ab-test-vue.git"
},
"module": "esnext",
"scripts": {
"init": "pnpm i",
Expand All @@ -21,16 +25,6 @@
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"release:tag": "bumpp package.json --commit --push --tag"
},
"repository": {
"type": "git",
"url": "http://192.168.110.101:8081/bigdata/frontend/ab-test-vue.git"
},
"lint-staged": {
"*.{vue,js,ts,jsx,tsx,md,json}": [
"eslint ./ --fix",
"git add"
]
},
"dependencies": {
"@element-plus/icons-vue": "^2.0.10",
"@vueuse/core": "^8.5.0",
Expand All @@ -49,9 +43,8 @@
"vue-router": "^4.0.14"
},
"devDependencies": {
"eslint": "^8.18.0",
"@baiwusanyu/eslint-config": "^1.0.10",
"@babel/preset-typescript": "^7.16.0",
"@baiwusanyu/eslint-config": "^1.0.10",
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"@types/file-saver": "^2.0.5",
Expand All @@ -60,23 +53,30 @@
"@vitejs/plugin-vue": "^4.0.0",
"@vue/compiler-sfc": "^3.2.45",
"bumpp": "^8.2.1",
"chalk": "4.1.2",
"chokidar": "^3.5.3",
"conventional-changelog-cli": "^2.2.2",
"eslint": "^8.18.0",
"fs-extra": "^10.0.1",
"husky": "^7.0.4",
"ora": "^6.1.2",
"randomcolor": "^0.6.2",
"sass": "^1.52.1",
"tinify": "^1.7.1",
"typescript": "^4.1.3",
"unconfig": "^0.3.5",
"unplugin-auto-import": "^0.8.5",
"unplugin-img-compress": "^1.0.7",
"vite": "4.0.4",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-svg-icons": "^2.0.1",
"vite-plugin-vue-setup-extend": "^0.4.0",
"vue-tsc": "^1.0.24",
"chalk": "4.1.2",
"chokidar": "^3.5.3",
"fs-extra": "^10.0.1",
"ora": "^6.1.2",
"tinify": "^1.7.1",
"unconfig": "^0.3.5"
"vue-tsc": "^1.0.24"
},
"lint-staged": {
"*.{vue,js,ts,jsx,tsx,md,json}": [
"eslint ./ --fix",
"git add"
]
}
}
12 changes: 6 additions & 6 deletions template/other/bms/src/views/demo/index.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div>
demo
</div>
<div>
demo
</div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { defineComponent } from 'vue'
export default defineComponent({
name: "demo"
name: 'Demo',
})
</script>
</script>
2 changes: 1 addition & 1 deletion utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface ILibOption extends ICliOption{

export interface IOtherOption extends ICliOption{
unitTestLibType: string
otherType : string
otherType: string
}

export interface ICliOption {
Expand Down

0 comments on commit 63ef0b3

Please sign in to comment.