Script for platform-specific flipper-server bundles
Summary: To roll out Flipper Server for desktop, we need a bundle that comes with all node dependencies pre-installed and a bundled Node runtime. This creates some platform-specific sub-folders in `dist/` with both. The `--mac`, `--linux`, `--win` options are chosen to be compatible with the main build script. For now, we only build x64 builds for Mac which is also in line with the Desktop build as we don't have signing for the whole bundle. Reviewed By: lblasa Differential Revision: D35545492 fbshipit-source-id: cce7165916d91a333f305713b9d6d7b9984984f4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f1fe66afd9
commit
92f88e877b
@@ -24,6 +24,16 @@ import fs from 'fs-extra';
|
||||
import {downloadIcons} from './build-icons';
|
||||
import {spawn} from 'promisify-child-process';
|
||||
import {homedir} from 'os';
|
||||
import {need} from 'pkg-fetch';
|
||||
|
||||
// This needs to be tested individually. As of 2022Q2, node17 is not supported.
|
||||
const SUPPORTED_NODE_PLATFORM = 'node16';
|
||||
|
||||
enum BuildPlatform {
|
||||
LINUX = 'linux',
|
||||
WINDOWS = 'windows',
|
||||
MAC_X64 = 'mac-x64',
|
||||
}
|
||||
|
||||
const argv = yargs
|
||||
.usage('yarn build-flipper-server [args]')
|
||||
@@ -92,6 +102,21 @@ const argv = yargs
|
||||
'Unique build identifier to be used as the version patch part for the build',
|
||||
type: 'number',
|
||||
},
|
||||
mac: {
|
||||
describe: 'Build a platform-specific bundle for MacOS.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
win: {
|
||||
describe: 'Build a platform-specific bundle for Windows.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
linux: {
|
||||
describe: 'Build a platform-specific bundle for Linux.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
.help()
|
||||
.parse(process.argv.slice(1));
|
||||
@@ -271,9 +296,7 @@ async function runPostBuildAction(archive: string, dir: string) {
|
||||
});
|
||||
} else if (argv.start) {
|
||||
console.log(`⚙️ Starting flipper-server from build dir`);
|
||||
await spawn('yarn', ['install', '--production', '--no-lockfile'], {
|
||||
cwd: dir,
|
||||
});
|
||||
await yarnInstall(dir);
|
||||
await spawn('./server.js', [argv.open ? '--open' : '--no-open'], {
|
||||
cwd: dir,
|
||||
stdio: 'inherit',
|
||||
@@ -281,6 +304,13 @@ async function runPostBuildAction(archive: string, dir: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function yarnInstall(dir: string) {
|
||||
console.log(`⚙️ Running yarn install in ${dir}`);
|
||||
await spawn('yarn', ['install', '--production', '--no-lockfile'], {
|
||||
cwd: dir,
|
||||
});
|
||||
}
|
||||
|
||||
async function buildServerRelease() {
|
||||
console.log(`⚙️ Starting build-flipper-server-release`);
|
||||
console.dir(argv);
|
||||
@@ -309,6 +339,65 @@ async function buildServerRelease() {
|
||||
const archive = await packNpmArchive(dir, versionNumber);
|
||||
|
||||
await runPostBuildAction(archive, dir);
|
||||
|
||||
const platforms: BuildPlatform[] = [];
|
||||
if (argv.linux) {
|
||||
platforms.push(BuildPlatform.LINUX);
|
||||
}
|
||||
// TODO: In the future, also cover aarch64 here.
|
||||
if (argv.mac) {
|
||||
platforms.push(BuildPlatform.MAC_X64);
|
||||
}
|
||||
if (argv.win) {
|
||||
platforms.push(BuildPlatform.WINDOWS);
|
||||
}
|
||||
|
||||
if (platforms.length > 0) {
|
||||
await yarnInstall(dir);
|
||||
}
|
||||
platforms.forEach(bundleServerReleaseForPlatform.bind(null, dir));
|
||||
}
|
||||
|
||||
function nodeArchFromBuildPlatform(_platform: BuildPlatform): string {
|
||||
// TODO: Change this as we support aarch64.
|
||||
return 'x64';
|
||||
}
|
||||
|
||||
function nodePlatformFromBuildPlatform(platform: BuildPlatform): string {
|
||||
switch (platform) {
|
||||
case BuildPlatform.LINUX:
|
||||
return 'linux';
|
||||
case BuildPlatform.MAC_X64:
|
||||
return 'macos';
|
||||
case BuildPlatform.WINDOWS:
|
||||
return 'win32';
|
||||
default:
|
||||
throw new Error(`Unsupported platform: ${platform}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function bundleServerReleaseForPlatform(
|
||||
dir: string,
|
||||
platform: BuildPlatform,
|
||||
) {
|
||||
console.log(`⚙️ Building platform-specific bundle for ${platform}`);
|
||||
const outputDir = path.join(
|
||||
distDir,
|
||||
`flipper-server-${platform.toString().toLocaleLowerCase()}`,
|
||||
);
|
||||
await fs.mkdirp(outputDir);
|
||||
|
||||
console.log(`⚙️ Copying from ${dir} to ${outputDir}`);
|
||||
await fs.copy(dir, outputDir);
|
||||
|
||||
console.log(`⚙️ Downloading compatible node version`);
|
||||
await need({
|
||||
arch: nodeArchFromBuildPlatform(platform),
|
||||
platform: nodePlatformFromBuildPlatform(platform),
|
||||
output: path.join(outputDir, 'node'),
|
||||
nodeRange: SUPPORTED_NODE_PLATFORM,
|
||||
});
|
||||
console.log(`✅ Wrote ${platform}-specific server version to ${outputDir}`);
|
||||
}
|
||||
|
||||
buildServerRelease().catch((e) => {
|
||||
|
||||
Reference in New Issue
Block a user