|
|
@ -1,22 +1,20 @@ |
|
|
|
import fs from "fs/promises"; |
|
|
|
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 { 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 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 = [ |
|
|
|
export const options = [ |
|
|
|
["--repo", "repository to dupe and setup", BANDO_GIT], |
|
|
|
["--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 = ["<target>", "name of the project"]; |
|
|
|
export const argument = ["<target>", "name of the project directory (must not exist)"]; |
|
|
|
|
|
|
|
|
|
|
|
export const main = async (target, opts) => { |
|
|
|
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 { |
|
|
|
try { |
|
|
|
await fs.access(target); |
|
|
|
await fs.access(target); |
|
|
|
log.error(`Target ${target} exists. Won't install into it.`); |
|
|
|
log.error(`Target ${target} exists. Won't install into it.`); |
|
|
@ -24,6 +22,20 @@ export const main = async (target, opts) => { |
|
|
|
} catch(error) { |
|
|
|
} catch(error) { |
|
|
|
// access is stupid, it throws an exception but we want the negative response as a positive outcome
|
|
|
|
// 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}`); |
|
|
|
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}`); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|