From f0421a2976afec740c42df12ab2539d25b7dfdb4 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 2 Dec 2022 14:19:02 -0500 Subject: [PATCH] First sort of working isntaller. --- commands/create.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/commands/create.js b/commands/create.js index 630490b..e25ecff 100644 --- a/commands/create.js +++ b/commands/create.js @@ -2,14 +2,27 @@ 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/ljsthw-bandolier.git"; + export const description = "Test command."; export const options = [ - ["--force", "obliterate files in the target directory", false] + ["--repo", "repository to dupe and setup", BANDO_GIT], ]; -export const argument = ["", "name of the project"]; +export const argument = ["", "name of the project"]; -export const main = async (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 { + 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}`); + process.exit(0); + } }