build headless

Summary:
- create a zip-file when building the headless version of Flipper
- restore pkg cache in Sandcastle from pantri
- run build script in sandcastle.

Changes need to go together with D13942919

Reviewed By: passy

Differential Revision: D13942701

fbshipit-source-id: caac7d6cda99fec2a6836c652957ff609a0bf8bb
This commit is contained in:
Daniel Büchele
2019-02-05 11:33:05 -08:00
committed by Facebook Github Bot
parent dc9160d05c
commit e78bd57514
5 changed files with 62 additions and 9 deletions

View File

@@ -101,7 +101,8 @@
"which": "^1.3.1",
"ws": "^6.1.2",
"xml2js": "^0.4.19",
"yargs": "^11.0.0"
"yargs": "^11.0.0",
"yazl": "^2.5.1"
},
"scripts": {
"postinstall": "node scripts/yarn-install.js",

View File

@@ -5,8 +5,10 @@
* @format
*/
const fs = require('fs');
const path = require('path');
const lineReplace = require('line-replace');
const yazl = require('yazl');
const {exec: createBinary} = require('pkg');
const {
buildFolder,
@@ -15,6 +17,8 @@ const {
getVersionNumber,
} = require('./build-utils.js');
const PLUGINS_FOLDER_NAME = 'plugins';
function preludeBundle(dir, versionNumber) {
return new Promise((resolve, reject) =>
lineReplace({
@@ -27,25 +31,53 @@ function preludeBundle(dir, versionNumber) {
);
}
async function createZip(buildDir, distDir, targets) {
return Promise.all(
targets.map(
target =>
new Promise((resolve, reject) => {
const zip = new yazl.ZipFile();
const binary = `flipper-${target === 'mac' ? 'macos' : target}`;
zip.addFile(path.join(buildDir, binary), binary);
const pluginDir = path.join(buildDir, PLUGINS_FOLDER_NAME);
fs.readdirSync(pluginDir).forEach(file => {
zip.addFile(
path.join(pluginDir, file),
path.join(PLUGINS_FOLDER_NAME, file),
);
});
zip.outputStream
.pipe(
fs.createWriteStream(
path.join(distDir, `Flipper-headless-${target}.zip`),
),
)
.on('close', resolve);
zip.end();
}),
),
);
}
(async () => {
const targets = [];
const targets = {};
let platformPostfix;
if (process.argv.indexOf('--mac') > -1) {
targets.push('node10-macos-x64');
targets.mac = 'node10-macos-x64';
platformPostfix = '-macos';
}
if (process.argv.indexOf('--linux') > -1) {
targets.push('node10-linux-x64');
targets.linux = 'node10-linux-x64';
platformPostfix = '-linux';
}
if (process.argv.indexOf('--win') > -1) {
targets.push('node10-win-x64');
targets.win = 'node10-win-x64';
platformPostfix = '-win';
}
if (targets.length === 0) {
throw new Error('No targets specified. eg. --mac, --win, or --linux');
} else if (targets.length > 1) {
} else if (Object.keys(targets).length > 1) {
// platformPostfix is automatically added by pkg
platformPostfix = '';
}
@@ -58,14 +90,16 @@ function preludeBundle(dir, versionNumber) {
await compile(buildDir, path.join(__dirname, '..', 'headless', 'index.js'));
const versionNumber = getVersionNumber();
await preludeBundle(buildDir, versionNumber);
await compileDefaultPlugins(path.join(distDir, 'plugins'));
await compileDefaultPlugins(path.join(buildDir, PLUGINS_FOLDER_NAME));
await createBinary([
path.join(buildDir, 'bundle.js'),
'--output',
path.join(distDir, `flipper${platformPostfix}`),
path.join(buildDir, `flipper${platformPostfix}`),
'--targets',
targets.join(','),
Object.values(targets).join(','),
'--debug',
]);
await createZip(buildDir, distDir, Object.keys(targets));
// eslint-disable-next-line no-console
console.log('✨ Done');
process.exit();

View File

@@ -60,6 +60,9 @@ function compile(buildFolder, entry) {
'index.js',
),
},
resolver: {
blacklistRE: /\/sonar\/dist\//,
},
},
{
dev: false,

View File

@@ -206,6 +206,9 @@ async function compilePlugin(
'index.js',
),
},
resolver: {
blacklistRE: /\/sonar\/dist\//,
},
},
{
entry: entry.replace(rootDir, '.'),

View File

@@ -1455,6 +1455,11 @@ bser@^2.0.0:
dependencies:
node-int64 "^0.4.0"
buffer-crc32@~0.2.3:
version "0.2.13"
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
integrity sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=
buffer-from@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.0.tgz#87fcaa3a298358e0ade6e442cfce840740d1ad04"
@@ -7409,6 +7414,13 @@ yauzl@2.4.1:
dependencies:
fd-slicer "~1.0.1"
yazl@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/yazl/-/yazl-2.5.1.tgz#a3d65d3dd659a5b0937850e8609f22fffa2b5c35"
integrity sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw==
dependencies:
buffer-crc32 "~0.2.3"
yeast@0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419"