diff --git a/clone.js b/clone.js new file mode 100755 index 000000000..a1f308b0b --- /dev/null +++ b/clone.js @@ -0,0 +1,59 @@ +#! /usr/bin/env node + +// NPM ecosystem includes +const parseArgs = require("minimist") +const path = require("path") +const fs = require("fs") +const os = require("os") +const { spawn } = require("child_process") + +// Particles Includes +const { Disk } = require("scrollsdk/products/Disk.node.js") +const { Particle } = require("scrollsdk/products/Particle.js") +const { ScrollCli, ScrollFile, ScrollFileSystem, SimpleCLI } = require("./scroll.js") +const packageJson = require("./package.json") + +class CloneCli extends SimpleCLI { + welcomeMessage = `\nšŸ‘Æ WELCOME TO CLONE` + + async cloneCommand(cwd, urls) { + for (const gitUrl of urls) { + const protocolPrefix = gitUrl.startsWith("http") ? "" : "https://" + const url = new URL(protocolPrefix + gitUrl) + const { hostname, pathname } = url + let cloneUrl = gitUrl + let folderName = pathname.replace(/\.git$/, "") + if (pathname.length < 2) { + // Allow cloning of domains like: clone capitaldb.togger.com + folderName = hostname + cloneUrl = url + hostname + ".git" + } + const cloneCommand = `git clone ${cloneUrl} ${folderName}` + console.log(`Running: ${cloneCommand}`) + + const cloneProcess = spawn("git", ["clone", cloneUrl, folderName], { cwd }) + + cloneProcess.stdout.on("data", data => { + process.stdout.write(data.toString()) + }) + + cloneProcess.stderr.on("data", data => { + process.stderr.write(data.toString()) + }) + + cloneProcess.on("close", async code => { + if (code === 0) { + console.log(`Cloned successfully into ${folderName}`) + const scrollCli = new ScrollCli() + await scrollCli.buildCommand(path.join(cwd, folderName)) + } else { + console.error(`git clone failed with code ${code}`) + } + }) + } + } +} + +if (module && !module.parent) new CloneCli().cloneCommand(process.cwd(), parseArgs(process.argv.slice(2))._) + +module.exports = { CloneCli } diff --git a/package.json b/package.json index ce780e7ae..e1cb41a74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scroll-cli", - "version": "141.3.1", + "version": "142.0.0", "description": "A language for scientists of all ages. A curated collection of tools for refining and sharing thoughts.", "main": "scroll.js", "engines": { @@ -16,7 +16,8 @@ "test": "node tests/scroll.test.js" }, "bin": { - "scroll": "./scroll.js" + "scroll": "./scroll.js", + "clone": "./clone.js" }, "files": [ "scroll.js", diff --git a/releaseNotes.scroll b/releaseNotes.scroll index 78eda0c4c..0a1845f2e 100644 --- a/releaseNotes.scroll +++ b/releaseNotes.scroll @@ -20,6 +20,9 @@ ciBadges.scroll br thinColumns +šŸ“¦ 142.0.0 10/14/2024 +šŸŽ‰ added new `clone` cli command + šŸ“¦ 141.3.1 10/14/2024 āš ļø BREAKING: whoops! major format regression