Add TypeScript · standardnotes/desktop@b2ce848 · GitHub
Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit b2ce848

Browse files
committed
Add TypeScript
1 parent 2672716 commit b2ce848

11 files changed

Lines changed: 230 additions & 51 deletions

File tree

‎.eslintrc‎

Lines changed: 5 additions & 3 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules/
44
npm-debug.log
55

66
/app/dist
7+
.vscode

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ npm run dev
1010
npm run start
1111
```
1212

13+
Before commiting, make sure the code is correctly typed:
14+
15+
```
16+
npm run check-types
17+
```
18+
1319
## Building
1420

1521
Build for all platforms:
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,28 @@ const electron = require('electron');
22
const path = require('path');
33
const fs = require('fs');
44

5-
export const StoreKeys = {
6-
ExtServerHost: 'extServerHost',
7-
UseSystemMenuBar: 'useSystemMenuBar',
8-
MenuBarVisible: 'isMenuBarVisible',
9-
BackupsLocation: 'backupsLocation',
10-
BackupsDisabled: 'backupsDisabled',
11-
MinimizeToTray: 'minimizeToTray',
12-
ZoomFactor: 'zoomFactor',
5+
export enum StoreKeys {
6+
ExtServerHost = 'extServerHost',
7+
UseSystemMenuBar = 'useSystemMenuBar',
8+
MenuBarVisible = 'isMenuBarVisible',
9+
BackupsLocation = 'backupsLocation',
10+
BackupsDisabled = 'backupsDisabled',
11+
MinimizeToTray = 'minimizeToTray',
12+
ZoomFactor = 'zoomFactor',
1313
/**
1414
* @type {Set<String> | null} a set of language codes.
1515
*/
16-
SelectedSpellCheckerLanguageCodes: 'selectedSpellCheckerLanguageCodes'
16+
SelectedSpellCheckerLanguageCodes = 'selectedSpellCheckerLanguageCodes'
17+
};
18+
19+
type StoreData = {
20+
[key in StoreKeys]?: any;
1721
};
1822

1923
export class Store {
20-
static instance = null;
24+
static instance: Store;
25+
readonly path: string;
26+
readonly data: StoreData;
2127

2228
static getInstance() {
2329
if (!this.instance) {
@@ -38,15 +44,15 @@ export class Store {
3844
return this.instance;
3945
}
4046

41-
static get(key) {
47+
static get(key: StoreKeys) {
4248
return this.getInstance().get(key);
4349
}
4450

45-
static set(key, val) {
51+
static set(key: StoreKeys, val: any) {
4652
return this.getInstance().set(key, val);
4753
}
4854

49-
constructor(opts) {
55+
constructor(opts: { configName: string; defaults: StoreData }) {
5056
/**
5157
* Renderer process has to get `app` module via `remote`, whereas the main process
5258
* can get it directly app.getPath('userData') will return a string of the user's
@@ -57,11 +63,11 @@ export class Store {
5763
this.data = parseDataFile(this.path, opts.defaults);
5864
}
5965

60-
get(key) {
66+
get(key: StoreKeys) {
6167
return this.data[key];
6268
}
6369

64-
set(key, val) {
70+
set(key: StoreKeys, val: any) {
6571
this.data[key] = val;
6672
fs.writeFileSync(this.path, JSON.stringify(this.data, (_key, value) => {
6773
if (value instanceof Set) {
@@ -72,7 +78,7 @@ export class Store {
7278
}
7379
}
7480

75-
function parseDataFile(filePath, defaults) {
81+
function parseDataFile(filePath: string, defaults: StoreData) {
7682
try {
7783
const userData = JSON.parse(fs.readFileSync(filePath));
7884

‎babel.config.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ module.exports = function (api) {
22
api.cache(true);
33

44
const presets = [
5-
["@babel/preset-env", {
5+
"@babel/typescript",
6+
[
7+
"@babel/preset-env", {
68
"targets": {
7-
"electron": 5
9+
"electron": 8
810
}
911
}]
1012
];

‎package-lock.json‎

Lines changed: 139 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"@babel/core": "^7.8.4",
1212
"@babel/plugin-proposal-class-properties": "^7.8.3",
1313
"@babel/preset-env": "^7.8.4",
14+
"@babel/preset-typescript": "^7.8.3",
15+
"@typescript-eslint/eslint-plugin": "^2.23.0",
16+
"@typescript-eslint/parser": "^2.23.0",
1417
"babel-eslint": "^10.0.3",
1518
"babel-loader": "^8.0.6",
1619
"copy-webpack-plugin": "^5.1.1",
@@ -32,6 +35,7 @@
3235
"mocha": "^7.1.0",
3336
"rimraf": "^3.0.2",
3437
"spectron": "^10.0.1",
38+
"typescript": "^3.8.3",
3539
"webpack": "^4.41.6",
3640
"webpack-cli": "^3.3.11",
3741
"webpack-merge": "^4.2.2"
@@ -95,7 +99,8 @@
9599
"start": "electron . --enable-logging --icon _icon/icon.png",
96100
"clean": "rimraf app/dist/",
97101
"setup": "npm install && npm --prefix ./app install ./app && git submodule update --init --force --remote",
98-
"lint": "eslint --fix app/index.js app/application.js app/javascripts/**/*.js test/*.js",
99-
"test": "mocha"
102+
"lint": "eslint app/index.js app/application.js app/javascripts/**/*.js test/*.js",
103+
"test": "mocha",
104+
"check-types": "tsc"
100105
}
101106
}

‎tsconfig.json‎

Lines changed: 18 additions & 0 deletions

0 commit comments

Comments
 (0)