|
| 1 | +module.exports = (api, options, rootOptions) => { |
| 2 | + // Generator |
| 3 | + // This file will execute... |
| 4 | + // 1) If the plugin is included in the preset |
| 5 | + // 2) During the invoke command, after the plugin is installed |
| 6 | + // Docs: https://cli.vuejs.org/dev-guide/plugin-dev.html#generator |
| 7 | + // Creator Class: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli/lib/Creator.js |
| 8 | + // Generator API Code: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli/lib/GeneratorAPI.js |
| 9 | + |
| 10 | + // Arguments: |
| 11 | + // api: Generator API |
| 12 | + // options: Generator options for this plugin, or options from the preset |
| 13 | + // rootOptions: The preset used to create the project |
| 14 | + |
| 15 | + // Modify an eslint rule based on an inputted option. Default is false. |
| 16 | + const eslintConfig = { |
| 17 | + rules: {} |
| 18 | + } |
| 19 | + if (options.forceComponentOrder) { |
| 20 | + eslintConfig.rules['vue/order-in-components'] = 'error' |
| 21 | + } else { |
| 22 | + eslintConfig.rules['vue/order-in-components'] = 'never' |
| 23 | + } |
| 24 | + |
| 25 | + // Modify package.json fields |
| 26 | + api.extendPackage({ |
| 27 | + dependencies: { |
| 28 | + axios: "^0.18.0" |
| 29 | + }, |
| 30 | + eslintConfig |
| 31 | + }); |
| 32 | + |
| 33 | + api.onCreateComplete(() => { |
| 34 | + // Delete a file |
| 35 | + // TODO: Delete a folder if it's empty |
| 36 | + // const fs = require('fs'); |
| 37 | + // const filename = api.resolve('HelloVueDC.vue'); |
| 38 | + // const fileExists = fs.existsSync(filename); |
| 39 | + // if (fileExists) { |
| 40 | + // fs.unlink(filename, function(error) { |
| 41 | + // if (error) { |
| 42 | + // throw error; |
| 43 | + // } |
| 44 | + // console.log('Deleted filename', filename); |
| 45 | + // }); |
| 46 | + // } |
| 47 | + }) |
| 48 | + |
| 49 | + // Copy and render all files in ./template with ejs |
| 50 | + api.render("./template", { |
| 51 | + ...options, |
| 52 | + }); |
| 53 | +}; |
0 commit comments