import fs from "fs/promises"; import { mkdir_to, exec_i, copy, glob } from "../lib/builderator.js"; import { log } from "../lib/logging.js"; import path from "path"; export const BANDO_GIT = "https://git.learnjsthehardway.com/learn-javascript-the-hard-way/bandolier-template.git"; export const description = "Generates projects using the Bandolier educational framework."; export const options = [ ["--repo", "repository to dupe and setup", BANDO_GIT], ["--template", "templates directory to use for setups", "commands/templates"] ]; export const argument = ["", "name of the project directory (must not exist)"]; export const main = async (target, opts) => { try { await fs.access(target); log.error(`Target ${target} exists. Won't install into it.`); process.exit(1); } catch(error) { // access is stupid, it throws an exception but we want the negative response as a positive outcome exec_i(`git clone --depth 1 ${BANDO_GIT} ${target}`); } // normalize the temp directory const temp_dir = path.join(opts.template, ''); const temp_files = glob(path.join(target, temp_dir, "/**/*")); log.info("Copying template files..."); // copy all of the template files to the destination for(let f of temp_files) { // kind of dumb way to trim the middle of the path out const copy_to = f.replace(`${temp_dir}/`, ''); mkdir_to(copy_to); copy(f, copy_to); // we can add a template thing here log.debug(`${f} ---> ${copy_to}`); } }