UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

49 lines (48 loc) 2.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.importUpgradeFolder = importUpgradeFolder; const fs_1 = __importDefault(require("fs")); const glob_1 = require("glob"); const path_1 = __importDefault(require("path")); const picocolors_1 = __importDefault(require("picocolors")); const constants_1 = require("../../../constants"); const prompter_1 = require("../../../prompter"); const getProjectPath_1 = require("../../getProjectPath"); function importUpgradeFolder(projectPath) { try { const upgradeFolderPath = path_1.default.join(projectPath, constants_1.Constants.UPGRADE_FOLDER_NAME); if (!fs_1.default.existsSync(upgradeFolderPath)) return null; const files = (0, glob_1.globSync)([projectPath, constants_1.Constants.UPGRADE_FOLDER_NAME, '**/*'].join('/'), { nodir: true, dot: true }); return { id: 'upgradeFolder', title: 'Upgrade Folder', value: `${files.length} files`, apply: () => setUpgradeFolder(projectPath, files), }; } catch (_e) { return null; } } async function setUpgradeFolder(oldProjectPath, files) { for (const file of files) { const relativePath = path_1.default.relative(oldProjectPath, file); const destination = path_1.default.join((0, getProjectPath_1.getProjectPath)(), relativePath); // ensure dir exists await new Promise(r => fs_1.default.mkdir(path_1.default.dirname(destination), { recursive: true }, r)); await new Promise((res, rej) => { fs_1.default.copyFile(file, destination, err => { if (err) rej(err); else res(null); }); }); } (0, prompter_1.logMessage)(`imported ${picocolors_1.default.yellow('.upgrade')}`); return Promise.resolve(); }