-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added husky * Fixed csvconf image path * Removed fixtures folder * Added electron * Migrated ts on react-jsx * Setup electron-vite * Maximize electron window * Removed beta * Implemented AppImage build * Updated version * Fixed conflict * Bootstrapped build * Added server build * Added example build * Implemented runner build * Removed desktop build * Improved build * Fixed ignored folders * Rebase on exact deps for js * Rebase on exact deps for py * Add runner build to build command * Found python in dist * Bootstrapped desktop scripts * Stick to opendataeditor * Updated app home dir * Improved desktop * Improved desktop scripts * Simplifed runner structure * Ensured python/libraries * Updted python deps * Improved logging * Bootstrapped start server * Fixed running server * Fixed server * Added project/check endpoint * Fixed server * Fixed tests
- Loading branch information
Showing
24 changed files
with
519 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,3 +156,4 @@ tmp/ | |
.vim | ||
.vercel | ||
client/coverage | ||
.opendataeditor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import fs from 'fs' | ||
import fsp from 'fs/promises' | ||
import * as settings from './settings' | ||
import { join } from 'path' | ||
import log from 'electron-log' | ||
import toml from 'toml' | ||
import * as system from './system' | ||
|
||
export async function ensurePython() { | ||
log.info('[ensurePython]', { path: settings.APP_PYTHON }) | ||
|
||
let message = 'existed' | ||
if (!fs.existsSync(settings.APP_PYTHON)) { | ||
await system.execFile(settings.ORIGINAL_PYTHON, ['-m', 'venv', settings.APP_PYTHON]) | ||
message = 'created' | ||
} | ||
|
||
log.info('[ensurePython]', { message }) | ||
} | ||
|
||
export async function ensureLibraries() { | ||
log.info('[ensureLibraries]') | ||
|
||
const required = await readRequiredLibraries() | ||
const installed = await readInstalledLibraries() | ||
|
||
for (const spec of required) { | ||
if (installed.includes(spec)) continue | ||
await system.execFile(settings.PIP, [ | ||
'install', | ||
spec, | ||
'--upgrade', | ||
'--disable-pip-version-check', | ||
]) | ||
} | ||
|
||
log.info('[ensureLibraries]', { message: 'done' }) | ||
} | ||
|
||
export async function readRequiredLibraries() { | ||
log.info('[readRequiredLibraries]') | ||
|
||
const path = join(settings.DIST, 'pyproject.toml') | ||
const text = await fsp.readFile(path, 'utf-8') | ||
const data = toml.parse(text).project.dependencies | ||
|
||
log.info('[readRequiredLibraries]', { data }) | ||
return data | ||
} | ||
|
||
export async function readInstalledLibraries() { | ||
log.info('[readInstalledLibraries]') | ||
|
||
const text = await system.execFile(settings.PIP, [ | ||
'list', | ||
'--format', | ||
'freeze', | ||
'--disable-pip-version-check', | ||
]) | ||
const data = text.split(/\r?\n/).map((line) => line.trim().toLowerCase()) | ||
|
||
log.info('[readInstalledLibraries]', { data }) | ||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import fs from 'fs' | ||
import fsp from 'fs/promises' | ||
import * as settings from './settings' | ||
import log from 'electron-log' | ||
|
||
export async function ensureExample() { | ||
log.info('[ensureExample]', { path: settings.APP_RUNNER }) | ||
|
||
let message = 'existed' | ||
if (!fs.existsSync(settings.APP_EXAMPLE)) { | ||
await fsp.mkdir(settings.APP_EXAMPLE, { recursive: true }) | ||
await fsp.cp(settings.DIST_EXAMPLE, settings.APP_EXAMPLE, { | ||
recursive: true, | ||
verbatimSymlinks: true, | ||
}) | ||
message = 'created' | ||
} | ||
|
||
log.info('[ensureExample]', { message }) | ||
} | ||
|
||
export async function ensureRunner() { | ||
log.info('[ensureRunner]', { path: settings.APP_RUNNER }) | ||
|
||
let message = 'existed' | ||
if (!fs.existsSync(settings.APP_RUNNER)) { | ||
await fsp.mkdir(settings.APP_RUNNER, { recursive: true }) | ||
await fsp.cp(settings.DIST_RUNNER, settings.APP_RUNNER, { | ||
recursive: true, | ||
verbatimSymlinks: true, | ||
}) | ||
message = 'created' | ||
} | ||
|
||
log.info('[ensureRunner]', { message }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { spawnFile } from './system' | ||
import timersp from 'timers/promises' | ||
import portfinder from 'portfinder' | ||
import * as settings from './settings' | ||
import log from 'electron-log' | ||
|
||
export async function startServer() { | ||
const port = await portfinder.getPortPromise({ port: 4040 }) | ||
const url = `http://localhost:${port}` | ||
log.info('[startServer]', { url }) | ||
|
||
// Start server | ||
const proc = spawnFile( | ||
settings.PYTHON, | ||
['-m', 'server', settings.APP_EXAMPLE, '--port', port.toString()], | ||
process.resourcesPath | ||
) | ||
|
||
// Wait for server | ||
let ready = false | ||
let attempt = 0 | ||
const maxAttempts = 10 | ||
const delaySeconds = 0.5 | ||
const checkUrl = `${url}/project/check` | ||
while (!ready) { | ||
try { | ||
const response = await fetch(checkUrl, { method: 'POST' }) | ||
if (response.status !== 200) throw new Error() | ||
ready = true | ||
} catch { | ||
attempt += 1 | ||
if (attempt >= maxAttempts) throw new Error('Server is not responding') | ||
await timersp.setTimeout(delaySeconds * 1000) | ||
} | ||
} | ||
|
||
return { port, proc } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os from 'os' | ||
import { join } from 'path' | ||
|
||
export const HOME = os.homedir() | ||
|
||
export const DIST = process.resourcesPath | ||
export const DIST_EXAMPLE = join(DIST, 'example') | ||
export const DIST_RUNNER = join(DIST, 'runner') | ||
export const DIST_SERVER = join(DIST, 'server') | ||
|
||
export const APP_NAME = 'opendataeditor' | ||
export const APP_USER_MODEL_ID = 'org.opendataeditor' | ||
export const APP_HOME = join(HOME, `.${APP_NAME}`) | ||
export const APP_RUNNER = join(APP_HOME, 'runner') | ||
export const APP_PYTHON = join(APP_HOME, 'python') | ||
export const APP_EXAMPLE = join(APP_HOME, 'example') | ||
|
||
export const ORIGINAL_PYTHON = join(APP_RUNNER, 'bin', 'python3') | ||
export const PYTHON = join(APP_PYTHON, 'bin', 'python3') | ||
export const PIP = join(APP_PYTHON, 'bin', 'pip3') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import cp from 'child_process' | ||
import util from 'util' | ||
import log from 'electron-log' | ||
const execFilePromise = util.promisify(cp.execFile) | ||
|
||
export async function execFile(path: string, args: string[], cwd?: string) { | ||
log.info('[execFile]', { path, args, cwd }) | ||
const { stdout } = await execFilePromise(path, args, { cwd }) | ||
return stdout | ||
} | ||
|
||
export async function spawnFile(path: string, args: string[], cwd?: string) { | ||
log.info('[spawnFile]', { path, args, cwd }) | ||
const proc = cp.spawn(path, args, { cwd }) | ||
proc.stdout.on('data', (data) => log.info(data.toString().trim())) | ||
proc.stderr.on('data', (data) => log.error(data.toString().trim())) | ||
proc.on('close', (code) => { | ||
log.info('[spawnFile]', { message: `child process exited with code ${code}` }) | ||
}) | ||
process.on('exit', () => { | ||
log.info('[spawnFile]', { message: `exiting child process on node exit` }) | ||
proc.kill() | ||
}) | ||
return proc | ||
} |
Oops, something went wrong.