diff --git a/.eslintignore b/.eslintignore index 39274ba2d..9ceb6ff29 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ _*.js template/nuxt/pages/index.vue template/frameworks/iview/pages/index.vue +template/frameworks/jest/jest.config.js diff --git a/README.md b/README.md index dfe6bf0f8..faeecd23c 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ yarn create nuxt-app 1. Choose the package manager - Yarn - Npm +1. Choose programming language + - JavaScript + - TypeScript 1. Choose your favorite UI framework: - None (feel free to add one later) - [Ant Design Vue](https://github.com/vueComponent/ant-design-vue) @@ -58,6 +61,9 @@ yarn create nuxt-app - [Hapi](https://github.com/hapijs/hapi) - [Koa](https://github.com/koajs/koa) - [Micro](https://github.com/zeit/micro) +1. Choose the runtime for TypeScript (if you choose TypeScript) + - Default + - [@nuxt/typescript-runtime](https://github.com/nuxt/typescript) 1. Choose Nuxt.js modules: - [Axios](https://github.com/nuxt-community/axios-module) - [Progressive Web App (PWA) Support](https://github.com/nuxt-community/pwa-module) diff --git a/prompts.js b/prompts.js index 25658f95e..2a0f60795 100644 --- a/prompts.js +++ b/prompts.js @@ -18,6 +18,16 @@ module.exports = [ default: '{gitUser.name}', store: true }, + { + name: 'language', + message: 'Choose programming language', + choices: [ + { name: 'JavaScript', value: 'js' }, + { name: 'TypeScript', value: 'ts' } + ], + type: 'list', + default: 'js' + }, { name: 'pm', message: 'Choose the package manager', @@ -66,6 +76,16 @@ module.exports = [ ], default: 'none' }, + { + name: 'runtime', + message: 'Choose the runtime for TypeScript', + type: 'list', + choices: [ + { name: 'Default', value: 'none' }, + { name: '@nuxt/typescript-runtime', value: 'ts-runtime' } + ], + when: answers => answers.language === 'ts' && answers.server === 'none' + }, { name: 'features', message: 'Choose Nuxt.js modules', diff --git a/saofile.js b/saofile.js index 77d3a1f27..65d2ed63b 100644 --- a/saofile.js +++ b/saofile.js @@ -8,6 +8,8 @@ const rootDir = __dirname module.exports = { prompts: require('./prompts'), templateData () { + const typescript = this.answers.language.includes('ts') + const tsRuntime = this.answers.runtime && this.answers.runtime.includes('ts-runtime') const pwa = this.answers.features.includes('pwa') const eslint = this.answers.linter.includes('eslint') const prettier = this.answers.linter.includes('prettier') @@ -23,6 +25,8 @@ module.exports = { const edge = cliOptions.edge ? '-edge' : '' return { + typescript, + tsRuntime, pwa, eslint, prettier, @@ -87,6 +91,7 @@ module.exports = { patterns: files }) } + actions.push({ type: 'add', files: '**', @@ -101,6 +106,7 @@ module.exports = { '_.eslintrc.js': 'linter.includes("eslint")', '_.prettierrc': 'linter.includes("prettier")', '_jsconfig.json': 'devTools.includes("jsconfig.json")', + 'tsconfig.json': 'language.includes("ts")', 'semantic.yml': 'devTools.includes("semantic-pull-requests")', '.env': 'features.includes("dotenv")', '_stylelint.config.js': 'linter.includes("stylelint")' @@ -168,5 +174,9 @@ module.exports = { console.log(chalk` {bold To test:}\n`) console.log(chalk`${cdMsg}\t{cyan ${pmRun} test}\n`) } + + if (this.answers.language.includes('ts')) { + console.log(chalk`\n {bold For TypeScript users.} \n\n See : https://typescript.nuxtjs.org/cookbook/components/`) + } } } diff --git a/template/_.eslintrc.js b/template/_.eslintrc.js index 9d0fac13d..c6e7b6f3c 100644 --- a/template/_.eslintrc.js +++ b/template/_.eslintrc.js @@ -9,11 +9,17 @@ module.exports = { use: true }, <%_ } _%> + <%_ if (!typescript) { _%> parserOptions: { parser: 'babel-eslint' }, + <%_ } _%> extends: [ + <%_ if (typescript) { _%> + '@nuxtjs/eslint-config-typescript', + <%_ } else {_%> '@nuxtjs', + <%_ } _%> <%_ if (prettier) { _%> 'prettier', 'prettier/vue', diff --git a/template/_package.json b/template/_package.json index f6cca2431..f647cd0f8 100644 --- a/template/_package.json +++ b/template/_package.json @@ -6,10 +6,17 @@ "private": true, "scripts": { <%_ if (server === 'none') { _%> + <%_ if (tsRuntime) { _%> + "dev": "nuxt-ts", + "build": "nuxt-ts build", + "generate": "nuxt-ts generate", + "start": "nuxt-ts start", + <%_ } else { _%> "dev": "nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate", + <%_ } _%> <%_ } else if (server === 'adonis') { _%> "serve:dev": "<%= pmRun %> dev", "dev": "nodemon --watch app --watch bootstrap --watch config --watch .env -x node server.js", @@ -58,6 +65,9 @@ <%_ } else { _%> "nuxt": "^2.0.0", <%_ } _%> + <%_ if (tsRuntime) { _%> + "@nuxt/typescript-runtime": "^0.4.0", + <%_ } _%> <%_ if (server !== 'none') { _%> "cross-env": "^5.2.0", <%_ } _%> @@ -125,6 +135,9 @@ <%_ if (server !== 'none') { _%> "nodemon": "^1.18.9", <%_ } _%> + <%_ if (typescript) { _%> + "@nuxt/typescript-build": "^0.6.0", + <%_ } _%> <%_ if (ui === 'tailwind') { _%> "@nuxtjs/tailwindcss": "^1.0.0", <%_ } else if (ui === 'vuetify') { _%> @@ -133,7 +146,11 @@ "framevuerk-builder": "^2.0.2", <%_ } _%> <%_ if (eslint) { _%> + <%_ if (typescript) { _%> + "@nuxtjs/eslint-config-typescript": "^1.0.0", + <%_ } else { _%> "@nuxtjs/eslint-config": "^2.0.0", + <%_ } _%> "@nuxtjs/eslint-module": "^1.0.0", "babel-eslint": "^10.0.1", "eslint": "^6.1.0", @@ -159,6 +176,9 @@ "babel-jest": "^24.1.0", "jest": "^24.1.0", "vue-jest": "^4.0.0-0", + <%_ if (typescript) { _%> + "ts-jest": "^25.0.0", + <%_ } _%> <%_ } else if (test === 'ava') { _%> "ava": "^3.0.0", "@ava/babel": "^1.0.0", diff --git a/template/frameworks/jest/jest.config.js b/template/frameworks/jest/jest.config.js index ac587076f..4915aa80f 100644 --- a/template/frameworks/jest/jest.config.js +++ b/template/frameworks/jest/jest.config.js @@ -4,8 +4,18 @@ module.exports = { '^~/(.*)$': '/$1', '^vue$': 'vue/dist/vue.common.js' }, - moduleFileExtensions: ['js', 'vue', 'json'], + moduleFileExtensions: [ + <%_ if (typescript) { _%> + 'ts', + <%_ } _%> + 'js', + 'vue', + 'json' + ], transform: { + <%_ if (typescript) { _%> + "^.+\\.ts$": "ts-jest", + <%_ } _%> '^.+\\.js$': 'babel-jest', '.*\\.(vue)$': 'vue-jest' }, diff --git a/template/nuxt/nuxt.config.js b/template/nuxt/nuxt.config.js index 43680a49e..13903d371 100644 --- a/template/nuxt/nuxt.config.js +++ b/template/nuxt/nuxt.config.js @@ -87,7 +87,10 @@ module.exports = { ** Nuxt.js dev-modules */ buildModules: [ - <%_ if (eslint) { _%> + <%_ if (typescript) {_%> + '@nuxt/typescript-build', + <%_ } _%> + <%_ if (eslint && !typescript) { _%> // Doc: https://github.com/nuxt-community/eslint-module '@nuxtjs/eslint-module', <%_ } _%> diff --git a/template/nuxt/pages/index.vue b/template/nuxt/pages/index.vue index 3b11a65e4..44a21e5de 100644 --- a/template/nuxt/pages/index.vue +++ b/template/nuxt/pages/index.vue @@ -28,6 +28,18 @@ +<%_ if (typescript) { _%> + +<%_ } else { _%> +<%_ } _%>