Skip to content

Commit d6bd98d

Browse files
committed
experimental typescript support
1 parent 92337fb commit d6bd98d

File tree

16 files changed

+6982
-7
lines changed

16 files changed

+6982
-7
lines changed

meta.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ module.exports = {
9292
}
9393
]
9494
},
95+
typescript: {
96+
type: 'confirm',
97+
message: 'Setup TypeScript support?',
98+
require: true
99+
},
95100
unit: {
96101
type: 'confirm',
97102
message: 'Setup unit testing with Karma + Mocha?',
@@ -151,6 +156,8 @@ module.exports = {
151156
filters: {
152157
'src/renderer/routes.js': 'plugins[\'vue-router\']',
153158
'src/renderer/components/LandingPageView/CurrentPage.vue': 'plugins[\'vue-router\']',
159+
'src/**/*.ts': 'typescript',
160+
'src/**/*.js': '!typescript',
154161
'src/renderer/router/**/*': 'plugins[\'vue-router\']',
155162
'src/renderer/store/**/*': 'plugins[\'vuex\']',
156163
'test/e2e/**/*': 'e2e',
@@ -159,6 +166,7 @@ module.exports = {
159166
'test/.eslintrc': 'e2e || unit',
160167
'.eslintignore': 'eslint',
161168
'.eslintrc.js': 'eslint',
169+
'tsconfig.json': 'typescript',
162170
'appveyor.yml': 'builder === \'builder\'',
163171
'.travis.yml': 'builder === \'builder\''
164172
},

template/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"babel-register": "^6.24.1",
8686
"cross-env": "^5.0.5",
8787
"del-cli": "^1.1.0",
88+
"devtron": "^1.4.0",
8889
"electron": "^1.7.5",
8990
"electron-debug": "^1.4.0",
9091
"electron-webpack": "^1.4.2",
@@ -110,6 +111,10 @@
110111
"eslint-plugin-import": "^2.2.0",
111112
{{/if_eq}}
112113
{{/eslint}}
114+
{{#if typescript}}
115+
"electron-webpack-ts": "^1.1.2",
116+
"typescript": "^2.5.2",
117+
{{/if}}
113118
{{#if unit}}
114119
"inject-loader": "^3.0.0",
115120
"karma": "^1.3.0",

template/src/main/global.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// global path to `static/` directory
2+
declare namespace NodeJS {
3+
export interface Global {
4+
__static: string
5+
}
6+
}
7+

template/src/main/index.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{{#if_eq eslintConfig 'standard'}}
2+
'use strict'
3+
4+
{{/if_eq}}
5+
import { app, BrowserWindow } from 'electron'{{#if_eq eslintConfig 'airbnb'}} // eslint-disable-line{{/if_eq}}
6+
7+
// Install `electron-debug` with `devtron`
8+
require('electron-debug')({ showDevTools: true })
9+
10+
/**
11+
* Set `__static` path to static files in production
12+
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
13+
*/
14+
if (process.env.NODE_ENV !== 'development') {
15+
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\'){{#if_eq eslintConfig 'airbnb'}} // eslint-disable-line{{/if_eq}}
16+
}
17+
18+
let mainWindow: Electron.BrowserWindow | null = null
19+
20+
const winURL: string = process.env.NODE_ENV === 'development'
21+
? `http://localhost:9080`
22+
: `file://${__dirname}/index.html`
23+
24+
function createWindow () {
25+
/**
26+
* Initial window options
27+
*/
28+
mainWindow = new BrowserWindow({
29+
height: 563,
30+
useContentSize: true,
31+
width: 1000
32+
})
33+
34+
mainWindow.loadURL(winURL)
35+
36+
mainWindow.on('closed', () => {
37+
mainWindow = null
38+
})
39+
}
40+
41+
app.on('ready', createWindow)
42+
43+
app.on('window-all-closed', () => {
44+
if (process.platform !== 'darwin') {
45+
app.quit()
46+
}
47+
})
48+
49+
app.on('activate', () => {
50+
if (mainWindow === null) {
51+
createWindow()
52+
}
53+
})
54+
{{#if_eq builder 'builder'}}
55+
56+
/**
57+
* Auto Updater
58+
*
59+
* Uncomment the following code below and install `electron-updater` to
60+
* support auto updating. Code Signing with a valid certificate is required.
61+
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
62+
*/
63+
64+
/*
65+
import { autoUpdater } from 'electron-updater'
66+
67+
autoUpdater.on('update-downloaded', () => {
68+
autoUpdater.quitAndInstall()
69+
})
70+
71+
app.on('ready', () => {
72+
if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
73+
})
74+
*/
75+
{{/if_eq}}

template/src/renderer/App.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
</div>
99
</template>
1010

11-
<script>
11+
<script{{#if typescript}} lang="ts"{{/if}}>
12+
{{#if typescript}}import Vue, { ComponentOptions } from 'vue'{{/if}}
1213
{{#isEnabled plugins 'vue-router'}}
1314
{{else}}
14-
import LandingPage from '@/components/LandingPage'
15+
import LandingPage from '@/components/LandingPage{{#if typescript}}.vue{{/if}}'
1516
1617
{{/isEnabled}}
1718
export default {
@@ -22,7 +23,19 @@
2223
LandingPage
2324
}
2425
{{/isEnabled}}
26+
}{{#if typescript}} as ComponentOptions<Vue>{{/if}}
27+
{{#if typescript}}
28+
29+
/*
30+
import Vue from 'vue'
31+
import Component from 'vue-class-component'
32+
33+
@Component
34+
export default class DidItWork extends Vue {
35+
name = 'did-it-work'
2536
}
37+
*/
38+
{{/if}}
2639
</script>
2740

2841
<style>

template/src/renderer/components/LandingPage.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,38 @@
2929
</div>
3030
</template>
3131

32-
<script>
33-
import SystemInformation from './LandingPage/SystemInformation'
32+
<script{{#if typescript}} lang="ts"{{/if}}>
33+
{{#if typescript}}import Vue, { ComponentOptions } from 'vue'{{/if}}
34+
import SystemInformation from './LandingPage/SystemInformation{{#if typescript}}.vue{{/if}}'
3435
3536
export default {
3637
name: 'landing-page',
3738
components: { SystemInformation },
3839
methods: {
39-
open (link) {
40+
open (link{{#if typescript}}: string{{/if}}) {
4041
{{#isEnabled plugins 'vue-electron'}}this.$electron{{else}}require('electron'){{/isEnabled}}.shell.openExternal(link)
4142
}
4243
}
44+
}{{#if typescript}} as ComponentOptions<Vue>{{/if}}
45+
{{#if typescript}}
46+
47+
/*
48+
import Vue from 'vue'
49+
import Component from 'vue-class-component'
50+
import SystemInformation from './LandingPage/SystemInformation.vue'
51+
52+
@Component({
53+
components: {
54+
SystemInformation
55+
}
56+
})
57+
export default class LandingPage extends Vue {
58+
open (link: string) {
59+
this.$electron.shell.openExternal(link)
60+
}
4361
}
62+
*/
63+
{{/if}}
4464
</script>
4565

4666
<style>

template/src/renderer/components/LandingPage/SystemInformation.vue

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232
</div>
3333
</template>
3434

35-
<script>
35+
<script{{#if typescript}} lang="ts"{{/if}}>
36+
{{#if typescript}}
37+
import Vue, { ComponentOptions } from 'vue'
38+
39+
{{/if}}
3640
export default {
3741
data () {
3842
return {
39-
electron: process.versions['atom-shell'],
43+
electron: process.versions.electron,
4044
{{#isEnabled plugins 'vue-router'}}
4145
name: 'landing-page',
4246
{{/isEnabled}}
@@ -48,7 +52,24 @@
4852
vue: require('vue/package.json').version
4953
}
5054
}
55+
}{{#if typescript}} as ComponentOptions<Vue>{{/if}}
56+
{{#if typescript}}
57+
58+
/*
59+
import Vue from 'vue'
60+
import Component from 'vue-class-component'
61+
62+
@Component
63+
export default class SystemInformation extends Vue {
64+
electron = process.versions.electron
65+
name = 'landing-page'
66+
node = process.versions.node
67+
path = '/'
68+
platform = require('os').platform()
69+
vue = require('vue/package.json').version
5170
}
71+
*/
72+
{{/if}}
5273
</script>
5374

5475
<style scoped>

template/src/renderer/main.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Vue from 'vue'
2+
{{#isEnabled plugins 'axios'}}
3+
import axios from 'axios'
4+
{{/isEnabled}}
5+
6+
import App from './App.vue'
7+
{{#isEnabled plugins 'vue-router'}}
8+
import router from './router'
9+
{{/isEnabled}}
10+
{{#isEnabled plugins 'vuex'}}
11+
import store from './store'
12+
{{/isEnabled}}
13+
14+
{{#isEnabled plugins 'vue-electron'}}
15+
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
16+
{{/isEnabled}}
17+
{{#isEnabled plugins 'axios'}}
18+
Vue.http = Vue.prototype.$http = axios
19+
{{/isEnabled}}
20+
Vue.config.productionTip = false
21+
22+
/* eslint-disable no-new */
23+
new Vue({
24+
components: { App },
25+
{{#isEnabled plugins 'vue-router'}}
26+
router,
27+
{{/isEnabled}}
28+
{{#isEnabled plugins 'vuex'}}
29+
store,
30+
{{/isEnabled}}
31+
template: '<App/>'
32+
}).$mount('#app')

template/src/renderer/router/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Vue from 'vue'
2+
import Router from 'vue-router'
3+
4+
Vue.use(Router)
5+
6+
export default new Router({
7+
routes: [
8+
{
9+
path: '/',
10+
name: 'landing-page',
11+
component: require('@/components/LandingPage')
12+
},
13+
{
14+
path: '*',
15+
redirect: '/'
16+
}
17+
]
18+
})

template/src/renderer/store/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Vue from 'vue'
2+
import Vuex from 'vuex'
3+
4+
import modules from './modules'
5+
6+
Vue.use(Vuex)
7+
8+
export default new Vuex.Store({
9+
modules,
10+
strict: process.env.NODE_ENV !== 'production'
11+
})

0 commit comments

Comments
 (0)