generated from thzxcx/vue3
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
/*
|
||
* @Author: zhaojinfeng 121016171@qq.com
|
||
* @Date: 2023-06-20 16:46:04
|
||
* @LastEditors: zhaojinfeng 121016171@qq.com
|
||
* @LastEditTime: 2023-06-25 10:47:14
|
||
* @FilePath: \uni\bin\gen.ts
|
||
* @Description:
|
||
*
|
||
*/
|
||
/* eslint-env node */
|
||
import consola from 'consola'
|
||
import co from 'co'
|
||
import coprompt from 'co-prompt'
|
||
import { renderFile } from 'ejs'
|
||
import { outputFile } from 'fs-extra'
|
||
|
||
interface RenderData {
|
||
lowerName: string
|
||
component: string
|
||
}
|
||
|
||
async function rendenStories(data: RenderData) {
|
||
const text = await renderFile('./ejs/stories.ejs', data)
|
||
await outputFile(`./stories/${data.component}.stories.ts`, text)
|
||
consola.success('创建了story:', `stories/${data.component}.stories.ts`)
|
||
}
|
||
|
||
async function rendenVUE(data: RenderData) {
|
||
const text = await renderFile('./ejs/vue.ejs', data)
|
||
await outputFile(`./packages/${data.lowerName}/index.vue`, text)
|
||
consola.success('创建了VUE组件:', `packages/${data.lowerName}/index.vue`)
|
||
}
|
||
|
||
co(function*() {
|
||
const input: string = yield coprompt('起一个组件英文名称(不区分大小写): ')
|
||
|
||
if (!input)
|
||
throw new Error('不能创建')
|
||
|
||
const lowerName = input.toLowerCase()
|
||
let component = ''
|
||
|
||
input.split('-').forEach((name) => {
|
||
const first = name[0]
|
||
component += first.toUpperCase() + name.slice(1)
|
||
})
|
||
const data = { lowerName, component }
|
||
Promise
|
||
.all([rendenStories(data), rendenVUE(data)])
|
||
.then(() => {
|
||
process.exit()
|
||
})
|
||
})
|