Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
61407e4854 | |||
2771413723 | |||
b83752a98a | |||
48f71ed1c2 | |||
54ed2f97b8 | |||
92198a75c9 | |||
f82a34b1ea | |||
c3b68fa0fc | |||
1af7afd723 | |||
66e45154e3 | |||
dcc58a312e | |||
90f57bee1a | |||
98d1f8aea2 | |||
1f542367e6 | |||
201a5014ed | |||
6cc245ae7e | |||
1377fb6eb7 | |||
daf8c80513 | |||
46fce49356 | |||
8616613a95 | |||
352e4d8e96 | |||
c2105ce78f | |||
2864fc5507 | |||
fea523ff5c | |||
872f2354c5 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
108
.gitlab-ci.yml
108
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,60 +18,74 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
@ -79,33 +93,39 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -113,5 +133,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
19
.travis.yml
19
.travis.yml
@ -1,19 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- 4
|
|
||||||
- stable
|
|
||||||
before_install:
|
|
||||||
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
|
|
||||||
- sudo apt-get update
|
|
||||||
- sudo apt-get install libstdc++-4.9-dev -y
|
|
||||||
deploy:
|
|
||||||
provider: npm
|
|
||||||
email: npm@lossless.digital
|
|
||||||
api_key:
|
|
||||||
secure: o/3H4keWRAvHZaJnUN9UX+hqu+prKGtBsOEWVIaRXUpf6nIHIDm9zlJrS5cv2VUseOZqLAOkzeGYPqlOJlxccy5frKEYMhtCY97BjKvUOf01roL82OGiahw5Bv04NcaBoSepCliyyXihlgZO/5tSoR1seY4ycul2qWLktaEmh8HcTPjem8gB49Svpfk8yPKLpq6cv/sSakt2X24Cq+vfdxYiz7GcgBfv3EVAndUmQ9KMQfkSbq8XgYEZKrLi5kdpXX0y1LRdsbn2rwuMwLOmefCenmQSuBCbYmbOxPgVHHHjVm9To/rhx8YHBCcZSH9go2pdDLwrd7VPOCK+vMHCz/rlASwVM/BGr+aJHCFLAyovrIU7cvbbjLPOUjto6xY2XckMmDBD1YDxYnAJAON1QrdXE9hVVRfMNfaC2leFAwhla1WMok5DcEv+/Q9cUXQCBGQHtBhkhmCCt54ERLFnjXCDZr1icR/0lhtQY54hin5jSHqnU2hTZtTpQX7sF0yZM2sbhTBpV5FTDAGH/ohNWSEnTwAXmL9iwZCTvtWUbBeOUSDRj8BLS54uiaIcIVytNY0p2PdnhwJAWO+4FGjSOT+RuK8RiKzyVXjPiX8TCzaOqBFs947m8SSNMSt6zyqOI27gOSzU7szgsKY769Fl+X9sdzFXaSa72rj4EdvgiBA=
|
|
||||||
on:
|
|
||||||
tags: true
|
|
||||||
repo: pushrocks/smartgit
|
|
||||||
notifications:
|
|
||||||
slack:
|
|
||||||
secure: f5Uss0z9RPl/QcA/DroB8loyE93aOYI6bqCkrsiUscmZtlv/TVQtT4dxqGA6uvcG6iTQDBi3Ul88dQxWkRm4IqbhY35/iMaV2dHW4FVYMAh8GQMbsfL2sALCcufxD9blw47awv3iFcwhV1EeyesscjgL0JIjduk96v/7G/6QIO2838M1lzlgtj+kRUkim8qkaEs1je3gRrhMUIjLuAdscMXyUKYFMjWo9ACSjVUl30R/ZNemb18itIja6i92GotreBgcfEMczvy58ovDC7xdJUsY8LjMI01DwY+WPRnI0tAhsuI8moBwwcdM4e3bAjKjucQRjO33O5bMWRZ6QCiYd0DnCEFyCPQLJ4GSy/tkD00n8ijLHAOSV3AH1zNbdK1EAdSPQXDvlI36KJn/2hyQLoitGHVUPr76ujJWP82ypO2tgIp3XQU0dJVCxDuHnwJO2+hjdI+gCPqxNTpjeujHx3UdkTGNRjuuf9dlZ/D08fApjYxy2fxItTqo3QjP/nrqvBXUOPP8yPHpjIT4H2t5Pr4SJjBGI6X4qhKyFj6s9rA/Xu1rL+45zu1C3uC3z+u3T9UwrbzJ/cZM6r6UQvQmUvIfBNaMlg4I/diQCDIPL+Rhop2nylY3IcHmJnk2itn7kOqj1tohCpFEml5pRuSZy4udWywkdtyBAsHWFLF7oiQ=
|
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Push.Rocks
|
Copyright (c) 2015 Lossless GmbH
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
76
README.md
76
README.md
@ -1,76 +0,0 @@
|
|||||||
# @pushrocks/smartgit
|
|
||||||
smart wrapper for nodegit
|
|
||||||
|
|
||||||
## Availabililty and Links
|
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartgit)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartgit)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartgit)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartgit/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/smartgit/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartgit/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartgit)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartgit)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://prettier.io/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
We recommend the use of TypeScript for best in class intellisense
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// import smartgit:
|
|
||||||
import { GitRepo } from 'smartgit';
|
|
||||||
|
|
||||||
// Initialize smartgit:
|
|
||||||
// -- note: there are 3 ways to initialize smartgit
|
|
||||||
// -- -- 1. with a existing Git repo
|
|
||||||
// -- -- 2. with a cloned Git repo
|
|
||||||
// -- -- 3. with a new Git repo
|
|
||||||
|
|
||||||
// -- 1. existing Git Repo:
|
|
||||||
let myExistingGitRepo = new GitRepo('/path/to/existing/git/repo/');
|
|
||||||
|
|
||||||
// -- 2. cloned Git Repo:
|
|
||||||
let myClonedGitRepo: GitRepo;
|
|
||||||
smartgit.createRepoFromClone('git@github.com:username/reponame.git').then(gitRepo => {
|
|
||||||
// non blocking
|
|
||||||
myClonedGitRepo = gitRepo;
|
|
||||||
});
|
|
||||||
|
|
||||||
// -- 3. new Git Repo
|
|
||||||
let myNewGitRepo: GitRepo;
|
|
||||||
smartgit
|
|
||||||
.createRepoFromInit('/path/to/new/folder') // smartgit will create any new folder, be careful
|
|
||||||
.then(gitRepo => {
|
|
||||||
// non blocking
|
|
||||||
myNewGitRepo = gitRepo;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Using smartgit instance
|
|
||||||
// -- most used actions
|
|
||||||
// -- all actions return promises, so make sure to use promise chaining for any dependent tasks
|
|
||||||
myExistingGitRepo.addAll(); // returns promise, stages all changed files
|
|
||||||
myExistingGitRepo.add(['relative/path/to/file.txt', 'another/file2.txt']); // returns promise, stages specific files
|
|
||||||
myExistingGitRepo.commit('my commit message'); // returns promise, commits staged files
|
|
||||||
myExistingGitRepo
|
|
||||||
.status() // returns promise
|
|
||||||
.then(status => {
|
|
||||||
// Use TypeScript for status type information
|
|
||||||
});
|
|
||||||
myExistingGitRepo.check(); // returns promise, checks repo health
|
|
||||||
myExistingGitRepo.remoteAdd('git@github.com:username/reponame.git');
|
|
||||||
```
|
|
||||||
|
|
||||||
Tip: use [smartssh](https://npmjs.com/smartssh) to setup your SSH environment
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
90
index.js
90
index.js
@ -1,90 +0,0 @@
|
|||||||
/// <reference path="./index.ts" />
|
|
||||||
var SmartgitPlugins;
|
|
||||||
(function (SmartgitPlugins) {
|
|
||||||
SmartgitPlugins.init = function () {
|
|
||||||
var plugins = {
|
|
||||||
path: require("path"),
|
|
||||||
beautylog: require("beautylog"),
|
|
||||||
nodegit: require("nodegit"),
|
|
||||||
Q: require("q")
|
|
||||||
};
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
/***** Path Checks ******/
|
|
||||||
if (!/^\/.*/.test(options.to)) {
|
|
||||||
plugins.beautylog.error("It seems that the given path " + options.to + " is not absolute.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
plugins.beautylog.log("Now cloning " + options.from);
|
|
||||||
var cloneOptions = {};
|
|
||||||
var cloneRepository = plugins.nodegit.Clone(options.from, options.to, cloneOptions);
|
|
||||||
smartgit.check(cloneRepository);
|
|
||||||
};
|
|
||||||
return clone;
|
|
||||||
}
|
|
||||||
SmartgitClone.init = init;
|
|
||||||
})(SmartgitClone || (SmartgitClone = {}));
|
|
||||||
/// <reference path="./index.ts" />
|
|
||||||
var SmartgitInit;
|
|
||||||
(function (SmartgitInit) {
|
|
||||||
SmartgitInit.init = function () {
|
|
||||||
var gitinit = function (dest) {
|
|
||||||
if (dest === void 0) { dest = "undefined"; }
|
|
||||||
if (dest == "undefined") {
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
})(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;
|
|
@ -1,15 +1,10 @@
|
|||||||
{
|
{
|
||||||
"npmts": {
|
|
||||||
"mode": "default",
|
|
||||||
"codecov": true,
|
|
||||||
"coverageTreshold": 71
|
|
||||||
},
|
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
"npmAccessLevel": "public"
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
26841
package-lock.json
generated
26841
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartgit",
|
"name": "@pushrocks/smartgit",
|
||||||
"version": "1.0.6",
|
"version": "2.0.0",
|
||||||
"description": "smart wrapper for nodegit",
|
"description": "smart wrapper for nodegit",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,31 +24,36 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^7.0.2",
|
"@pushrocks/smartenv": "^4.0.16",
|
||||||
"@pushrocks/smartpath": "^4.0.1",
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpath": "^4.0.3",
|
||||||
"@pushrocks/smartshell": "^2.0.23",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"@pushrocks/smartstring": "^3.0.10",
|
"@pushrocks/smartshell": "^2.0.28",
|
||||||
"@types/minimatch": "^3.0.3",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
"@types/nodegit": "^0.24.8",
|
"@types/minimatch": "^3.0.5",
|
||||||
"nodegit": "^0.24.3"
|
"isomorphic-git": "^1.10.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@gitzone/tsbuild": "^2.1.28",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.59",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"tslint": "^5.17.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"private": false,
|
"private": false,
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"assets/*",
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
88
readme.md
Normal file
88
readme.md
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
# @pushrocks/smartgit
|
||||||
|
smart wrapper for nodegit
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartgit)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartgit)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartgit)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartgit/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
We recommend the use of TypeScript for best in class intellisense
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// import smartgit:
|
||||||
|
import { GitRepo } from 'smartgit';
|
||||||
|
|
||||||
|
// Initialize smartgit:
|
||||||
|
// -- note: there are 3 ways to initialize smartgit
|
||||||
|
// -- -- 1. with a existing Git repo
|
||||||
|
// -- -- 2. with a cloned Git repo
|
||||||
|
// -- -- 3. with a new Git repo
|
||||||
|
|
||||||
|
// -- 1. existing Git Repo:
|
||||||
|
let myExistingGitRepo = new GitRepo('/path/to/existing/git/repo/');
|
||||||
|
|
||||||
|
// -- 2. cloned Git Repo:
|
||||||
|
let myClonedGitRepo: GitRepo;
|
||||||
|
smartgit.createRepoFromClone('git@github.com:username/reponame.git').then((gitRepo) => {
|
||||||
|
// non blocking
|
||||||
|
myClonedGitRepo = gitRepo;
|
||||||
|
});
|
||||||
|
|
||||||
|
// -- 3. new Git Repo
|
||||||
|
let myNewGitRepo: GitRepo;
|
||||||
|
smartgit
|
||||||
|
.createRepoFromInit('/path/to/new/folder') // smartgit will create any new folder, be careful
|
||||||
|
.then((gitRepo) => {
|
||||||
|
// non blocking
|
||||||
|
myNewGitRepo = gitRepo;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Using smartgit instance
|
||||||
|
// -- most used actions
|
||||||
|
// -- all actions return promises, so make sure to use promise chaining for any dependent tasks
|
||||||
|
myExistingGitRepo.addAll(); // returns promise, stages all changed files
|
||||||
|
myExistingGitRepo.add(['relative/path/to/file.txt', 'another/file2.txt']); // returns promise, stages specific files
|
||||||
|
myExistingGitRepo.commit('my commit message'); // returns promise, commits staged files
|
||||||
|
myExistingGitRepo
|
||||||
|
.status() // returns promise
|
||||||
|
.then((status) => {
|
||||||
|
// Use TypeScript for status type information
|
||||||
|
});
|
||||||
|
myExistingGitRepo.check(); // returns promise, checks repo health
|
||||||
|
myExistingGitRepo.remoteAdd('git@github.com:username/reponame.git');
|
||||||
|
```
|
||||||
|
|
||||||
|
Tip: use [smartssh](https://npmjs.com/smartssh) to setup your SSH environment
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
||||||
|
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
9
test.js
9
test.js
@ -1,9 +0,0 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
|
||||||
var smartgit = require("./index.js");
|
|
||||||
var beautylog = require("beautylog");
|
|
||||||
var path = require("path");
|
|
||||||
smartgit.clone({
|
|
||||||
from: "https://github.com/pushrocks/docs.git",
|
|
||||||
to: path.resolve("./test/temp/")
|
|
||||||
});
|
|
||||||
beautylog.success("Test successfull");
|
|
20
test/test.ts
20
test/test.ts
@ -1,4 +1,24 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as smartgit from '../ts/index';
|
import * as smartgit from '../ts/index';
|
||||||
|
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
let testSmartgitInstance: smartgit.Smartgit;
|
||||||
|
const testRepoDir = path.join(__dirname, '../.nogit/testrepo');
|
||||||
|
const testRepoDirSmartfile = path.join(__dirname, '../.nogit/pushrocks_smartfile')
|
||||||
|
|
||||||
|
tap.test('should create a valid smartgit instance', async () => {
|
||||||
|
testSmartgitInstance = new smartgit.Smartgit();
|
||||||
|
await testSmartgitInstance.init();
|
||||||
|
expect(testSmartgitInstance).to.be.instanceOf(smartgit.Smartgit);
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.test('should create a new repo at .nogit', async () => {
|
||||||
|
const gitRepo = await testSmartgitInstance.createRepoByOpen(testRepoDir);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should clone a repo', async () => {
|
||||||
|
const gitRepo = await testSmartgitInstance.createRepoByClone('https://gitlab.com/pushrocks/smartfile.git', testRepoDirSmartfile);
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
28
ts/index.ts
28
ts/index.ts
@ -1,28 +1,4 @@
|
|||||||
import plugins = require('./smartgit.plugins');
|
import plugins = require('./smartgit.plugins');
|
||||||
|
|
||||||
import { GitRepo } from './smartgit.classes.gitrepo';
|
export * from './smartgit.classes.gitrepo';
|
||||||
export { GitRepo };
|
export * from './smartgit.classes.smartgit';
|
||||||
|
|
||||||
/**
|
|
||||||
* creates a new GitRepo Instance after cloning a project
|
|
||||||
*/
|
|
||||||
export const createRepoFromClone = async (fromArg: string, toArg: string): Promise<GitRepo> => {
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates a new GitRepo instance after initializing a new Git Repository
|
|
||||||
*/
|
|
||||||
export const createRepoFromInit = async (destinationDirArg: string): Promise<GitRepo> => {
|
|
||||||
const done = q.defer<GitRepo>();
|
|
||||||
plugins.smartfile.fs.ensureDir(destinationDirArg);
|
|
||||||
plugins.shelljs.exec(`cd ${destinationDirArg} && git init`);
|
|
||||||
let newRepo = new GitRepo(destinationDirArg);
|
|
||||||
done.resolve(newRepo);
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import * as plugins from './smartgit.plugins';
|
import * as plugins from './smartgit.plugins';
|
||||||
|
|
||||||
|
import { Smartgit } from './smartgit.classes.smartgit';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class GitRepo allows access to git directories from node
|
* class GitRepo allows access to git directories from node
|
||||||
*/
|
*/
|
||||||
@ -8,17 +10,105 @@ export class GitRepo {
|
|||||||
/**
|
/**
|
||||||
* creates a new GitRepo Instance after cloning a project
|
* creates a new GitRepo Instance after cloning a project
|
||||||
*/
|
*/
|
||||||
public static async createRepoFromClone(fromArg: string, toArg: string): Promise<GitRepo> {
|
public static async fromCloningIntoDir(
|
||||||
return new GitRepo();
|
smartgitRefArg: Smartgit,
|
||||||
|
fromArg: string,
|
||||||
|
toArg: string
|
||||||
|
): Promise<GitRepo> {
|
||||||
|
const dirArg = plugins.path.resolve(toArg);
|
||||||
|
await plugins.isomorphicGit.clone({
|
||||||
|
dir: toArg,
|
||||||
|
fs: smartgitRefArg.envDeps.fs,
|
||||||
|
http: smartgitRefArg.envDeps.http,
|
||||||
|
url: fromArg,
|
||||||
|
});
|
||||||
|
return new GitRepo(smartgitRefArg, toArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static async fromCreatingRepoInDir(
|
||||||
* creates a new GitRepo instance after initializing a new Git Repository
|
smartgitRefArg: Smartgit,
|
||||||
*/
|
dirArg: string
|
||||||
public static async createRepoFromInit(destinationDirArg: string): Promise<GitRepo> {
|
): Promise<GitRepo> {
|
||||||
return new GitRepo();
|
dirArg = plugins.path.resolve(dirArg);
|
||||||
|
await plugins.isomorphicGit.init({
|
||||||
|
dir: dirArg,
|
||||||
|
fs: smartgitRefArg.envDeps.fs,
|
||||||
|
});
|
||||||
|
return new GitRepo(smartgitRefArg, dirArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async fromOpeningRepoDir(smartgitRefArg: Smartgit, dirArg: string) {
|
||||||
|
dirArg = plugins.path.resolve(dirArg);
|
||||||
|
return new GitRepo(smartgitRefArg, dirArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
nodegitRepo;
|
public smartgitRef: Smartgit;
|
||||||
|
public repoDir: string;
|
||||||
|
|
||||||
|
constructor(smartgitRefArg: Smartgit, repoDirArg: string) {
|
||||||
|
this.smartgitRef = smartgitRefArg;
|
||||||
|
this.repoDir = repoDirArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lists remotes
|
||||||
|
*/
|
||||||
|
public async listRemotes(): Promise<
|
||||||
|
{
|
||||||
|
remote: string;
|
||||||
|
url: string;
|
||||||
|
}[]
|
||||||
|
> {
|
||||||
|
const remotes = await plugins.isomorphicGit.listRemotes({
|
||||||
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
dir: this.repoDir,
|
||||||
|
});
|
||||||
|
return remotes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ensures the existance of a remote within a repository
|
||||||
|
* @param remoteNameArg
|
||||||
|
* @param remoteUrlArg
|
||||||
|
*/
|
||||||
|
public async ensureRemote(remoteNameArg: string, remoteUrlArg: string): Promise<void> {
|
||||||
|
const remotes = await this.listRemotes();
|
||||||
|
const existingRemote =
|
||||||
|
remotes.find((itemArg) => itemArg.remote === remoteNameArg);
|
||||||
|
if (existingRemote) {
|
||||||
|
if (existingRemote.url !== remoteUrlArg) {
|
||||||
|
await plugins.isomorphicGit.deleteRemote({
|
||||||
|
remote: remoteNameArg,
|
||||||
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
dir: this.repoDir
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
await plugins.isomorphicGit.addRemote({
|
||||||
|
remote: remoteNameArg,
|
||||||
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
url: remoteUrlArg
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the url for a specific remote
|
||||||
|
*/
|
||||||
|
public async getUrlForRemote(remoteName: string): Promise<string> {
|
||||||
|
const remotes = await this.listRemotes();
|
||||||
|
const existingRemote = remotes.find(remoteArg => remoteArg.remote === remoteName);
|
||||||
|
return existingRemote?.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async pushBranchToRemote(branchName: string, remoteName: string) {
|
||||||
|
await plugins.isomorphicGit.push({
|
||||||
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
http: this.smartgitRef.envDeps.http,
|
||||||
|
ref: branchName,
|
||||||
|
remote: remoteName
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
36
ts/smartgit.classes.smartgit.ts
Normal file
36
ts/smartgit.classes.smartgit.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import * as plugins from './smartgit.plugins';
|
||||||
|
import { GitRepo } from './smartgit.classes.gitrepo';
|
||||||
|
|
||||||
|
export class Smartgit {
|
||||||
|
public smartenvInstance = new plugins.smartenv.Smartenv();
|
||||||
|
public envDeps: {
|
||||||
|
fs: any;
|
||||||
|
http: any;
|
||||||
|
} = {
|
||||||
|
fs: null,
|
||||||
|
http: null
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {};
|
||||||
|
|
||||||
|
public async init() {
|
||||||
|
if (this.smartenvInstance.isNode) {
|
||||||
|
this.envDeps.fs = this.smartenvInstance.getSafeNodeModule('fs');
|
||||||
|
this.envDeps.http = this.smartenvInstance.getSafeNodeModule('isomorphic-git/http/node');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public async createRepoByClone(fromUrlArg: string, toDirArg: string) {
|
||||||
|
const repo = await GitRepo.fromCloningIntoDir(this, fromUrlArg, toDirArg)
|
||||||
|
};
|
||||||
|
|
||||||
|
public async createRepoByInit(dirArg: string) {
|
||||||
|
const repo = await GitRepo.fromCreatingRepoInDir(this, dirArg);
|
||||||
|
return repo;
|
||||||
|
};
|
||||||
|
|
||||||
|
public async createRepoByOpen(dirArg: string) {
|
||||||
|
const repo = await GitRepo.fromOpeningRepoDir(this, dirArg);
|
||||||
|
return repo;
|
||||||
|
}
|
||||||
|
}
|
@ -3,14 +3,15 @@ import * as path from 'path';
|
|||||||
|
|
||||||
export { path };
|
export { path };
|
||||||
|
|
||||||
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
import * as smartpath from '@pushrocks/smartpath';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartstring from '@pushrocks/smartstring';
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
|
|
||||||
export { smartfile, smartpath, smartpromise, smartstring };
|
export { smartenv, smartfile, smartpath, smartpromise, smartstring };
|
||||||
|
|
||||||
// third party
|
// third party
|
||||||
import * as nodegit from 'nodegit';
|
import isomorphicGit from 'isomorphic-git';
|
||||||
|
|
||||||
export { nodegit };
|
export { isomorphicGit };
|
||||||
|
Reference in New Issue
Block a user