UNPKG

create-completion-spec

Version:

Initialize a Fig custom spec boilerplate in the current directory

49 lines (48 loc) 2.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBoilerplateFolder = void 0; const path_1 = __importDefault(require("path")); const picocolors_1 = __importDefault(require("picocolors")); const fs_1 = __importDefault(require("fs")); const child_process_1 = require("child_process"); function rCopySync(from, to) { if (fs_1.default.existsSync(from)) { fs_1.default.mkdirSync(path_1.default.dirname(to), { recursive: true }); if (fs_1.default.statSync(from).isDirectory()) { const children = fs_1.default.readdirSync(from); for (const child of children) { rCopySync(path_1.default.resolve(from, child), path_1.default.resolve(to, child)); } } else { fs_1.default.copyFileSync(from, to); } } } function createBoilerplateFolder() { const dir = path_1.default.join(process.cwd(), ".fig", "autocomplete"); if (!fs_1.default.existsSync(dir)) { const boilerplateDir = path_1.default.resolve(__dirname, "..", "boilerplate"); console.log(picocolors_1.default.yellow("Copying boilerplate directory...")); try { rCopySync(boilerplateDir, dir.replace(/(\s)/g, "\\$1")); } catch (_a) { throw new Error("An error occurred while copying the boilerplate directory"); } console.log(picocolors_1.default.green("Finished copying boilerplate directory")); console.log("----"); console.log(picocolors_1.default.yellow("Installing npm deps...")); try { (0, child_process_1.execSync)("npm i", { cwd: dir }); console.log(picocolors_1.default.green("Finished installing npm deps")); } catch (_b) { console.log(picocolors_1.default.red("Error installing npm deps, please install them manually")); } } } exports.createBoilerplateFolder = createBoilerplateFolder;