Compare commits
47 Commits
Author | SHA1 | Date | |
---|---|---|---|
c6e3a1caa3 | |||
a92275088b | |||
2b246502f5 | |||
81b2b225a3 | |||
9a2d5afc04 | |||
6404c8342a | |||
b14ae1d8a6 | |||
753bc49c4e | |||
a5dae9b3a3 | |||
af909047ae | |||
11cbe93b4b | |||
e8c3d3c44f | |||
a2485560b3 | |||
7aa83ac730 | |||
141af9843f | |||
71e84e79b1 | |||
aefcf56f0e | |||
ace668bfc1 | |||
f2949c5f21 | |||
6ebb7cec81 | |||
c64de19815 | |||
26d4753ddf | |||
6d5b9f3553 | |||
8dd8bd0be1 | |||
0bd91c2bda | |||
6ef3e6e6f5 | |||
93709f920e | |||
75fa530f73 | |||
f5617d9d45 | |||
b46d1e19a7 | |||
c8d173807d | |||
5944c7e96f | |||
39ea160fdf | |||
91ca5e53f1 | |||
778267bb36 | |||
61407e4854 | |||
2771413723 | |||
b83752a98a | |||
48f71ed1c2 | |||
54ed2f97b8 | |||
92198a75c9 | |||
f82a34b1ea | |||
c3b68fa0fc | |||
1af7afd723 | |||
66e45154e3 | |||
dcc58a312e | |||
90f57bee1a |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
4
.gitignore
vendored
4
.gitignore
vendored
@@ -15,8 +15,6 @@ node_modules/
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
dist_*/
|
||||
|
||||
# custom
|
105
.gitlab-ci.yml
105
.gitlab-ci.yml
@@ -1,105 +0,0 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
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)
|
76
changelog.md
Normal file
76
changelog.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-01-04 - 3.2.0 - feat(core)
|
||||
Enhanced error handling, type safety, and documentation
|
||||
|
||||
- Add comprehensive error handling with try/catch blocks and meaningful error messages
|
||||
- Improve type safety with proper IEnvDeps interface replacing 'any' types
|
||||
- Add complete JSDoc documentation for all classes and methods
|
||||
- Add return type annotations for better TypeScript support
|
||||
- Add ensureInitialized() validation method
|
||||
- Fix missing return statement in createRepoByClone() method
|
||||
- Remove deprecated @types/minimatch dependency
|
||||
- Complete readme rewrite with modern styling, accurate documentation, and proper API examples
|
||||
- Update license from LICENSE to license.md following project guidelines
|
||||
|
||||
## 2024-06-23 - 3.1.1 - fix(documentation)
|
||||
Remove outdated changelog entries
|
||||
|
||||
## 2024-06-23 - 3.1.0 - gitrepo
|
||||
Enhancements and fixes to GitRepo
|
||||
|
||||
- Enhance GitRepo to include commit date and version information
|
||||
|
||||
## 2024-06-22 - 3.0.3 to 3.0.4 - core & GitRepo
|
||||
General updates and new feature addition
|
||||
|
||||
- Fixed core functionality
|
||||
- Added diff function in GitRepo
|
||||
|
||||
## 2023-11-15 - 3.0.1 to 3.0.2 - core, tsconfig, npmextra
|
||||
Minor updates and fixes
|
||||
|
||||
- Fixed core functionality
|
||||
- Updated tsconfig and npmextra.json
|
||||
|
||||
## 2023-07-10 - 3.0.0 - core
|
||||
Structural changes to organization scheme
|
||||
|
||||
- Switched to a new organizational scheme
|
||||
|
||||
## 2023-07-27 - 3.0.0 to 3.0.1 - core
|
||||
Structural changes and updates
|
||||
|
||||
- Fixed core functionality
|
||||
- Switched to new organizational scheme
|
||||
|
||||
## 2022-07-31 - 2.0.2 to 3.0.0 - core
|
||||
Breaking changes and updates
|
||||
|
||||
- Switching to ESM for core
|
||||
- Fixed core functionality
|
||||
|
||||
## 2021-10-22 - 1.0.18 to 2.0.1 - dependencies, core
|
||||
Breaking changes and updates
|
||||
|
||||
- Switched to isomorphic git dependencies
|
||||
- Fixed core functionality
|
||||
|
||||
## 2020-08-15 - 1.0.14 to 1.0.18 - core
|
||||
Fixes
|
||||
|
||||
- Fixed core functionality in multiple patches
|
||||
|
||||
## 2019-06-18 - 1.0.5 to 1.0.10 - core
|
||||
Fixes
|
||||
|
||||
- Fixed core functionality in multiple patches
|
||||
|
||||
## 2016-06-23 - 0.0.10 to 0.1.11 - gitlab & other fixes
|
||||
Initial implementations and setup
|
||||
|
||||
- Fixed README and merge issues
|
||||
- Updated gitlab.yml and CI settings
|
||||
- Implemented new class approach and other updates
|
||||
- Removed unnecessary imports, postinstall
|
||||
- Added npmextra.json, CI tests, SSH key support
|
@@ -1,22 +1,31 @@
|
||||
{
|
||||
"npmts": {
|
||||
"mode": "default",
|
||||
"codecov": true,
|
||||
"coverageTreshold": 71
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartgit",
|
||||
"shortDescription": "smart wrapper for nodegit",
|
||||
"npmPackagename": "@pushrocks/smartgit",
|
||||
"license": "MIT"
|
||||
"description": "A smart wrapper for nodegit that simplifies Git operations in Node.js.",
|
||||
"npmPackagename": "@push.rocks/smartgit",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"git",
|
||||
"nodegit",
|
||||
"version control",
|
||||
"git wrapper",
|
||||
"programming",
|
||||
"development",
|
||||
"code management",
|
||||
"repository management",
|
||||
"git operations"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
2490
package-lock.json
generated
2490
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
74
package.json
74
package.json
@@ -1,54 +1,68 @@
|
||||
{
|
||||
"name": "@pushrocks/smartgit",
|
||||
"version": "1.0.13",
|
||||
"description": "smart wrapper for nodegit",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"name": "@push.rocks/smartgit",
|
||||
"version": "3.2.0",
|
||||
"description": "A smart wrapper for nodegit that simplifies Git operations in Node.js.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitlab.com/pushrocks/smartgit.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartgit.git"
|
||||
},
|
||||
"keywords": [
|
||||
"json",
|
||||
"jade",
|
||||
"template"
|
||||
"git",
|
||||
"nodegit",
|
||||
"version control",
|
||||
"git wrapper",
|
||||
"programming",
|
||||
"development",
|
||||
"code management",
|
||||
"repository management",
|
||||
"git operations"
|
||||
],
|
||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartgit/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartgit",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartfile": "^7.0.4",
|
||||
"@pushrocks/smartpath": "^4.0.1",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartshell": "^2.0.23",
|
||||
"@pushrocks/smartstring": "^3.0.10",
|
||||
"@types/minimatch": "^3.0.3",
|
||||
"@types/nodegit": "^0.24.10",
|
||||
"nodegit": "^0.25.1"
|
||||
"@push.rocks/smartenv": "^5.0.13",
|
||||
"@push.rocks/smartfile": "^11.2.5",
|
||||
"@push.rocks/smartpath": "^6.0.0",
|
||||
"@push.rocks/smartpromise": "^4.2.3",
|
||||
"@push.rocks/smartshell": "^3.2.3",
|
||||
"@push.rocks/smartstring": "^4.0.15",
|
||||
"@push.rocks/smarttime": "^4.1.1",
|
||||
"@types/diff": "^8.0.0",
|
||||
"diff": "^8.0.2",
|
||||
"isomorphic-git": "^1.32.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"tslint": "^5.19.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
"@git.zone/tsbuild": "^2.6.4",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^2.3.2"
|
||||
},
|
||||
"private": false,
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"assets/*",
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977"
|
||||
}
|
||||
|
9472
pnpm-lock.yaml
generated
Normal file
9472
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
4
pnpm-workspace.yaml
Normal file
4
pnpm-workspace.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
onlyBuiltDependencies:
|
||||
- esbuild
|
||||
- mongodb-memory-server
|
||||
- puppeteer
|
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@@ -0,0 +1 @@
|
||||
|
238
readme.md
Normal file
238
readme.md
Normal file
@@ -0,0 +1,238 @@
|
||||
# @push.rocks/smartgit
|
||||
|
||||
> 🚀 **Modern Git operations for Node.js** - A powerful TypeScript wrapper around isomorphic-git that makes repository management and analysis a breeze
|
||||
|
||||
[](https://badge.fury.io/js/@push.rocks%2Fsmartgit)
|
||||
[](https://www.typescriptlang.org/)
|
||||
|
||||
## ✨ What is SmartGit?
|
||||
|
||||
SmartGit is a sophisticated, promise-based Git toolkit designed for Node.js applications. Built on top of `isomorphic-git`, it provides a clean, intuitive API for repository management, diff analysis, and commit history exploration. Perfect for automation tools, CI/CD pipelines, and any application that needs to interact with Git repositories programmatically.
|
||||
|
||||
## 🎯 Key Features
|
||||
|
||||
- **🔧 Repository Management** - Create, clone, and open repositories with ease
|
||||
- **🌐 Remote Operations** - Manage remotes and push changes effortlessly
|
||||
- **📊 Diff Analysis** - Get detailed diffs of uncommitted changes
|
||||
- **📚 Commit History** - Extract commit messages with metadata and version tracking
|
||||
- **⚡ Async/Await** - Modern promise-based API throughout
|
||||
- **🛡️ TypeScript First** - Full type safety and IntelliSense support
|
||||
- **🎯 Production Ready** - Battle-tested and actively maintained
|
||||
|
||||
## 📦 Installation
|
||||
|
||||
```bash
|
||||
# Using pnpm (recommended)
|
||||
pnpm install @push.rocks/smartgit
|
||||
|
||||
# Using npm
|
||||
npm install @push.rocks/smartgit
|
||||
|
||||
# Using yarn
|
||||
yarn add @push.rocks/smartgit
|
||||
```
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
```typescript
|
||||
import { Smartgit } from '@push.rocks/smartgit';
|
||||
|
||||
// Initialize SmartGit
|
||||
const smartgit = new Smartgit();
|
||||
await smartgit.init();
|
||||
|
||||
// Clone a repository
|
||||
const repo = await smartgit.createRepoByClone(
|
||||
'https://github.com/username/repo.git',
|
||||
'./local-repo'
|
||||
);
|
||||
|
||||
console.log('🎉 Repository cloned successfully!');
|
||||
```
|
||||
|
||||
## 📖 Usage Guide
|
||||
|
||||
### 🏗️ Repository Operations
|
||||
|
||||
#### Creating a New Repository
|
||||
|
||||
```typescript
|
||||
const repo = await smartgit.createRepoByInit('./my-new-repo');
|
||||
```
|
||||
|
||||
#### Cloning from Remote
|
||||
|
||||
```typescript
|
||||
const repo = await smartgit.createRepoByClone(
|
||||
'https://github.com/octocat/Hello-World.git',
|
||||
'./hello-world'
|
||||
);
|
||||
```
|
||||
|
||||
#### Opening Existing Repository
|
||||
|
||||
```typescript
|
||||
const repo = await smartgit.createRepoByOpen('./existing-repo');
|
||||
```
|
||||
|
||||
### 🌐 Working with Remotes
|
||||
|
||||
#### List All Remotes
|
||||
|
||||
```typescript
|
||||
const remotes = await repo.listRemotes();
|
||||
console.log(remotes);
|
||||
// Output: [{ remote: 'origin', url: 'https://github.com/...' }]
|
||||
```
|
||||
|
||||
#### Ensure Remote Exists
|
||||
|
||||
```typescript
|
||||
await repo.ensureRemote('origin', 'https://github.com/username/repo.git');
|
||||
```
|
||||
|
||||
#### Get Remote URL
|
||||
|
||||
```typescript
|
||||
const originUrl = await repo.getUrlForRemote('origin');
|
||||
console.log(`📡 Origin URL: ${originUrl}`);
|
||||
```
|
||||
|
||||
#### Push to Remote
|
||||
|
||||
```typescript
|
||||
await repo.pushBranchToRemote('main', 'origin');
|
||||
console.log('✅ Changes pushed successfully!');
|
||||
```
|
||||
|
||||
### 📊 Diff Analysis
|
||||
|
||||
Get a detailed diff of uncommitted changes (perfect for code review automation):
|
||||
|
||||
```typescript
|
||||
const diffs = await repo.getUncommittedDiff(['node_modules/*', '*.log']);
|
||||
|
||||
diffs.forEach(diff => {
|
||||
console.log('📝 File changes:');
|
||||
console.log(diff);
|
||||
});
|
||||
```
|
||||
|
||||
### 📚 Commit History Analysis
|
||||
|
||||
Extract commit history with package.json version tracking:
|
||||
|
||||
```typescript
|
||||
const history = await repo.getAllCommitMessages();
|
||||
|
||||
history.forEach(commit => {
|
||||
console.log(`🕐 ${commit.date} | v${commit.version} | ${commit.message}`);
|
||||
});
|
||||
|
||||
// Example output:
|
||||
// 🕐 2024-01-15 | v1.2.3 | feat: add new authentication method
|
||||
// 🕐 2024-01-14 | v1.2.2 | fix: resolve memory leak in parser
|
||||
```
|
||||
|
||||
## 🛠️ Advanced Usage
|
||||
|
||||
### Error Handling
|
||||
|
||||
```typescript
|
||||
try {
|
||||
const repo = await smartgit.createRepoByClone(invalidUrl, './test');
|
||||
} catch (error) {
|
||||
console.error('❌ Clone failed:', error.message);
|
||||
}
|
||||
```
|
||||
|
||||
### Working with Multiple Repositories
|
||||
|
||||
```typescript
|
||||
const smartgit = new Smartgit();
|
||||
await smartgit.init();
|
||||
|
||||
const repositories = [
|
||||
await smartgit.createRepoByOpen('./repo1'),
|
||||
await smartgit.createRepoByOpen('./repo2'),
|
||||
await smartgit.createRepoByOpen('./repo3')
|
||||
];
|
||||
|
||||
// Analyze all repositories
|
||||
for (const repo of repositories) {
|
||||
const remotes = await repo.listRemotes();
|
||||
console.log(`📂 Repository has ${remotes.length} remotes`);
|
||||
}
|
||||
```
|
||||
|
||||
## 🏗️ Architecture
|
||||
|
||||
SmartGit is built with a clean, modular architecture:
|
||||
|
||||
- **`Smartgit`** - Main entry point and repository factory
|
||||
- **`GitRepo`** - Individual repository operations and analysis
|
||||
- **`isomorphic-git`** - Underlying Git implementation
|
||||
- **Environment Detection** - Automatic Node.js environment setup
|
||||
|
||||
## 🎯 Use Cases
|
||||
|
||||
- **🤖 Automation Scripts** - Automate repository management and analysis
|
||||
- **🔄 CI/CD Pipelines** - Repository operations in build processes
|
||||
- **📊 Code Analysis Tools** - Extract commit data and diff analysis
|
||||
- **🛠️ Developer Tools** - Build Git-powered development utilities
|
||||
- **📱 Release Management** - Track versions and generate changelogs
|
||||
|
||||
## 🔧 Requirements
|
||||
|
||||
- **Node.js** 16+ (Browser support not available)
|
||||
- **Git repository** access (for clone operations)
|
||||
- **TypeScript** 4+ (recommended)
|
||||
|
||||
## 🤝 API Reference
|
||||
|
||||
### Smartgit Class
|
||||
|
||||
| Method | Description | Returns |
|
||||
|--------|-------------|---------|
|
||||
| `init()` | Initialize the SmartGit instance | `Promise<void>` |
|
||||
| `createRepoByInit(dir)` | Create new repository | `Promise<GitRepo>` |
|
||||
| `createRepoByClone(url, dir)` | Clone repository | `Promise<GitRepo>` |
|
||||
| `createRepoByOpen(dir)` | Open existing repository | `Promise<GitRepo>` |
|
||||
|
||||
### GitRepo Class
|
||||
|
||||
| Method | Description | Returns |
|
||||
|--------|-------------|---------|
|
||||
| `listRemotes()` | List all remotes | `Promise<{remote: string, url: string}[]>` |
|
||||
| `ensureRemote(name, url)` | Ensure remote exists | `Promise<void>` |
|
||||
| `getUrlForRemote(name)` | Get URL for remote | `Promise<string>` |
|
||||
| `pushBranchToRemote(branch, remote)` | Push branch to remote | `Promise<void>` |
|
||||
| `getUncommittedDiff(excludeFiles?)` | Get uncommitted changes | `Promise<string[]>` |
|
||||
| `getAllCommitMessages()` | Get commit history | `Promise<CommitInfo[]>` |
|
||||
|
||||
## 💡 Pro Tips
|
||||
|
||||
- **🔧 Always call `init()`** before using any repository operations
|
||||
- **📁 Use absolute paths** for repository directories when possible
|
||||
- **🚫 Exclude large files** from diff analysis using the `excludeFiles` parameter
|
||||
- **⚡ Batch operations** when working with multiple repositories
|
||||
- **🛡️ Handle errors gracefully** - network issues can cause clone operations to fail
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
51
test/test.ts
51
test/test.ts
@@ -1,12 +1,51 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartgit from '../ts/index';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartgit from '../ts/index.js';
|
||||
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as path from 'path';
|
||||
|
||||
const testRepoDir = path.join(__dirname, '../.nogit/testrepo');
|
||||
let testSmartgitInstance: smartgit.Smartgit;
|
||||
const packageDir = path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
|
||||
const testRepoDir = path.join(packageDir, './.nogit/testrepo');
|
||||
const testRepoDirSmartfile = path.join(packageDir, './.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 () => {
|
||||
const gitRepo = await smartgit.GitRepo.fromCreatingRepoInDir(testRepoDir);
|
||||
})
|
||||
const gitRepo = await testSmartgitInstance.createRepoByOpen(testRepoDir);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
tap.test('should clone a repo', async () => {
|
||||
const gitRepo = await testSmartgitInstance.createRepoByClone(
|
||||
'https://gitlab.com/push.rocks/smartfile.git',
|
||||
testRepoDirSmartfile
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('should open a repo', async () => {
|
||||
const gitRepo = await testSmartgitInstance.createRepoByOpen(packageDir);
|
||||
const diff = await gitRepo.getUncommittedDiff([
|
||||
'pnpm-lock.yaml',
|
||||
]);
|
||||
console.log(diff);
|
||||
});
|
||||
|
||||
tap.test('should get the diff to HEAD', async () => {
|
||||
const gitRepo = await testSmartgitInstance.createRepoByOpen(packageDir);
|
||||
const diff = await gitRepo.getUncommittedDiff([
|
||||
'pnpm-lock.yaml',
|
||||
]);
|
||||
console.log(diff);
|
||||
});
|
||||
|
||||
tap.test('should print all commit messages', async () => {
|
||||
const gitRepo = await testSmartgitInstance.createRepoByOpen(packageDir);
|
||||
const commitMessages = await gitRepo.getAllCommitMessages();
|
||||
console.log(commitMessages);
|
||||
});
|
||||
|
||||
await 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 @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartgit',
|
||||
version: '3.1.1',
|
||||
description: 'A smart wrapper for nodegit that simplifies Git operations in Node.js.'
|
||||
}
|
@@ -1,3 +1,2 @@
|
||||
import plugins = require('./smartgit.plugins');
|
||||
|
||||
export * from './smartgit.classes.gitrepo';
|
||||
export * from './smartgit.classes.gitrepo.js';
|
||||
export * from './smartgit.classes.smartgit.js';
|
||||
|
@@ -1,4 +1,5 @@
|
||||
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
|
||||
@@ -8,72 +9,220 @@ export class GitRepo {
|
||||
/**
|
||||
* 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 ngRespository = await plugins.nodegit.Clone.clone(fromArg, toArg, {
|
||||
bare: 0,
|
||||
checkoutBranch: 'master'
|
||||
await plugins.isomorphicGit.clone({
|
||||
dir: toArg,
|
||||
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);
|
||||
const ngRepository = await plugins.nodegit.Repository.init(dirArg, 0);
|
||||
return new GitRepo(ngRepository);
|
||||
await plugins.isomorphicGit.init({
|
||||
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);
|
||||
const ngRepository = await plugins.nodegit.Repository.open(dirArg);
|
||||
return new GitRepo(ngRepository);
|
||||
return new GitRepo(smartgitRefArg, dirArg);
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public nodegitRepo: plugins.nodegit.Repository;
|
||||
public smartgitRef: Smartgit;
|
||||
public repoDir: string;
|
||||
|
||||
constructor(nodegitRepoArg: plugins.nodegit.Repository) {
|
||||
this.nodegitRepo = nodegitRepoArg;
|
||||
constructor(smartgitRefArg: Smartgit, repoDirArg: string) {
|
||||
this.smartgitRef = smartgitRefArg;
|
||||
this.repoDir = repoDirArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* lists remotes
|
||||
*/
|
||||
public async listRemotes(): Promise<string[]> {
|
||||
return this.nodegitRepo.getRemotes();
|
||||
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
|
||||
* ensures the existence of a remote within a repository
|
||||
* @param remoteNameArg
|
||||
* @param remoteUrlArg
|
||||
* @param remoteUrlArg
|
||||
*/
|
||||
public async ensureRemote(remoteNameArg: string, remoteUrlArg: string): Promise<void> {
|
||||
const existingUrl = await this.getUrlForRemote(remoteNameArg);
|
||||
if (existingUrl === remoteUrlArg) {
|
||||
return;
|
||||
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;
|
||||
}
|
||||
}
|
||||
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
|
||||
*/
|
||||
public async getUrlForRemote(remoteName: string): Promise<string> {
|
||||
const ngRemote = await this.nodegitRepo.getRemote(remoteName);
|
||||
if (ngRemote) {
|
||||
return ngRemote.url();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
const remotes = await this.listRemotes();
|
||||
const existingRemote = remotes.find((remoteArg) => remoteArg.remote === remoteName);
|
||||
return existingRemote?.url;
|
||||
}
|
||||
|
||||
public async pushBranchToRemote(branchName: string, remoteName: string) {
|
||||
await this.nodegitRepo.checkoutBranch(branchName);
|
||||
const ngRemote = await this.nodegitRepo.getRemote(remoteName);
|
||||
ngRemote.push([branchName]);
|
||||
await plugins.isomorphicGit.push({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
http: this.smartgitRef.envDeps.http,
|
||||
ref: branchName,
|
||||
remote: remoteName,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the diff of the current uncommitted changes while excluding specified files
|
||||
*/
|
||||
public async getUncommittedDiff(excludeFiles: string[] = []): Promise<string[]> {
|
||||
const statusMatrix = await plugins.isomorphicGit.statusMatrix({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
dir: this.repoDir,
|
||||
});
|
||||
|
||||
const diffs: string[] = [];
|
||||
for (const row of statusMatrix) {
|
||||
const [filepath, head, workdir] = row;
|
||||
if (excludeFiles.includes(filepath)) {
|
||||
continue; // Skip excluded files
|
||||
}
|
||||
|
||||
let headContent = '';
|
||||
let workdirContent = '';
|
||||
|
||||
// Handle modified files
|
||||
if (head !== 0 && workdir !== 0 && head !== workdir) {
|
||||
headContent = await plugins.isomorphicGit
|
||||
.readBlob({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
dir: this.repoDir,
|
||||
oid: await plugins.isomorphicGit.resolveRef({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
dir: this.repoDir,
|
||||
ref: 'HEAD',
|
||||
}),
|
||||
filepath,
|
||||
})
|
||||
.then((result) => new TextDecoder().decode(result.blob));
|
||||
|
||||
workdirContent = await this.smartgitRef.envDeps.fs.promises.readFile(
|
||||
plugins.path.join(this.repoDir, filepath),
|
||||
'utf8'
|
||||
);
|
||||
}
|
||||
|
||||
// Handle added files
|
||||
if (head === 0 && workdir !== 0) {
|
||||
workdirContent = await this.smartgitRef.envDeps.fs.promises.readFile(
|
||||
plugins.path.join(this.repoDir, filepath),
|
||||
'utf8'
|
||||
);
|
||||
}
|
||||
|
||||
// Handle deleted files
|
||||
if (head !== 0 && workdir === 0) {
|
||||
headContent = await plugins.isomorphicGit
|
||||
.readBlob({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
dir: this.repoDir,
|
||||
oid: await plugins.isomorphicGit.resolveRef({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
dir: this.repoDir,
|
||||
ref: 'HEAD',
|
||||
}),
|
||||
filepath,
|
||||
})
|
||||
.then((result) => new TextDecoder().decode(result.blob));
|
||||
}
|
||||
|
||||
if (headContent || workdirContent) {
|
||||
const diff = plugins.diff.createTwoFilesPatch(
|
||||
filepath,
|
||||
filepath,
|
||||
headContent,
|
||||
workdirContent
|
||||
);
|
||||
diffs.push(diff);
|
||||
}
|
||||
}
|
||||
|
||||
return diffs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all commit messages with their dates and package.json version at each commit
|
||||
*/
|
||||
public async getAllCommitMessages(): Promise<
|
||||
{ date: string; version: string; message: string }[]
|
||||
> {
|
||||
const commits = await plugins.isomorphicGit.log({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
dir: this.repoDir,
|
||||
});
|
||||
|
||||
const results = [];
|
||||
|
||||
for (const commit of commits) {
|
||||
let version = 'unknown';
|
||||
try {
|
||||
const packageJsonBlob = await plugins.isomorphicGit.readBlob({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
dir: this.repoDir,
|
||||
oid: commit.oid,
|
||||
filepath: 'package.json',
|
||||
});
|
||||
const packageJson = JSON.parse(new TextDecoder().decode(packageJsonBlob.blob));
|
||||
version = packageJson.version;
|
||||
} catch (error) {
|
||||
// If package.json does not exist or any error occurs, leave version as 'unknown'
|
||||
}
|
||||
|
||||
results.push({
|
||||
date: new plugins.smarttime.ExtendedDate(commit.commit.committer.timestamp * 1000).exportToHyphedSortableDate(),
|
||||
version: version,
|
||||
message: commit.commit.message,
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
90
ts/smartgit.classes.smartgit.ts
Normal file
90
ts/smartgit.classes.smartgit.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import * as plugins from './smartgit.plugins.js';
|
||||
import { GitRepo } from './smartgit.classes.gitrepo.js';
|
||||
|
||||
interface IEnvDeps {
|
||||
fs: typeof import('fs') | null;
|
||||
http: any | null; // isomorphic-git http interface
|
||||
}
|
||||
|
||||
/**
|
||||
* class Smartgit provides a high-level interface for git operations
|
||||
* Must be initialized before use by calling init()
|
||||
*/
|
||||
export class Smartgit {
|
||||
public smartenvInstance = new plugins.smartenv.Smartenv();
|
||||
public envDeps: IEnvDeps = {
|
||||
fs: null,
|
||||
http: null,
|
||||
};
|
||||
|
||||
/**
|
||||
* initializes the Smartgit instance with required environment dependencies
|
||||
* Must be called before using any repository methods
|
||||
*/
|
||||
public async init(): Promise<void> {
|
||||
try {
|
||||
if (this.smartenvInstance.isNode) {
|
||||
this.envDeps.fs = await this.smartenvInstance.getSafeNodeModule('fs');
|
||||
this.envDeps.http = await this.smartenvInstance.getSafeNodeModule(
|
||||
'isomorphic-git/http/node'
|
||||
);
|
||||
} else {
|
||||
throw new Error('currently only node.js is supported.');
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to initialize Smartgit: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
private ensureInitialized(): void {
|
||||
if (!this.envDeps.fs || !this.envDeps.http) {
|
||||
throw new Error('Smartgit must be initialized before use. Call init() first.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new GitRepo instance by cloning from a remote URL
|
||||
* @param fromUrlArg the URL to clone from
|
||||
* @param toDirArg the directory to clone into
|
||||
* @returns Promise<GitRepo> the created repository instance
|
||||
*/
|
||||
public async createRepoByClone(fromUrlArg: string, toDirArg: string): Promise<GitRepo> {
|
||||
this.ensureInitialized();
|
||||
try {
|
||||
const repo = await GitRepo.fromCloningIntoDir(this, fromUrlArg, toDirArg);
|
||||
return repo;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to clone repository: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new GitRepo instance by initializing a new repository in a directory
|
||||
* @param dirArg the directory to initialize the repository in
|
||||
* @returns Promise<GitRepo> the created repository instance
|
||||
*/
|
||||
public async createRepoByInit(dirArg: string): Promise<GitRepo> {
|
||||
this.ensureInitialized();
|
||||
try {
|
||||
const repo = await GitRepo.fromCreatingRepoInDir(this, dirArg);
|
||||
return repo;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to initialize repository: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new GitRepo instance by opening an existing repository in a directory
|
||||
* @param dirArg the directory containing the existing repository
|
||||
* @returns Promise<GitRepo> the opened repository instance
|
||||
*/
|
||||
public async createRepoByOpen(dirArg: string): Promise<GitRepo> {
|
||||
this.ensureInitialized();
|
||||
try {
|
||||
const repo = await GitRepo.fromOpeningRepoDir(this, dirArg);
|
||||
return repo;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to open repository: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,14 +3,17 @@ import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
import * as smartenv from '@push.rocks/smartenv';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartstring from '@push.rocks/smartstring';
|
||||
import * as smarttime from '@push.rocks/smarttime';
|
||||
|
||||
export { smartfile, smartpath, smartpromise, smartstring };
|
||||
export { smartenv, smartfile, smartpath, smartpromise, smartstring, smarttime };
|
||||
|
||||
// third party
|
||||
import nodegit from 'nodegit';
|
||||
import * as diff from 'diff';
|
||||
import isomorphicGit from 'isomorphic-git';
|
||||
|
||||
export { nodegit };
|
||||
export { diff, isomorphicGit };
|
||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
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