UNPKG

create-nx-workspace

Version:

Smart Repos · Fast Builds

26 lines (25 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cloneTemplate = cloneTemplate; const child_process_utils_1 = require("../child-process-utils"); const fs_1 = require("fs"); const promises_1 = require("fs/promises"); const path_1 = require("path"); const error_utils_1 = require("../error-utils"); async function cloneTemplate(templateUrl, targetDirectory) { if ((0, fs_1.existsSync)(targetDirectory)) { throw new error_utils_1.CnwError('DIRECTORY_EXISTS', `The directory '${targetDirectory}' already exists. Choose a different name or remove the existing directory.`); } try { await (0, child_process_utils_1.execAndWait)(`git clone --depth 1 "${templateUrl}" "${targetDirectory}"`, process.cwd()); // Ensure clean history const gitDir = (0, path_1.join)(targetDirectory, '.git'); if ((0, fs_1.existsSync)(gitDir)) { await (0, promises_1.rm)(gitDir, { recursive: true, force: true }); } } catch (e) { const message = e instanceof Error ? e.message : String(e); throw new error_utils_1.CnwError('TEMPLATE_CLONE_FAILED', `Failed to create starter workspace: ${message}`); } }