|
| 1 | +import chalk from "chalk"; |
| 2 | +import BaseVueGenerator from "./VueBaseGenerator"; |
| 3 | + |
| 4 | +export default class extends BaseVueGenerator { |
| 5 | + constructor(params) { |
| 6 | + super(params); |
| 7 | + |
| 8 | + this.registerTemplates(`nuxt/`, [ |
| 9 | + // components |
| 10 | + "components/ActionCell.vue", |
| 11 | + "components/Alert.vue", |
| 12 | + "components/ConfirmDelete.vue", |
| 13 | + "components/DataFilter.vue", |
| 14 | + "components/InputDate.vue", |
| 15 | + "components/Loading.vue", |
| 16 | + "components/Toolbar.vue", |
| 17 | + "components/foo/Filter.vue", |
| 18 | + "components/foo/Form.vue", |
| 19 | + |
| 20 | + // mixins |
| 21 | + "mixins/create.js", |
| 22 | + "mixins/list.js", |
| 23 | + "mixins/notification.js", |
| 24 | + "mixins/show.js", |
| 25 | + "mixins/update.js", |
| 26 | + |
| 27 | + // pages |
| 28 | + "pages/foos/new.vue", |
| 29 | + "pages/foos/index.vue", |
| 30 | + "pages/foos/_id.vue", |
| 31 | + |
| 32 | + // store |
| 33 | + "store/crud.js", |
| 34 | + "store/foo.js" |
| 35 | + ]); |
| 36 | + } |
| 37 | + |
| 38 | + help(resource) { |
| 39 | + console.log( |
| 40 | + chalk.green('Code for the "%s" resource type has been generated!'), |
| 41 | + resource.title |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + generateFiles(api, resource, dir, params) { |
| 46 | + const context = super.getContextForResource(resource, params); |
| 47 | + const lc = context.lc; |
| 48 | + |
| 49 | + [ |
| 50 | + `${dir}/config`, |
| 51 | + `${dir}/error`, |
| 52 | + `${dir}/mixins`, |
| 53 | + `${dir}/services`, |
| 54 | + `${dir}/utils`, |
| 55 | + `${dir}/validators` |
| 56 | + ].forEach(dir => this.createDir(dir, false)); |
| 57 | + |
| 58 | + // error |
| 59 | + this.createFile( |
| 60 | + "error/SubmissionError.js", |
| 61 | + `${dir}/error/SubmissionError.js`, |
| 62 | + {}, |
| 63 | + false |
| 64 | + ); |
| 65 | + |
| 66 | + // mixins |
| 67 | + [ |
| 68 | + "mixins/create.js", |
| 69 | + "mixins/list.js", |
| 70 | + "mixins/notification.js", |
| 71 | + "mixins/show.js", |
| 72 | + "mixins/update.js" |
| 73 | + ].forEach(file => this.createFile(file, `${dir}/${file}`, context, false)); |
| 74 | + |
| 75 | + // stores |
| 76 | + this.createFile( |
| 77 | + `store/modules/notifications.js`, |
| 78 | + `${dir}/store/notifications.js`, |
| 79 | + { hydraPrefix: this.hydraPrefix }, |
| 80 | + false |
| 81 | + ); |
| 82 | + |
| 83 | + this.createFile( |
| 84 | + `store/crud.js`, |
| 85 | + `${dir}/store/crud.js`, |
| 86 | + { hydraPrefix: this.hydraPrefix }, |
| 87 | + false |
| 88 | + ); |
| 89 | + |
| 90 | + // validators |
| 91 | + this.createFile( |
| 92 | + "validators/date.js", |
| 93 | + `${dir}/validators/date.js`, |
| 94 | + { hydraPrefix: this.hydraPrefix }, |
| 95 | + false |
| 96 | + ); |
| 97 | + |
| 98 | + // utils |
| 99 | + ["dates.js", "fetch.js", "hydra.js"].forEach(file => |
| 100 | + this.createFile(`utils/${file}`, `${dir}/utils/${file}`, {}, false) |
| 101 | + ); |
| 102 | + |
| 103 | + this.createEntrypoint(api.entrypoint, `${dir}/config/entrypoint.js`); |
| 104 | + |
| 105 | + for (let dir of [`${dir}/components/${lc}`, `${dir}/pages/${lc}s`]) { |
| 106 | + this.createDir(dir); |
| 107 | + } |
| 108 | + |
| 109 | + this.createFile("services/api.js", `${dir}/services/api.js`, {}, false); |
| 110 | + |
| 111 | + [ |
| 112 | + // components |
| 113 | + "components/%s/Filter.vue", |
| 114 | + "components/%s/Form.vue", |
| 115 | + |
| 116 | + // pages |
| 117 | + "pages/%ss/new.vue", |
| 118 | + "pages/%ss/index.vue", |
| 119 | + "pages/%ss/_id.vue", |
| 120 | + |
| 121 | + // service |
| 122 | + "services/%s.js", |
| 123 | + |
| 124 | + // store |
| 125 | + "store/%s.js" |
| 126 | + ].forEach(pattern => this.createFileFromPattern(pattern, dir, lc, context)); |
| 127 | + |
| 128 | + // components |
| 129 | + [ |
| 130 | + "ActionCell.vue", |
| 131 | + "Alert.vue", |
| 132 | + "ConfirmDelete.vue", |
| 133 | + "DataFilter.vue", |
| 134 | + "InputDate.vue", |
| 135 | + "Loading.vue", |
| 136 | + "Toolbar.vue" |
| 137 | + ].forEach(file => |
| 138 | + this.createFile( |
| 139 | + `components/${file}`, |
| 140 | + `${dir}/components/${file}`, |
| 141 | + context, |
| 142 | + false |
| 143 | + ) |
| 144 | + ); |
| 145 | + } |
| 146 | +} |
0 commit comments