Skip to content

Minimal TypeScript support option added #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
be474b0
Added minimal possible configuration option for typescript to work
Jul 13, 2017
7cf08a6
TypeScript Vue typings filtered
Jul 13, 2017
5df5b7c
Merge branch 'master' into minimal-typescript-option
igogrek Jul 18, 2017
4fd29f8
Merge remote-tracking branch 'upstream/develop' into minimal-typescri…
Oct 9, 2017
c7ca1a5
TypeScript unit test support
Oct 9, 2017
109ead8
Cleanup
Oct 9, 2017
5d4857a
Merge remote-tracking branch 'upstream/master' into minimal-typescrip…
Oct 16, 2017
31ae428
Merge branch 'develop' into minimal-typescript-option
Oct 16, 2017
150752a
Added Vue.extend for latest TypeScript definitions
Oct 16, 2017
e66b836
Removed vue shims
Oct 16, 2017
222ba2e
Removed allowSyntheticDefaultImports
Oct 22, 2017
ebe7bfd
Added chai TS typings for the unit test
Nov 14, 2017
9f06a63
Merge branch 'develop' into minimal-typescript-option
Nov 14, 2017
257b542
Put back vue-shims for better IDE support
Nov 15, 2017
d587493
Merge branch 'develop' into minimal-typescript-option
Nov 20, 2017
5bc2b0b
Vue shims moved to root for Karma to work properly, Jest support added
Nov 20, 2017
a6869f2
Merge branch 'develop' into minimal-typescript-option
Dec 4, 2017
84d90b4
tsconfig fix for Jest
Dec 4, 2017
9cdc05a
Fixed empty lines for when no typescript selected
Dec 4, 2017
4fc2e12
Whitespace fix
Dec 4, 2017
c5b4755
Merge branch 'develop' into minimal-typescript-option
Dec 19, 2017
e121082
Fixes after develop merge
Dec 19, 2017
0bbcf97
Cleanup
Dec 19, 2017
5d403d9
Added vue extension for better IDE support
Dec 21, 2017
0d1633e
Merge branch 'develop' into minimal-typescript-option
Jan 11, 2018
1a43702
Merge branch 'develop' into minimal-typescript-option
Jan 24, 2018
faac147
Test fixes
Jan 24, 2018
2e54c2b
Another test fix
Jan 24, 2018
74a6af8
Merge branch 'develop' into minimal-typescript-option
Feb 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ module.exports = {
},
],
},
typescript: {
when: 'isNotTest',
type: 'confirm',
message: 'Use TypeScript as default language?',
default: false
},
router: {
when: 'isNotTest',
type: 'confirm',
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
1 change: 1 addition & 0 deletions scenarios/full-karma-airbnb.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "A Vue.js project",
"author": "CircleCI",
"build": "standalone",
"typescript": false,
"router": false,
"lint": true,
"lintConfig": "airbnb",
Expand Down
1 change: 1 addition & 0 deletions scenarios/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "A Vue.js project",
"author": "CircleCI",
"build": "runtime",
"typescript": false,
"router": false,
"lint": true,
"lintConfig": "standard",
Expand Down
1 change: 1 addition & 0 deletions scenarios/minimal.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Testing the minimal template setup",
"author": "CircleCI",
"build": "standalone",
"typescript": false,
"router": false,
"lint": false,
"lintConfig": "standard",
Expand Down
3 changes: 2 additions & 1 deletion template/build/vue-loader.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = {
source: 'src',
img: 'src',
image: 'xlink:href'
}
}{{#typescript}},
esModule: true{{/typescript}}
}
13 changes: 11 additions & 2 deletions template/build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions template/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
</div>
</template>

<script>
<script{{#typescript}} lang="ts"{{/typescript}}>
{{#typescript}}import Vue from 'vue'{{/typescript}}
{{#unless router}}
import HelloWorld from './components/HelloWorld'
import HelloWorld from './components/HelloWorld{{#typescript}}.vue{{/typescript}}'

{{/unless}}
export default {
export default {{#typescript}}Vue.extend({{/typescript}}{
name: 'App'{{#router}}{{else}},
components: {
HelloWorld
}{{/router}}
}
}{{#typescript}}){{/typescript}}
</script>

<style>
Expand Down
8 changes: 5 additions & 3 deletions template/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,17 @@
</div>
</template>

<script>
export default {
<script{{#typescript}} lang="ts"{{/typescript}}>
{{#typescript}}import Vue from 'vue'

{{/typescript}}export default {{#typescript}}Vue.extend({{/typescript}}{
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
}{{#typescript}}){{/typescript}}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
Expand Down
2 changes: 1 addition & 1 deletion template/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should change the file name to main.ts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is changed via metalsmith - that was the basic idea of the PR.
See my initial comment and meta.js

{{/if_eq}}
import Vue from 'vue'
import App from './App'
import App from './App{{#typescript}}.vue{{/typescript}}'
{{#router}}
import router from './router'
{{/router}}
Expand Down
2 changes: 1 addition & 1 deletion template/src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import HelloWorld from '@/components/HelloWorld{{#typescript}}.vue{{/typescript}}'

Vue.use(Router)

Expand Down
9 changes: 6 additions & 3 deletions template/test/unit/jest.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ const path = require('path')
module.exports = {
rootDir: path.resolve(__dirname, '../../'),
moduleFileExtensions: [
'js',
'js',{{#typescript}}
'ts',{{/typescript}}
'json',
'vue'
],
],{{#typescript}}
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",{{/typescript}}
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',{{#typescript}}
'^.+\\.ts$': 'ts-jest',{{/typescript}}
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest'
},{{#e2e}}
testPathIgnorePatterns: [
Expand Down
3 changes: 2 additions & 1 deletion template/test/unit/specs/HelloWorld.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Vue from 'vue'
import HelloWorld from '@/components/HelloWorld'
{{#typescript}}{{#if_eq runner "karma"}}import {expect} from 'chai'

describe('HelloWorld.vue', () => {
{{/if_eq}}{{/typescript}}describe('HelloWorld.vue', () => {
it('should render correct contents', () => {
const Constructor = Vue.extend(HelloWorld)
const vm = new Constructor().$mount()
Expand Down
21 changes: 21 additions & 0 deletions template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed anymore I presume

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, removed. Thanks.

"strict": true,{{#if_eq runner "jest"}}
"sourceMap": true,{{/if_eq}}
"lib": [
"dom",
"es5",
"es6",
"es2015.promise"
]
},
"include": [
"./src/**/*.ts"
],
"files" : [
"vue-shims.d.ts"
]
}
4 changes: 4 additions & 0 deletions template/vue-shims.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.vue" {
import Vue from "vue";
export default Vue;
}