update
This commit is contained in:
parent
93af3cd0e1
commit
6618463e0a
@ -30,6 +30,7 @@
|
|||||||
"beautylog": "^6.0.0",
|
"beautylog": "^6.0.0",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"shelljs": "^0.7.5",
|
"shelljs": "^0.7.5",
|
||||||
|
"simple-git": "^1.62.0",
|
||||||
"smartfile": "^4.1.0",
|
"smartfile": "^4.1.0",
|
||||||
"smartpath": "^3.2.5",
|
"smartpath": "^3.2.5",
|
||||||
"smartstring": "^2.0.22",
|
"smartstring": "^2.0.22",
|
||||||
|
@ -1,10 +1,3 @@
|
|||||||
import plugins = require("./smartgit.plugins");
|
import plugins = require("./smartgit.plugins");
|
||||||
|
|
||||||
export {add} from "./smartgit.add";
|
export * from './smartgit.classes.smartgit'
|
||||||
export {clone} from "./smartgit.clone";
|
|
||||||
export {commit} from "./smartgit.commit";
|
|
||||||
export {init} from "./smartgit.init";
|
|
||||||
export {pull} from "./smartgit.pull";
|
|
||||||
export {push} from "./smartgit.push";
|
|
||||||
export {remote} from "./smartgit.remote";
|
|
||||||
export {status} from "./smartgit.status";
|
|
||||||
|
@ -1,19 +1,4 @@
|
|||||||
import * as plugins from "./smartgit.plugins";
|
import * as plugins from "./smartgit.plugins";
|
||||||
import * as helpers from "./smartgit.helpers";
|
|
||||||
|
|
||||||
let addAll = (dirPathArg:string) => {
|
|
||||||
let done = plugins.Q.defer();
|
|
||||||
if(!helpers.isGitDirectory(dirPathArg)){
|
|
||||||
let err = new Error("smartgit.add expects a valid git directory!");
|
|
||||||
plugins.beautylog.error(err.message);
|
|
||||||
done.reject(err);
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
// if everything is ok proceed
|
|
||||||
plugins.shelljs.exec(`(cd ${dirPathArg} && git add -A && git status)`);
|
|
||||||
done.resolve(dirPathArg);
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
export let add = {
|
export let add = {
|
||||||
addAll: addAll
|
addAll: addAll
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
import plugins = require("./smartgit.plugins");
|
|
||||||
export = function(repoArg) {
|
|
||||||
return true;
|
|
||||||
};
|
|
92
ts/smartgit.classes.smartgit.ts
Normal file
92
ts/smartgit.classes.smartgit.ts
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
import * as q from 'q'
|
||||||
|
import * as plugins from './smartgit.plugins'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class GitRepo allows access to git directories from node
|
||||||
|
*/
|
||||||
|
export class GitRepo {
|
||||||
|
repoBase: string
|
||||||
|
constructor(repoBaseArg: string) {
|
||||||
|
this.repoBase = repoBaseArg
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks if the Repo is valid
|
||||||
|
*/
|
||||||
|
check(): boolean {
|
||||||
|
try {
|
||||||
|
return plugins.smartfile.fs.isDirectory(plugins.path.join(this.repoBase, '.git'))
|
||||||
|
} catch (err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stage all files in working directory
|
||||||
|
*/
|
||||||
|
addAll(dirPathArg: string) {
|
||||||
|
let done = q.defer()
|
||||||
|
plugins.shelljs.exec(`(cd ${dirPathArg} && git add -A && git status)`)
|
||||||
|
done.resolve(dirPathArg)
|
||||||
|
return done.promise
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* commit all files that are currently staged
|
||||||
|
*/
|
||||||
|
commit(commitMessage: string) {
|
||||||
|
let done = q.defer()
|
||||||
|
plugins.shelljs.exec(`(cd ${this.repoBase} && git commit -m "${commitMessage}")`)
|
||||||
|
done.resolve()
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pull latest changes from remote
|
||||||
|
*/
|
||||||
|
pull(sourceArg: string = '', branchArg: string = '') {
|
||||||
|
let done = q.defer()
|
||||||
|
// if everything is allright proceed
|
||||||
|
plugins.shelljs.exec(`(cd ${this.repoBase} && git pull ${sourceArg} ${branchArg})`)
|
||||||
|
done.resolve()
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* push new commits to remote
|
||||||
|
*/
|
||||||
|
push(remoteNameArg: string = '', remoteBranchArg: string = '') {
|
||||||
|
let done = q.defer()
|
||||||
|
// if everything seems allright proceed
|
||||||
|
plugins.shelljs.exec(`(cd ${this.repoBase} && git push ${remoteNameArg} ${remoteBranchArg})`)
|
||||||
|
done.resolve()
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sync
|
||||||
|
*/
|
||||||
|
sync() {
|
||||||
|
this.pull().then(() => {
|
||||||
|
this.push()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export let createRepoFromClone = (fromArg: string, toArg: string) => {
|
||||||
|
let done = q.defer<GitRepo>()
|
||||||
|
plugins.smartfile.fs.ensureDir(toArg)
|
||||||
|
plugins.shelljs.exec(`git clone ${fromArg} ${toArg}`)
|
||||||
|
let newRepo = new GitRepo(toArg)
|
||||||
|
done.resolve(newRepo)
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
export let createRepoFromInit = (destinationDirArg: string) => {
|
||||||
|
let done = q.defer<GitRepo>()
|
||||||
|
plugins.smartfile.fs.ensureDir(destinationDirArg)
|
||||||
|
plugins.shelljs.exec(`cd destinationDirArg && git init`)
|
||||||
|
let newRepo = new GitRepo(destinationDirArg)
|
||||||
|
done.resolve(newRepo)
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
import plugins = require("./smartgit.plugins");
|
|
||||||
import SmartgitCheck = require("./smartgit.check");
|
|
||||||
|
|
||||||
export let clone = (optionsArg: {
|
|
||||||
from: string,
|
|
||||||
to: string,
|
|
||||||
key?: string,
|
|
||||||
keyPath?: string,
|
|
||||||
keyPassphrase?: string
|
|
||||||
}) => {
|
|
||||||
let done = plugins.Q.defer();
|
|
||||||
plugins.smartfile.fs.ensureDir(optionsArg.to);
|
|
||||||
plugins.shelljs.exec(`git clone ${optionsArg.from} ${optionsArg.to}`);
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
@ -1,16 +0,0 @@
|
|||||||
import * as plugins from "./smartgit.plugins";
|
|
||||||
import * as helpers from "./smartgit.helpers";
|
|
||||||
|
|
||||||
export let commit = (dirPathArg:string,commitMessage:string) => {
|
|
||||||
let done = plugins.Q.defer();
|
|
||||||
if(!helpers.isGitDirectory(dirPathArg)){
|
|
||||||
let err = new Error("smartgit.commit expects a valid git directory");
|
|
||||||
plugins.beautylog.error(err.message);
|
|
||||||
done.reject(err);
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
// if everything is all right proceed
|
|
||||||
plugins.shelljs.exec(`(cd ${dirPathArg} && git commit -m "${commitMessage}")`);
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
@ -1,12 +0,0 @@
|
|||||||
import * as plugins from "./smartgit.plugins";
|
|
||||||
|
|
||||||
export let isGitDirectory = (dirPathArg):boolean => {
|
|
||||||
try {
|
|
||||||
return plugins.smartfile.fs.isDirectory(
|
|
||||||
plugins.path.join(dirPathArg,".git")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch(err){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
import plugins = require("./smartgit.plugins");
|
|
||||||
|
|
||||||
export let init = (dirPathArg:string) => {
|
|
||||||
let done = plugins.Q.defer();
|
|
||||||
if (typeof dirPathArg == "undefined") { //lets check if a destination is defined...
|
|
||||||
let err = new Error("smartgit.init requires an absolute directory path!")
|
|
||||||
plugins.beautylog.error(err.message);
|
|
||||||
done.reject("err");
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
plugins.smartfile.fs.ensureDir(dirPathArg);
|
|
||||||
plugins.shelljs.exec(`(cd ${dirPathArg} && git init)`);
|
|
||||||
done.resolve(dirPathArg);
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
@ -1,8 +1,7 @@
|
|||||||
import "typings-global"
|
import 'typings-global'
|
||||||
export import path = require("path")
|
export import path = require('path')
|
||||||
export import beautylog = require("beautylog")
|
export import beautylog = require('beautylog')
|
||||||
export import Q = require("q")
|
export import shelljs = require('shelljs')
|
||||||
export import shelljs = require("shelljs")
|
export import smartfile = require('smartfile')
|
||||||
export import smartfile = require("smartfile")
|
export import smartpath = require('smartpath')
|
||||||
export import smartpath = require("smartpath")
|
export import smartstring = require('smartstring')
|
||||||
export import smartstring = require("smartstring")
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
import * as plugins from "./smartgit.plugins";
|
|
||||||
import * as helpers from "./smartgit.helpers";
|
|
||||||
|
|
||||||
export let pull = (dirPathArg:string,sourceArg:string = "", branchArg:string = "") => {
|
|
||||||
let done = plugins.Q.defer();
|
|
||||||
if(!helpers.isGitDirectory(dirPathArg)){
|
|
||||||
let err = new Error("smartgit.pull expects a valid git directory");
|
|
||||||
plugins.beautylog.error(err.message);
|
|
||||||
done.reject(err);
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
// if everything is allright proceed
|
|
||||||
plugins.shelljs.exec(`(cd ${dirPathArg} && git pull ${sourceArg} ${branchArg})`);
|
|
||||||
done.resolve(dirPathArg);
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
@ -1,16 +0,0 @@
|
|||||||
import * as plugins from "./smartgit.plugins";
|
|
||||||
import * as helpers from "./smartgit.helpers";
|
|
||||||
|
|
||||||
export let push = (dirPathArg:string, remoteNameArg:string = "", remoteBranchArg:string = "") => {
|
|
||||||
let done = plugins.Q.defer();
|
|
||||||
if(!helpers.isGitDirectory(dirPathArg)){
|
|
||||||
let err = new Error("smartgit.push expects a valid git directory");
|
|
||||||
plugins.beautylog.error(err.message);
|
|
||||||
done.reject(err);
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
// if everything seems allright proceed
|
|
||||||
plugins.shelljs.exec(`(cd ${dirPathArg} && git push ${remoteNameArg} ${remoteBranchArg})`);
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "tslint-config-standard"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user