2024-03-30 12:06:09 +03:00
|
|
|
import fs from 'node:fs/promises';
|
|
|
|
import path from 'node:path';
|
|
|
|
|
2023-05-09 10:30:01 +03:00
|
|
|
import * as esbuild from 'esbuild';
|
|
|
|
|
2024-03-30 12:06:09 +03:00
|
|
|
import { config, mode, rootDir } from './common';
|
2023-05-17 07:36:51 +03:00
|
|
|
|
2023-05-09 10:30:01 +03:00
|
|
|
async function buildLayers() {
|
|
|
|
const common = config();
|
2023-10-17 04:15:19 +03:00
|
|
|
|
2023-10-18 09:13:47 +03:00
|
|
|
const define: Record<string, string> = {
|
2024-03-25 06:55:26 +03:00
|
|
|
...common.define,
|
2023-10-18 09:13:47 +03:00
|
|
|
'process.env.NODE_ENV': `"${mode}"`,
|
2023-10-17 04:15:19 +03:00
|
|
|
'process.env.BUILD_TYPE': `"${process.env.BUILD_TYPE || 'stable'}"`,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (process.env.BUILD_TYPE_OVERRIDE) {
|
2023-11-23 08:18:05 +03:00
|
|
|
define['process.env.BUILD_TYPE_OVERRIDE'] =
|
|
|
|
`"${process.env.BUILD_TYPE_OVERRIDE}"`;
|
2023-10-17 04:15:19 +03:00
|
|
|
}
|
|
|
|
|
2024-03-30 12:06:09 +03:00
|
|
|
const metafile = process.env.METAFILE;
|
|
|
|
|
|
|
|
const result = await esbuild.build({
|
2023-10-18 09:13:47 +03:00
|
|
|
...common,
|
2023-10-17 04:15:19 +03:00
|
|
|
define: define,
|
2024-03-30 12:06:09 +03:00
|
|
|
metafile: !!metafile,
|
2023-05-09 10:30:01 +03:00
|
|
|
});
|
2024-03-30 12:06:09 +03:00
|
|
|
|
|
|
|
if (metafile) {
|
|
|
|
await fs.writeFile(
|
|
|
|
path.resolve(rootDir, `metafile-${Date.now()}.json`),
|
|
|
|
JSON.stringify(result.metafile, null, 2)
|
|
|
|
);
|
|
|
|
}
|
2023-05-09 10:30:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
await buildLayers();
|
2023-10-18 09:13:47 +03:00
|
|
|
console.log('Build layers done');
|