prompt.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const { notEmpty } = require("../utils.js");
  2. module.exports = {
  3. description: "generate vue component",
  4. prompts: [
  5. {
  6. type: "input",
  7. name: "name",
  8. message: "component name please",
  9. validate: notEmpty("name")
  10. },
  11. {
  12. type: "checkbox",
  13. name: "blocks",
  14. message: "Blocks:",
  15. choices: [
  16. {
  17. name: "<template>",
  18. value: "template",
  19. checked: true
  20. },
  21. {
  22. name: "<script>",
  23. value: "script",
  24. checked: true
  25. },
  26. {
  27. name: "style",
  28. value: "style",
  29. checked: true
  30. }
  31. ],
  32. validate(value) {
  33. if (
  34. value.indexOf("script") === -1 &&
  35. value.indexOf("template") === -1
  36. ) {
  37. return "Components require at least a <script> or <template> tag.";
  38. }
  39. return true;
  40. }
  41. }
  42. ],
  43. actions: data => {
  44. const name = "{{properCase name}}";
  45. const actions = [
  46. {
  47. type: "add",
  48. path: `src/components/${name}/index.vue`,
  49. templateFile: "plop-templates/component/index.hbs",
  50. data: {
  51. name: name,
  52. template: data.blocks.includes("template"),
  53. script: data.blocks.includes("script"),
  54. style: data.blocks.includes("style")
  55. }
  56. }
  57. ];
  58. return actions;
  59. }
  60. };