2023-03-15 06:42:14 +03:00
|
|
|
/** @file Esbuild config file. */
|
|
|
|
import * as path from 'node:path'
|
|
|
|
|
|
|
|
import * as esbuild from 'esbuild'
|
|
|
|
|
2023-03-31 17:19:07 +03:00
|
|
|
import * as paths from './paths'
|
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;
|
|
|
|
* - `ENSO_BUILD_IDE_BUNDLED_ENGINE_VERSION` - version of the Engine (backend) that is bundled
|
|
|
|
* along with this client build.
|
2023-03-03 01:00:47 +03:00
|
|
|
*
|
|
|
|
* @see bundlerOptions
|
2023-03-15 06:42:14 +03:00
|
|
|
*/
|
2023-03-03 01:00:47 +03:00
|
|
|
export function bundlerOptionsFromEnv(): esbuild.BuildOptions {
|
|
|
|
return bundlerOptions(
|
2023-03-15 06:42:14 +03:00
|
|
|
path.join(paths.getIdeDirectory(), 'client'),
|
|
|
|
paths.getProjectManagerInBundlePath(),
|
|
|
|
paths.getBundledEngineVersion()
|
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,
|
|
|
|
bundledEngineVersion: string
|
|
|
|
): esbuild.BuildOptions {
|
|
|
|
return {
|
|
|
|
bundle: true,
|
|
|
|
outdir,
|
|
|
|
entryPoints: ['src/index.ts', 'src/preload.ts'],
|
|
|
|
outbase: 'src',
|
|
|
|
format: 'cjs',
|
|
|
|
platform: 'node',
|
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: {
|
|
|
|
BUNDLED_ENGINE_VERSION: JSON.stringify(bundledEngineVersion),
|
|
|
|
PROJECT_MANAGER_IN_BUNDLE_PATH: JSON.stringify(projectManagerInBundlePath),
|
|
|
|
},
|
2023-06-19 02:02:08 +03:00
|
|
|
/* eslint-enable @typescript-eslint/naming-convention */
|
2023-03-03 01:00:47 +03:00
|
|
|
sourcemap: true,
|
|
|
|
external: ['electron'],
|
|
|
|
}
|
|
|
|
}
|