UNPKG

server-renderer

Version:

library of server side render for React

57 lines (56 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const fs_1 = tslib_1.__importDefault(require("fs")); const path_1 = tslib_1.__importDefault(require("path")); const chalk_1 = tslib_1.__importDefault(require("chalk")); function deleteDir(directory) { if (directory && fs_1.default.existsSync(directory)) { const files = fs_1.default.readdirSync(directory); if (files.length) { files.forEach(filename => { const filePath = path_1.default.join(directory, filename); const stats = fs_1.default.statSync(filePath); if (stats.isDirectory()) { deleteDir(filePath); } else { fs_1.default.unlinkSync(filePath); } }); } fs_1.default.rmdirSync(directory); } } exports.deleteDir = deleteDir; function copyDir(source, dest) { if (fs_1.default.existsSync(source)) { if (!fs_1.default.existsSync(dest)) { fs_1.default.mkdirSync(dest); } const files = fs_1.default.readdirSync(source); if (files.length) { files.forEach(filename => { const filePath = path_1.default.join(source, filename); const targetPath = path_1.default.join(dest, filename); const stats = fs_1.default.statSync(filePath); if (stats.isDirectory()) { fs_1.default.mkdirSync(targetPath); copyDir(filePath, targetPath); } else { fs_1.default.copyFileSync(filePath, targetPath); } }); } } } exports.copyDir = copyDir; function logError(msg) { console.log(chalk_1.default.red(msg)); } exports.logError = logError; function logSuccess(msg) { console.log(chalk_1.default.green(msg)); } exports.logSuccess = logSuccess;