From 6618463e0a458ace01dfb75ebe297f94812fb506 Mon Sep 17 00:00:00 2001 From: PhilKunz Date: Tue, 22 Nov 2016 00:07:36 +0100 Subject: [PATCH] update --- package.json | 1 + ts/index.ts | 9 +--- ts/smartgit.add.ts | 15 ------ ts/smartgit.check.ts | 4 -- ts/smartgit.classes.smartgit.ts | 92 +++++++++++++++++++++++++++++++++ ts/smartgit.clone.ts | 16 ------ ts/smartgit.commit.ts | 16 ------ ts/smartgit.helpers.ts | 12 ----- ts/smartgit.init.ts | 15 ------ ts/smartgit.plugins.ts | 15 +++--- ts/smartgit.pull.ts | 16 ------ ts/smartgit.push.ts | 16 ------ tslint.json | 3 ++ 13 files changed, 104 insertions(+), 126 deletions(-) delete mode 100644 ts/smartgit.check.ts create mode 100644 ts/smartgit.classes.smartgit.ts delete mode 100644 ts/smartgit.clone.ts delete mode 100644 ts/smartgit.commit.ts delete mode 100644 ts/smartgit.helpers.ts delete mode 100644 ts/smartgit.init.ts delete mode 100644 ts/smartgit.pull.ts delete mode 100644 ts/smartgit.push.ts create mode 100644 tslint.json diff --git a/package.json b/package.json index 6773fc1..bc887ae 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "beautylog": "^6.0.0", "q": "^1.4.1", "shelljs": "^0.7.5", + "simple-git": "^1.62.0", "smartfile": "^4.1.0", "smartpath": "^3.2.5", "smartstring": "^2.0.22", diff --git a/ts/index.ts b/ts/index.ts index f3f9b88..c571037 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,10 +1,3 @@ import plugins = require("./smartgit.plugins"); -export {add} from "./smartgit.add"; -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"; +export * from './smartgit.classes.smartgit' diff --git a/ts/smartgit.add.ts b/ts/smartgit.add.ts index e504b92..c181845 100644 --- a/ts/smartgit.add.ts +++ b/ts/smartgit.add.ts @@ -1,19 +1,4 @@ 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 = { addAll: addAll diff --git a/ts/smartgit.check.ts b/ts/smartgit.check.ts deleted file mode 100644 index b407e1e..0000000 --- a/ts/smartgit.check.ts +++ /dev/null @@ -1,4 +0,0 @@ -import plugins = require("./smartgit.plugins"); -export = function(repoArg) { - return true; -}; \ No newline at end of file diff --git a/ts/smartgit.classes.smartgit.ts b/ts/smartgit.classes.smartgit.ts new file mode 100644 index 0000000..f112b02 --- /dev/null +++ b/ts/smartgit.classes.smartgit.ts @@ -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() + 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() + plugins.smartfile.fs.ensureDir(destinationDirArg) + plugins.shelljs.exec(`cd destinationDirArg && git init`) + let newRepo = new GitRepo(destinationDirArg) + done.resolve(newRepo) +} diff --git a/ts/smartgit.clone.ts b/ts/smartgit.clone.ts deleted file mode 100644 index 6b3bbe4..0000000 --- a/ts/smartgit.clone.ts +++ /dev/null @@ -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; -}; diff --git a/ts/smartgit.commit.ts b/ts/smartgit.commit.ts deleted file mode 100644 index 0649b9c..0000000 --- a/ts/smartgit.commit.ts +++ /dev/null @@ -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; -}; \ No newline at end of file diff --git a/ts/smartgit.helpers.ts b/ts/smartgit.helpers.ts deleted file mode 100644 index 09aba2e..0000000 --- a/ts/smartgit.helpers.ts +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/ts/smartgit.init.ts b/ts/smartgit.init.ts deleted file mode 100644 index 0c2bf9d..0000000 --- a/ts/smartgit.init.ts +++ /dev/null @@ -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; -}; \ No newline at end of file diff --git a/ts/smartgit.plugins.ts b/ts/smartgit.plugins.ts index bd0a019..ef1b9f8 100644 --- a/ts/smartgit.plugins.ts +++ b/ts/smartgit.plugins.ts @@ -1,8 +1,7 @@ -import "typings-global" -export import path = require("path") -export import beautylog = require("beautylog") -export import Q = require("q") -export import shelljs = require("shelljs") -export import smartfile = require("smartfile") -export import smartpath = require("smartpath") -export import smartstring = require("smartstring") +import 'typings-global' +export import path = require('path') +export import beautylog = require('beautylog') +export import shelljs = require('shelljs') +export import smartfile = require('smartfile') +export import smartpath = require('smartpath') +export import smartstring = require('smartstring') diff --git a/ts/smartgit.pull.ts b/ts/smartgit.pull.ts deleted file mode 100644 index b4f9c05..0000000 --- a/ts/smartgit.pull.ts +++ /dev/null @@ -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; -}; \ No newline at end of file diff --git a/ts/smartgit.push.ts b/ts/smartgit.push.ts deleted file mode 100644 index 285cd52..0000000 --- a/ts/smartgit.push.ts +++ /dev/null @@ -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; -}; \ No newline at end of file diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..45052ad --- /dev/null +++ b/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "tslint-config-standard" +}