|
|
|
import fs from "fs/promises";
|
|
|
|
import { mkdir_to, exec_i } from "../lib/builderator.js";
|
|
|
|
import { log } from "../lib/logging.js";
|
|
|
|
|
|
|
|
export const BANDO_GIT = "https://git.learnjsthehardway.com/learn-javascript-the-hard-way/bandolier-template.git";
|
|
|
|
|
|
|
|
export const description = "Test command.";
|
|
|
|
|
|
|
|
export const options = [
|
|
|
|
["--repo", "repository to dupe and setup", BANDO_GIT],
|
|
|
|
["--templates", "templates directory to use for setups", "commands/templates"]
|
|
|
|
];
|
|
|
|
|
|
|
|
export const argument = ["<target>", "name of the project"];
|
|
|
|
|
|
|
|
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.`);
|
|
|
|
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} --templates=${opts.templates}`);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
}
|