Skip to content

Commit

Permalink
feat: The main process of lib template is written
Browse files Browse the repository at this point in the history
  • Loading branch information
baiwusanyu-c committed Sep 6, 2022
1 parent 55c56b6 commit 7ab3901
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 45 deletions.
33 changes: 6 additions & 27 deletions PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,7 @@ Be-cli

## v1.0.0
### vue3 + vite + ts模板
1.集成hasky、commitlint 🐶
2.集成eslint与格式修复 🐶
3.集成pinia 🐶
4.集成vue-router 🐶
5.集成tsx 🐶
6.集成版本日志 changelog 🐶
7.集成发版bumpp 🐶
8.选择集成 UI组件库 or 原子CSS 🐶
-》可选集成ant-design-vue -》集成sass-》自动前缀、rem转化 🐶
element-plus -》集成sass-》自动前缀、rem转化🐶
-》可选集成windicss、(windi.config,main.ts,package.json、vite.config)🐶
unocss 🐶
9.集成图片压缩 🐶
10.适当的打包优化集成 🐶
11.选择集成单元测试
-》可选集成vitest、
jest
12.集成axios 🐶
13.多后台环境 🐶

模板分支
ant-design-vue
element-plus
windicss
unocss



## v1.0.1
Expand All @@ -43,8 +19,11 @@ unocss
支持指令参数修改环境变量

选择模板
gulp + rollup
unbuild + turbo + tsup
gulp + rollup + turbo
unbuild + turbo
tsup + turbo

选择脚本是运行在浏览器还是node


## v1.0.2
Expand Down
35 changes: 28 additions & 7 deletions core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import * as path from 'path'
import { Command } from 'commander'
import {
cssLibTypeOptions,
buildLibTypeOptions,
cssLibTypeOptions, envTypeOptions,
getConfigFile,
projectNameOptions,
projectNameOptions, PROJECTTYPE,
projectTypeOptions,
promptsRun,
uiLibTypeOptions, unitTestTypeOptions,
Expand All @@ -30,18 +31,38 @@ program.action(async () => {
// 选择项目模板类型
const typeRes = await promptsRun(projectTypeOptions)

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

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

// 项目存储路径
const rootPath = process.cwd()
const projectPath = path.resolve(rootPath, nameRes.projectName)
// 组装配置对象
const options = { ...nameRes, ...typeRes, projectPath, ...cssUiRes, ...componentUiRes, ...unitTestRes } as any
const options = {
projectPath,
...componentUiRes,
...cssUiRes,
...buildRes,
...runEnvRes,
...nameRes,
...typeRes,
...unitTestRes } as any
// 开始运行命令
await run(options)
})
Expand Down
6 changes: 6 additions & 0 deletions core/rumtime/runtime-lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ILibOption } from "../../../utils";


export const runRuntimeLib = async (option: ILibOption) => {
console.log(option)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs-extra'
import chalk from 'chalk'
import type { IViteVueOption } from '../../../utils'
import { templatePath } from '../../../utils'
export const runViteVue = async (option: IViteVueOption) => {
export const runRuntimeVue = async (option: IViteVueOption) => {
const {
projectName,
projectPath,
Expand Down
29 changes: 24 additions & 5 deletions core/rumtime/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
import chalk from 'chalk'
import type { ICliOption } from '../../utils'
import { runViteVue } from './vite-vue'
export async function run(option: ICliOption) {
import { runRuntimeVue } from './runtime-vue'
import {ILibOption, IViteVueOption, PROJECTTYPE} from "../../utils";
import {runRuntimeLib} from "./runtime-lib";
export async function run(option: IViteVueOption & ILibOption) {
const {
projectName,
projectType,
projectPath,
uiLibType,
cssLibType,
unitTestLibType,
envType,
buildLibType,
} = option

if (projectType === 'vue') {
console.log(chalk.bgBlueBright.bold(`\nstart creating project <${projectName}> ...`))
console.log(chalk.bgBlueBright.bold(`\nstart creating project <${projectName}> ...`))

if (projectType === PROJECTTYPE.VUE) {
const viteVueOption = {
projectName,
projectPath,
uiLibType,
cssLibType,
projectType,
unitTestLibType,
}
await runRuntimeVue(viteVueOption)
return
}

if(projectType === PROJECTTYPE.LIB){
const libOption = {
projectName,
projectPath,
projectType,
unitTestLibType,
envType,
buildLibType,
}
await runViteVue(viteVueOption)
await runRuntimeLib(libOption)
}
}
25 changes: 24 additions & 1 deletion utils/command-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as prompts from 'prompts'
import { CSSLIBTYPE, PROJECTTYPE, UILIBTYPE, UNITTESTLIBTYPE } from './enums'
import {BUILDLIBTYPE, CSSLIBTYPE, PROJECTTYPE, RUNENVTYPE, UILIBTYPE, UNITTESTLIBTYPE} from './enums'

export const projectNameOptions = [{
type: 'text',
Expand Down Expand Up @@ -50,3 +50,26 @@ export const unitTestTypeOptions = [{
return { title: item, value: valueDict[index] }
}),
}] as prompts.PromptObject[]

export const buildLibTypeOptions = [{
type: 'select',
name: 'buildLibType',
message: 'please choose your packaging tool',
choices: ['tsup', 'unbuild', 'rollup'].map((item, index) => {
const valueDict = [BUILDLIBTYPE.TSUP, BUILDLIBTYPE.UNBUILD, BUILDLIBTYPE.ROLLUP]
// 选择时的标题和选择时的值
return { title: item, value: valueDict[index] }
}),
}] as prompts.PromptObject[]

export const envTypeOptions = [{
type: 'select',
name: 'envType',
message: 'please select your library runtime environment',
choices: ['node', 'browser'].map((item, index) => {
const valueDict = [RUNENVTYPE.NODE, RUNENVTYPE.BROWSER]
// 选择时的标题和选择时的值
return { title: item, value: valueDict[index] }
}),
}] as prompts.PromptObject[]

12 changes: 12 additions & 0 deletions utils/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@ export enum UNITTESTLIBTYPE {
JEST = 'jest',
VITEST = 'vitest',
}

export enum BUILDLIBTYPE {
ROLLUP = 'rollup',
TSUP = 'tsup',
UNBUILD = 'unbuild'
}

export enum RUNENVTYPE {
NODE = 'node',
BROWSER = 'browser',
}

14 changes: 10 additions & 4 deletions utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ export interface IPackageInfo {
description: string
author: string
}
export interface IViteVueOption {
projectName: string
projectPath: string
export interface IViteVueOption extends ICliOption{
uiLibType: string
cssLibType: string
unitTestLibType: string
}

export interface ICliOption extends IViteVueOption {
export interface ILibOption extends ICliOption{
unitTestLibType: string
envType: string
buildLibType: string
}

export interface ICliOption {
projectType: string
projectName: string
projectPath: string
}

export interface ISpawnOptions {
Expand Down

0 comments on commit 7ab3901

Please sign in to comment.