diff --git a/desktop/scripts/build-flipper-server-release.tsx b/desktop/scripts/build-flipper-server-release.tsx index f775941a2..e6b48bf1c 100644 --- a/desktop/scripts/build-flipper-server-release.tsx +++ b/desktop/scripts/build-flipper-server-release.tsx @@ -24,7 +24,7 @@ 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'; +import {need as pkgFetch} from 'pkg-fetch'; // This needs to be tested individually. As of 2022Q2, node17 is not supported. const SUPPORTED_NODE_PLATFORM = 'node16'; @@ -114,8 +114,6 @@ const argv = yargs }, linux: { describe: 'Build a platform-specific bundle for Linux.', - type: 'boolean', - default: false, }, }) .help() @@ -337,7 +335,6 @@ async function buildServerRelease() { await buildBrowserBundle(path.join(dir, 'static'), false); await modifyPackageManifest(dir, versionNumber, hgRevision, argv.channel); const archive = await packNpmArchive(dir, versionNumber); - await runPostBuildAction(archive, dir); const platforms: BuildPlatform[] = []; @@ -355,7 +352,9 @@ async function buildServerRelease() { if (platforms.length > 0) { await yarnInstall(dir); } - platforms.forEach(bundleServerReleaseForPlatform.bind(null, dir)); + platforms.forEach( + bundleServerReleaseForPlatform.bind(null, dir, versionNumber), + ); } function nodeArchFromBuildPlatform(_platform: BuildPlatform): string { @@ -376,8 +375,58 @@ function nodePlatformFromBuildPlatform(platform: BuildPlatform): string { } } +async function installNodeBinary(outputPath: string, platform: BuildPlatform) { + const nodePath = await buildFolder('flipper-node-download-'); + const path = await pkgFetch({ + arch: nodeArchFromBuildPlatform(platform), + platform: nodePlatformFromBuildPlatform(platform), + output: nodePath, + nodeRange: SUPPORTED_NODE_PLATFORM, + }); + await fs.rename(path, outputPath); +} + +async function setUpMacBundle( + outputDir: string, + versionNumber: string, +): Promise<{nodePath: string; resourcesPath: string}> { + console.log(`⚙️ Creating Mac bundle in ${outputDir}`); + await fs.copy(path.join(staticDir, 'flipper-server-app-template'), outputDir); + + console.log(`⚙️ Writing plist`); + const pListPath = path.join( + outputDir, + 'Flipper.app', + 'Contents', + 'Info.plist', + ); + const pListContents = await fs.readFile(pListPath, 'utf-8'); + const updatedPlistContents = pListContents.replace( + '{flipper-server-version}', + versionNumber, + ); + await fs.writeFile(pListPath, updatedPlistContents, 'utf-8'); + + const resourcesOutputDir = path.join( + outputDir, + 'Flipper.app', + 'Contents', + 'Resources', + 'server', + ); + const nodeOutputPath = path.join( + outputDir, + 'Flipper.app', + 'Contents', + 'MacOS', + 'node', + ); + return {resourcesPath: resourcesOutputDir, nodePath: nodeOutputPath}; +} + async function bundleServerReleaseForPlatform( dir: string, + versionNumber: string, platform: BuildPlatform, ) { console.log(`⚙️ Building platform-specific bundle for ${platform}`); @@ -387,16 +436,23 @@ async function bundleServerReleaseForPlatform( ); await fs.mkdirp(outputDir); - console.log(`⚙️ Copying from ${dir} to ${outputDir}`); - await fs.copy(dir, outputDir); + let outputPaths = { + nodePath: path.join(outputDir, 'node'), + resourcesPath: outputDir, + }; + + // On the mac, we need to set up a resource bundle which expects paths + // to be in different places from Linux/Windows bundles. + if (platform === BuildPlatform.MAC_X64) { + outputPaths = await setUpMacBundle(outputDir, versionNumber); + } + + console.log(`⚙️ Copying from ${dir} to ${outputPaths.resourcesPath}`); + await fs.copy(dir, outputPaths.resourcesPath); console.log(`⚙️ Downloading compatible node version`); - await need({ - arch: nodeArchFromBuildPlatform(platform), - platform: nodePlatformFromBuildPlatform(platform), - output: path.join(outputDir, 'node'), - nodeRange: SUPPORTED_NODE_PLATFORM, - }); + await installNodeBinary(outputPaths.nodePath, platform); + console.log(`✅ Wrote ${platform}-specific server version to ${outputDir}`); } diff --git a/desktop/scripts/build-utils.tsx b/desktop/scripts/build-utils.tsx index ec08c1e32..db38e7a03 100644 --- a/desktop/scripts/build-utils.tsx +++ b/desktop/scripts/build-utils.tsx @@ -368,11 +368,13 @@ export async function compileMain() { die(err); } } -export function buildFolder(): Promise { +export function buildFolder( + prefix: string = 'flipper-build-', +): Promise { // eslint-disable-next-line no-console console.log('Creating build directory'); return new Promise((resolve, reject) => { - tmp.dir({prefix: 'flipper-build-'}, (err, buildFolder) => { + tmp.dir({prefix}, (err, buildFolder) => { if (err) { reject(err); } else { diff --git a/desktop/static/flipper-server-app-template/Flipper.app/Contents/Info.plist b/desktop/static/flipper-server-app-template/Flipper.app/Contents/Info.plist new file mode 100644 index 000000000..e505a7e2d --- /dev/null +++ b/desktop/static/flipper-server-app-template/Flipper.app/Contents/Info.plist @@ -0,0 +1,44 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + Flipper + CFBundleIconFile + app.icns + CFBundleIdentifier + com.facebook.flipper.server + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Flipper Server + CFBundlePackageType + APPL + CFBundleShortVersionString + {flipper-server-version} + CFBundleSignature + ???? + CFBundleVersion + {flipper-server-version} + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTSDKBuild + 12.0 + DTSDKName + macosx12.0 + DTXcode + 1310 + DTXcodeBuild + 13A1030d + LSHasLocalizedDisplayName + + LSMinimumSystemVersion + 10.11.0 + NSAppleScriptEnabled + + NSHighResolutionCapable + + + diff --git a/desktop/static/flipper-server-app-template/Flipper.app/Contents/MacOS/Flipper b/desktop/static/flipper-server-app-template/Flipper.app/Contents/MacOS/Flipper new file mode 100755 index 000000000..10d1b05a4 --- /dev/null +++ b/desktop/static/flipper-server-app-template/Flipper.app/Contents/MacOS/Flipper @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +NODE_PATH="${SCRIPT_PATH}/node" +SERVER_RESOURCES="$SCRIPT_PATH/../Resources/server" + +cd "$SERVER_RESOURCES" || exit 1 +"$NODE_PATH" . diff --git a/desktop/static/flipper-server-app-template/Flipper.app/Contents/PkgInfo b/desktop/static/flipper-server-app-template/Flipper.app/Contents/PkgInfo new file mode 100644 index 000000000..bd04210fb --- /dev/null +++ b/desktop/static/flipper-server-app-template/Flipper.app/Contents/PkgInfo @@ -0,0 +1 @@ +APPL???? \ No newline at end of file diff --git a/desktop/static/flipper-server-app-template/Flipper.app/Contents/Resources/app.icns b/desktop/static/flipper-server-app-template/Flipper.app/Contents/Resources/app.icns new file mode 100644 index 000000000..e5ee71025 Binary files /dev/null and b/desktop/static/flipper-server-app-template/Flipper.app/Contents/Resources/app.icns differ diff --git a/desktop/static/flipper-server-app-template/Flipper.app/Contents/Resources/en-GB.lproj/InfoPlist.strings b/desktop/static/flipper-server-app-template/Flipper.app/Contents/Resources/en-GB.lproj/InfoPlist.strings new file mode 100644 index 000000000..f5dab86fa --- /dev/null +++ b/desktop/static/flipper-server-app-template/Flipper.app/Contents/Resources/en-GB.lproj/InfoPlist.strings @@ -0,0 +1,10 @@ + + + + + CFBundleDisplayName + Flipper Server + CFBundleName + Flipper Server + + diff --git a/desktop/static/flipper-server-app-template/Flipper.app/Contents/Resources/server/.keep b/desktop/static/flipper-server-app-template/Flipper.app/Contents/Resources/server/.keep new file mode 100644 index 000000000..e69de29bb