From 3777963f8c6d64c085149cc6ac230e041aa119d1 Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Thu, 17 Jan 2019 23:27:45 +0100 Subject: [PATCH] Switch electron.js to typescript --- .gitignore | 1 + electron.js => electron.ts | 50 ++++++++++++++++++++------------------ package.json | 4 +-- tsconfig.json | 7 +++--- 4 files changed, 34 insertions(+), 28 deletions(-) rename electron.js => electron.ts (67%) diff --git a/.gitignore b/.gitignore index 2acb99c..3583643 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules backend/coverage backend/.nyc_output build +/dist .DS_Store test.dot test.png diff --git a/electron.js b/electron.ts similarity index 67% rename from electron.js rename to electron.ts index 94c19cb..809fb35 100644 --- a/electron.js +++ b/electron.ts @@ -1,49 +1,53 @@ -const { app, BrowserWindow } = require('electron') -const { autoUpdater } = require("electron-updater") -const log = require('electron-log'); -const { ConnectionManager, updateNotifier } = require('./backend/build/backend/src/index.js') -const fs = require('fs') -const path = require('path') -require('electron-debug')({enabled: process.argv[2] === '--debug'}); +import { UpdateInfo } from './events' +import { BrowserWindow, app } from 'electron' +import * as path from 'path' +import * as fs from 'fs' -autoUpdater.logger = log; -autoUpdater.logger.transports.file.level = 'info'; -log.info('App starting...'); +const { autoUpdater } = require('electron-updater') +const log = require('electron-log') +import { ConnectionManager, updateNotifier } from './backend/src/index' + +const isDebugEnabled = Boolean(process.argv.find(arg => arg === 'debug')) +require('electron-debug')({ enabled: isDebugEnabled }) + +autoUpdater.logger = log +autoUpdater.logger.transports.file.level = 'info' +log.info('App starting...') const connectionManager = new ConnectionManager() connectionManager.manageConnections() // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. -let mainWindow +let mainWindow: BrowserWindow | undefined -function createWindow () { - const icon = path.join(__dirname, 'icon.png') +function createWindow() { + const iconPath = path.join(__dirname, 'icon.png') // Create the browser window. mainWindow = new BrowserWindow({ width: 1024, height: 700, webPreferences: { - nodeIntegration: true + nodeIntegration: true, }, - icon + icon: iconPath, }) - console.log(icon) + console.log(iconPath) // and load the index.html of the app. mainWindow.loadFile('app/index.html') // Emitted when the window is closed. - mainWindow.on('close', function () { + mainWindow.on('close', () => { connectionManager.closeAllConnections() }) // Emitted when the window is closed. - mainWindow.on('closed', function () { + mainWindow.on('closed', () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. - mainWindow = null + mainWindow = undefined app.quit() }) } @@ -54,8 +58,8 @@ function createWindow () { app.on('ready', () => { createWindow() - let updateInfo - autoUpdater.on('update-available', (info) => { + let updateInfo: UpdateInfo + autoUpdater.on('update-available', (info: UpdateInfo) => { console.log('there is an update') updateInfo = info }) @@ -78,7 +82,7 @@ app.on('ready', () => { }) // Quit when all windows are closed. -app.on('window-all-closed', function () { +app.on('window-all-closed', () => { // On macOS it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { @@ -86,7 +90,7 @@ app.on('window-all-closed', function () { } }) -app.on('activate', function () { +app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (mainWindow === null) { diff --git a/package.json b/package.json index a49b4f0..73c3ad9 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,12 @@ "name": "MQTT-Explorer", "version": "0.0.7", "description": "Explore your message queues", - "main": "electron.js", + "main": "dist/electron.js", "scripts": { "start": "electron .", "install": "cd app; npm install; cd ..", "test": "npm run test-backend", - "build": "cd app; npm run build; cd ..; cd backend; npm run build; cd ..", + "build": "tsc && cd app && npm run build && cd ..", "test-backend": "cd backend && npm run test && cd ..", "prepare-release": "./prepare-release.sh", "package": "ts-node package.ts", diff --git a/tsconfig.json b/tsconfig.json index ef6fd16..a1811f7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,9 +3,10 @@ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true, - "outDir": "./build", + "outDir": "./dist", "strict": true, - "lib": ["es2017"], + "lib": ["es2017", "dom"], "sourceMap": true - } + }, + "include": ["electron.ts"] }