diff --git a/package.json b/package.json index 31c4f0ccb..981d80f1c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/build-headless.js b/scripts/build-headless.js index 42b8789ac..416fe744d 100644 --- a/scripts/build-headless.js +++ b/scripts/build-headless.js @@ -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(); diff --git a/scripts/build-utils.js b/scripts/build-utils.js index dae354468..e9150c0b0 100644 --- a/scripts/build-utils.js +++ b/scripts/build-utils.js @@ -60,6 +60,9 @@ function compile(buildFolder, entry) { 'index.js', ), }, + resolver: { + blacklistRE: /\/sonar\/dist\//, + }, }, { dev: false, diff --git a/static/compilePlugins.js b/static/compilePlugins.js index 39fb15208..d57f37cf6 100644 --- a/static/compilePlugins.js +++ b/static/compilePlugins.js @@ -206,6 +206,9 @@ async function compilePlugin( 'index.js', ), }, + resolver: { + blacklistRE: /\/sonar\/dist\//, + }, }, { entry: entry.replace(rootDir, '.'), diff --git a/yarn.lock b/yarn.lock index d0bb2f262..ba42ba330 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"