Comparing version 0.0.1 to 0.0.2
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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6632
102
56
4
+ Addedis-whatwg-url@^1.0.0
+ Addedis-whatwg-url@1.0.0(transitive)