prompt.cjs 892 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. }