| 1 | import path from "path"; |
| 2 | import pc from "picocolors"; |
| 3 | import fs from "fs"; |
| 4 | import { execSync } from "child_process"; |
| 5 | |
| 6 | function rCopySync(from: string, to: string) { |
| 7 | if (fs.existsSync(from)) { |
| 8 | fs.mkdirSync(path.dirname(to), { recursive: true }); |
| 9 | if (fs.statSync(from).isDirectory()) { |
| 10 | const children = fs.readdirSync(from); |
| 11 | for (const child of children) { |
| 12 | rCopySync(path.resolve(from, child), path.resolve(to, child)); |
| 13 | } |
| 14 | } else { |
| 15 | fs.copyFileSync(from, to); |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | export function createBoilerplateFolder() { |
| 21 | const dir = path.join(process.cwd(), ".fig", "autocomplete"); |
| 22 | if (!fs.existsSync(dir)) { |
| 23 | const boilerplateDir = path.resolve(__dirname, "..", "boilerplate"); |
| 24 | console.log(pc.yellow("Copying boilerplate directory...")); |
| 25 | try { |
| 26 | rCopySync(boilerplateDir, dir.replace(/(\s)/g, "\\$1")); |
| 27 | } catch { |
| 28 | throw new Error("An error occurred while copying the boilerplate directory"); |
| 29 | } |
| 30 | console.log(pc.green("Finished copying boilerplate directory")); |
| 31 | console.log("----"); |
| 32 | console.log(pc.yellow("Installing npm deps...")); |
| 33 | try { |
| 34 | execSync("npm i", { cwd: dir }); |
| 35 | console.log(pc.green("Finished installing npm deps")); |
| 36 | } catch { |
| 37 | console.log(pc.red("Error installing npm deps, please install them manually")); |
| 38 | } |
| 39 | } |
| 40 | } |