generated from thzxcx/vue3
49 lines
1.4 KiB
TypeScript
49 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-21 10:56:31
|
||
* @FilePath: \tianheng-design\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 name: string = yield coprompt('起一个组件英文名称(不区分大小写): ')
|
||
if (!name)
|
||
throw new Error('不能创建')
|
||
|
||
const lowerName = name.toLowerCase()
|
||
const first = lowerName[0]
|
||
const component = first.toUpperCase() + lowerName.slice(1)
|
||
const data = { lowerName, component }
|
||
Promise
|
||
.all([rendenStories(data), rendenVUE(data)])
|
||
.then(() => {
|
||
process.exit()
|
||
})
|
||
})
|