1. 'use strict';
    
  2. 
    
  3. const asyncCopyTo = require('./utils').asyncCopyTo;
    
  4. const chalk = require('chalk');
    
  5. const resolvePath = require('./utils').resolvePath;
    
  6. 
    
  7. const DEFAULT_FB_SOURCE_PATH = '~/fbsource/';
    
  8. const DEFAULT_WWW_PATH = '~/www/';
    
  9. const RELATIVE_RN_OSS_PATH = 'xplat/js/react-native-github/Libraries/Renderer/';
    
  10. const RELATIVE_WWW_PATH = 'html/shared/react/';
    
  11. 
    
  12. async function doSync(buildPath, destPath) {
    
  13.   console.log(`${chalk.bgYellow.black(' SYNCING ')} React to ${destPath}`);
    
  14. 
    
  15.   await asyncCopyTo(buildPath, destPath);
    
  16.   console.log(`${chalk.bgGreen.black(' SYNCED ')} React to ${destPath}`);
    
  17. }
    
  18. 
    
  19. async function syncReactDom(buildPath, wwwPath) {
    
  20.   wwwPath = typeof wwwPath === 'string' ? wwwPath : DEFAULT_WWW_PATH;
    
  21. 
    
  22.   if (wwwPath.charAt(wwwPath.length - 1) !== '/') {
    
  23.     wwwPath += '/';
    
  24.   }
    
  25. 
    
  26.   const destPath = resolvePath(wwwPath + RELATIVE_WWW_PATH);
    
  27.   await doSync(buildPath, destPath);
    
  28. }
    
  29. 
    
  30. async function syncReactNativeHelper(
    
  31.   buildPath,
    
  32.   fbSourcePath,
    
  33.   relativeDestPath
    
  34. ) {
    
  35.   fbSourcePath =
    
  36.     typeof fbSourcePath === 'string' ? fbSourcePath : DEFAULT_FB_SOURCE_PATH;
    
  37. 
    
  38.   if (fbSourcePath.charAt(fbSourcePath.length - 1) !== '/') {
    
  39.     fbSourcePath += '/';
    
  40.   }
    
  41. 
    
  42.   const destPath = resolvePath(fbSourcePath + relativeDestPath);
    
  43.   await doSync(buildPath, destPath);
    
  44. }
    
  45. 
    
  46. async function syncReactNative(fbSourcePath) {
    
  47.   await syncReactNativeHelper(
    
  48.     'build/react-native',
    
  49.     fbSourcePath,
    
  50.     RELATIVE_RN_OSS_PATH
    
  51.   );
    
  52. }
    
  53. 
    
  54. module.exports = {
    
  55.   syncReactDom,
    
  56.   syncReactNative,
    
  57. };