UNPKG

st-create-app

Version:
60 lines 2.62 kB
"use strict"; var __values = (this && this.__values) || function (o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; }; Object.defineProperty(exports, "__esModule", { value: true }); var path = require('path'); var fs = require('fs-extra'); var chalk = require('chalk'); var logFiles_1 = require("../definition/logFiles"); var filesAllowedToResistInAppDir_1 = require("../definition/filesAllowedToResistInAppDir"); exports.isSafeToCreateAppIn = function (rootPath, name) { var e_1, _a; console.log(); var conflicts = fs .readdirSync(rootPath) .filter(function (file) { return !filesAllowedToResistInAppDir_1.filesAllowedToResistInAppDir.includes(file); }) // IntelliJ IDEA creates module files before CRA is launched .filter(function (file) { return !/\.iml$/.test(file); }) // Don't treat log files from previous installation as conflicts .filter(function (file) { return !logFiles_1.logFiles.some(function (pattern) { return file.indexOf(pattern) === 0; }); }); if (conflicts.length > 0) { console.log("The directory " + chalk.green(name) + " contains files that could conflict:"); console.log(); try { for (var conflicts_1 = __values(conflicts), conflicts_1_1 = conflicts_1.next(); !conflicts_1_1.done; conflicts_1_1 = conflicts_1.next()) { var file = conflicts_1_1.value; console.log(" " + file); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (conflicts_1_1 && !conflicts_1_1.done && (_a = conflicts_1.return)) _a.call(conflicts_1); } finally { if (e_1) throw e_1.error; } } console.log(); console.log('Either try using a new directory name, or remove the files listed above.'); return false; } // Remove any remnant files from a previous installation var currentFiles = fs.readdirSync(path.join(rootPath)); currentFiles.forEach(function (file) { logFiles_1.logFiles.forEach(function (errorLogFilePattern) { // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files if (file.indexOf(errorLogFilePattern) === 0) { fs.removeSync(path.join(rootPath, file)); } }); }); return true; }; //# sourceMappingURL=isSafeToCreateAppIn.js.map