Skip to content

Commit

Permalink
🔧 migrate to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
HusamElbashir committed Nov 2, 2019
1 parent 1ef1ac0 commit 8529f7f
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 18 deletions.
13 changes: 12 additions & 1 deletion .eslintrc.js
@@ -1,9 +1,12 @@
module.exports = {
root: true,

env: {
node: true,
},

extends: ['plugin:vue/recommended', '@vue/prettier'],

rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
Expand All @@ -16,9 +19,11 @@ module.exports = {
},
],
},

parserOptions: {
parser: 'babel-eslint',
parser: '@typescript-eslint/parser',
},

overrides: [
{
files: ['**/__tests__/*.{j,t}s?(x)'],
Expand All @@ -27,4 +32,10 @@ module.exports = {
},
},
],

'extends': [
'plugin:vue/recommended',
'@vue/prettier',
'@vue/typescript'
]
}
26 changes: 23 additions & 3 deletions jest.config.js
@@ -1,22 +1,42 @@
module.exports = {
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
moduleFileExtensions: [
'js',
'jsx',
'json',
'vue',
'ts',
'tsx'
],

transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.tsx?$': 'ts-jest'
},

transformIgnorePatterns: ['/node_modules/'],

moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},

snapshotSerializers: ['jest-serializer-vue'],

testMatch: [
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
],

testURL: 'http://localhost/',

watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],

globals: {
'ts-jest': {
babelConfig: true
}
}
}
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -14,12 +14,15 @@
"vue": "^2.6.10"
},
"devDependencies": {
"@types/jest": "^23.1.4",
"@vue/cli-plugin-babel": "^3.11.0",
"@vue/cli-plugin-e2e-cypress": "^3.11.0",
"@vue/cli-plugin-eslint": "^3.11.0",
"@vue/cli-plugin-typescript": "^4.0.5",
"@vue/cli-plugin-unit-jest": "^3.11.0",
"@vue/cli-service": "^3.11.0",
"@vue/eslint-config-prettier": "^5.0.0",
"@vue/eslint-config-typescript": "^4.0.0",
"@vue/test-utils": "1.0.0-beta.29",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
Expand All @@ -28,6 +31,8 @@
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-vue": "^5.0.0",
"prettier": "^1.18.2",
"ts-jest": "^23.0.0",
"typescript": "~3.5.3",
"vue-template-compiler": "^2.6.10"
}
}
28 changes: 22 additions & 6 deletions src/App.vue
@@ -1,12 +1,28 @@
<template>
<div></div>
<div id="app">
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App" />
</div>
</template>

<script>
export default {
<script lang="ts">
import Vue from 'vue'
import HelloWorld from './components/HelloWorld.vue'
export default Vue.extend({
name: 'App',
components: {},
}
components: {
HelloWorld,
},
})
</script>

<style></style>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
108 changes: 108 additions & 0 deletions src/components/HelloWorld.vue
@@ -0,0 +1,108 @@
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,
<br />check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener"
>vue-cli documentation</a
>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript"
target="_blank"
rel="noopener"
>typescript</a
>
</li>
</ul>
<h3>Essential Links</h3>
<ul>
<li>
<a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a>
</li>
<li>
<a href="https://forum.vuejs.org" target="_blank" rel="noopener"
>Forum</a
>
</li>
<li>
<a href="https://chat.vuejs.org" target="_blank" rel="noopener"
>Community Chat</a
>
</li>
<li>
<a href="https://twitter.com/vuejs" target="_blank" rel="noopener"
>Twitter</a
>
</li>
<li>
<a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a>
</li>
</ul>
<h3>Ecosystem</h3>
<ul>
<li>
<a href="https://router.vuejs.org" target="_blank" rel="noopener"
>vue-router</a
>
</li>
<li>
<a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a>
</li>
<li>
<a
href="https://github.com/vuejs/vue-devtools#vue-devtools"
target="_blank"
rel="noopener"
>vue-devtools</a
>
</li>
<li>
<a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener"
>vue-loader</a
>
</li>
<li>
<a
href="https://github.com/vuejs/awesome-vue"
target="_blank"
rel="noopener"
>awesome-vue</a
>
</li>
</ul>
</div>
</template>

<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
name: 'HelloWorld',
props: {
msg: String,
},
})
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
File renamed without changes.
13 changes: 13 additions & 0 deletions src/shims-tsx.d.ts
@@ -0,0 +1,13 @@
import Vue, { VNode } from 'vue'

declare global {
namespace JSX {
// tslint:disable no-empty-interface
interface Element extends VNode {}
// tslint:disable no-empty-interface
interface ElementClass extends Vue {}
interface IntrinsicElements {
[elem: string]: any
}
}
}
4 changes: 4 additions & 0 deletions src/shims-vue.d.ts
@@ -0,0 +1,4 @@
declare module '*.vue' {
import Vue from 'vue'
export default Vue
}
File renamed without changes.
39 changes: 39 additions & 0 deletions tsconfig.json
@@ -0,0 +1,39 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env",
"jest"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}

0 comments on commit 8529f7f

Please sign in to comment.