Skip to content

Commit

Permalink
Feat: Converted the main EP to typescript.
Browse files Browse the repository at this point in the history
Extended the base tsconfig to cover the new main.ts entry point.

Added a new build:desktop script to build the main.ts entry point to JS.

Added the aforementioned script to the dev and build scripts so the file is rebuilt before the app is launched.
  • Loading branch information
Ozzie Bock authored and itsMapleLeaf committed Mar 6, 2022
1 parent 12c3b22 commit 973bc96
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -5,3 +5,5 @@ build
dist
.env
.vscode

.idea
28 changes: 0 additions & 28 deletions template/desktop/main.js

This file was deleted.

29 changes: 29 additions & 0 deletions template/desktop/main.ts
@@ -0,0 +1,29 @@
import { initRemix } from "remix-electron";
import { app, BrowserWindow, dialog } from "electron";
import { join } from "node:path";

/** @type {BrowserWindow | undefined} */
let win

/** @param {string} url */
async function createWindow(url: string) {
win = new BrowserWindow({ show: false })
await win.loadURL(url)
win.show()
}

app.on("ready", async () => {
try {
const url = await initRemix({ serverBuild: join(__dirname, "build") })
await createWindow(url)
} catch (error) {
dialog.showErrorBox("Error", getErrorStack(error))
console.error(error)
}
})

/** @param {unknown} error */
function getErrorStack(error: any) {
return error instanceof Error ? error.stack || error.message : String(error)
}

7 changes: 4 additions & 3 deletions template/package.json
Expand Up @@ -6,11 +6,12 @@
"main": "desktop/main.js",
"scripts": {
"prepare": "remix setup node",
"clean": "del-cli dist desktop/build public/build .cache",
"dev": "npm run clean && cross-env NODE_ENV=development npm-run-all --parallel --print-label --race dev:*",
"clean": "del-cli dist desktop/build public/build .cache desktop/main.js",
"dev": "npm run clean && npm run build:desktop && cross-env NODE_ENV=development npm-run-all --parallel --print-label --race dev:*",
"dev:remix": "remix watch",
"dev:nodemon": "wait-on file:desktop/main.js && nodemon .",
"build": "npm run clean && remix build && electron-builder",
"build": "npm run clean && npm run build:desktop && remix build && electron-builder",
"build:desktop": "yarn tsc -p tsconfig.electron-build.json",
"start": "cross-env NODE_ENV=production electron ."
},
"build": {
Expand Down
21 changes: 21 additions & 0 deletions template/tsconfig.electron-build.json
@@ -0,0 +1,21 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES5"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"resolveJsonModule": true,
"target": "ES3",
"strict": true,
"noEmit": false,
"allowJs": true,
"checkJs": true,
"skipLibCheck": true
},
"include": [
"desktop/main.ts"
],
"exclude": ["desktop/build", "public/build", ".cache"]
}

0 comments on commit 973bc96

Please sign in to comment.