Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
8dd8bd0be1 | |||
0bd91c2bda | |||
6ef3e6e6f5 | |||
93709f920e | |||
75fa530f73 | |||
f5617d9d45 | |||
b46d1e19a7 | |||
c8d173807d | |||
5944c7e96f | |||
39ea160fdf | |||
91ca5e53f1 | |||
778267bb36 | |||
61407e4854 | |||
2771413723 | |||
b83752a98a | |||
48f71ed1c2 | |||
54ed2f97b8 | |||
92198a75c9 | |||
f82a34b1ea | |||
c3b68fa0fc | |||
1af7afd723 | |||
66e45154e3 | |||
dcc58a312e | |||
90f57bee1a |
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
|
@ -4,60 +4,79 @@ 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
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
auditProductionDependencies:
|
||||||
stage: security
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
snyk:
|
|
||||||
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
|
allow_failure: true
|
||||||
|
|
||||||
|
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:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -67,11 +86,14 @@ 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 typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
@ -82,18 +104,19 @@ trigger:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci node install stable
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm test",
|
||||||
|
"name": "Run npm test",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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)
|
|
@ -1,20 +1,15 @@
|
|||||||
{
|
{
|
||||||
"npmts": {
|
|
||||||
"mode": "default",
|
|
||||||
"codecov": true,
|
|
||||||
"coverageTreshold": 71
|
|
||||||
},
|
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartgit",
|
"gitrepo": "smartgit",
|
||||||
"shortDescription": "smart wrapper for nodegit",
|
"description": "smart wrapper for nodegit",
|
||||||
"npmPackagename": "@pushrocks/smartgit",
|
"npmPackagename": "@pushrocks/smartgit",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
15198
package-lock.json
generated
15198
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
49
package.json
49
package.json
@ -1,12 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartgit",
|
"name": "@pushrocks/smartgit",
|
||||||
"version": "1.0.13",
|
"version": "3.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",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,31 +26,34 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^7.0.4",
|
"@pushrocks/smartenv": "^5.0.2",
|
||||||
"@pushrocks/smartpath": "^4.0.1",
|
"@pushrocks/smartfile": "^10.0.4",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpath": "^5.0.5",
|
||||||
"@pushrocks/smartshell": "^2.0.23",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartstring": "^3.0.10",
|
"@pushrocks/smartshell": "^2.0.30",
|
||||||
"@types/minimatch": "^3.0.3",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
"@types/nodegit": "^0.24.10",
|
"@types/minimatch": "^3.0.5",
|
||||||
"nodegit": "^0.25.1"
|
"isomorphic-git": "^1.19.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.72",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^5.0.4"
|
||||||
"tslint": "^5.19.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"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
87
readme.md
Normal file
87
readme.md
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
# @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)
|
23
test/test.ts
23
test/test.ts
@ -1,12 +1,29 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as smartgit from '../ts/index';
|
import * as smartgit from '../ts/index.js';
|
||||||
|
|
||||||
|
import * as smartpath from '@pushrocks/smartpath';
|
||||||
|
const __dirname = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
|
let testSmartgitInstance: smartgit.Smartgit;
|
||||||
const testRepoDir = path.join(__dirname, '../.nogit/testrepo');
|
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).toBeInstanceOf(smartgit.Smartgit);
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('should create a new repo at .nogit', async () => {
|
tap.test('should create a new repo at .nogit', async () => {
|
||||||
const gitRepo = await smartgit.GitRepo.fromCreatingRepoInDir(testRepoDir);
|
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();
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@pushrocks/smartgit',
|
||||||
|
version: '3.0.0',
|
||||||
|
description: 'smart wrapper for nodegit'
|
||||||
|
}
|
@ -1,3 +1,2 @@
|
|||||||
import plugins = require('./smartgit.plugins');
|
export * from './smartgit.classes.gitrepo.js';
|
||||||
|
export * from './smartgit.classes.smartgit.js';
|
||||||
export * from './smartgit.classes.gitrepo';
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import * as plugins from './smartgit.plugins';
|
import * as plugins from './smartgit.plugins.js';
|
||||||
|
|
||||||
|
import { Smartgit } from './smartgit.classes.smartgit.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class GitRepo allows access to git directories from node
|
* class GitRepo allows access to git directories from node
|
||||||
@ -8,39 +10,61 @@ export class GitRepo {
|
|||||||
/**
|
/**
|
||||||
* creates a new GitRepo Instance after cloning a project
|
* creates a new GitRepo Instance after cloning a project
|
||||||
*/
|
*/
|
||||||
public static async fromCloningIntoDir(fromArg: string, toArg: string): Promise<GitRepo> {
|
public static async fromCloningIntoDir(
|
||||||
|
smartgitRefArg: Smartgit,
|
||||||
|
fromArg: string,
|
||||||
|
toArg: string
|
||||||
|
): Promise<GitRepo> {
|
||||||
const dirArg = plugins.path.resolve(toArg);
|
const dirArg = plugins.path.resolve(toArg);
|
||||||
const ngRespository = await plugins.nodegit.Clone.clone(fromArg, toArg, {
|
await plugins.isomorphicGit.clone({
|
||||||
bare: 0,
|
dir: toArg,
|
||||||
checkoutBranch: 'master'
|
fs: smartgitRefArg.envDeps.fs,
|
||||||
|
http: smartgitRefArg.envDeps.http,
|
||||||
|
url: fromArg,
|
||||||
});
|
});
|
||||||
return new GitRepo(ngRespository);
|
return new GitRepo(smartgitRefArg, toArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async fromCreatingRepoInDir(dirArg: string): Promise<GitRepo> {
|
public static async fromCreatingRepoInDir(
|
||||||
|
smartgitRefArg: Smartgit,
|
||||||
|
dirArg: string
|
||||||
|
): Promise<GitRepo> {
|
||||||
dirArg = plugins.path.resolve(dirArg);
|
dirArg = plugins.path.resolve(dirArg);
|
||||||
const ngRepository = await plugins.nodegit.Repository.init(dirArg, 0);
|
await plugins.isomorphicGit.init({
|
||||||
return new GitRepo(ngRepository);
|
dir: dirArg,
|
||||||
|
fs: smartgitRefArg.envDeps.fs,
|
||||||
|
});
|
||||||
|
return new GitRepo(smartgitRefArg, dirArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async fromOpeningRepoDir(dirArg: string) {
|
public static async fromOpeningRepoDir(smartgitRefArg: Smartgit, dirArg: string) {
|
||||||
dirArg = plugins.path.resolve(dirArg);
|
dirArg = plugins.path.resolve(dirArg);
|
||||||
const ngRepository = await plugins.nodegit.Repository.open(dirArg);
|
return new GitRepo(smartgitRefArg, dirArg);
|
||||||
return new GitRepo(ngRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public nodegitRepo: plugins.nodegit.Repository;
|
public smartgitRef: Smartgit;
|
||||||
|
public repoDir: string;
|
||||||
|
|
||||||
constructor(nodegitRepoArg: plugins.nodegit.Repository) {
|
constructor(smartgitRefArg: Smartgit, repoDirArg: string) {
|
||||||
this.nodegitRepo = nodegitRepoArg;
|
this.smartgitRef = smartgitRefArg;
|
||||||
|
this.repoDir = repoDirArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lists remotes
|
* lists remotes
|
||||||
*/
|
*/
|
||||||
public async listRemotes(): Promise<string[]> {
|
public async listRemotes(): Promise<
|
||||||
return this.nodegitRepo.getRemotes();
|
{
|
||||||
|
remote: string;
|
||||||
|
url: string;
|
||||||
|
}[]
|
||||||
|
> {
|
||||||
|
const remotes = await plugins.isomorphicGit.listRemotes({
|
||||||
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
dir: this.repoDir,
|
||||||
|
});
|
||||||
|
return remotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,31 +73,41 @@ export class GitRepo {
|
|||||||
* @param remoteUrlArg
|
* @param remoteUrlArg
|
||||||
*/
|
*/
|
||||||
public async ensureRemote(remoteNameArg: string, remoteUrlArg: string): Promise<void> {
|
public async ensureRemote(remoteNameArg: string, remoteUrlArg: string): Promise<void> {
|
||||||
const existingUrl = await this.getUrlForRemote(remoteNameArg);
|
const remotes = await this.listRemotes();
|
||||||
if (existingUrl === remoteUrlArg) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (existingUrl) {
|
|
||||||
await plugins.nodegit.Remote.delete(this.nodegitRepo, remoteNameArg);
|
|
||||||
}
|
}
|
||||||
await plugins.nodegit.Remote.create(this.nodegitRepo, remoteNameArg, remoteUrlArg);
|
await plugins.isomorphicGit.addRemote({
|
||||||
|
remote: remoteNameArg,
|
||||||
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
url: remoteUrlArg,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the url for a specific remote
|
* gets the url for a specific remote
|
||||||
*/
|
*/
|
||||||
public async getUrlForRemote(remoteName: string): Promise<string> {
|
public async getUrlForRemote(remoteName: string): Promise<string> {
|
||||||
const ngRemote = await this.nodegitRepo.getRemote(remoteName);
|
const remotes = await this.listRemotes();
|
||||||
if (ngRemote) {
|
const existingRemote = remotes.find((remoteArg) => remoteArg.remote === remoteName);
|
||||||
return ngRemote.url();
|
return existingRemote?.url;
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async pushBranchToRemote(branchName: string, remoteName: string) {
|
public async pushBranchToRemote(branchName: string, remoteName: string) {
|
||||||
await this.nodegitRepo.checkoutBranch(branchName);
|
await plugins.isomorphicGit.push({
|
||||||
const ngRemote = await this.nodegitRepo.getRemote(remoteName);
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
ngRemote.push([branchName]);
|
http: this.smartgitRef.envDeps.http,
|
||||||
|
ref: branchName,
|
||||||
|
remote: remoteName,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
40
ts/smartgit.classes.smartgit.ts
Normal file
40
ts/smartgit.classes.smartgit.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import * as plugins from './smartgit.plugins.js';
|
||||||
|
import { GitRepo } from './smartgit.classes.gitrepo.js';
|
||||||
|
|
||||||
|
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 = await this.smartenvInstance.getSafeNodeModule('fs');
|
||||||
|
this.envDeps.http = await this.smartenvInstance.getSafeNodeModule(
|
||||||
|
'isomorphic-git/http/node/index.js'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw new Error('currently only node.js is supported.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 nodegit from 'nodegit';
|
import isomorphicGit from 'isomorphic-git';
|
||||||
|
|
||||||
export { nodegit };
|
export { isomorphicGit };
|
||||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user