Skip to content

Commit 3d5837c

Browse files
authored
Migrate EME to Typescript (#144)
* migrate_to_typescript * refractor_common_js * fix_build_break * migrate_to_ts * fix_babel_spread_error * fix_typo * fix_asar_error * refine_code * refractor_svg_icon_ts * refine_wordcount * fix_build_issue
1 parent 1d9c552 commit 3d5837c

22 files changed

+5373
-2865
lines changed

.babelrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
presets: [
3+
['es2015', {"module": false}],
4+
'stage-1'
5+
],
6+
7+
plugins: [
8+
'transform-runtime',
9+
'transform-object-rest-spread'
10+
]
11+
}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
node_modules
22
*.log
33
.DS_Store
4-
/app/dist
4+
/app/libvue
55
/dist
66
stats.html
77
stats.json

app/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link rel="stylesheet" href="./vendor/github-markdown-css/github-markdown.css">
77
<link rel="stylesheet" href="./vendor/katex/katex.min.css">
88
<link rel="stylesheet" href="./vendor/css/spinners.css">
9-
<link rel="stylesheet" href="./dist/app.css">
9+
<link rel="stylesheet" href="./libvue/app.css">
1010
</head>
1111
<body>
1212
<div id="eme">
@@ -15,8 +15,8 @@
1515
<script>start = performance.now();</script>
1616
<script src="./vendor/mousetrap/mousetrap.js"></script>
1717
<script src="./vendor/mousetrap/global-bind.js"></script>
18-
<script src="./dist/vendor.js"></script>
19-
<script src="./dist/app.js"></script>
18+
<script src="./libvue/vendor.js"></script>
19+
<script src="./libvue/app.js"></script>
2020
<script>console.log('total init time', performance.now() - start);</script>
2121
</body>
2222
</html>

app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "EME",
33
"productName": "EME",
4-
"version": "0.13.0",
4+
"version": "0.15.0",
55
"description": "Elegant Markdown Editor",
66
"author": {
77
"name": "EGOIST",

build/icons/512x512.png

144 KB
Loading

package.json

+26-22
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77
"lint": "npm run lint:app && npm run lint:src",
88
"lint:app": "eslint app/index.js app/eme --ext .js --fix",
99
"lint:src": "eslint src/* src/* --ext .js --ext .vue --fix",
10-
"postinstall": "install-app-deps",
10+
"postinstall": "electron-builder install-app-deps",
1111
"app": "cross-env NODE_ENV=development electron app/",
1212
"build": "rm -rf app/dist && webpack --progress --config scripts/webpack.config.prod.js --profile --json > stats.json",
1313
"watch": "webpack --config scripts/webpack.config.dev.js --watch",
1414
"dist": "npm run mac && npm run linux && npm run win",
15-
"mac": "build --mac",
16-
"linux": "build --linux deb tar.xz",
17-
"win": "build --win --ia32",
15+
"mac": "electron-build --mac",
16+
"linux": "electron-builder --linux deb tar.xz",
17+
"win": "electron-builder --win --ia32",
1818
"stats": "webpack-bundle-analyzer stats.json"
1919
},
2020
"build": {
2121
"appId": "com.egoistian.eme",
22-
"category": "public.app-category.utilities",
2322
"asar": true,
23+
"copyright": "Copyright @2019 The EME authors",
2424
"win": {
25-
"target": [
26-
"squirrel"
27-
]
25+
"target": "squirrel"
26+
},
27+
"linux": {
28+
"category": "public.app-category.utilities"
2829
}
2930
},
3031
"repository": {
@@ -36,30 +37,31 @@
3637
"editor"
3738
],
3839
"devDependencies": {
40+
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
3941
"autoprefixer": "^6.4.0",
4042
"babel-core": "^6.18.2",
4143
"babel-eslint": "^6.1.2",
42-
"babel-loader": "^6.2.4",
44+
"babel-loader": "^7.1.3",
4345
"babel-plugin-transform-runtime": "^6.9.0",
4446
"babel-preset-es2015": "^6.9.0",
4547
"babel-preset-stage-1": "^6.5.0",
4648
"cross-env": "^2.0.0",
4749
"css-loader": "^0.23.1",
4850
"devtron": "^1.2.1",
49-
"electron-builder": "^11.7.0",
51+
"electron": "^2.0.18",
52+
"electron-builder": "^20.13.4",
5053
"electron-builder-squirrel-windows": "^11.6.1",
51-
"electron-devtools-installer": "^1.1.5",
52-
"electron-packager": "^7.5.1",
53-
"electron-prebuilt": "^1.3.2",
54+
"electron-devtools-installer": "^2.0.0",
55+
"electron-packager": "^11.2.1",
5456
"eslint": "^3.12.2",
5557
"eslint-config-xo-space": "^0.15.0",
5658
"eslint-plugin-babel": "^4.0.0",
5759
"eslint-plugin-vue": "^2.0.0",
58-
"extract-text-webpack-plugin": "^1.0.1",
60+
"extract-text-webpack-plugin": "^2.1.2",
5961
"file-loader": "^0.9.0",
6062
"json-loader": "^0.5.4",
6163
"minimist": "^1.2.0",
62-
"postcss-import": "^9.0.0",
64+
"postcss-import": "^9.1.0",
6365
"postcss-loader": "^1.2.1",
6466
"postcss-mixins": "^5.0.0",
6567
"postcss-nested": "^1.0.0",
@@ -68,17 +70,21 @@
6870
"shelljs": "^0.7.4",
6971
"style-loader": "^0.13.1",
7072
"svg-inline-loader": "^0.6.1",
73+
"ts-loader": "^3.5.0",
74+
"typescript": "^3.4.5",
7175
"url-loader": "^0.5.7",
76+
"vue": "^2.6.10",
7277
"vue-hot-reload-api": "^2.0.6",
7378
"vue-html-loader": "^1.2.3",
74-
"vue-loader": "^10.0.2",
79+
"vue-loader": "^12.0.3",
7580
"vue-style-loader": "^1.0.0",
76-
"vue-template-compiler": "^2.1.8",
77-
"webpack": "^1.14.0",
81+
"vue-template-compiler": "^2.6.10",
82+
"webpack": "^2.7.0",
7883
"webpack-bundle-analyzer": "^2.2.1",
7984
"webpack-hot-middleware": "^2.12.1"
8085
},
8186
"dependencies": {
87+
"@wordpress/wordcount": "^2.2.0",
8288
"babel-runtime": "^6.11.6",
8389
"codemirror": "^5.17.0",
8490
"color-preset": "^0.1.1",
@@ -91,10 +97,8 @@
9197
"object-picker": "^0.2.0",
9298
"pify": "^2.3.0",
9399
"sanitize-html": "^1.13.0",
94-
"tildify": "^1.2.0",
100+
"sumchecker": "^2.0.1",
95101
"unique-random-array": "^1.0.0",
96-
"vue": "^2.1.8",
97-
"vuex": "^2.1.1",
98-
"wordcount": "^1.1.1"
102+
"vuex": "^2.1.1"
99103
}
100104
}

scripts/webpack.config.js

+42-36
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ const postcss = [
1616

1717
module.exports = {
1818
entry: {
19-
app: ['./src/index.js'],
19+
app: './src/index.ts',
2020
vendor: ['vue', 'vuex']
2121
},
2222
output: {
23-
path: process.cwd() + '/app/dist',
23+
path: process.cwd() + '/app/libvue',
2424
filename: '[name].js'
2525
},
2626
resolve: {
27-
extensions: ['', '.js', '.vue', '.css', '.json'],
27+
extensions: ['.js', '.vue', '.css', '.json', '.ts'],
2828
alias: {
29-
'vue$': 'vue/dist/vue.common.js',
29+
'vue$': 'vue/dist/vue.esm.js',
3030
src: path.join(__dirname, '../src'),
3131
utils: path.join(__dirname, '../src/utils'),
3232
components: path.join(__dirname, '../src/components'),
@@ -36,48 +36,52 @@ module.exports = {
3636
}
3737
},
3838
module: {
39-
loaders: [
39+
rules: [
4040
{
41-
test: /\.js$/,
42-
loaders: ['babel'],
43-
exclude: [/node_modules/]
41+
test: /\.tsx?$/,
42+
loaders: 'ts-loader',
43+
exclude: /node_modules/,
44+
options: {
45+
appendTsSuffixTo: [/\.vue$/],
46+
}
4447
},
4548
{
4649
test: /\.vue$/,
47-
loaders: ['vue']
50+
loader: 'vue-loader',
51+
options: {
52+
autoprefixer: false,
53+
postcss,
54+
loaders: {
55+
css: ExtractTextPlugin.extract({
56+
fallback: 'vue-style-loader',
57+
loader: 'css-loader?sourceMap'
58+
}
59+
)
60+
}
61+
}
4862
},
4963
{
50-
test: /\.css$/,
51-
loader: ExtractTextPlugin.extract(
52-
'style-loader',
53-
'css-loader!postcss-loader'
54-
)
64+
test: /\.js$/,
65+
loader: 'babel-loader',
66+
exclude: /node_modules/,
5567
},
5668
{
57-
test: /\.json$/,
58-
loaders: ['json']
69+
test: /\.svg$/,
70+
exclude: /node_modules/,
71+
loader: 'svg-inline-loader'
5972
},
6073
{
61-
test: /\.svg$/,
62-
loaders: ['svg-inline']
63-
}
64-
]
65-
},
66-
babel: {
67-
presets: ['es2015', 'stage-1'],
68-
plugins: ['transform-runtime']
69-
},
70-
vue: {
71-
autoprefixer: false,
72-
postcss,
73-
loaders: {
74-
css: ExtractTextPlugin.extract(
75-
'vue-style-loader',
76-
'css-loader?sourceMap'
77-
)
78-
}
74+
test: /\.css$/,
75+
exclude: /node_modules/,
76+
loader: ExtractTextPlugin.extract(
77+
{
78+
fallback: 'style-loader',
79+
loader: 'css-loader!postcss-loader'
80+
}
81+
)
82+
},
83+
],
7984
},
80-
postcss,
8185
target: 'electron-renderer',
8286
plugins: [
8387
new webpack.ExternalsPlugin('commonjs2', [
@@ -89,5 +93,7 @@ module.exports = {
8993
name: 'vendor',
9094
filename: 'vendor.js'
9195
})
92-
]
96+
],
97+
98+
devtool: '#eval-source-map'
9399
}

scripts/webpack.config.prod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const webpack = require('webpack')
33
const config = require('./webpack.config')
44

55
config.plugins = config.plugins.concat([
6-
new webpack.optimize.OccurenceOrderPlugin(),
76
new webpack.optimize.UglifyJsPlugin({
7+
sourceMap: true,
88
compressor: {
99
warnings: false
1010
},

src/components/footer.vue

+17-15
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,24 @@
114114
</footer>
115115
</template>
116116

117-
<script>
118-
import tildify from 'tildify'
119-
import {shell} from 'electron'
120-
import wordCount from 'wordcount'
117+
<script lang='ts'>
118+
import Vue from "vue";
121119
122-
import WritingModes from 'components/writing-modes'
120+
import {shell} from 'electron';
123121
124-
export default {
122+
import countTabContent from 'utils/wordcount';
123+
import tildify from 'utils/tildify';
124+
import WritingModes from 'components/writing-modes';
125+
126+
export default Vue.extend ({
125127
computed: {
126128
currentTabIndex() {
127-
return this.$store.state.editor.currentTabIndex
129+
return this.$store.state.editor.currentTabIndex;
128130
},
129131
status() {
130-
const tab = this.$store.state.editor.tabs[this.$store.state.editor.currentTabIndex] || {}
132+
const tab = this.$store.state.editor.tabs[this.$store.state.editor.currentTabIndex] || {};
131133
return {
132-
wordCount: tab.content ? wordCount(tab.content) : 0,
134+
wordCount: tab.content ? countTabContent(tab.content) : 0,
133135
charCount: tab.content ? tab.content.length : 0,
134136
lineCount: (tab.content && tab.editor) ? tab.editor.lineCount() : 0,
135137
filePath: tab.filePath ?
@@ -139,19 +141,19 @@
139141
pdf: tab.pdf,
140142
gist: tab.gist,
141143
exporting: tab.exporting
142-
}
144+
};
143145
}
144146
},
145147
methods: {
146-
openPDF(pdf) {
147-
shell.showItemInFolder(pdf)
148+
openPDF(pdf: string) {
149+
shell.showItemInFolder(pdf);
148150
},
149-
openURL(id) {
150-
shell.openExternal(`https://gist.github.com/${id}`)
151+
openURL(id: string) {
152+
shell.openExternal(`https://gist.github.com/${id}`);
151153
}
152154
},
153155
components: {
154156
WritingModes
155157
}
156-
}
158+
});
157159
</script>

0 commit comments

Comments
 (0)