FEMessage / vue-sfc-cli

🔨A powerful tool for developing vue single-file component
https://medium.com/deepexi/reveal-the-secret-of-vue-sfc-cli-69f0f21dbad3
MIT License
149 stars 36 forks source link

feat: 支持选择模板 #119

Open 2nthony opened 4 years ago

2nthony commented 4 years ago

提供初始化项目类型(支持多模板

使用 cli 生成文件时,我想通过选择我要生成的项目是什么类型,vue组件 或者 工具型 的开源项目

以致于生成后的整套文件完整的,只需要关注我要开发的文件 src 即可;不再需要修改文件以免受失误而造成的工程出错。

PS: vue组件 和 工具型 应该成为模板,以方便的扩展(或许可以优化为 本地或者在线模板。

2nthony commented 4 years ago

理想的过程

vue-sfc-cli init

# 1
# Q
choose a type of the project
# A
🔘 vue 组件
🔘 插件

# 2
the project name

# 3
the owner
2nthony commented 4 years ago

关于扩展

基本文件

// /commons 必要的文件,如CI和脚本

扩展/定制模板(vue 组件例子

// vue
// /templates/vue-component/index.js
exports.name = 'vue 组件' // 模板名称
exports.apply = api => {
  // 做任何事情
  api.on('packageJson', json => json.dependencies.vue = 'v2.6.10')
  // 必要的文件不会因此而过滤
  api.on('files', files => {
    const newFiles = [...files, 'src/index.js', 'src/component.vue']
    return newFiles
  })
}
2nthony commented 4 years ago

使用到

inquirer,命令行提问