From 99c787ce9235c5d01853530cbbc096a75b864e19 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 3 Dec 2022 06:34:24 -0500 Subject: [PATCH] Now it will copy the contents of the template directory, but with no processing currently. --- commands/create.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/commands/create.js b/commands/create.js index 3cae628..3e4b0e1 100644 --- a/commands/create.js +++ b/commands/create.js @@ -1,22 +1,20 @@ import fs from "fs/promises"; -import { mkdir_to, exec_i } from "../lib/builderator.js"; +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 = "Installs demo/template repositories for the Bandolier project of Learn JavaScript the Hard Way."; +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"] + ["--template", "templates directory to use for setups", "commands/templates"] ]; -export const argument = ["", "name of the project"]; +export const argument = ["", "name of the project directory (must not exist)"]; export const main = async (target, opts) => { - // cloning force is an odd feature that's much more complex - // https://stackoverflow.com/questions/2411031/how-do-i-clone-into-a-non-empty-directory - try { await fs.access(target); log.error(`Target ${target} exists. Won't install into it.`); @@ -24,6 +22,20 @@ export const main = async (target, opts) => { } 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}`); - process.exit(0); + } + + // 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}`); } }