split build process
Summary: Moving a couple of build function from `build-release` to `build-utils` so they can be shared between the desktop build process and the headless build process. Reviewed By: passy Differential Revision: D13786575 fbshipit-source-id: df0a0da6d9a643e3e1c65470e1e96254e8966dd9
This commit is contained in:
committed by
Facebook Github Bot
parent
e02d823e5f
commit
78cd40e890
@@ -5,12 +5,15 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const tmp = require('tmp');
|
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const builder = require('electron-builder');
|
const builder = require('electron-builder');
|
||||||
const Platform = builder.Platform;
|
const Platform = builder.Platform;
|
||||||
const Metro = require('../static/node_modules/metro');
|
const {
|
||||||
const compilePlugins = require('../static/compilePlugins');
|
buildFolder,
|
||||||
|
compile,
|
||||||
|
die,
|
||||||
|
compileDefaultPlugins,
|
||||||
|
} = require('./build-utils.js');
|
||||||
|
|
||||||
function generateManifest(versionNumber) {
|
function generateManifest(versionNumber) {
|
||||||
const filePath = path.join(__dirname, '..', 'dist');
|
const filePath = path.join(__dirname, '..', 'dist');
|
||||||
@@ -26,20 +29,6 @@ function generateManifest(versionNumber) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildFolder() {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('Creating build directory');
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
tmp.dir((err, buildFolder) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(buildFolder);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).catch(die);
|
|
||||||
}
|
|
||||||
|
|
||||||
function modifyPackageManifest(buildFolder) {
|
function modifyPackageManifest(buildFolder) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('Creating package.json manifest');
|
console.log('Creating package.json manifest');
|
||||||
@@ -122,45 +111,6 @@ function buildDist(buildFolder) {
|
|||||||
.catch(die);
|
.catch(die);
|
||||||
}
|
}
|
||||||
|
|
||||||
function die(err) {
|
|
||||||
console.error(err.stack);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function compile(buildFolder) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(
|
|
||||||
'Building main bundle',
|
|
||||||
path.join(__dirname, '..', 'src', 'init.js'),
|
|
||||||
);
|
|
||||||
const projectRoots = path.join(__dirname, '..');
|
|
||||||
return Metro.runBuild(
|
|
||||||
{
|
|
||||||
reporter: {update: () => {}},
|
|
||||||
projectRoot: projectRoots,
|
|
||||||
watchFolders: [projectRoots],
|
|
||||||
serializer: {},
|
|
||||||
transformer: {
|
|
||||||
babelTransformerPath: path.join(
|
|
||||||
__dirname,
|
|
||||||
'..',
|
|
||||||
'static',
|
|
||||||
'transforms',
|
|
||||||
'index.js',
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dev: false,
|
|
||||||
minify: false,
|
|
||||||
resetCache: true,
|
|
||||||
sourceMap: true,
|
|
||||||
entry: path.join(__dirname, '..', 'src', 'init.js'),
|
|
||||||
out: path.join(buildFolder, 'bundle.js'),
|
|
||||||
},
|
|
||||||
).catch(die);
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyStaticFolder(buildFolder) {
|
function copyStaticFolder(buildFolder) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.copy(
|
fs.copy(
|
||||||
@@ -180,39 +130,13 @@ function copyStaticFolder(buildFolder) {
|
|||||||
}).catch(die);
|
}).catch(die);
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileDefaultPlugins(buildFolder) {
|
|
||||||
const defaultPluginFolder = 'defaultPlugins';
|
|
||||||
const defaultPluginDir = path.join(buildFolder, defaultPluginFolder);
|
|
||||||
return compilePlugins(
|
|
||||||
null,
|
|
||||||
[
|
|
||||||
path.join(__dirname, '..', 'src', 'plugins'),
|
|
||||||
path.join(__dirname, '..', 'src', 'fb', 'plugins'),
|
|
||||||
],
|
|
||||||
defaultPluginDir,
|
|
||||||
{force: true, failSilently: false},
|
|
||||||
)
|
|
||||||
.then(defaultPlugins =>
|
|
||||||
fs.writeFileSync(
|
|
||||||
path.join(defaultPluginDir, 'index.json'),
|
|
||||||
JSON.stringify(
|
|
||||||
defaultPlugins.map(plugin => ({
|
|
||||||
...plugin,
|
|
||||||
out: path.join(defaultPluginFolder, path.parse(plugin.out).base),
|
|
||||||
})),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.catch(die);
|
|
||||||
}
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const dir = await buildFolder();
|
const dir = await buildFolder();
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('Created build directory', dir);
|
console.log('Created build directory', dir);
|
||||||
await copyStaticFolder(dir);
|
await copyStaticFolder(dir);
|
||||||
await compileDefaultPlugins(dir);
|
await compileDefaultPlugins(dir);
|
||||||
await compile(dir);
|
await compile(dir, path.join(__dirname, '..', 'src', 'init.js'));
|
||||||
const versionNumber = await modifyPackageManifest(dir);
|
const versionNumber = await modifyPackageManifest(dir);
|
||||||
generateManifest(versionNumber);
|
generateManifest(versionNumber);
|
||||||
await buildDist(dir);
|
await buildDist(dir);
|
||||||
|
|||||||
96
scripts/build-utils.js
Normal file
96
scripts/build-utils.js
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2018-present Facebook.
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Metro = require('../static/node_modules/metro');
|
||||||
|
const compilePlugins = require('../static/compilePlugins');
|
||||||
|
const tmp = require('tmp');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
|
function die(err) {
|
||||||
|
console.error(err.stack);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function compileDefaultPlugins(buildFolder) {
|
||||||
|
const defaultPluginFolder = 'defaultPlugins';
|
||||||
|
const defaultPluginDir = path.join(buildFolder, defaultPluginFolder);
|
||||||
|
return compilePlugins(
|
||||||
|
null,
|
||||||
|
[
|
||||||
|
path.join(__dirname, '..', 'src', 'plugins'),
|
||||||
|
path.join(__dirname, '..', 'src', 'fb', 'plugins'),
|
||||||
|
],
|
||||||
|
defaultPluginDir,
|
||||||
|
{force: true, failSilently: false},
|
||||||
|
)
|
||||||
|
.then(defaultPlugins =>
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(defaultPluginDir, 'index.json'),
|
||||||
|
JSON.stringify(
|
||||||
|
defaultPlugins.map(plugin => ({
|
||||||
|
...plugin,
|
||||||
|
out: path.join(defaultPluginFolder, path.parse(plugin.out).base),
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.catch(die);
|
||||||
|
}
|
||||||
|
|
||||||
|
function compile(buildFolder, entry) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Building main bundle', entry);
|
||||||
|
|
||||||
|
const projectRoots = path.join(__dirname, '..');
|
||||||
|
return Metro.runBuild(
|
||||||
|
{
|
||||||
|
reporter: {update: () => {}},
|
||||||
|
projectRoot: projectRoots,
|
||||||
|
watchFolders: [projectRoots],
|
||||||
|
serializer: {},
|
||||||
|
transformer: {
|
||||||
|
babelTransformerPath: path.join(
|
||||||
|
__dirname,
|
||||||
|
'..',
|
||||||
|
'static',
|
||||||
|
'transforms',
|
||||||
|
'index.js',
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dev: false,
|
||||||
|
minify: false,
|
||||||
|
resetCache: true,
|
||||||
|
sourceMap: true,
|
||||||
|
entry,
|
||||||
|
out: path.join(buildFolder, 'bundle.js'),
|
||||||
|
},
|
||||||
|
).catch(die);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildFolder() {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Creating build directory');
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
tmp.dir((err, buildFolder) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(buildFolder);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch(die);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
buildFolder,
|
||||||
|
compile,
|
||||||
|
die,
|
||||||
|
compileDefaultPlugins,
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user