diff --git a/lib/generators/vue/index.js b/lib/generators/vue/index.js new file mode 100644 index 0000000..27ea174 --- /dev/null +++ b/lib/generators/vue/index.js @@ -0,0 +1,76 @@ +const Generator = require("yeoman-generator"); +const { basename } = require("path"); +const debug = require("debug")("create-umi"); + +module.exports = class BasicGenerator extends Generator { + constructor(args, opts) { + super(args, opts); + + this.name = basename(process.cwd()); + this.props = {}; + } + + writing() { + debug(`this.name: ${this.name}`); + debug(`this.props: ${JSON.stringify(this.props)}`); + + const context = { + name: this.name, + props: this.props + }; + + this.fs.copy(this.templatePath("mock", ".*"), this.destinationPath("mock")); + this.fs.copy( + this.templatePath("src", "layouts"), + this.destinationPath("src/layouts") + ); + this.fs.copy( + this.templatePath("src", "models"), + this.destinationPath("src/models") + ); + this.fs.copy( + this.templatePath("src", "pages", "index"), + this.destinationPath("src/pages/index") + ); + + this.fs.copy( + this.templatePath("src", "pages", "list"), + this.destinationPath("src/pages/list") + ); + this.fs.copy( + this.templatePath("src", "global.less"), + this.destinationPath("src/global.less") + ); + this.fs.copyTpl( + this.templatePath("tsconfig.json"), + this.destinationPath("tsconfig.json") + ); + this.fs.copyTpl( + this.templatePath("package.json"), + this.destinationPath("package.json"), + context + ); + this.fs.copy( + this.templatePath("_gitignore"), + this.destinationPath(".gitignore") + ); + this.fs.copy(this.templatePath(".env"), this.destinationPath(".env")); + this.fs.copyTpl( + this.templatePath(".umirc.js"), + this.destinationPath(".umirc.js"), + context + ); + this.fs.copy( + this.templatePath(".eslintrc"), + this.destinationPath(".eslintrc") + ); + this.fs.copy( + this.templatePath(".prettierrc"), + this.destinationPath(".prettierrc") + ); + this.fs.copy( + this.templatePath(".prettierignore"), + this.destinationPath(".prettierignore") + ); + } +}; diff --git a/lib/generators/vue/meta.json b/lib/generators/vue/meta.json new file mode 100644 index 0000000..9e5fe28 --- /dev/null +++ b/lib/generators/vue/meta.json @@ -0,0 +1,3 @@ +{ + "description": "Create project with default vuex and vue-router" +} diff --git a/lib/generators/vue/templates/.env b/lib/generators/vue/templates/.env new file mode 100644 index 0000000..6ce384e --- /dev/null +++ b/lib/generators/vue/templates/.env @@ -0,0 +1 @@ +BROWSER=none diff --git a/lib/generators/vue/templates/.eslintrc b/lib/generators/vue/templates/.eslintrc new file mode 100644 index 0000000..a50a5d2 --- /dev/null +++ b/lib/generators/vue/templates/.eslintrc @@ -0,0 +1,4 @@ +{ + "extends": ["plugin:vue/essential"] + } + \ No newline at end of file diff --git a/lib/generators/vue/templates/.gitignore b/lib/generators/vue/templates/.gitignore new file mode 100644 index 0000000..75da99a --- /dev/null +++ b/lib/generators/vue/templates/.gitignore @@ -0,0 +1,122 @@ + + +# Created by https://www.gitignore.io/api/osx,node,visualstudiocode + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless + +### OSX ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + + +# End of https://www.gitignore.io/api/osx,node,visualstudiocode + +# dependencies +/yarn.lock +/package-lock.json + +# umi +.umi +.umi-production \ No newline at end of file diff --git a/lib/generators/vue/templates/.prettierignore b/lib/generators/vue/templates/.prettierignore new file mode 100644 index 0000000..64e4150 --- /dev/null +++ b/lib/generators/vue/templates/.prettierignore @@ -0,0 +1,7 @@ +**/*.md +**/*.svg +**/*.ejs +**/*.html +dist +.umi +.umi-production diff --git a/lib/generators/vue/templates/.prettierrc b/lib/generators/vue/templates/.prettierrc new file mode 100644 index 0000000..d440171 --- /dev/null +++ b/lib/generators/vue/templates/.prettierrc @@ -0,0 +1,5 @@ +{ + "singleQuote": true, + "trailingComma": "es5", + "printWidth": 100 +} diff --git a/lib/generators/vue/templates/.umirc.js b/lib/generators/vue/templates/.umirc.js new file mode 100644 index 0000000..3c2a2b0 --- /dev/null +++ b/lib/generators/vue/templates/.umirc.js @@ -0,0 +1,4 @@ +// ref: https://umijs.org/config/ +export default { + plugins: [['@didi/umi-plugin-vue']], +}; diff --git a/lib/generators/vue/templates/_gitignore b/lib/generators/vue/templates/_gitignore new file mode 100644 index 0000000..75da99a --- /dev/null +++ b/lib/generators/vue/templates/_gitignore @@ -0,0 +1,122 @@ + + +# Created by https://www.gitignore.io/api/osx,node,visualstudiocode + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless + +### OSX ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + + +# End of https://www.gitignore.io/api/osx,node,visualstudiocode + +# dependencies +/yarn.lock +/package-lock.json + +# umi +.umi +.umi-production \ No newline at end of file diff --git a/lib/generators/vue/templates/mock/.gitkeep b/lib/generators/vue/templates/mock/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/generators/vue/templates/package.json b/lib/generators/vue/templates/package.json new file mode 100644 index 0000000..549483a --- /dev/null +++ b/lib/generators/vue/templates/package.json @@ -0,0 +1,27 @@ +{ + "private": true, + "scripts": { + "start": "umi dev", + "build": "umi build", + "test": "umi test", + "lint": "pretty-quick --staged", + "inpsect": "umi inspect > webpack.js" + }, + "devDependencies": { + "@didi/umi-plugin-vue": "^0.0.7", + "eslint": "^5.6.0", + "eslint-plugin-vue": "^5.0.0-beta.3", + "husky": "^1.0.0-rc.14", + "prettier": "^1.14.2", + "pretty-quick": "^1.6.0", + "umi": "2.10.7" + }, + "husky": { + "hooks": { + "pre-commit": "pretty-quick --staged" + } + }, + "engines": { + "node": ">=8.0.0" + } +} \ No newline at end of file diff --git a/lib/generators/vue/templates/src/app.js b/lib/generators/vue/templates/src/app.js new file mode 100644 index 0000000..e69de29 diff --git a/lib/generators/vue/templates/src/global.less b/lib/generators/vue/templates/src/global.less new file mode 100644 index 0000000..ccab77c --- /dev/null +++ b/lib/generators/vue/templates/src/global.less @@ -0,0 +1,3 @@ +html { + background: #fff; +} diff --git a/lib/generators/vue/templates/src/layouts/index.vue b/lib/generators/vue/templates/src/layouts/index.vue new file mode 100644 index 0000000..a44ab87 --- /dev/null +++ b/lib/generators/vue/templates/src/layouts/index.vue @@ -0,0 +1,3 @@ + diff --git a/lib/generators/vue/templates/src/models/global.ts b/lib/generators/vue/templates/src/models/global.ts new file mode 100644 index 0000000..7299136 --- /dev/null +++ b/lib/generators/vue/templates/src/models/global.ts @@ -0,0 +1,6 @@ +export default { + state: { + lang: 'js', + }, + getters: {}, +}; diff --git a/lib/generators/vue/templates/src/pages/index/index.vue b/lib/generators/vue/templates/src/pages/index/index.vue new file mode 100644 index 0000000..884fac0 --- /dev/null +++ b/lib/generators/vue/templates/src/pages/index/index.vue @@ -0,0 +1,35 @@ + + diff --git a/lib/generators/vue/templates/src/pages/index/model.ts b/lib/generators/vue/templates/src/pages/index/model.ts new file mode 100644 index 0000000..d37c19a --- /dev/null +++ b/lib/generators/vue/templates/src/pages/index/model.ts @@ -0,0 +1,26 @@ +function delay(s) { + return new Promise((resolve, reject) => { + setTimeout(resolve, s * 1000); + }); +} + +export default { + namespace: 'index', + state: { + isAuth: false, + name: 'hys', + count: 1, + }, + getters: {}, + mutations: { + increment(state) { + state.count++; + }, + }, + actions: { + async incrementAsync({ commit }) { + await delay(2); + commit('increment'); + }, + }, +}; diff --git a/lib/generators/vue/templates/src/pages/list/$id/index.vue b/lib/generators/vue/templates/src/pages/list/$id/index.vue new file mode 100644 index 0000000..7bcd185 --- /dev/null +++ b/lib/generators/vue/templates/src/pages/list/$id/index.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/lib/generators/vue/templates/src/pages/list/index.vue b/lib/generators/vue/templates/src/pages/list/index.vue new file mode 100644 index 0000000..aa1ea60 --- /dev/null +++ b/lib/generators/vue/templates/src/pages/list/index.vue @@ -0,0 +1,33 @@ + + diff --git a/lib/generators/vue/templates/src/pages/list/model.ts b/lib/generators/vue/templates/src/pages/list/model.ts new file mode 100644 index 0000000..4f20bc8 --- /dev/null +++ b/lib/generators/vue/templates/src/pages/list/model.ts @@ -0,0 +1,12 @@ +export default { + namespace: 'list', + state: { + abc: 'a', + }, + mutations: { + changeSelect(state, { payload }) { + state.abc = payload.value; + }, + }, + actions: {}, +}; diff --git a/lib/generators/vue/templates/tsconfig.json b/lib/generators/vue/templates/tsconfig.json new file mode 100644 index 0000000..25f9f69 --- /dev/null +++ b/lib/generators/vue/templates/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "moduleResolution": "node", + "experimentalDecorators": true + }, + "include": ["./src/**/*"] +}