2023-03-15 06:42:14 +03:00
|
|
|
/** @file Esbuild config file. */
|
|
|
|
import * as path from 'node:path'
|
|
|
|
|
2023-10-11 13:24:33 +03:00
|
|
|
import type * as esbuild from 'esbuild'
|
2023-08-09 12:30:40 +03:00
|
|
|
import esbuildPluginYaml from 'esbuild-plugin-yaml'
|
2023-03-15 06:42:14 +03:00
|
|
|
|
2024-03-08 06:14:26 +03:00
|
|
|
import * as appConfig from 'enso-common/src/appConfig'
|
2023-03-31 17:19:07 +03:00
|
|
|
import * as paths from './paths'
|
2023-03-03 01:00:47 +03:00
|
|
|
|
2024-03-08 06:14:26 +03:00
|
|
|
// ====================
|
|
|
|
// === Global setup ===
|
|
|
|
// ====================
|
|
|
|
|
|
|
|
await appConfig.readEnvironmentFromFile()
|
|
|
|
|
2023-03-03 01:00:47 +03:00
|
|
|
// ================
|
|
|
|
// === Bundling ===
|
|
|
|
// ================
|
|
|
|
|
2023-05-19 22:55:29 +03:00
|
|
|
/** Get the bundler options using the environment.
|
2023-03-03 01:00:47 +03:00
|
|
|
*
|
|
|
|
* The following environment variables are required:
|
|
|
|
* - `ENSO_BUILD_IDE` - output directory for bundled client files;
|
2023-05-19 22:55:29 +03:00
|
|
|
* - `ENSO_BUILD_PROJECT_MANAGER_IN_BUNDLE_PATH` - path to the project manager executable relative
|
|
|
|
* to the PM bundle root;
|
2023-03-03 01:00:47 +03:00
|
|
|
* @see bundlerOptions
|
2023-03-15 06:42:14 +03:00
|
|
|
*/
|
2024-03-27 17:42:23 +03:00
|
|
|
export function bundlerOptionsFromEnv(devMode = false): esbuild.BuildOptions {
|
2023-03-03 01:00:47 +03:00
|
|
|
return bundlerOptions(
|
2023-03-15 06:42:14 +03:00
|
|
|
path.join(paths.getIdeDirectory(), 'client'),
|
|
|
|
paths.getProjectManagerInBundlePath(),
|
2024-03-27 17:42:23 +03:00
|
|
|
devMode
|
2023-03-03 01:00:47 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-03-15 06:42:14 +03:00
|
|
|
/** Get options without relying on the environment. */
|
2023-03-03 01:00:47 +03:00
|
|
|
export function bundlerOptions(
|
|
|
|
outdir: string,
|
|
|
|
projectManagerInBundlePath: string,
|
2024-03-27 17:42:23 +03:00
|
|
|
devMode = false
|
2023-03-03 01:00:47 +03:00
|
|
|
): esbuild.BuildOptions {
|
|
|
|
return {
|
|
|
|
bundle: true,
|
|
|
|
outdir,
|
|
|
|
entryPoints: ['src/index.ts', 'src/preload.ts'],
|
|
|
|
outbase: 'src',
|
|
|
|
format: 'cjs',
|
|
|
|
platform: 'node',
|
2023-08-09 12:30:40 +03:00
|
|
|
plugins: [esbuildPluginYaml.yamlPlugin({})],
|
2023-06-19 02:02:08 +03:00
|
|
|
// The names come from a third-party API and cannot be changed.
|
|
|
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
|
|
outExtension: { '.js': '.cjs' },
|
2023-03-03 01:00:47 +03:00
|
|
|
define: {
|
|
|
|
PROJECT_MANAGER_IN_BUNDLE_PATH: JSON.stringify(projectManagerInBundlePath),
|
2024-03-27 17:42:23 +03:00
|
|
|
'process.env.ELECTRON_DEV_MODE': JSON.stringify(String(devMode)),
|
|
|
|
'process.env.GUI_CONFIG_PATH': JSON.stringify(
|
|
|
|
path.resolve('../../../gui2/vite.config.ts')
|
|
|
|
),
|
2023-03-03 01:00:47 +03:00
|
|
|
},
|
2023-06-19 02:02:08 +03:00
|
|
|
/* eslint-enable @typescript-eslint/naming-convention */
|
2023-03-03 01:00:47 +03:00
|
|
|
sourcemap: true,
|
2024-03-27 17:42:23 +03:00
|
|
|
external: ['electron', 'vite', 'lightningcss'],
|
2023-03-03 01:00:47 +03:00
|
|
|
}
|
|
|
|
}
|