UNPKG

a2r

Version:
45 lines (44 loc) 1.97 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const telemetry_1 = require("@a2r/telemetry"); const fs_1 = require("@a2r/fs"); const settings_1 = require("../settings"); const colors_1 = require("./colors"); const getFrameworkPath_1 = __importDefault(require("./getFrameworkPath")); /** * Checks if destination path has `gitignore` file and renames it to right `.gitignore` name * @param destPath Destination path */ const checkAndRenameGitIgnore = async (destPath) => { const gitIgnorePath = path_1.default.resolve(destPath, 'gitignore'); if (await (0, fs_1.exists)(gitIgnorePath)) { const rightGitIgnorePath = path_1.default.resolve(destPath, '.gitignore'); (0, colors_1.log)(`Renaming ${(0, colors_1.fullPath)(gitIgnorePath)} to ${(0, colors_1.fullPath)(rightGitIgnorePath)}...`); await (0, fs_1.rename)(gitIgnorePath, rightGitIgnorePath); } }; /** * Copies files from template to destination path * @param project Project type (next, expo, service) * @param destPath Destination path */ const copyFilesFromTemplate = async (project, destPath) => { (0, colors_1.log)(`Copying files...`); const frameworkPath = await (0, getFrameworkPath_1.default)(); const templateFolder = project === settings_1.mainTemplateFolder ? settings_1.mainTemplateFolder : settings_1.templatesFolders[project]; if (templateFolder) { const templatePath = path_1.default.resolve(frameworkPath, settings_1.templatesPath, templateFolder); await (0, fs_1.copyContents)(templatePath, destPath); await checkAndRenameGitIgnore(destPath); } else { telemetry_1.out.error(`No template path found for project ${project}`); } }; exports.default = copyFilesFromTemplate;