2023-03-15 06:42:14 +03:00
|
|
|
/** @file This script starts the IDE using the Electron executable. */
|
|
|
|
|
|
|
|
import * as childProcess from 'node:child_process'
|
|
|
|
import * as fs from 'node:fs/promises'
|
|
|
|
import * as path from 'node:path'
|
|
|
|
|
|
|
|
import * as esbuild from 'esbuild'
|
|
|
|
|
2023-03-31 17:19:07 +03:00
|
|
|
import * as esbuildConfig from './esbuild-config'
|
|
|
|
import * as paths from './paths'
|
2023-03-15 06:42:14 +03:00
|
|
|
|
|
|
|
const GUI_PATH = path.resolve(paths.getGuiDirectory())
|
|
|
|
const IDE_PATH = paths.getIdeDirectory()
|
|
|
|
const PROJECT_MANAGER_BUNDLE = paths.getProjectManagerBundlePath()
|
|
|
|
|
|
|
|
const SCRIPT_ARGS = process.argv.slice(2)
|
|
|
|
console.log('Script arguments:', ...SCRIPT_ARGS.map(arg => JSON.stringify(arg)))
|
2023-03-03 01:00:47 +03:00
|
|
|
|
|
|
|
console.log('Cleaning IDE dist directory.')
|
2023-03-15 06:42:14 +03:00
|
|
|
await fs.rm(IDE_PATH, { recursive: true, force: true })
|
|
|
|
await fs.mkdir(IDE_PATH, { recursive: true })
|
2023-03-03 01:00:47 +03:00
|
|
|
|
|
|
|
console.log('Bundling client.')
|
2023-03-15 06:42:14 +03:00
|
|
|
const BUNDLER_OPTIONS = esbuildConfig.bundlerOptionsFromEnv()
|
|
|
|
BUNDLER_OPTIONS.outdir = path.resolve(IDE_PATH)
|
|
|
|
await esbuild.build(BUNDLER_OPTIONS)
|
2023-03-03 01:00:47 +03:00
|
|
|
|
|
|
|
console.log('Linking GUI files.')
|
2023-03-15 06:42:14 +03:00
|
|
|
await fs.symlink(path.join(GUI_PATH, 'assets'), path.join(IDE_PATH, 'assets'), 'dir')
|
2023-03-03 01:00:47 +03:00
|
|
|
|
|
|
|
console.log('LinkingProject Manager files.')
|
2023-03-15 06:42:14 +03:00
|
|
|
await fs.symlink(PROJECT_MANAGER_BUNDLE, path.join(IDE_PATH, paths.PROJECT_MANAGER_BUNDLE), 'dir')
|
2023-03-03 01:00:47 +03:00
|
|
|
|
|
|
|
console.log('Spawning Electron process.')
|
2023-03-15 06:42:14 +03:00
|
|
|
const ELECTRON_ARGS = [path.join(IDE_PATH, 'index.cjs'), '--', ...SCRIPT_ARGS]
|
|
|
|
const ELECTRON_PROCESS = childProcess.spawn('electron', ELECTRON_ARGS, {
|
2023-03-03 01:00:47 +03:00
|
|
|
stdio: 'inherit',
|
|
|
|
shell: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Wait till process finished.
|
2023-03-15 06:42:14 +03:00
|
|
|
const CODE = await new Promise<string>((resolve, reject) => {
|
|
|
|
ELECTRON_PROCESS.on('close', resolve)
|
|
|
|
ELECTRON_PROCESS.on('error', reject)
|
2023-03-03 01:00:47 +03:00
|
|
|
})
|
2023-03-15 06:42:14 +03:00
|
|
|
console.log(`Electron process finished. Exit code: ${CODE}.`)
|