improve structure
This commit is contained in:
parent
a2d9a3a3e5
commit
981cb04161
109
index.js
109
index.js
@ -1,47 +1,90 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
/// <reference path="./index.ts" />
|
||||||
var path = require("path");
|
var SmartgitPlugins;
|
||||||
var beautylog = require("beautylog")("os");
|
(function (SmartgitPlugins) {
|
||||||
var nodegit = require("nodegit");
|
SmartgitPlugins.init = function () {
|
||||||
var smartgit = {};
|
var plugins = {
|
||||||
smartgit.clone = function (cloneURL, dest) {
|
path: require("path"),
|
||||||
if (cloneURL === void 0) { cloneURL = "undefined"; }
|
beautylog: require("beautylog"),
|
||||||
if (dest === void 0) { dest = "undefined"; }
|
nodegit: require("nodegit"),
|
||||||
if (cloneURL == "undefined" || dest == "undefined") {
|
Q: require("q")
|
||||||
beautylog.error("smartgit.clone".blue + " : Something is strange about the way you invoked the function");
|
};
|
||||||
|
return plugins;
|
||||||
|
};
|
||||||
|
})(SmartgitPlugins || (SmartgitPlugins = {}));
|
||||||
|
/// <reference path="./index.ts" />
|
||||||
|
var SmartgitClone;
|
||||||
|
(function (SmartgitClone) {
|
||||||
|
function init() {
|
||||||
|
var clone = function (options) {
|
||||||
|
/***** URL Checks ******/
|
||||||
|
if (options.from == "undefined" || options.to == "undefined") {
|
||||||
|
plugins.beautylog.error("smartgit.clone".blue + " : Something is strange about the way you invoked the function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!/^\/.*/.test(dest)) {
|
/***** Path Checks ******/
|
||||||
beautylog.error("It seems that the given path " + dest + " is not absolute.");
|
if (!/^\/.*/.test(options.to)) {
|
||||||
|
plugins.beautylog.error("It seems that the given path " + options.to + " is not absolute.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
beautylog.log("Now cloning " + cloneURL);
|
plugins.beautylog.log("Now cloning " + options.from);
|
||||||
var cloneOptions = {};
|
var cloneOptions = {};
|
||||||
cloneOptions.remoteCallbacks = {
|
var cloneRepository = plugins.nodegit.Clone(options.from, options.to, cloneOptions);
|
||||||
certificateCheck: function () { return 1; },
|
smartgit.check(cloneRepository);
|
||||||
credentials: function (url, userName) {
|
};
|
||||||
return nodegit.Cred.sshKeyFromAgent(userName);
|
return clone;
|
||||||
}
|
}
|
||||||
};
|
SmartgitClone.init = init;
|
||||||
var cloneRepository = nodegit.Clone(cloneURL, dest, {});
|
})(SmartgitClone || (SmartgitClone = {}));
|
||||||
var errorAndAttemptOpen = function () {
|
/// <reference path="./index.ts" />
|
||||||
return nodegit.Repository.open(dest);
|
var SmartgitInit;
|
||||||
};
|
(function (SmartgitInit) {
|
||||||
cloneRepository.catch(errorAndAttemptOpen)
|
SmartgitInit.init = function () {
|
||||||
.then(function (repository) {
|
var gitinit = function (dest) {
|
||||||
// Access any repository methods here.
|
|
||||||
console.log("Is the repository bare? %s", Boolean(repository.isBare()));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
smartgit.commit = function (commitMessage) {
|
|
||||||
};
|
|
||||||
smartgit.init = function (dest) {
|
|
||||||
if (dest === void 0) { dest = "undefined"; }
|
if (dest === void 0) { dest = "undefined"; }
|
||||||
if (dest == "undefined") {
|
if (dest == "undefined") {
|
||||||
return; // ...and return function here if not
|
return; // ...and return function here if not
|
||||||
}
|
}
|
||||||
var isBare = 0; //lets create a subfolder
|
var isBare = 0; //lets create a subfolder
|
||||||
nodegit.Repository.init(dest, isBare).then(function (repo) {
|
plugins.nodegit.Repository.init(dest, isBare).then(function (repo) {
|
||||||
// do something with repo here.
|
// do something with repo here.
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
return gitinit;
|
||||||
|
};
|
||||||
|
})(SmartgitInit || (SmartgitInit = {}));
|
||||||
|
/// <reference path="./index.ts" />
|
||||||
|
var SmartgitCommit;
|
||||||
|
(function (SmartgitCommit) {
|
||||||
|
SmartgitCommit.init = function () {
|
||||||
|
var commit = function (pathArg, commitMessage) {
|
||||||
|
var result = plugins.nodegit.index.addByPath(pathArg);
|
||||||
|
if (result == 0) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return commit;
|
||||||
|
};
|
||||||
|
})(SmartgitCommit || (SmartgitCommit = {}));
|
||||||
|
/// <reference path="./index.ts" />
|
||||||
|
var SmartgitCheck;
|
||||||
|
(function (SmartgitCheck) {
|
||||||
|
SmartgitCheck.init = function () {
|
||||||
|
var check = function () {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
return check;
|
||||||
|
};
|
||||||
|
})(SmartgitCheck || (SmartgitCheck = {}));
|
||||||
|
/// <reference path="typings/tsd.d.ts" />
|
||||||
|
/// <reference path="smartgit.plugins.ts" />
|
||||||
|
/// <reference path="smartgit.clone.ts" />
|
||||||
|
/// <reference path="smartgit.init.ts" />
|
||||||
|
/// <reference path="smartgit.commit.ts" />
|
||||||
|
/// <reference path="smartgit.check.ts" />
|
||||||
|
var plugins = SmartgitPlugins.init();
|
||||||
|
//Build the smartgit object
|
||||||
|
var smartgit = {};
|
||||||
|
smartgit.clone = SmartgitClone.init();
|
||||||
|
smartgit.commit = SmartgitCommit.init();
|
||||||
|
smartgit.check = SmartgitCheck.init();
|
||||||
|
smartgit.init = SmartgitInit.init();
|
||||||
module.exports = smartgit;
|
module.exports = smartgit;
|
||||||
|
12
package.json
12
package.json
@ -4,7 +4,7 @@
|
|||||||
"description": "an easy wrapper for nodegit",
|
"description": "an easy wrapper for nodegit",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(cd ts/compile && node compile.js) && (node test.js)",
|
"test": "(npmts) && (node test.js)",
|
||||||
"reinstall": "(rm -r node_modules && npm install)",
|
"reinstall": "(rm -r node_modules && npm install)",
|
||||||
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
|
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
|
||||||
"startdev": "(git checkout master && git pull origin master)"
|
"startdev": "(git checkout master && git pull origin master)"
|
||||||
@ -25,13 +25,11 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/smartgit",
|
"homepage": "https://github.com/pushrocks/smartgit",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^1.0.2",
|
"beautylog": "2.0.2",
|
||||||
"nodegit": "^0.5.0",
|
"nodegit": "0.8.0",
|
||||||
"q": "^1.4.1"
|
"q": "1.4.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gulp": "3.9.0",
|
"npmts": "1.0.3"
|
||||||
"gulp-typescript": "2.9.2",
|
|
||||||
"pushrocks": "^1.0.20"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
test.js
7
test.js
@ -1,6 +1,9 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
/// <reference path="typings/tsd.d.ts" />
|
||||||
var smartgit = require("./index.js");
|
var smartgit = require("./index.js");
|
||||||
var beautylog = require("beautylog")("os");
|
var beautylog = require("beautylog");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
smartgit.clone("https://github.com/pushrocks/cooltest.git", path.resolve("./test/"));
|
smartgit.clone({
|
||||||
|
from: "https://github.com/pushrocks/docs.git",
|
||||||
|
to: path.resolve("./test/temp/")
|
||||||
|
});
|
||||||
beautylog.success("Test successfull");
|
beautylog.success("Test successfull");
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
// import gulp
|
|
||||||
var gulp = require("gulp")
|
|
||||||
var gulpTypescript = require("gulp-typescript");
|
|
||||||
var pr = require("pushrocks");
|
|
||||||
|
|
||||||
gulp.task('compileTS', function() {
|
|
||||||
var stream = gulp.src('../index.ts')
|
|
||||||
.pipe(gulpTypescript({
|
|
||||||
out: "index.js"
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest("../../"));
|
|
||||||
return stream;
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('compileTestTS', function() {
|
|
||||||
var stream = gulp.src('../test.ts')
|
|
||||||
.pipe(gulpTypescript({
|
|
||||||
out: "test.js"
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest("../../"));
|
|
||||||
return stream;
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('default',['compileTS','compileTestTS'], function() {
|
|
||||||
pr.beautylog.success('Typescript compiled');
|
|
||||||
});
|
|
||||||
|
|
||||||
//lets tell gulp to start with the default task.
|
|
||||||
pr.beautylog.log('Starting Gulp to compile TypeScript');
|
|
||||||
gulp.start.apply(gulp, ['default']);
|
|
@ -1,2 +0,0 @@
|
|||||||
# How to compile.
|
|
||||||
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.
|
|
38
ts/index.ts
38
ts/index.ts
@ -1,40 +1,18 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
/// <reference path="typings/tsd.d.ts" />
|
||||||
|
/// <reference path="smartgit.plugins.ts" />
|
||||||
/// <reference path="smartgit.clone.ts" />
|
/// <reference path="smartgit.clone.ts" />
|
||||||
/// <reference path="smartgit.init.ts" />
|
/// <reference path="smartgit.init.ts" />
|
||||||
/// <reference path="smartgit.commit.ts" />
|
/// <reference path="smartgit.commit.ts" />
|
||||||
|
/// <reference path="smartgit.check.ts" />
|
||||||
|
|
||||||
var plugins = {
|
var plugins = SmartgitPlugins.init();
|
||||||
path: require("path"),
|
|
||||||
beautylog: require("beautylog")("os"),
|
|
||||||
nodegit: require("nodegit"),
|
|
||||||
Q: require("q")
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
//Build the smartgit object
|
||||||
var smartgit:any = {};
|
var smartgit:any = {};
|
||||||
|
smartgit.clone = SmartgitClone.init();
|
||||||
smartgit.clone = SmartgitClone
|
smartgit.commit = SmartgitCommit.init();
|
||||||
|
smartgit.check = SmartgitCheck.init();
|
||||||
smartgit.commit = function(pathArg:string,commitMessage:string) {
|
smartgit.init = SmartgitInit.init();
|
||||||
var result = plugins.nodegit.index.addByPath(pathArg);
|
|
||||||
if (result == 0) {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
smartgit.init = function(dest:string = "undefined") {
|
|
||||||
if (dest == "undefined") { //lets check if a destination is defined...
|
|
||||||
return; // ...and return function here if not
|
|
||||||
}
|
|
||||||
var isBare = 0; //lets create a subfolder
|
|
||||||
plugins.nodegit.Repository.init(dest, isBare).then(function (repo) {
|
|
||||||
// do something with repo here.
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
smartgit.check = function(repository) {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = smartgit;
|
module.exports = smartgit;
|
||||||
|
9
ts/smartgit.check.ts
Normal file
9
ts/smartgit.check.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/// <reference path="./index.ts" />
|
||||||
|
module SmartgitCheck {
|
||||||
|
export var init = function(){
|
||||||
|
var check = function() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
return check;
|
||||||
|
}
|
||||||
|
}
|
@ -1,30 +1,24 @@
|
|||||||
/// <reference path="./index.ts" />
|
/// <reference path="./index.ts" />
|
||||||
module SmartgitClone {
|
module SmartgitClone {
|
||||||
export function init() {
|
export function init() {
|
||||||
var clone = function(cloneURL:string = "undefined" ,dest:string = "undefined"){
|
var clone = function(options){
|
||||||
|
|
||||||
/***** URL Checks ******/
|
/***** URL Checks ******/
|
||||||
if (cloneURL == "undefined" || dest == "undefined") {
|
if (options.from == "undefined" || options.to == "undefined") {
|
||||||
plugins.beautylog.error("smartgit.clone".blue + " : Something is strange about the way you invoked the function");
|
plugins.beautylog.error("smartgit.clone".blue + " : Something is strange about the way you invoked the function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Path Checks ******/
|
/***** Path Checks ******/
|
||||||
if (!/^\/.*/.test(dest)){ //check wether path is absolute
|
if (!/^\/.*/.test(options.to)){ //check wether path is absolute
|
||||||
plugins.beautylog.error("It seems that the given path " + dest + " is not absolute.");
|
plugins.beautylog.error("It seems that the given path " + options.to + " is not absolute.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
plugins.beautylog.log("Now cloning " + cloneURL);
|
plugins.beautylog.log("Now cloning " + options.from);
|
||||||
var cloneOptions:any = {};
|
var cloneOptions:any = {};
|
||||||
cloneOptions.remoteCallbacks = {
|
var cloneRepository = plugins.nodegit.Clone(options.from, options.to, cloneOptions);
|
||||||
certificateCheck: function() { return 1; },
|
|
||||||
credentials: function(url, userName) {
|
|
||||||
return plugins.nodegit.Cred.sshKeyFromAgent(userName);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var cloneRepository = plugins.nodegit.Clone(cloneURL, dest, cloneOptions);
|
|
||||||
smartgit.check(cloneRepository);
|
smartgit.check(cloneRepository);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
12
ts/smartgit.commit.ts
Normal file
12
ts/smartgit.commit.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/// <reference path="./index.ts" />
|
||||||
|
module SmartgitCommit {
|
||||||
|
export var init = function() {
|
||||||
|
var commit = function(pathArg:string,commitMessage:string) {
|
||||||
|
var result = plugins.nodegit.index.addByPath(pathArg);
|
||||||
|
if (result == 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return commit;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
/// <reference path="./index.ts" />
|
||||||
|
module SmartgitInit {
|
||||||
|
export var init = function(){
|
||||||
|
var gitinit = function(dest:string = "undefined") {
|
||||||
|
if (dest == "undefined") { //lets check if a destination is defined...
|
||||||
|
return; // ...and return function here if not
|
||||||
|
}
|
||||||
|
var isBare = 0; //lets create a subfolder
|
||||||
|
plugins.nodegit.Repository.init(dest, isBare).then(function (repo) {
|
||||||
|
// do something with repo here.
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return gitinit;
|
||||||
|
}
|
||||||
|
}
|
12
ts/smartgit.plugins.ts
Normal file
12
ts/smartgit.plugins.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/// <reference path="./index.ts" />
|
||||||
|
module SmartgitPlugins {
|
||||||
|
export var init = function() {
|
||||||
|
var plugins = {
|
||||||
|
path: require("path"),
|
||||||
|
beautylog: require("beautylog"),
|
||||||
|
nodegit: require("nodegit"),
|
||||||
|
Q: require("q")
|
||||||
|
};
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
/// <reference path="typings/tsd.d.ts" />
|
||||||
var smartgit = require("./index.js");
|
var smartgit = require("./index.js");
|
||||||
var beautylog = require("beautylog")("os");
|
var beautylog = require("beautylog");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
|
smartgit.clone({
|
||||||
|
from:"https://github.com/pushrocks/docs.git",
|
||||||
smartgit.clone("https://github.com/pushrocks/cooltest.git",path.resolve("./test/"));
|
to:path.resolve("./test/temp/")
|
||||||
|
});
|
||||||
|
|
||||||
beautylog.success("Test successfull");
|
beautylog.success("Test successfull");
|
Loading…
Reference in New Issue
Block a user