"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.versionCheck = exports.upgradeProjectDependencies = exports.upgradeDependencies = exports.parseFonts = exports.copyRuntimeAssets = exports.copyBuildsFolder = exports.copyAssetsFolder = exports.cleanPlaformAssets = exports.checkAndCreateGitignore = exports.checkAndCreateBabelConfig = exports.checkAndBootstrapIfRequired = void 0;var _path = _interopRequireDefault(require("path"));
var _prompt = require("../../cli/prompt");
var _common = require("../common");






var _constants = require("../constants");
var _engineManager = require("../engineManager");
var _platformManager = require("../platformManager");
var _pluginManager = require("../pluginManager");
var _fileutils = require("../systemManager/fileutils");











var _npmUtils = require("../systemManager/npmUtils");
var _exec = require("../systemManager/exec");

var _logger = require("../systemManager/logger");


var _templateManager = require("../templateManager");
var _configManager = require("../configManager");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { "default": obj };}function _toConsumableArray(arr) {return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();}function _nonIterableSpread() {throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o, minLen) {if (!o) return;if (typeof o === "string") return _arrayLikeToArray(o, minLen);var n = Object.prototype.toString.call(o).slice(8, -1);if (n === "Object" && o.constructor) n = o.constructor.name;if (n === "Map" || n === "Set") return Array.from(o);if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);}function _iterableToArray(iter) {if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);}function _arrayWithoutHoles(arr) {if (Array.isArray(arr)) return _arrayLikeToArray(arr);}function _arrayLikeToArray(arr, len) {if (len == null || len > arr.length) len = arr.length;for (var i = 0, arr2 = new Array(len); i < len; i++) {arr2[i] = arr[i];}return arr2;}function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);enumerableOnly && (symbols = symbols.filter(function (sym) {return Object.getOwnPropertyDescriptor(object, sym).enumerable;})), keys.push.apply(keys, symbols);}return keys;}function _objectSpread(target) {for (var i = 1; i < arguments.length; i++) {var source = null != arguments[i] ? arguments[i] : {};i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {_defineProperty(target, key, source[key]);}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));});}return target;}function _defineProperty(obj, key, value) {if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return obj;}function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {Promise.resolve(value).then(_next, _throw);}}function _asyncToGenerator(fn) {return function () {var self = this,args = arguments;return new Promise(function (resolve, reject) {var gen = fn.apply(self, args);function _next(value) {asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);}function _throw(err) {asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);}_next(undefined);});};}


var checkAndBootstrapIfRequired = /*#__PURE__*/function () {var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(c) {var template, _appConfigObj$default, _c$files$rnv$projectT, _c$files$rnv$projectT2, _c$files$rnv$projectT3, _c$files$rnv$projectT4, templateArr, templateDir, templatePath, templateObj, appConfigPath, appConfigObj, supportedPlatforms, engineTemplates, rnvPlatforms, activeEngineKeys, config, pkgJson, installPromises, appConfigsPath;return regeneratorRuntime.wrap(function _callee$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:
            (0, _logger.logTask)('checkAndBootstrapIfRequired');
            template = c.program.template;if (!(
            !c.paths.project.configExists && template)) {_context.next = 45;break;}_context.next = 5;return (
              (0, _exec.executeAsync)("npx yarn add ".concat(template), {
                cwd: c.paths.project.dir }));case 5:


            templateArr = template.split('@').filter(function (v) {return v !== '';});
            templateDir = template.startsWith('@') ? "@".concat(templateArr[0]) : templateArr[0];
            templatePath = _path["default"].join(c.paths.project.dir, 'node_modules', templateDir);

            c.paths.template.dir = templatePath;
            c.paths.template.configTemplate = _path["default"].join(templatePath, 'renative.template.json');

            templateObj = (0, _fileutils.readObjectSync)(c.paths.template.configTemplate);
            appConfigPath = _path["default"].join(c.paths.project.appConfigsDir, c.program.appConfigID, 'renative.json');
            appConfigObj = (0, _fileutils.readObjectSync)(appConfigPath);
            supportedPlatforms = appConfigObj === null || appConfigObj === void 0 ? void 0 : (_appConfigObj$default = appConfigObj.defaults) === null || _appConfigObj$default === void 0 ? void 0 : _appConfigObj$default.supportedPlatforms;
            engineTemplates = (_c$files$rnv$projectT = c.files.rnv.projectTemplates) === null || _c$files$rnv$projectT === void 0 ? void 0 : (_c$files$rnv$projectT2 = _c$files$rnv$projectT.config) === null || _c$files$rnv$projectT2 === void 0 ? void 0 : _c$files$rnv$projectT2.engineTemplates;
            rnvPlatforms = (_c$files$rnv$projectT3 = c.files.rnv.projectTemplates) === null || _c$files$rnv$projectT3 === void 0 ? void 0 : (_c$files$rnv$projectT4 = _c$files$rnv$projectT3.config) === null || _c$files$rnv$projectT4 === void 0 ? void 0 : _c$files$rnv$projectT4.platforms;
            activeEngineKeys = [];

            supportedPlatforms.forEach(function (supPlat) {
              Object.keys(engineTemplates).forEach(function (eKey) {var _rnvPlatforms$supPlat;
                if (engineTemplates[eKey].id === ((_rnvPlatforms$supPlat = rnvPlatforms[supPlat]) === null || _rnvPlatforms$supPlat === void 0 ? void 0 : _rnvPlatforms$supPlat.engine)) {
                  activeEngineKeys.push(eKey);
                }
              });
            });

            config = _objectSpread({},
            templateObj);


            // Clean unused engines
            Object.keys(config.engines).forEach(function (k) {
              if (!activeEngineKeys.includes(k)) {
                delete config.engines[k];
              }
            });if (!


            config.templateConfig.packageTemplate) {_context.next = 33;break;}
            pkgJson = config.templateConfig.packageTemplate;
            if (!pkgJson.devDependencies) pkgJson.devDependencies = {};
            if (!pkgJson.dependencies) pkgJson.dependencies = {};
            c.files.project["package"] = pkgJson;


            installPromises = [];
            Object.keys(pkgJson.devDependencies).forEach(function (devDepKey) {
              if (activeEngineKeys.includes(devDepKey)) {
                installPromises.push((0, _exec.executeAsync)("npx yarn add ".concat(
                devDepKey, "@").concat(pkgJson.devDependencies[devDepKey]), {
                  cwd: c.paths.project.dir }));

              }
            });if (!

            installPromises.length) {_context.next = 32;break;}_context.next = 30;return (
              Promise.all(installPromises));case 30:

            (0, _logger.logInfo)('Installed engines DONE');

            activeEngineKeys.forEach(function (aek) {
              var engineConfigPath = _path["default"].join(c.paths.project.dir, 'node_modules', aek, 'renative.engine.json');
              var eConfig = (0, _fileutils.readObjectSync)(engineConfigPath);
              if (eConfig.platforms) {
                supportedPlatforms.forEach(function (supPlat) {var _eConfig$platforms$su;
                  var engPlatNpm = (_eConfig$platforms$su = eConfig.platforms[supPlat]) === null || _eConfig$platforms$su === void 0 ? void 0 : _eConfig$platforms$su.npm;
                  if (engPlatNpm) {
                    var engPlatDeps = engPlatNpm.dependencies;
                    pkgJson.dependencies = pkgJson.dependencies || {};
                    if (engPlatDeps) {
                      Object.keys(engPlatDeps).forEach(function (engPlatDepKey) {
                        if (!pkgJson.dependencies[engPlatDepKey]) {
                          (0, _logger.logInfo)("Installing active engine dependency ".concat(engPlatDepKey));
                          pkgJson.dependencies[engPlatDepKey] = engPlatDeps[engPlatDepKey];
                        }
                      });
                    }

                    var engPlatDevDeps = engPlatNpm.devDependencies;
                    if (engPlatDevDeps) {
                      Object.keys(engPlatDevDeps).forEach(function (engPlatDevDepKey) {
                        pkgJson.devDependencies = pkgJson.devDependencies || {};
                        if (!pkgJson.devDependencies[engPlatDevDepKey]) {
                          (0, _logger.logInfo)("Installing active engine dependency ".concat(engPlatDevDepKey));
                          pkgJson.devDependencies[
                          engPlatDevDepKey] = engPlatDevDeps[engPlatDevDepKey];
                        }
                      });
                    }

                    var engPlatOptDeps = engPlatNpm.optionalDependencies;
                    if (engPlatOptDeps) {
                      Object.keys(engPlatOptDeps).forEach(function (engPlatOptDepKey) {
                        pkgJson.optionalDependencies = pkgJson.optionalDependencies || {};
                        if (!pkgJson.optionalDependencies[engPlatOptDepKey]) {
                          (0, _logger.logInfo)("Installing active engine dependency ".concat(engPlatOptDepKey));
                          pkgJson.optionalDependencies[
                          engPlatOptDepKey] = engPlatOptDeps[engPlatOptDepKey];
                        }
                      });
                    }
                  }
                });
              }
            });case 32:


            (0, _fileutils.writeFileSync)(c.paths.project["package"], pkgJson);case 33:


            delete config.templateConfig;
            (0, _fileutils.writeFileSync)(c.paths.project.config, config);

            appConfigsPath = _path["default"].join(templatePath, 'appConfigs');
            if ((0, _fileutils.fsExistsSync)(appConfigsPath)) {
              (0, _fileutils.copyFolderContentsRecursiveSync)(
              appConfigsPath,
              _path["default"].join(c.paths.project.appConfigsDir));

            }_context.next = 39;return (

              (0, _npmUtils.installPackageDependencies)(c));case 39:_context.next = 41;return (

              (0, _configManager.parseRenativeConfigs)(c));case 41:_context.next = 43;return (

              (0, _templateManager.configureTemplateFiles)(c));case 43:_context.next = 45;return (
              (0, _templateManager.configureEntryPoint)(c));case 45:return _context.abrupt("return",




            true);case 46:case "end":return _context.stop();}}}, _callee);}));return function checkAndBootstrapIfRequired(_x) {return _ref.apply(this, arguments);};}();exports.checkAndBootstrapIfRequired = checkAndBootstrapIfRequired;



var checkAndCreateGitignore = /*#__PURE__*/function () {var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(c) {var ignrPath;return regeneratorRuntime.wrap(function _callee2$(_context2) {while (1) {switch (_context2.prev = _context2.next) {case 0:
            (0, _logger.logTask)('checkAndCreateGitignore');
            ignrPath = _path["default"].join(c.paths.project.dir, '.gitignore');
            if (!(0, _fileutils.fsExistsSync)(ignrPath)) {
              (0, _logger.logInfo)(
              'Your .gitignore is missing. CREATING...DONE');


              (0, _fileutils.copyFileSync)(
              _path["default"].join(c.paths.rnv.dir, 'coreTemplateFiles/gitignore-template'),
              ignrPath);

            }return _context2.abrupt("return",
            true);case 4:case "end":return _context2.stop();}}}, _callee2);}));return function checkAndCreateGitignore(_x2) {return _ref2.apply(this, arguments);};}();exports.checkAndCreateGitignore = checkAndCreateGitignore;


var checkAndCreateBabelConfig = /*#__PURE__*/function () {var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(c) {return regeneratorRuntime.wrap(function _callee3$(_context3) {while (1) {switch (_context3.prev = _context3.next) {case 0:
            (0, _logger.logTask)('checkAndCreateBabelConfig');if (

            c.paths.project.configExists) {_context3.next = 3;break;}return _context3.abrupt("return", false);case 3:

            // Check babel-config
            (0, _logger.logDebug)('configureProject:check babel config');
            if (!(0, _fileutils.fsExistsSync)(c.paths.project.babelConfig)) {
              (0, _logger.logInfo)("Your babel config file ".concat(
              (0, _logger.chalk)().white(
              c.paths.project.babelConfig), " is missing! CREATING...DONE"));


              (0, _fileutils.copyFileSync)(
              _path["default"].join(c.paths.rnv.projectTemplate.dir, _constants.RN_BABEL_CONFIG_NAME),
              c.paths.project.babelConfig);

            }return _context3.abrupt("return",

            true);case 6:case "end":return _context3.stop();}}}, _callee3);}));return function checkAndCreateBabelConfig(_x3) {return _ref3.apply(this, arguments);};}();exports.checkAndCreateBabelConfig = checkAndCreateBabelConfig;



var copyRuntimeAssets = function copyRuntimeAssets(c) {return new Promise(function (resolve, reject) {var _c$buildConfig;
    (0, _logger.logTask)('copyRuntimeAssets');

    var destPath = _path["default"].join(c.paths.project.assets.dir, 'runtime');

    // FOLDER MERGERS FROM APP CONFIG + EXTEND
    if (c.paths.appConfig.dirs) {
      c.paths.appConfig.dirs.forEach(function (v) {
        var sourcePath = _path["default"].join(v, 'assets/runtime');
        (0, _fileutils.copyFolderContentsRecursiveSync)(sourcePath, destPath);
      });
    } else {
      var sourcePath = _path["default"].join(
      c.paths.appConfig.dir,
      'assets/runtime');

      (0, _fileutils.copyFolderContentsRecursiveSync)(sourcePath, destPath);
    }

    if (!((_c$buildConfig = c.buildConfig) !== null && _c$buildConfig !== void 0 && _c$buildConfig.common)) {
      (0, _logger.logDebug)('BUILD_CONFIG', c.buildConfig);
      reject("Your ".concat(
      (0, _logger.chalk)().white(
      c.paths.appConfig.config), " is missconfigured. (Maybe you have older version?). Missing ").concat(
      (0, _logger.chalk)().white(
      '{ common: {} }'), " object at root"));



      return;
    }


    // FONTS
    var fontsObj = 'export default [';

    var duplicateFontCheck = [];
    parseFonts(c, function (font, dir) {
      if (font.includes('.ttf') || font.includes('.otf') || font.includes('.woff')) {
        var key = font.split('.')[0];
        var includedFonts = (0, _common.getConfigProp)(
        c,
        c.platform,
        'includedFonts');

        if (includedFonts) {
          if (
          includedFonts.includes('*') ||
          includedFonts.includes(key))
          {
            if (font && !duplicateFontCheck.includes(font)) {
              duplicateFontCheck.push(font);
              var fontSource = _path["default"].join(dir, font).replace(/\\/g, '\\\\');
              if ((0, _fileutils.fsExistsSync)(fontSource)) {
                // const fontFolder = path.join(appFolder, 'app/src/main/assets/fonts');
                // mkdirSync(fontFolder);
                // const fontDest = path.join(fontFolder, font);
                // copyFileSync(fontSource, fontDest);
                fontsObj += "{\n                              fontFamily: '".concat(
                key, "',\n                              file: require('").concat(
                fontSource, "'),\n                          },");

              } else {
                (0, _logger.logWarning)("Font ".concat(
                (0, _logger.chalk)().white(
                fontSource), " doesn't exist! Skipping."));


              }
            }
          }
        }
      }
    });

    fontsObj += '];';
    if (!(0, _fileutils.fsExistsSync)(c.paths.project.assets.runtimeDir)) {
      (0, _fileutils.mkdirSync)(c.paths.project.assets.runtimeDir);
    }
    var fontJsPath = _path["default"].join(
    c.paths.project.assets.dir,
    'runtime',
    'fonts.web.js');

    if ((0, _fileutils.fsExistsSync)(fontJsPath)) {
      var existingFileContents = (0, _fileutils.fsReadFileSync)(fontJsPath).toString();

      if (existingFileContents !== fontsObj) {
        (0, _logger.logDebug)('newFontsJsFile');
        (0, _fileutils.fsWriteFileSync)(fontJsPath, fontsObj);
      }
    } else {
      (0, _logger.logDebug)('newFontsJsFile');
      (0, _fileutils.fsWriteFileSync)(fontJsPath, fontsObj);
    }

    var coreTemplateFiles = _path["default"].resolve(c.paths.rnv.dir, 'coreTemplateFiles');
    (0, _fileutils.copyFileSync)(
    _path["default"].resolve(coreTemplateFiles, 'fontManager.js'),
    _path["default"].resolve(
    c.paths.project.assets.dir,
    'runtime',
    'fontManager.js'));


    (0, _fileutils.copyFileSync)(
    _path["default"].resolve(coreTemplateFiles, 'fontManager.js'),
    _path["default"].resolve(
    c.paths.project.assets.dir,
    'runtime',
    'fontManager.server.web.js'));


    (0, _fileutils.copyFileSync)(
    _path["default"].resolve(coreTemplateFiles, 'fontManager.web.js'),
    _path["default"].resolve(
    c.paths.project.assets.dir,
    'runtime',
    'fontManager.web.js'));



    resolve();
  });};exports.copyRuntimeAssets = copyRuntimeAssets;

var parseFonts = function parseFonts(c, callback) {
  (0, _logger.logTask)('parseFonts');

  if (c.buildConfig) {
    // FONTS - PROJECT CONFIG
    if ((0, _fileutils.fsExistsSync)(c.paths.project.appConfigBase.fontsDir)) {
      (0, _fileutils.fsReaddirSync)(c.paths.project.appConfigBase.fontsDir).forEach(
      function (font) {
        if (callback) {callback(font, c.paths.project.appConfigBase.fontsDir);}
      });

    }
    // FONTS - APP CONFIG
    if (c.paths.appConfig.fontsDirs) {
      c.paths.appConfig.fontsDirs.forEach(function (v) {
        if ((0, _fileutils.fsExistsSync)(v)) {
          (0, _fileutils.fsReaddirSync)(v).forEach(function (font) {
            if (callback) callback(font, v);
          });
        }
      });
    } else if ((0, _fileutils.fsExistsSync)(c.paths.appConfig.fontsDir)) {
      (0, _fileutils.fsReaddirSync)(c.paths.appConfig.fontsDir).forEach(function (font) {
        if (callback) callback(font, c.paths.appConfig.fontsDir);
      });
    }
  }
};exports.parseFonts = parseFonts;

var copyAssetsFolder = /*#__PURE__*/function () {var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(c, platform, subPath, customFn) {var hasAssetFolder, sourcePath, destPath, tsPathsConfig, _sourcePath;return regeneratorRuntime.wrap(function _callee4$(_context4) {while (1) {switch (_context4.prev = _context4.next) {case 0:
            (0, _logger.logTask)('copyAssetsFolder');if (

            (0, _platformManager.isPlatformActive)(c, platform)) {_context4.next = 3;break;}return _context4.abrupt("return");case 3:if (!


            c.paths.appConfig.dirs) {_context4.next = 10;break;}
            hasAssetFolder = c.paths.appConfig.dirs.
            filter(function (v) {return (0, _fileutils.fsExistsSync)(_path["default"].join(v, "assets/".concat(platform)));}).length;if (
            hasAssetFolder) {_context4.next = 8;break;}_context4.next = 8;return (
              generateDefaultAssets(
              c,
              platform,
              _path["default"].join(c.paths.appConfig.dirs[0], "assets/".concat(platform))));case 8:_context4.next = 14;break;case 10:



            sourcePath = _path["default"].join(
            c.paths.appConfig.dir, "assets/".concat(
            platform));if (

            (0, _fileutils.fsExistsSync)(sourcePath)) {_context4.next = 14;break;}_context4.next = 14;return (
              generateDefaultAssets(c, platform, sourcePath));case 14:if (!



            customFn) {_context4.next = 16;break;}return _context4.abrupt("return",
            customFn(c, platform));case 16:


            destPath = _path["default"].join(
            (0, _common.getPlatformProjectDir)(c, platform),
            subPath || '');


            tsPathsConfig = (0, _common.getTimestampPathsConfig)(c, platform);

            // FOLDER MERGERS FROM APP CONFIG + EXTEND
            if (c.paths.appConfig.dirs) {
              c.paths.appConfig.dirs.forEach(function (v) {
                var sourcePath = _path["default"].join(v, "assets/".concat(platform));
                (0, _fileutils.copyFolderContentsRecursiveSync)(sourcePath, destPath, true, false, false, null, tsPathsConfig);
              });
            } else {
              _sourcePath = _path["default"].join(
              c.paths.appConfig.dir, "assets/".concat(
              platform));

              (0, _fileutils.copyFolderContentsRecursiveSync)(_sourcePath, destPath, true, false, false, null, tsPathsConfig);
            }case 19:case "end":return _context4.stop();}}}, _callee4);}));return function copyAssetsFolder(_x4, _x5, _x6, _x7) {return _ref4.apply(this, arguments);};}();exports.copyAssetsFolder = copyAssetsFolder;


var generateDefaultAssets = /*#__PURE__*/function () {var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(c, platform, sourcePath) {var confirmAssets, _yield$inquirerPrompt, confirm, engine;return regeneratorRuntime.wrap(function _callee5$(_context5) {while (1) {switch (_context5.prev = _context5.next) {case 0:
            (0, _logger.logTask)('generateDefaultAssets');
            confirmAssets = true;if (!(
            c.program.ci !== true)) {_context5.next = 8;break;}_context5.next = 5;return (
              (0, _prompt.inquirerPrompt)({
                type: 'confirm',
                message: "It seems you don't have assets configured in ".concat((0, _logger.chalk)().white(
                sourcePath), " do you want generate default ones?") }));case 5:_yield$inquirerPrompt = _context5.sent;confirm = _yield$inquirerPrompt.confirm;


            confirmAssets = confirm;case 8:


            if (confirmAssets) {
              engine = (0, _engineManager.getEngineRunnerByPlatform)(c, c.platform);
              if ((0, _fileutils.fsExistsSync)(_path["default"].join(engine.originalTemplateAssetsDir, platform))) {
                (0, _fileutils.copyFolderContentsRecursiveSync)(
                _path["default"].join(engine.originalTemplateAssetsDir, platform),
                sourcePath);

              } else {
                (0, _logger.logWarning)('Currently used engine does not have default assets, creating an empty folder');
                (0, _fileutils.mkdirSync)(sourcePath);
              }
            }case 9:case "end":return _context5.stop();}}}, _callee5);}));return function generateDefaultAssets(_x8, _x9, _x10) {return _ref5.apply(this, arguments);};}();


var copyBuildsFolder = function copyBuildsFolder(c, platform) {return new Promise(function (resolve) {var _c$runtime$currentPla;
    (0, _logger.logTask)('copyBuildsFolder');
    if (!(0, _platformManager.isPlatformActive)(c, platform, resolve)) return;

    var destPath = _path["default"].join((0, _common.getAppFolder)(c));
    var tsPathsConfig = (0, _common.getTimestampPathsConfig)(c, platform);

    var configPropsInjects = [];
    _constants.INJECTABLE_CONFIG_PROPS.forEach(function (v) {
      configPropsInjects.push({
        pattern: "{{configProps.".concat(v, "}}"),
        override: (0, _common.getConfigProp)(c, c.platform, v) });

    });
    c.configPropsInjects = configPropsInjects;
    var allInjects = [].concat(_toConsumableArray(c.configPropsInjects), _toConsumableArray(c.systemPropsInjects), _toConsumableArray(c.runtimePropsInjects));

    // FOLDER MERGERS PROJECT CONFIG
    var sourcePath1 = (0, _common.getBuildsFolder)(
    c,
    platform,
    c.paths.project.appConfigBase.dir);

    (0, _fileutils.copyFolderContentsRecursiveSync)(sourcePath1, destPath, true, false, false, allInjects, tsPathsConfig);

    // FOLDER MERGERS PROJECT CONFIG (PRIVATE)
    var sourcePath1secLegacy = (0, _common.getBuildsFolder)(
    c,
    platform,
    c.paths.workspace.project.appConfigBase.dir_LEGACY);

    (0, _fileutils.copyFolderContentsRecursiveSync)(sourcePath1secLegacy, destPath, true,
    false, false, allInjects, tsPathsConfig);

    // FOLDER MERGERS PROJECT CONFIG (PRIVATE)
    var sourcePath1sec = (0, _common.getBuildsFolder)(
    c,
    platform,
    c.paths.workspace.project.appConfigBase.dir);

    (0, _fileutils.copyFolderContentsRecursiveSync)(sourcePath1sec, destPath, true, false, false, allInjects, tsPathsConfig);

    if ((0, _fileutils.fsExistsSync)(sourcePath1secLegacy)) {
      (0, _logger.logWarning)("Path: ".concat((0, _logger.chalk)().red(sourcePath1secLegacy), " is DEPRECATED.\nMove your files to: ").concat(
      (0, _logger.chalk)().white(sourcePath1sec), " instead"));
    }

    // DEPRECATED SHARED
    if ((_c$runtime$currentPla = c.runtime.currentPlatform) !== null && _c$runtime$currentPla !== void 0 && _c$runtime$currentPla.isWebHosted) {
      var sourcePathShared = _path["default"].join(
      c.paths.project.appConfigBase.dir,
      'builds/_shared');

      if ((0, _fileutils.fsExistsSync)(sourcePathShared)) {
        (0, _logger.logWarning)('Folder builds/_shared is DEPRECATED. use builds/<PLATFORM> instead ');
      }
      (0, _fileutils.copyFolderContentsRecursiveSync)(
      sourcePathShared,
      (0, _common.getPlatformBuildDir)(c),
      true, false, false, allInjects);

    }

    // FOLDER MERGERS FROM APP CONFIG + EXTEND
    if (c.paths.appConfig.dirs) {
      c.paths.appConfig.dirs.forEach(function (v) {
        var sourceV = (0, _common.getBuildsFolder)(c, platform, v);
        (0, _fileutils.copyFolderContentsRecursiveSync)(
        sourceV,
        destPath,
        true, false, false, allInjects, tsPathsConfig);

      });
    } else {
      (0, _fileutils.copyFolderContentsRecursiveSync)(
      (0, _common.getBuildsFolder)(c, platform, c.paths.appConfig.dir),
      destPath,
      true, false, false, allInjects, tsPathsConfig);

    }

    // FOLDER MERGERS FROM APP CONFIG (PRIVATE)
    var sourcePath0sec = (0, _common.getBuildsFolder)(
    c,
    platform,
    c.paths.workspace.appConfig.dir);

    (0, _fileutils.copyFolderContentsRecursiveSync)(sourcePath0sec, destPath, true, false, false, allInjects, tsPathsConfig);

    (0, _pluginManager.copyTemplatePluginsSync)(c);

    resolve();
  });};exports.copyBuildsFolder = copyBuildsFolder;

var SYNCED_DEPS = [
'rnv',
'@rnv/engine-rn',
'@rnv/engine-rn-next',
'@rnv/engine-lightning',
'@rnv/engine-rn-web',
'@rnv/engine-rn-electron',
'@rnv/engine-rn-tvos',
'renative',
'renative-template-hello-world',
'renative-template-blank'];


var SYNCED_TEMPLATES = [
'renative-template-hello-world',
'renative-template-blank'];


var versionCheck = /*#__PURE__*/function () {var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(c) {var _c$files$project, _c$files$project$conf, _c$files$rnv, _c$files$rnv$package, _c$files$project2, _c$files$project2$pac, _c$files$project2$pac2;var recCmd, actionNoUpdate, actionWithUpdate, actionUpgrade, _yield$inquirerPrompt2, chosenAction;return regeneratorRuntime.wrap(function _callee6$(_context6) {while (1) {switch (_context6.prev = _context6.next) {case 0:
            (0, _logger.logTask)('versionCheck');if (!(

            c.runtime.isWrapper || c.runtime.versionCheckCompleted || (_c$files$project = c.files.project) !== null && _c$files$project !== void 0 && (_c$files$project$conf = _c$files$project.config) !== null && _c$files$project$conf !== void 0 && _c$files$project$conf.skipAutoUpdate)) {_context6.next = 3;break;}return _context6.abrupt("return",
            true);case 3:

            c.runtime.rnvVersionRunner = (_c$files$rnv = c.files.rnv) === null || _c$files$rnv === void 0 ? void 0 : (_c$files$rnv$package = _c$files$rnv["package"]) === null || _c$files$rnv$package === void 0 ? void 0 : _c$files$rnv$package.version;
            c.runtime.rnvVersionProject = (_c$files$project2 = c.files.project) === null || _c$files$project2 === void 0 ? void 0 : (_c$files$project2$pac = _c$files$project2["package"]) === null || _c$files$project2$pac === void 0 ? void 0 : (_c$files$project2$pac2 = _c$files$project2$pac.devDependencies) === null || _c$files$project2$pac2 === void 0 ? void 0 : _c$files$project2$pac2.rnv;
            (0, _logger.logTask)("versionCheck:rnvRunner:".concat(
            c.runtime.rnvVersionRunner, ",rnvProject:").concat(
            c.runtime.rnvVersionProject),

            (0, _logger.chalk)().grey);if (!(

            c.runtime.rnvVersionRunner && c.runtime.rnvVersionProject)) {_context6.next = 19;break;}if (!(
            c.runtime.rnvVersionRunner !== c.runtime.rnvVersionProject && !c.program.skipRnvCheck)) {_context6.next = 19;break;}
            recCmd = (0, _logger.chalk)().white("$ npx ".concat((0, _logger.getCurrentCommand)(true)));
            actionNoUpdate = 'Continue and skip updating package.json';
            actionWithUpdate = 'Continue and update package.json';
            actionUpgrade = "Upgrade project to ".concat(
            c.runtime.rnvVersionRunner);_context6.next = 14;return (


              (0, _prompt.inquirerPrompt)({
                message: 'What to do next?',
                type: 'list',
                name: 'chosenAction',
                choices: [actionNoUpdate, actionWithUpdate, actionUpgrade],
                warningMessage: "You are running $rnv v".concat((0, _logger.chalk)().red(
                c.runtime.rnvVersionRunner), " against project built with rnv v").concat(
                (0, _logger.chalk)().red(
                c.runtime.rnvVersionProject), ". This might result in unexpected behaviour!\nIt is recommended that you run your rnv command with npx prefix: ").concat(


                recCmd, " . or manually update your devDependencies.rnv version in your package.json.") }));case 14:_yield$inquirerPrompt2 = _context6.sent;chosenAction = _yield$inquirerPrompt2.chosenAction;



            c.runtime.versionCheckCompleted = true;

            c.runtime.skipPackageUpdate = chosenAction === actionNoUpdate;

            if (chosenAction === actionUpgrade) {
              upgradeProjectDependencies(c, c.runtime.rnvVersionRunner);
            }case 19:return _context6.abrupt("return",


            true);case 20:case "end":return _context6.stop();}}}, _callee6);}));return function versionCheck(_x11) {return _ref6.apply(this, arguments);};}();exports.versionCheck = versionCheck;


var upgradeProjectDependencies = function upgradeProjectDependencies(c, version) {
  (0, _logger.logTask)('upgradeProjectDependencies');

  // const templates = c.files.project.config?.templates;
  // TODO: Make this dynamically injected
  // SYNC DEPS
  var result = upgradeDependencies(
  c.files.project["package"],
  c.paths.project["package"],
  c.files.project.config,
  c.paths.project.config,
  version);

  c._requiresNpmInstall = true;
  return result;
};exports.upgradeProjectDependencies = upgradeProjectDependencies;

var upgradeDependencies = function upgradeDependencies(packageFile, packagesPath, configFile, configPath, version) {
  // logTask('upgradeDependencies');

  var result = [];

  _fixDeps(packageFile === null || packageFile === void 0 ? void 0 : packageFile.devDependencies, version);
  _fixDeps(packageFile === null || packageFile === void 0 ? void 0 : packageFile.dependencies, version);
  _fixDeps(packageFile === null || packageFile === void 0 ? void 0 : packageFile.peerDependencies, version);
  SYNCED_TEMPLATES.forEach(function (templ) {var _configFile$templates, _configFile$templates2;
    if (configFile !== null && configFile !== void 0 && (_configFile$templates = configFile.templates) !== null && _configFile$templates !== void 0 && (_configFile$templates2 = _configFile$templates[templ]) !== null && _configFile$templates2 !== void 0 && _configFile$templates2.version) {
      configFile.templates[templ].version = version;
    }
  });

  if (packageFile) {
    (0, _fileutils.writeFileSync)(packagesPath, packageFile);
    result.push(packagesPath);
  }
  if (configFile) {
    (0, _fileutils.writeFileSync)(configPath, configFile);
    result.push(configPath);
  }
  return result;
};exports.upgradeDependencies = upgradeDependencies;

var _fixDeps = function _fixDeps(deps, version) {
  SYNCED_DEPS.forEach(function (dep) {
    var d = deps === null || deps === void 0 ? void 0 : deps[dep];
    if (d) {
      var prefix = d.match(/~|>|>=|\^|<|<=/) || '';
      deps[dep] = "".concat(prefix).concat(version);
    }
  });
};

var cleanPlaformAssets = /*#__PURE__*/function () {var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(c) {return regeneratorRuntime.wrap(function _callee7$(_context7) {while (1) {switch (_context7.prev = _context7.next) {case 0:
            (0, _logger.logTask)('cleanPlaformAssets');_context7.next = 3;return (

              (0, _fileutils.cleanFolder)(c.paths.project.assets.dir));case 3:
            (0, _fileutils.mkdirSync)(c.paths.project.assets.runtimeDir);return _context7.abrupt("return",
            true);case 5:case "end":return _context7.stop();}}}, _callee7);}));return function cleanPlaformAssets(_x12) {return _ref7.apply(this, arguments);};}();exports.cleanPlaformAssets = cleanPlaformAssets;
//# sourceMappingURL=index.js.map