Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
breck7 committed Oct 15, 2024
1 parent aba1959 commit f9b0df7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
59 changes: 59 additions & 0 deletions clone.js
Original file line number Diff line number Diff line change
@@ -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 }
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -16,7 +16,8 @@
"test": "node tests/scroll.test.js"
},
"bin": {
"scroll": "./scroll.js"
"scroll": "./scroll.js",
"clone": "./clone.js"
},
"files": [
"scroll.js",
Expand Down
3 changes: 3 additions & 0 deletions releaseNotes.scroll
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f9b0df7

Please sign in to comment.