UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

40 lines (39 loc) 2.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.restoreBackupFiles = restoreBackupFiles; 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"); async function restoreBackupFiles() { const backupFiles = (0, glob_1.globSync)([(0, getProjectPath_1.getProjectPath)(), constants_1.Constants.UPGRADE_FOLDER_NAME, 'imports', '**/*'].join('/'), { nodir: true, dot: true }); if (backupFiles.length === 0) { (0, prompter_1.logMessageGray)('skipped, found no files to import'); return false; } (0, prompter_1.startSpinner)(`copying files from ${picocolors_1.default.yellow('.upgrade/imports')}`); for (let i = 0; i < backupFiles.length; i++) { (0, prompter_1.updateSpinner)(`copying files from ${picocolors_1.default.yellow('.upgrade/imports')} (${i + 1}/${backupFiles.length})`); const file = backupFiles[i]; const relativePath = path_1.default.relative(path_1.default.join((0, getProjectPath_1.getProjectPath)(), constants_1.Constants.UPGRADE_FOLDER_NAME, 'imports'), 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.stopSpinner)(`copied ${picocolors_1.default.yellow(backupFiles.length)} files`); return true; }