diff --git a/meta.js b/meta.js index a521f9bdd0..e7b4350f47 100644 --- a/meta.js +++ b/meta.js @@ -69,6 +69,12 @@ module.exports = { }, ], }, + typescript: { + when: 'isNotTest', + type: 'confirm', + message: 'Use TypeScript as default language?', + default: false + }, router: { when: 'isNotTest', type: 'confirm', @@ -170,6 +176,8 @@ module.exports = { 'test/unit/setup.js': "unit && runner === 'jest'", 'test/e2e/**/*': 'e2e', 'src/router/**/*': 'router', + 'tsconfig.json': 'typescript', + 'vue-shims.d.ts': 'typescript' }, complete: function(data, { chalk }) { const green = chalk.green @@ -193,4 +201,20 @@ module.exports = { printMessage(data, chalk) } }, + metalsmith: function (metalsmith, opts, helpers) { + function renameJsSourcesToTs(files, metalsmith, done) { + // If typescript is enabled rename any .js files in src/ folder to .ts extension + if (metalsmith.metadata().typescript) { + Object.keys(files).forEach(filename => { + if (/^(src|test\\unit\\specs).*\.js$/.test(filename)) { + const renamed = filename.replace(/\.js$/, '.ts'); + files[renamed] = files[filename] + delete files[filename] + } + }) + } + done(null, files) + } + metalsmith.use(renameJsSourcesToTs) + } } diff --git a/scenarios/full-karma-airbnb.json b/scenarios/full-karma-airbnb.json index 4e70e573b2..aac802cc18 100644 --- a/scenarios/full-karma-airbnb.json +++ b/scenarios/full-karma-airbnb.json @@ -4,6 +4,7 @@ "description": "A Vue.js project", "author": "CircleCI", "build": "standalone", + "typescript": false, "router": false, "lint": true, "lintConfig": "airbnb", diff --git a/scenarios/full.json b/scenarios/full.json index f12d01e828..5b99532945 100644 --- a/scenarios/full.json +++ b/scenarios/full.json @@ -4,6 +4,7 @@ "description": "A Vue.js project", "author": "CircleCI", "build": "runtime", + "typescript": false, "router": false, "lint": true, "lintConfig": "standard", diff --git a/scenarios/minimal.json b/scenarios/minimal.json index abf2637541..8bae6084eb 100644 --- a/scenarios/minimal.json +++ b/scenarios/minimal.json @@ -4,6 +4,7 @@ "description": "Testing the minimal template setup", "author": "CircleCI", "build": "standalone", + "typescript": false, "router": false, "lint": false, "lintConfig": "standard", diff --git a/template/build/vue-loader.conf.js b/template/build/vue-loader.conf.js index 33ed58bc0a..f05b1f43c6 100644 --- a/template/build/vue-loader.conf.js +++ b/template/build/vue-loader.conf.js @@ -18,5 +18,6 @@ module.exports = { source: 'src', img: 'src', image: 'xlink:href' - } + }{{#typescript}}, + esModule: true{{/typescript}} } diff --git a/template/build/webpack.base.conf.js b/template/build/webpack.base.conf.js index 391160c571..e866e31d26 100644 --- a/template/build/webpack.base.conf.js +++ b/template/build/webpack.base.conf.js @@ -22,7 +22,7 @@ function resolve (dir) { module.exports = { context: path.resolve(__dirname, '../'), entry: { - app: './src/main.js' + app: './src/main.{{#typescript}}ts{{else}}js{{/typescript}}' }, output: { path: config.build.assetsRoot, @@ -32,7 +32,7 @@ module.exports = { : config.dev.assetsPublicPath }, resolve: { - extensions: ['.js', '.vue', '.json'], + extensions: [{{#typescript}}'.ts', {{/typescript}}'.js', '.vue', '.json'], alias: { {{#if_eq build "standalone"}} 'vue$': 'vue/dist/vue.esm.js', @@ -50,6 +50,15 @@ module.exports = { loader: 'vue-loader', options: vueLoaderConfig }, + {{#typescript}} + { + test: /\.ts$/, + loader: "ts-loader", + options: { + appendTsSuffixTo: [/\.vue$/] + } + }, + {{/typescript}} { test: /\.js$/, loader: 'babel-loader', diff --git a/template/package.json b/template/package.json index 207322b98c..6b0a42c95b 100644 --- a/template/package.json +++ b/template/package.json @@ -29,6 +29,18 @@ "vue-router": "^3.0.1"{{/router}} }, "devDependencies": { + {{#typescript}} + "ts-loader": "^2.3.7", + "typescript": "^2.5.3", + {{#if_eq runner "karma"}} + "@types/mocha": "^2.2.43", + "@types/chai": "^4.0.4", + {{/if_eq}} + {{#if_eq runner "jest"}} + "ts-jest": "^21.2.3", + "@types/jest": "^21.1.6", + {{/if_eq}} + {{/typescript}} {{#lint}} "babel-eslint": "^7.2.3", "eslint": "^4.15.0", diff --git a/template/src/App.vue b/template/src/App.vue index 0156030e49..5993a15eb5 100644 --- a/template/src/App.vue +++ b/template/src/App.vue @@ -9,17 +9,18 @@ -