Skip to content

Commit

Permalink
fix loading package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dworthen committed Apr 8, 2024
1 parent 4f37427 commit cfee8ff
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
4 changes: 0 additions & 4 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ extraResources:
to: 'migrations'
filter:
- '**/*'
- from: '.'
to: '.'
filter:
- 'package.json'
win:
executableName: Gov4Git
nsis:
Expand Down
15 changes: 2 additions & 13 deletions src/electron/configs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'

import * as pkgJson from '../../package.json'
import { toResolvedPath } from './lib/paths.js'

export const CONFIG_PATH = toResolvedPath(
Expand All @@ -15,15 +15,4 @@ export const COMMUNITY_REPO_NAME =

export const GITHUB_OAUTH_CLIENT_ID = '912c0ab18e0f0b4a1abe'

export let CLI_VERSION = ''

export function setCliVersion(isPackaged: boolean) {
const packageJsonPath = resolve(
isPackaged ? process.resourcesPath : process.cwd(),
'package.json',
)

const pkgJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))

CLI_VERSION = pkgJson['dependencies']['@gov4git/js-client']
}
export const CLI_VERSION = pkgJson['dependencies']['@gov4git/js-client']
9 changes: 1 addition & 8 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
CONFIG_PATH,
DB_PATH,
GITHUB_OAUTH_CLIENT_ID,
setCliVersion,
} from './configs.js'
import { DB, loadDb } from './db/db.js'
import { migrateDb } from './db/migrate.js'
Expand All @@ -41,15 +40,9 @@ const logService = new LogService(resolve(CONFIG_PATH, 'logs.txt'))
services.register('log', logService)

logService.info(`Gov4Git Version ${logService.getAppVersion()}`)
logService.info(`CLI_VERSION of protocol: ${CLI_VERSION}`)

async function setup(): Promise<void> {
try {
logService.info(`Setting CLI Version for protocol`)
setCliVersion(app.isPackaged)
logService.info(`CLI_VERSION of protocol: ${CLI_VERSION}`)
} catch (ex) {
logService.error(`Failed to set CLI_VERSION`)
}
try {
logService.info(`Initializing DB: ${DB_PATH}`)
const db = loadDb(DB_PATH)
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true
}
}
}

0 comments on commit cfee8ff

Please sign in to comment.