-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters