|
| 1 | +import { join } from 'node:path'; |
| 2 | +import { BIN_DIST_FOLDER_PATH } from '@shared/naming/project-fs-paths'; |
| 3 | +import { getPlatform } from '@shared/utils/bin-executable'; |
| 4 | +import { logInfo, logSuccess } from '@shared/utils/logging'; |
| 5 | +import { archiveItem } from '@shared/utils/zip'; |
| 6 | +import { remove } from 'fs-extra'; |
| 7 | +import yargsParser from 'yargs-parser'; |
| 8 | +import { generateStarterProjectsMetadata } from './generate-starter-projects-metadata'; |
| 9 | +import { packageHelperLambdas } from './package-helper-lambdas'; |
| 10 | +import { getCliArgs } from './release/args'; |
| 11 | +import { |
| 12 | + buildBinaryFile, |
| 13 | + buildEsbuildRegister, |
| 14 | + copyConfigSchema, |
| 15 | + copyEsbuildBinary, |
| 16 | + copyNixpacksBinary, |
| 17 | + copyPackBinary, |
| 18 | + copySessionsManagerPluginBinary, |
| 19 | + createReleaseDataFile, |
| 20 | + EXECUTABLE_FILE_PATTERNS, |
| 21 | + generateSourceMapInstall |
| 22 | +} from './release/build-cli-sources'; |
| 23 | + |
| 24 | +const { debug, keepUnarchived } = getCliArgs(); |
| 25 | + |
| 26 | +const buildEverything = async () => { |
| 27 | + const argv = yargsParser(process.argv.slice(2)); |
| 28 | + const platform = (argv.platform as SupportedPlatform) || getPlatform(); |
| 29 | + const version = (argv.version as string) || 'dev'; |
| 30 | + |
| 31 | + if (!platform || !version) { |
| 32 | + throw new Error('Platform and version are required. Usage: --platform <platform> --version <version>'); |
| 33 | + } |
| 34 | + |
| 35 | + logInfo(`Building binary for platform: ${platform}, version: ${version}`); |
| 36 | + |
| 37 | + const distFolderPath = BIN_DIST_FOLDER_PATH; |
| 38 | + await remove(distFolderPath); |
| 39 | + |
| 40 | + const platformDistFolderPath = await buildBinaryFile({ |
| 41 | + distFolderPath, |
| 42 | + platform, |
| 43 | + debug, |
| 44 | + version |
| 45 | + }); |
| 46 | + |
| 47 | + await Promise.all([ |
| 48 | + copyPackBinary({ distFolderPath, platform }), |
| 49 | + copyNixpacksBinary({ distFolderPath, platform }), |
| 50 | + copySessionsManagerPluginBinary({ distFolderPath, platform }), |
| 51 | + copyEsbuildBinary({ distFolderPath, platform }), |
| 52 | + buildEsbuildRegister({ distFolderPath: platformDistFolderPath }), |
| 53 | + copyConfigSchema({ distFolderPath: platformDistFolderPath }), |
| 54 | + generateStarterProjectsMetadata({ distFolderPath: platformDistFolderPath }), |
| 55 | + packageHelperLambdas({ isDev: false, distFolderPath: platformDistFolderPath }), |
| 56 | + createReleaseDataFile({ distFolderPath: platformDistFolderPath, version }), |
| 57 | + generateSourceMapInstall({ distFolderPath: platformDistFolderPath }) |
| 58 | + ]); |
| 59 | + // await copyLegalComments({ distFolderPath: platformDistFolderPath }); |
| 60 | + |
| 61 | + // Archive the binary |
| 62 | + const archivePath = await archiveItem({ |
| 63 | + absoluteSourcePath: platformDistFolderPath, |
| 64 | + format: platform === 'win' ? 'zip' : 'tgz', |
| 65 | + executablePatterns: EXECUTABLE_FILE_PATTERNS |
| 66 | + }); |
| 67 | + |
| 68 | + if (!keepUnarchived) { |
| 69 | + logInfo('Cleaning up temporary files...'); |
| 70 | + await Promise.all([remove(platformDistFolderPath), remove(join(platformDistFolderPath, 'downloaded'))]); |
| 71 | + logSuccess('Temporary files cleaned up successfully.'); |
| 72 | + } |
| 73 | + |
| 74 | + logSuccess(`Binary for platform ${platform} built successfully: ${archivePath}`); |
| 75 | +}; |
| 76 | + |
| 77 | +if (import.meta.main) { |
| 78 | + buildEverything().catch((error) => { |
| 79 | + console.error('Error building platform binary:', error); |
| 80 | + process.exit(1); |
| 81 | + }); |
| 82 | +} |
0 commit comments