prompt.js 892 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const toUpperCase = (str) => str.charAt(0).toUpperCase() + str.slice(1)
  2. module.exports = {
  3. description: 'Create vue component',
  4. prompts: [
  5. {
  6. type: 'input',
  7. name: 'name',
  8. message: '请输入组件名称(Please enter the component name)'
  9. }
  10. ],
  11. actions: (data) => {
  12. const { name } = data
  13. const upperFirstName = toUpperCase(name)
  14. const actions = []
  15. if (name) {
  16. actions.push({
  17. type: 'add',
  18. path: `./src/components/${upperFirstName}/src/${upperFirstName}.vue`,
  19. templateFile: './plop/component/component.hbs',
  20. data: {
  21. name,
  22. upperFirstName
  23. }
  24. }, {
  25. type: 'add',
  26. path: `./src/components/${upperFirstName}/index.ts`,
  27. templateFile: './plop/component/index.hbs',
  28. data: {
  29. upperFirstName
  30. }
  31. })
  32. }
  33. return actions
  34. }
  35. }