Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clonit

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clonit - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

80

lib/clonit.js
const path = require('path');
const url = require('url');
const { URL }= require('url');
const del = require('del');
const isURL = require('is-whatwg-url');
const git = require('./git');
function clonit (input, options) {
function normalizeInput (input) {
if (input.length < 2) {
return process.exit(1);
throw new Error('missing arguments')
}
// get source repo
const sourceRepo = input[0]
if (!isURL(sourceRepo)) throw new Error('invalid input');
// get target repo, folder name
let targetRepo, folderName;
if (input.length < 3) {
const target = input[1];
// get starter repo url
const sourceRepo = input[0];
if (isURL(target)) {
// get target folder name
let folderName;
let targetRepo;
// target is repository url
targetRepo = target;
// get folder name
folderName = path.parse(targetRepo).name;
if (input.length < 3) {
} else {
folderName = input[1];
const parsedUrl = new url.URL(sourceRepo);
parsedUrl.pathname = path.resolve(parsedUrl.pathname, `../${folderName}`);
targetRepo = parsedUrl.toString();
// target is repository name
folderName = target;
const parsedSrcUrl = new URL(sourceRepo);
parsedSrcUrl.pathname = path.resolve(parsedSrcUrl.pathname, `../${folderName}`);
targetRepo = parsedSrcUrl.toString();
}
} else {
targetRepo = input[1];

@@ -30,2 +44,30 @@ folderName = input[2];

if (!isURL(targetRepo))
throw new Error('invalid input');
if (typeof folderName !== 'string')
throw new Error('invalid input');
return {
sourceRepo,
targetRepo,
folderName,
}
}
function clonit (input, options) {
let normalized;
try {
normalized = normalizeInput(input);
} catch (err) {
console.error(err);
process.exit(-1);
}
const {
sourceRepo,
targetRepo,
folderName,
} = normalized;
// cwd after clone

@@ -35,13 +77,13 @@ const targetCwd = path.resolve(process.cwd(), folderName);

git.clone([sourceRepo, folderName])
.then(logger('cloned'))
.then(logger(`cloned ${sourceRepo} to ${folderName}`))
.then(() => del([`${folderName}/.git`]))
.then(logger('deleted .git'))
.then(() => git.init({ cwd: targetCwd }))
.then(logger('inited'))
.then(logger('git inited'))
.then(() => git.remoteAdd(['origin', targetRepo], { cwd: targetCwd }))
.then(logger('remote added'))
.then(logger(`remote ${targetRepo} added as origin`))
.then(() => git.add(['.'], { cwd: targetCwd }))
.then(logger('added'))
.then(logger('added all file'))
.then(() => git.commit(['init'], { cwd: targetCwd }))
.then(logger('commited'))
.then(logger('first commit'))
}

@@ -48,0 +90,0 @@

{
"name": "clonit",
"version": "0.0.1",
"version": "0.0.2",
"description": "initialize your repo with cloned repository",

@@ -12,2 +12,3 @@ "main": "index.js",

"execa": "^0.10.0",
"is-whatwg-url": "^1.0.0",
"meow": "^5.0.0"

@@ -24,3 +25,9 @@ },

},
"keywords": [],
"keywords": [
"git",
"clone",
"starter",
"init",
"cli"
],
"author": "zeakd",

@@ -27,0 +34,0 @@ "license": "MIT",

@@ -24,5 +24,13 @@ # clonit

Examples
$ clonit https://github.com/zeakd/rollup-module-starter my-module # YOU SHOULD HAVE https://github.com/zeakd/my-module
$ clonit https://github.com/zeakd/rollup-module-starter my-module
remote: https://github.com/zeakd/my-module
folder: my-module
$ clonit https://github.com/zeakd/rollup-module-starter https://github.com/zeakd/my-module
remote: https://github.com/zeakd/my-module
folder: my-module
$ clonit https://github.com/zeakd/rollup-module-starter https://github.com/zeakd/my-module mine
remote: https://github.com/zeakd/my-module
folder: mine
```

@@ -29,0 +37,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc