2017-04-05 16:47:29 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const basename = require('path').basename;
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const join = require('path').join;
|
|
|
|
|
const resolve = require('path').resolve;
|
|
|
|
|
const Bundles = require('./bundles');
|
2017-05-24 17:06:30 +01:00
|
|
|
const asyncCopyTo = require('./utils').asyncCopyTo;
|
2017-04-05 16:47:29 +01:00
|
|
|
|
|
|
|
|
const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
|
|
|
|
|
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
|
|
|
|
|
const NODE_DEV = Bundles.bundleTypes.NODE_DEV;
|
|
|
|
|
const NODE_PROD = Bundles.bundleTypes.NODE_PROD;
|
|
|
|
|
const FB_DEV = Bundles.bundleTypes.FB_DEV;
|
|
|
|
|
const FB_PROD = Bundles.bundleTypes.FB_PROD;
|
|
|
|
|
const RN_DEV = Bundles.bundleTypes.RN_DEV;
|
|
|
|
|
const RN_PROD = Bundles.bundleTypes.RN_PROD;
|
|
|
|
|
|
|
|
|
|
const facebookWWW = 'facebook-www';
|
|
|
|
|
// these files need to be copied to the facebook-www build
|
|
|
|
|
const facebookWWWSrcDependencies = [
|
2017-10-20 13:51:50 +01:00
|
|
|
'packages/react-dom/src/client/event/plugins/TapEventPlugin.js',
|
2017-04-05 16:47:29 +01:00
|
|
|
];
|
|
|
|
|
|
2017-05-24 17:06:30 +01:00
|
|
|
// these files need to be copied to the react-native build
|
|
|
|
|
const reactNativeSrcDependencies = [
|
2017-10-19 00:22:21 +01:00
|
|
|
'packages/react-reconciler/src/isomorphic/ReactTypes.js',
|
|
|
|
|
'packages/react-native-renderer/src/ReactNativeTypes.js',
|
2017-05-24 17:06:30 +01:00
|
|
|
];
|
2017-04-05 16:47:29 +01:00
|
|
|
|
2017-10-19 00:22:21 +01:00
|
|
|
// these files need to be copied to the react-rt build
|
2017-10-10 13:44:43 -07:00
|
|
|
const reactNativeRTSrcDependencies = [
|
2017-10-19 00:22:21 +01:00
|
|
|
'packages/react-rt-renderer/src/ReactNativeRTTypes.js',
|
2017-10-10 13:44:43 -07:00
|
|
|
];
|
|
|
|
|
|
2017-10-19 00:22:21 +01:00
|
|
|
// these files need to be copied to the react-cs build
|
2017-10-13 14:29:59 -07:00
|
|
|
const reactNativeCSSrcDependencies = [
|
2017-10-19 00:22:21 +01:00
|
|
|
'packages/react-cs-renderer/src/ReactNativeCSTypes.js',
|
2017-10-13 14:29:59 -07:00
|
|
|
];
|
|
|
|
|
|
2017-04-05 16:47:29 +01:00
|
|
|
function getPackageName(name) {
|
|
|
|
|
if (name.indexOf('/') !== -1) {
|
|
|
|
|
return name.split('/')[0];
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createReactNativeBuild() {
|
|
|
|
|
// create the react-native folder for FB bundles
|
|
|
|
|
fs.mkdirSync(join('build', 'react-native'));
|
|
|
|
|
// create the react-native shims folder for FB shims
|
|
|
|
|
fs.mkdirSync(join('build', 'react-native', 'shims'));
|
|
|
|
|
// copy in all the shims from build/rollup/shims/react-native
|
|
|
|
|
const from = join('scripts', 'rollup', 'shims', 'react-native');
|
|
|
|
|
const to = join('build', 'react-native', 'shims');
|
|
|
|
|
|
2017-05-24 17:06:30 +01:00
|
|
|
return asyncCopyTo(from, to).then(() => {
|
|
|
|
|
let promises = [];
|
|
|
|
|
// we also need to copy over some specific files from src
|
|
|
|
|
// defined in reactNativeSrcDependencies
|
|
|
|
|
for (const srcDependency of reactNativeSrcDependencies) {
|
|
|
|
|
promises.push(
|
|
|
|
|
asyncCopyTo(resolve(srcDependency), join(to, basename(srcDependency)))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return Promise.all(promises);
|
|
|
|
|
});
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:44:43 -07:00
|
|
|
function createReactNativeRTBuild() {
|
2017-10-19 00:22:21 +01:00
|
|
|
// create the react-rt folder for FB bundles
|
|
|
|
|
fs.mkdirSync(join('build', 'react-rt'));
|
|
|
|
|
// create the react-rt shims folder for FB shims
|
|
|
|
|
fs.mkdirSync(join('build', 'react-rt', 'shims'));
|
2017-10-10 13:44:43 -07:00
|
|
|
|
2017-10-19 00:22:21 +01:00
|
|
|
const to = join('build', 'react-rt', 'shims');
|
2017-10-10 13:44:43 -07:00
|
|
|
|
|
|
|
|
let promises = [];
|
|
|
|
|
// we also need to copy over some specific files from src
|
|
|
|
|
// defined in reactNativeRTSrcDependencies
|
|
|
|
|
for (const srcDependency of reactNativeRTSrcDependencies) {
|
|
|
|
|
promises.push(
|
|
|
|
|
asyncCopyTo(resolve(srcDependency), join(to, basename(srcDependency)))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return Promise.all(promises);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-13 14:29:59 -07:00
|
|
|
function createReactNativeCSBuild() {
|
2017-10-19 00:22:21 +01:00
|
|
|
// create the react-cs folder for FB bundles
|
|
|
|
|
fs.mkdirSync(join('build', 'react-cs'));
|
|
|
|
|
// create the react-cs shims folder for FB shims
|
|
|
|
|
fs.mkdirSync(join('build', 'react-cs', 'shims'));
|
2017-10-13 14:29:59 -07:00
|
|
|
|
2017-10-19 00:22:21 +01:00
|
|
|
const to = join('build', 'react-cs', 'shims');
|
2017-10-13 14:29:59 -07:00
|
|
|
|
|
|
|
|
let promises = [];
|
|
|
|
|
// we also need to copy over some specific files from src
|
|
|
|
|
// defined in reactNativeCSSrcDependencies
|
|
|
|
|
for (const srcDependency of reactNativeCSSrcDependencies) {
|
|
|
|
|
promises.push(
|
|
|
|
|
asyncCopyTo(resolve(srcDependency), join(to, basename(srcDependency)))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return Promise.all(promises);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 16:47:29 +01:00
|
|
|
function createFacebookWWWBuild() {
|
|
|
|
|
// create the facebookWWW folder for FB bundles
|
|
|
|
|
fs.mkdirSync(join('build', facebookWWW));
|
|
|
|
|
// create the facebookWWW shims folder for FB shims
|
|
|
|
|
fs.mkdirSync(join('build', facebookWWW, 'shims'));
|
|
|
|
|
// copy in all the shims from build/rollup/shims/facebook-www
|
|
|
|
|
const from = join('scripts', 'rollup', 'shims', facebookWWW);
|
|
|
|
|
const to = join('build', facebookWWW, 'shims');
|
|
|
|
|
|
|
|
|
|
return asyncCopyTo(from, to).then(() => {
|
|
|
|
|
let promises = [];
|
|
|
|
|
// we also need to copy over some specific files from src
|
|
|
|
|
// defined in facebookWWWSrcDependencies
|
|
|
|
|
for (const srcDependency of facebookWWWSrcDependencies) {
|
|
|
|
|
promises.push(
|
|
|
|
|
asyncCopyTo(resolve(srcDependency), join(to, basename(srcDependency)))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return Promise.all(promises);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function copyBundleIntoNodePackage(packageName, filename, bundleType) {
|
|
|
|
|
const packageDirectory = resolve(`./build/packages/${packageName}`);
|
|
|
|
|
|
|
|
|
|
if (fs.existsSync(packageDirectory)) {
|
|
|
|
|
let from = resolve(`./build/${filename}`);
|
|
|
|
|
let to = `${packageDirectory}/${filename}`;
|
|
|
|
|
// for UMD bundles we have to move the files into a umd directory
|
|
|
|
|
// within the package directory. we also need to set the from
|
|
|
|
|
// to be the root build from directory
|
|
|
|
|
if (bundleType === UMD_DEV || bundleType === UMD_PROD) {
|
|
|
|
|
const distDirectory = `${packageDirectory}/umd`;
|
|
|
|
|
// create a dist directory if not created
|
|
|
|
|
if (!fs.existsSync(distDirectory)) {
|
|
|
|
|
fs.mkdirSync(distDirectory);
|
|
|
|
|
}
|
|
|
|
|
from = resolve(`./build/dist/${filename}`);
|
|
|
|
|
to = `${packageDirectory}/umd/${filename}`;
|
|
|
|
|
}
|
|
|
|
|
// for NODE bundles we have to move the files into a cjs directory
|
|
|
|
|
// within the package directory. we also need to set the from
|
|
|
|
|
// to be the root build from directory
|
|
|
|
|
if (bundleType === NODE_DEV || bundleType === NODE_PROD) {
|
|
|
|
|
const distDirectory = `${packageDirectory}/cjs`;
|
|
|
|
|
// create a dist directory if not created
|
|
|
|
|
if (!fs.existsSync(distDirectory)) {
|
|
|
|
|
fs.mkdirSync(distDirectory);
|
|
|
|
|
}
|
|
|
|
|
to = `${packageDirectory}/cjs/${filename}`;
|
|
|
|
|
}
|
|
|
|
|
return asyncCopyTo(from, to).then(() => {
|
|
|
|
|
// delete the old file if this is a not a UMD bundle
|
|
|
|
|
if (bundleType !== UMD_DEV && bundleType !== UMD_PROD) {
|
|
|
|
|
fs.unlinkSync(from);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function copyNodePackageTemplate(packageName) {
|
|
|
|
|
const from = resolve(`./packages/${packageName}`);
|
|
|
|
|
const to = resolve(`./build/packages/${packageName}`);
|
2017-10-19 00:22:21 +01:00
|
|
|
const npmFrom = resolve(`${from}/npm`);
|
|
|
|
|
if (!fs.existsSync(npmFrom)) {
|
|
|
|
|
// The package is not meant for npm consumption.
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
if (fs.existsSync(to)) {
|
|
|
|
|
// We already created this package (e.g. due to another entry point).
|
2017-04-05 16:47:29 +01:00
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
2017-10-19 00:22:21 +01:00
|
|
|
// TODO: verify that all copied files are either in the "files"
|
|
|
|
|
// whitelist or implicitly published by npm.
|
|
|
|
|
return asyncCopyTo(npmFrom, to).then(() =>
|
|
|
|
|
Promise.all([
|
|
|
|
|
asyncCopyTo(resolve(`${from}/package.json`), `${to}/package.json`),
|
|
|
|
|
asyncCopyTo(resolve(`${from}/README.md`), `${to}/README.md`),
|
|
|
|
|
asyncCopyTo(resolve('./LICENSE'), `${to}/LICENSE`),
|
|
|
|
|
])
|
|
|
|
|
);
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createNodePackage(bundleType, packageName, filename) {
|
|
|
|
|
// the only case where we don't want to copy the package is for FB bundles
|
|
|
|
|
if (bundleType !== FB_DEV && bundleType !== FB_PROD) {
|
|
|
|
|
return copyNodePackageTemplate(packageName).then(() =>
|
2017-04-20 11:18:33 -07:00
|
|
|
copyBundleIntoNodePackage(packageName, filename, bundleType)
|
|
|
|
|
);
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:44:43 -07:00
|
|
|
function getPackageDestination(config, bundleType, filename, hasteName) {
|
2017-04-05 16:47:29 +01:00
|
|
|
let dest = config.destDir + filename;
|
|
|
|
|
|
|
|
|
|
if (bundleType === FB_DEV || bundleType === FB_PROD) {
|
|
|
|
|
dest = `${config.destDir}${facebookWWW}/${filename}`;
|
|
|
|
|
} else if (bundleType === UMD_DEV || bundleType === UMD_PROD) {
|
|
|
|
|
dest = `${config.destDir}dist/${filename}`;
|
|
|
|
|
} else if (bundleType === RN_DEV || bundleType === RN_PROD) {
|
2017-10-10 13:44:43 -07:00
|
|
|
if (hasteName === 'ReactNativeRTFiber') {
|
2017-10-19 00:22:21 +01:00
|
|
|
dest = `${config.destDir}react-rt/${filename}`;
|
2017-10-18 13:56:07 +01:00
|
|
|
} else if (hasteName === 'ReactNativeCSFiber') {
|
2017-10-19 00:22:21 +01:00
|
|
|
dest = `${config.destDir}react-cs/${filename}`;
|
2017-10-10 13:44:43 -07:00
|
|
|
} else {
|
|
|
|
|
dest = `${config.destDir}react-native/${filename}`;
|
|
|
|
|
}
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
return dest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
getPackageDestination,
|
|
|
|
|
createNodePackage,
|
|
|
|
|
getPackageName,
|
|
|
|
|
createFacebookWWWBuild,
|
|
|
|
|
createReactNativeBuild,
|
2017-10-10 13:44:43 -07:00
|
|
|
createReactNativeRTBuild,
|
2017-10-13 14:29:59 -07:00
|
|
|
createReactNativeCSBuild,
|
2017-04-05 16:47:29 +01:00
|
|
|
};
|