Skip to content

Commit e86bc12

Browse files
committed
build: Use typescript, update webpack, linters etc.
* added 🐶husky to run prepush * fix .editorconfig - corrected to use LF setting for all files * lint: semi set to never * lint: comma dange - always-multiline, because of duplicating lines * moved jest config into .jestrc * update package.json scripts * added tsconfig, tslint, tsfmt for styling codebase * migrated all impl to ts * migrated non-vue tests to ts Closes realreality#74 realreality#75
1 parent 37a5b8a commit e86bc12

40 files changed

+1670
-812
lines changed

.editorconfig

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
# EditorConfig helps developers define and maintain consistent
22
# coding styles between different editors and IDEs
33
# editorconfig.org
4-
54
root = true
65

7-
86
[*]
9-
10-
# Change these settings to your own preference
7+
end_of_line = lf
8+
insert_final_newline = true
119
indent_style = space
1210
indent_size = 2
13-
14-
[*.json]
15-
indent_size = 2
16-
17-
# We recommend you to keep these unchanged
18-
end_of_line = lf
1911
charset = utf-8
2012
trim_trailing_whitespace = true
21-
insert_final_newline = true
13+
max_line_length = 120
14+
15+
[*.{js,ts}]
16+
quote_type = single
17+
curly_bracket_next_line = false
18+
spaces_around_brackets = inside
19+
indent_brace_style = BSD KNF
20+
21+
[*.html]
22+
quote_type = double
2223

2324
[*.md]
2425
trim_trailing_whitespace = false

.eslintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"error",
1919
"unix"
2020
],
21+
"comma-dangle": [
22+
"error",
23+
"always-multiline"
24+
],
2125
"no-unused-vars": ["warn", { "vars": "all", "args": "none" }],
2226
"no-console": ["off"],
2327
"no-var": "error",
@@ -28,7 +32,7 @@
2832
],
2933
"semi": [
3034
"error",
31-
"always"
35+
"never"
3236
]
3337
},
3438
"globals": {

.jestrc

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"globals": {
3+
"__TS_CONFIG__": {
4+
"module": "commonjs"
5+
}
6+
},
7+
"collectCoverage": false,
8+
"collectCoverageFrom": [
9+
"**/src/js/*.js",
10+
"**/src/**/*.vue",
11+
"**/src/js/components/**.js",
12+
"**/src/js/sites/**.js",
13+
"**/src/js/services/**.js",
14+
"!**/src/js/18n/*.js",
15+
"!**/src/js/background.js"
16+
],
17+
"moduleFileExtensions": [
18+
"js",
19+
"json",
20+
"ts",
21+
"vue"
22+
],
23+
"roots": [
24+
"<rootDir>/src"
25+
],
26+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
27+
"transform": {
28+
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
29+
"^.+\\.(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js",
30+
"^.+\\.vue$": "<rootDir>/node_modules/jest-vue-preprocessor"
31+
},
32+
"verbose": true
33+
}

.yarnrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-prefix false

package.json

+31-36
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,69 @@
44
"description": "Adds little side panel to some real estate sites which shows you quality of location eg. commutation times, air pollution.",
55
"private": true,
66
"scripts": {
7-
"cleanup": "rm -rf build",
87
"build": "node scripts/build.js",
8+
"cleanup": "rm -rf build coverage",
99
"commit": "git-cz",
10-
"lint": "eslint -c .eslintrc ./src/",
11-
"start": "yarn cleanup && node scripts/webserver.js",
12-
"test": "jest",
13-
"test:ci": "yarn lint && yarn test -- --coverage"
10+
"js:lint": "eslint -c .eslintrc ./src/",
11+
"js:lint:fix": "eslint -c .eslintrc --fix ./src/",
12+
"prepush": "npm run js:lint && npm run ts:style && npm t",
13+
"start": "npm run cleanup && node scripts/webserver.js",
14+
"test": "jest --config .jestrc",
15+
"test:ci": "npm run js:lint && npm run ts:style && npm t -- --watch false --coverage",
16+
"test:watch": "npm t -- --watch",
17+
"ts:format:fix": "tsfmt -r",
18+
"ts:format": "tsfmt --verify",
19+
"ts:lint:fix": "npm run ts:lint -- --fix",
20+
"ts:lint": "tslint \"src/**/*.ts\"",
21+
"ts:style:fix": "npm run ts:format:fix && npm run ts:lint:fix",
22+
"ts:style": "npm run ts:format && npm run ts:lint"
1423
},
1524
"dependencies": {
16-
"dotenv": "2.0.0",
17-
"font-awesome": "^4.7.0",
25+
"font-awesome": "4.7.0",
1826
"jquery": "3.2.1",
27+
"ts-jest": "19.0.6",
1928
"vue": "2.1.4",
2029
"vue-i18n": "5.0.3"
2130
},
2231
"devDependencies": {
32+
"@types/chrome": "0.0.44",
33+
"@types/jest": "19.2.2",
34+
"@types/jquery": "2.0.41",
35+
"awesome-typescript-loader": "3.1.2",
2336
"babel-core": "6.24.0",
24-
"babel-loader": "6.4.1",
2537
"babel-plugin-transform-runtime": "6.23.0",
2638
"babel-preset-es2015": "6.24.0",
27-
"chai": "^3.5.0",
39+
"chai": "3.5.0",
2840
"commitizen": "2.9.6",
29-
"copy-webpack-plugin": "^4.0.1",
41+
"copy-webpack-plugin": "4.0.1",
3042
"css-loader": "0.28.0",
3143
"cz-conventional-changelog": "2.0.0",
44+
"dotenv": "4.0.0",
3245
"eslint": "3.19.0",
3346
"eslint-loader": "1.7.1",
34-
"expose-loader": "0.7.1",
47+
"expose-loader": "0.7.3",
3548
"extract-text-webpack-plugin": "2.1.0",
3649
"fs-extra": "2.1.2",
3750
"html-loader": "0.4.5",
3851
"html-webpack-plugin": "2.28.0",
52+
"husky": "0.13.3",
3953
"jest": "19.0.2",
4054
"jest-vue-preprocessor": "0.2.0",
4155
"postcss-loader": "1.3.3",
42-
"precss": "^1.4.0",
56+
"precss": "1.4.0",
4357
"progress-bar-webpack-plugin": "1.9.3",
4458
"pug": "2.0.0-beta11",
4559
"style-loader": "0.16.1",
60+
"tslint": "4.5.0",
61+
"tslint-config-standard": "4.0.0",
62+
"typescript": "2.2.2",
63+
"typescript-formatter": "5.1.2",
4664
"vue-loader": "11.3.4",
4765
"vue-template-compiler": "2.1.4",
48-
"webpack": "2.3.2",
66+
"webpack": "2.3.3",
4967
"webpack-dev-server": "2.4.2",
5068
"write-file-webpack-plugin": "4.0.0"
5169
},
52-
"jest": {
53-
"collectCoverage": false,
54-
"collectCoverageFrom": [
55-
"**/src/js/*.js",
56-
"**/src/**/*.vue",
57-
"**/src/js/components/**.js",
58-
"**/src/js/sites/**.js",
59-
"**/src/js/services/**.js",
60-
"!**/src/js/18n/*.js",
61-
"!**/src/js/background.js"
62-
],
63-
"moduleFileExtensions": [
64-
"js",
65-
"json",
66-
"vue"
67-
],
68-
"testRegex": "<rootDir>/src/.*\\.spec\\.(js)$",
69-
"transform": {
70-
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
71-
"^.+\\.vue$": "<rootDir>/node_modules/jest-vue-preprocessor"
72-
},
73-
"verbose": true
74-
},
7570
"engines": {
7671
"node": ">=6.3"
7772
},

scripts/build.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
process.env.NODE_ENV = 'production';
1+
process.env.NODE_ENV = 'production'
22

3-
const webpack = require('webpack');
4-
const config = require('../webpack.config');
3+
const webpack = require('webpack')
4+
const config = require('../webpack.config')
55

6-
require('./prepare');
6+
require('./prepare')
77

88
webpack(
99
config,
10-
function (err) { if (err) throw err; }
11-
);
10+
function (err) { if (err) throw err }
11+
)

scripts/prepare.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const fs = require('fs-extra');
2-
const manifest = require('../src/manifest.json');
3-
const packageJson = require('../package.json');
4-
const path = require('path');
1+
const fs = require('fs-extra')
2+
const manifest = require('../src/manifest.json')
3+
const packageJson = require('../package.json')
4+
const path = require('path')
55

66
// generates the manifest file using the package.json information
77
fs.outputFile(
88
path.join(__dirname, '../build/manifest.json'),
99
JSON.stringify(Object.assign({}, manifest, {
1010
description: packageJson.description,
11-
version: packageJson.version
11+
version: packageJson.version,
1212
}))
13-
);
13+
)

scripts/webserver.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
const WebpackDevServer = require('webpack-dev-server');
2-
const webpack = require('webpack');
3-
const path = require('path');
4-
const WriteFilePlugin = require('write-file-webpack-plugin');
1+
const WebpackDevServer = require('webpack-dev-server')
2+
const webpack = require('webpack')
3+
const path = require('path')
4+
const WriteFilePlugin = require('write-file-webpack-plugin')
55

6-
const config = require('../webpack.config');
7-
const env = require('./../config/env');
6+
const config = require('../webpack.config')
7+
const env = require('./../config/env')
88

9-
require('./prepare');
9+
require('./prepare')
1010

1111
const {
1212
entry,
1313
excludeEntriesToHotReload = [],
1414
plugins = [],
15-
} = config;
15+
} = config
1616

1717
Object.keys(entry)
1818
.filter(entryName => !excludeEntriesToHotReload.includes(entryName)) // not possible to hot-reload contentscript
1919
.forEach(entryName => {
2020
entry[entryName] = [
2121
`webpack-dev-server/client?https://localhost:${env.PORT}`,
2222
'webpack/hot/dev-server',
23-
entry[entryName]
24-
];
25-
});
23+
entry[entryName],
24+
]
25+
})
2626

2727
const compilerOptions = Object.assign({}, config, {
2828
entry,
2929
plugins: [
3030
new webpack.HotModuleReplacementPlugin(),
3131
new WriteFilePlugin({ log: false}),
32-
...plugins
33-
]
34-
});
32+
...plugins,
33+
],
34+
})
3535

36-
const compiler = webpack(compilerOptions);
36+
const compiler = webpack(compilerOptions)
3737
const server = new WebpackDevServer(compiler, {
3838
hot: true,
3939
https: true,
4040
contentBase: path.join(__dirname, '../build'),
4141
headers: { 'Access-Control-Allow-Origin': '*' },
42-
stats: { colors: true }
43-
});
42+
stats: { colors: true },
43+
})
4444

45-
server.listen(env.PORT);
45+
server.listen(env.PORT)

src/globals.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
declare module '*.vue' {
2+
import * as Vue from 'vue'
3+
export default typeof Vue
4+
}
5+
6+
declare module 'vue-i18n'
7+
8+
declare module '*.html'
9+
10+
declare namespace RR {
11+
function logInfo(s: string): void
12+
}

src/js/background.js

-15
This file was deleted.

src/js/background.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Code that detects host page and switches icons in toolbar.
3+
*/
4+
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
5+
console.log('request', request)
6+
if (request.switchIconOn) {
7+
chrome.browserAction.setIcon({
8+
path: {
9+
19: 'images/icon-19.png',
10+
38: 'images/icon-19.png',
11+
},
12+
tabId: sender.tab && sender.tab.id,
13+
})
14+
}
15+
})

0 commit comments

Comments
 (0)