Compare commits
50 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
98d1f8aea2 | |||
1f542367e6 | |||
201a5014ed | |||
6cc245ae7e | |||
1377fb6eb7 | |||
daf8c80513 | |||
46fce49356 | |||
8616613a95 | |||
352e4d8e96 | |||
c2105ce78f | |||
2864fc5507 | |||
fea523ff5c | |||
872f2354c5 | |||
ff0318534f | |||
e103074684 | |||
f72beabd90 | |||
958a625633 | |||
871fd55c5c | |||
07fd9b9fa7 | |||
62d6a8d685 | |||
047cf02e6a | |||
69127cacdd |
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 @gitzone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
23
.gitignore
vendored
23
.gitignore
vendored
@ -1,13 +1,20 @@
|
||||
node_modules/
|
||||
test/temp/
|
||||
test/temp2/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
#npm debug
|
||||
npm-debug.log
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
ts/*.js
|
||||
ts/*.js.map
|
||||
ts/typings/
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
@ -1,49 +0,0 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
|
||||
before_script:
|
||||
- npmci prepare ssh
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
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=
|
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
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
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
68
README.md
68
README.md
@ -1,68 +0,0 @@
|
||||
# smartgit
|
||||
smart git wrapper for node.
|
||||
|
||||
smartgit expects git to be installed on target machine.
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smartgit)
|
||||
[](https://gitlab.com/pushrocks/smartgit)
|
||||
[](https://github.com/pushrocks/smartgit)
|
||||
[](https://pushrocks.gitlab.io/smartgit/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartgit/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartgit/commits/master)
|
||||
[](https://david-dm.org/pushrocks/smartgit)
|
||||
[](https://www.bithound.io/github/pushrocks/smartgit/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartgit)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## 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)
|
12
dist/index.d.ts
vendored
12
dist/index.d.ts
vendored
@ -1,12 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as q from 'q';
|
||||
import { GitRepo } from './smartgit.classes.gitrepo';
|
||||
export { GitRepo };
|
||||
/**
|
||||
* creates a new GitRepo Instance after cloning a project
|
||||
*/
|
||||
export declare let createRepoFromClone: (fromArg: string, toArg: string) => q.Promise<GitRepo>;
|
||||
/**
|
||||
* creates a new GitRepo instance after initializing a new Git Repository
|
||||
*/
|
||||
export declare let createRepoFromInit: (destinationDirArg: string) => q.Promise<GitRepo>;
|
28
dist/index.js
vendored
28
dist/index.js
vendored
@ -1,28 +0,0 @@
|
||||
"use strict";
|
||||
const q = require("q");
|
||||
const plugins = require("./smartgit.plugins");
|
||||
const smartgit_classes_gitrepo_1 = require("./smartgit.classes.gitrepo");
|
||||
exports.GitRepo = smartgit_classes_gitrepo_1.GitRepo;
|
||||
/**
|
||||
* creates a new GitRepo Instance after cloning a project
|
||||
*/
|
||||
exports.createRepoFromClone = (fromArg, toArg) => {
|
||||
let done = q.defer();
|
||||
plugins.smartfile.fs.ensureDir(toArg);
|
||||
plugins.shelljs.exec(`git clone ${fromArg} ${toArg}`);
|
||||
let newRepo = new smartgit_classes_gitrepo_1.GitRepo(toArg);
|
||||
done.resolve(newRepo);
|
||||
return done.promise;
|
||||
};
|
||||
/**
|
||||
* creates a new GitRepo instance after initializing a new Git Repository
|
||||
*/
|
||||
exports.createRepoFromInit = (destinationDirArg) => {
|
||||
let done = q.defer();
|
||||
plugins.smartfile.fs.ensureDir(destinationDirArg);
|
||||
plugins.shelljs.exec(`cd ${destinationDirArg} && git init`);
|
||||
let newRepo = new smartgit_classes_gitrepo_1.GitRepo(destinationDirArg);
|
||||
done.resolve(newRepo);
|
||||
return done.promise;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsdUJBQXNCO0FBQ3RCLDhDQUErQztBQUUvQyx5RUFBb0Q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/smartgit.classes.gitrepo.d.ts
vendored
@ -1,57 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as q from 'q';
|
||||
/**
|
||||
* class GitRepo allows access to git directories from node
|
||||
*/
|
||||
export declare class GitRepo {
|
||||
repoBase: string;
|
||||
constructor(repoBaseArg: string);
|
||||
/**
|
||||
* checks if the Repo is valid
|
||||
*/
|
||||
check(): boolean;
|
||||
/**
|
||||
* stage all files in working directory
|
||||
*/
|
||||
addAll(dirPathArg: string): q.Promise<{}>;
|
||||
/**
|
||||
* add a remote to the GitRepo
|
||||
*/
|
||||
remoteAdd(remoteNameArg: string, remoteLinkArg: string): q.Promise<{}>;
|
||||
/**
|
||||
* list remotes for a Gip
|
||||
*/
|
||||
remoteList(): q.Promise<{}>;
|
||||
/**
|
||||
* remove remote
|
||||
*/
|
||||
remoteRemove(dirPathArg: string): q.Promise<{}>;
|
||||
/**
|
||||
* commit all files that are currently staged
|
||||
*/
|
||||
commit(commitMessage: string): q.Promise<{}>;
|
||||
/**
|
||||
* pull latest changes from remote
|
||||
*/
|
||||
pull(sourceArg?: string, branchArg?: string): q.Promise<{}>;
|
||||
/**
|
||||
* push new commits to remote
|
||||
*/
|
||||
push(remoteNameArg?: string, remoteBranchArg?: string): q.Promise<{}>;
|
||||
/**
|
||||
* sync
|
||||
*/
|
||||
sync(): void;
|
||||
/**
|
||||
* get the current status
|
||||
*/
|
||||
status(): q.Promise<{}>;
|
||||
}
|
||||
/**
|
||||
* creates a new GitRepo Instance after cloning a project
|
||||
*/
|
||||
export declare let createRepoFromClone: (fromArg: string, toArg: string) => q.Promise<GitRepo>;
|
||||
/**
|
||||
* creates a new GitRepo instance after initializing a new Git Repository
|
||||
*/
|
||||
export declare let createRepoFromInit: (destinationDirArg: string) => void;
|
141
dist/smartgit.classes.gitrepo.js
vendored
141
dist/smartgit.classes.gitrepo.js
vendored
File diff suppressed because one or more lines are too long
7
dist/smartgit.plugins.d.ts
vendored
7
dist/smartgit.plugins.d.ts
vendored
@ -1,7 +0,0 @@
|
||||
import 'typings-global';
|
||||
export import path = require('path');
|
||||
export import beautylog = require('beautylog');
|
||||
export import shelljs = require('shelljs');
|
||||
export import smartfile = require('smartfile');
|
||||
export import smartpath = require('smartpath');
|
||||
export import smartstring = require('smartstring');
|
9
dist/smartgit.plugins.js
vendored
9
dist/smartgit.plugins.js
vendored
@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.path = require("path");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.shelljs = require("shelljs");
|
||||
exports.smartfile = require("smartfile");
|
||||
exports.smartpath = require("smartpath");
|
||||
exports.smartstring = require("smartstring");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRnaXQucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Z2l0LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwrQkFBb0M7QUFDcEMseUNBQThDO0FBQzlDLHFDQUEwQztBQUMxQyx5Q0FBOEM7QUFDOUMseUNBQThDO0FBQzlDLDZDQUFrRCJ9
|
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;
|
17
npmextra.json
Normal file
17
npmextra.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartgit",
|
||||
"description": "smart wrapper for nodegit",
|
||||
"npmPackagename": "@push.rocks/smartgit",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"mode":"default",
|
||||
"codecov":true,
|
||||
"coverageTreshold":71
|
||||
}
|
61
package.json
61
package.json
@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "smartgit",
|
||||
"version": "1.0.2",
|
||||
"description": "smart git wrapper for node",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"name": "@push.rocks/smartgit",
|
||||
"version": "3.0.1",
|
||||
"description": "smart wrapper for nodegit",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"cleanTest": "rm -rf test/temp*",
|
||||
"test": "(npm run cleanTest && npmts)",
|
||||
"install": "node dist/postinstall.js"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -25,21 +26,35 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartgit",
|
||||
"dependencies": {
|
||||
"@types/minimatch": "*",
|
||||
"@types/shelljs": "^0.3.32",
|
||||
"beautylog": "^6.0.0",
|
||||
"q": "^1.4.1",
|
||||
"shelljs": "^0.7.5",
|
||||
"simple-git": "^1.62.0",
|
||||
"smartfile": "^4.1.0",
|
||||
"smartpath": "^3.2.5",
|
||||
"smartstring": "^2.0.22",
|
||||
"typings-global": "^1.0.14"
|
||||
"@push.rocks/smartenv": "^5.0.5",
|
||||
"@push.rocks/smartfile": "^10.0.26",
|
||||
"@push.rocks/smartpath": "^5.0.5",
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
"@push.rocks/smartshell": "^3.0.3",
|
||||
"@push.rocks/smartstring": "^4.0.7",
|
||||
"@types/minimatch": "^5.1.2",
|
||||
"isomorphic-git": "^1.24.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/should": "^8.1.30",
|
||||
"npmts-g": "^5.2.8",
|
||||
"should": "^11.1.1",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.66",
|
||||
"@gitzone/tsrun": "^1.2.44",
|
||||
"@gitzone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.8"
|
||||
},
|
||||
"private": false,
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
4860
pnpm-lock.yaml
generated
Normal file
4860
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
85
readme.md
Normal file
85
readme.md
Normal file
@ -0,0 +1,85 @@
|
||||
# @push.rocks/smartgit
|
||||
smart wrapper for nodegit
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartgit)
|
||||
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartgit)
|
||||
* [github.com (source mirror)](https://github.com/push.rocks/smartgit)
|
||||
* [docs (typedoc)](https://push.rocks.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)
|
||||
|
||||
## 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.
|
||||
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
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");
|
Submodule test/temp3 deleted from a261a2ea02
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
||||
import 'typings-test';
|
110
test/test.js
110
test/test.js
@ -1,110 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
let shelljs = require('shelljs');
|
||||
const path = require("path");
|
||||
const should = require("should");
|
||||
const smartgit = require("../dist/index");
|
||||
let paths = {
|
||||
temp1: path.resolve('./test/temp/'),
|
||||
temp2: path.resolve('./test/temp2/'),
|
||||
temp3: path.resolve('./test/temp3'),
|
||||
temp4: path.resolve('./test/temp4'),
|
||||
noGit: path.resolve('./test/')
|
||||
};
|
||||
describe('smartgit', function () {
|
||||
let testGitRepo;
|
||||
let testGitRepoCloned;
|
||||
let testGitRepoInit;
|
||||
describe('instance', function () {
|
||||
it('should error for invalid path', function (done) {
|
||||
try {
|
||||
testGitRepo = new smartgit.GitRepo(paths.temp1);
|
||||
}
|
||||
catch (err) {
|
||||
should(testGitRepo).not.be.instanceOf(smartgit.GitRepo);
|
||||
done();
|
||||
}
|
||||
});
|
||||
it('should init a new repo', function (done) {
|
||||
this.timeout(40000);
|
||||
smartgit.createRepoFromInit(paths.temp1)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo);
|
||||
done();
|
||||
}).catch(err => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
it('should create am instance for an existing repo', function () {
|
||||
testGitRepo = new smartgit.GitRepo(paths.temp1);
|
||||
should(testGitRepo).be.instanceOf(smartgit.GitRepo);
|
||||
});
|
||||
it('should clone a repository using ssh and sshkey', function (done) {
|
||||
this.timeout(40000);
|
||||
smartgit.createRepoFromClone('git@gitlab.com:sandboxzone/sandbox-testrepo.git', paths.temp2)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo);
|
||||
done();
|
||||
}).catch(err => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
it('should clone a repository using https', function (done) {
|
||||
this.timeout(40000);
|
||||
smartgit.createRepoFromClone('https://gitlab.com/sandboxzone/sandbox-testrepo.git', paths.temp3)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo);
|
||||
done();
|
||||
}).catch(err => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('.add', function () {
|
||||
it('should add a file to an existing repository', function () {
|
||||
shelljs.exec(`(cd ${paths.temp1} && cp ../test.js .)`);
|
||||
testGitRepo.addAll(paths.temp1);
|
||||
});
|
||||
});
|
||||
describe('.check()', function (done) {
|
||||
it('should check a git repo', function () {
|
||||
let checkResult = testGitRepo.check();
|
||||
should(checkResult).be.true();
|
||||
});
|
||||
});
|
||||
describe('commit', function () {
|
||||
it('should commit a new file to an existing repository', function () {
|
||||
testGitRepo.commit('added a new file');
|
||||
});
|
||||
});
|
||||
describe('pull', function () {
|
||||
this.timeout(40000);
|
||||
it('should pull from origin', function (done) {
|
||||
testGitRepo.pull()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('push', function () {
|
||||
this.timeout(40000);
|
||||
it('should push to origin', function (done) {
|
||||
testGitRepo.push('origin', 'master')
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('remote', function () {
|
||||
it('should add a remote', function () {
|
||||
testGitRepo.remoteAdd('origin2', 'https://github.com/pushrocks/somerepo');
|
||||
});
|
||||
it('should', function (done) {
|
||||
testGitRepo.remoteList()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQixJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUE7QUFDaEMsNkJBQTZCO0FBQzdCLGlDQUFnQ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ts
133
test/test.ts
@ -1,112 +1,29 @@
|
||||
import 'typings-test'
|
||||
import beautylog = require('beautylog')
|
||||
let shelljs = require('shelljs')
|
||||
import path = require('path')
|
||||
import * as should from 'should'
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import * as smartgit from '../ts/index.js';
|
||||
|
||||
import smartgit = require('../dist/index')
|
||||
let paths = {
|
||||
temp1: path.resolve('./test/temp/'),
|
||||
temp2: path.resolve('./test/temp2/'),
|
||||
temp3: path.resolve('./test/temp3'),
|
||||
temp4: path.resolve('./test/temp4'),
|
||||
noGit: path.resolve('./test/')
|
||||
}
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
const __dirname = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
|
||||
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).toBeInstanceOf(smartgit.Smartgit);
|
||||
});
|
||||
|
||||
describe('smartgit', function () {
|
||||
let testGitRepo: smartgit.GitRepo
|
||||
let testGitRepoCloned: smartgit.GitRepo
|
||||
let testGitRepoInit: smartgit.GitRepo
|
||||
describe('instance', function () {
|
||||
it('should error for invalid path', function (done) {
|
||||
try {
|
||||
testGitRepo = new smartgit.GitRepo(paths.temp1)
|
||||
} catch (err) {
|
||||
should(testGitRepo).not.be.instanceOf(smartgit.GitRepo)
|
||||
done()
|
||||
}
|
||||
})
|
||||
it('should init a new repo', function (done) {
|
||||
this.timeout(40000)
|
||||
smartgit.createRepoFromInit(paths.temp1)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo)
|
||||
done()
|
||||
}).catch(err => {
|
||||
throw err
|
||||
})
|
||||
})
|
||||
it('should create am instance for an existing repo', function () {
|
||||
testGitRepo = new smartgit.GitRepo(paths.temp1)
|
||||
should(testGitRepo).be.instanceOf(smartgit.GitRepo)
|
||||
})
|
||||
it('should clone a repository using ssh and sshkey', function (done) {
|
||||
this.timeout(40000)
|
||||
smartgit.createRepoFromClone('git@gitlab.com:sandboxzone/sandbox-testrepo.git', paths.temp2)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo)
|
||||
done()
|
||||
}).catch(err => {
|
||||
throw err
|
||||
})
|
||||
})
|
||||
it('should clone a repository using https', function (done) {
|
||||
this.timeout(40000)
|
||||
smartgit.createRepoFromClone('https://gitlab.com/sandboxzone/sandbox-testrepo.git', paths.temp3)
|
||||
.then((gitRepo) => {
|
||||
should(gitRepo).be.instanceOf(smartgit.GitRepo)
|
||||
done()
|
||||
}).catch(err => {
|
||||
throw err
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.add', function () {
|
||||
it('should add a file to an existing repository', function () {
|
||||
shelljs.exec(`(cd ${paths.temp1} && cp ../test.js .)`)
|
||||
testGitRepo.addAll(paths.temp1)
|
||||
})
|
||||
})
|
||||
describe('.check()', function(done) {
|
||||
it('should check a git repo', function() {
|
||||
let checkResult = testGitRepo.check()
|
||||
should(checkResult).be.true()
|
||||
})
|
||||
})
|
||||
describe('commit', function () {
|
||||
it('should commit a new file to an existing repository', function () {
|
||||
testGitRepo.commit('added a new file')
|
||||
})
|
||||
})
|
||||
describe('pull', function () {
|
||||
this.timeout(40000)
|
||||
it('should pull from origin', function (done) {
|
||||
testGitRepo.pull()
|
||||
.then(() => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('push', function () {
|
||||
this.timeout(40000)
|
||||
it('should push to origin', function (done) {
|
||||
testGitRepo.push('origin', 'master')
|
||||
.then(() => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('remote', function () {
|
||||
it('should add a remote', function () {
|
||||
testGitRepo.remoteAdd('origin2', 'https://github.com/pushrocks/somerepo')
|
||||
})
|
||||
it('should', function(done) {
|
||||
testGitRepo.remoteList()
|
||||
.then(() => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
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/push.rocks/smartfile.git',
|
||||
testRepoDirSmartfile
|
||||
);
|
||||
});
|
||||
|
||||
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: '@push.rocks/smartgit',
|
||||
version: '3.0.1',
|
||||
description: 'smart wrapper for nodegit'
|
||||
}
|
33
ts/index.ts
33
ts/index.ts
@ -1,31 +1,2 @@
|
||||
import * as q from 'q'
|
||||
import plugins = require("./smartgit.plugins");
|
||||
|
||||
import { GitRepo } from './smartgit.classes.gitrepo'
|
||||
export {
|
||||
GitRepo
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new GitRepo Instance after cloning a project
|
||||
*/
|
||||
export let createRepoFromClone = (fromArg: string, toArg: string) => {
|
||||
let done = q.defer<GitRepo>()
|
||||
plugins.smartfile.fs.ensureDir(toArg)
|
||||
plugins.shelljs.exec(`git clone ${fromArg} ${toArg}`)
|
||||
let newRepo = new GitRepo(toArg)
|
||||
done.resolve(newRepo)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new GitRepo instance after initializing a new Git Repository
|
||||
*/
|
||||
export let createRepoFromInit = (destinationDirArg: string) => {
|
||||
let done = q.defer<GitRepo>()
|
||||
plugins.smartfile.fs.ensureDir(destinationDirArg)
|
||||
plugins.shelljs.exec(`cd ${destinationDirArg} && git init`)
|
||||
let newRepo = new GitRepo(destinationDirArg)
|
||||
done.resolve(newRepo)
|
||||
return done.promise
|
||||
}
|
||||
export * from './smartgit.classes.gitrepo.js';
|
||||
export * from './smartgit.classes.smartgit.js';
|
||||
|
@ -1,150 +1,113 @@
|
||||
import * as q from 'q'
|
||||
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
|
||||
*/
|
||||
export class GitRepo {
|
||||
repoBase: string
|
||||
constructor(repoBaseArg: string) {
|
||||
this.repoBase = repoBaseArg
|
||||
if (!this.check()) {
|
||||
throw new Error('no valid git repo')
|
||||
}
|
||||
// STATIC
|
||||
/**
|
||||
* creates a new GitRepo Instance after cloning a project
|
||||
*/
|
||||
public static async fromCloningIntoDir(
|
||||
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(
|
||||
smartgitRefArg: Smartgit,
|
||||
dirArg: string
|
||||
): Promise<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
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the Repo is valid
|
||||
*/
|
||||
check(): boolean {
|
||||
return plugins.smartfile.fs.isDirectory(plugins.path.join(this.repoBase, '.git'))
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* stage all files in working directory
|
||||
*/
|
||||
addAll(dirPathArg: string) {
|
||||
let done = q.defer()
|
||||
plugins.shelljs.exec(`(cd ${dirPathArg} && git add -A && git status)`)
|
||||
done.resolve(dirPathArg)
|
||||
return done.promise
|
||||
};
|
||||
|
||||
/**
|
||||
* add a remote to the GitRepo
|
||||
*/
|
||||
remoteAdd(remoteNameArg: string, remoteLinkArg: string) {
|
||||
let done = q.defer()
|
||||
if (!remoteNameArg) {
|
||||
let err = new Error('smartgit.remote.add expects a valid remote name')
|
||||
plugins.beautylog.error(err.message)
|
||||
done.reject(err)
|
||||
return done.promise
|
||||
};
|
||||
if (!remoteLinkArg) {
|
||||
let err = new Error()
|
||||
plugins.beautylog.error(err.message)
|
||||
done.reject(err)
|
||||
return done.promise
|
||||
};
|
||||
|
||||
// if everything is all right proceed
|
||||
plugins.shelljs.exec(`cd ${this.repoBase} && git remote add ${remoteNameArg} ${remoteLinkArg}`)
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* list remotes for a Gip
|
||||
*/
|
||||
remoteList() {
|
||||
let done = q.defer()
|
||||
let remotes = {}
|
||||
plugins.shelljs.exec(`cd ${this.repoBase} && git remote -v`)
|
||||
done.resolve(remotes)
|
||||
return done.promise
|
||||
};
|
||||
|
||||
/**
|
||||
* remove remote
|
||||
*/
|
||||
remoteRemove(dirPathArg: string) {
|
||||
let done = q.defer()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* commit all files that are currently staged
|
||||
*/
|
||||
commit(commitMessage: string) {
|
||||
let done = q.defer()
|
||||
plugins.shelljs.exec(`(cd ${this.repoBase} && git commit -m "${commitMessage}")`)
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* pull latest changes from remote
|
||||
*/
|
||||
pull(sourceArg: string = '', branchArg: string = '') {
|
||||
let done = q.defer()
|
||||
// if everything is allright proceed
|
||||
plugins.shelljs.exec(`(cd ${this.repoBase} && git pull ${sourceArg} ${branchArg})`)
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* push new commits to remote
|
||||
*/
|
||||
push(remoteNameArg: string = '', remoteBranchArg: string = '') {
|
||||
let done = q.defer()
|
||||
// if everything seems allright proceed
|
||||
plugins.shelljs.exec(`(cd ${this.repoBase} && git push ${remoteNameArg} ${remoteBranchArg})`)
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* sync
|
||||
*/
|
||||
sync() {
|
||||
this.pull().then(() => {
|
||||
this.push()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current status
|
||||
*/
|
||||
status() {
|
||||
let done = q.defer()
|
||||
plugins.shelljs.exec(`(cd ${this.repoBase} && git status)`)
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new GitRepo Instance after cloning a project
|
||||
*/
|
||||
export let createRepoFromClone = (fromArg: string, toArg: string) => {
|
||||
let done = q.defer<GitRepo>()
|
||||
plugins.smartfile.fs.ensureDir(toArg)
|
||||
plugins.shelljs.exec(`git clone ${fromArg} ${toArg}`)
|
||||
let newRepo = new GitRepo(toArg)
|
||||
done.resolve(newRepo)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new GitRepo instance after initializing a new Git Repository
|
||||
*/
|
||||
export let createRepoFromInit = (destinationDirArg: string) => {
|
||||
let done = q.defer<GitRepo>()
|
||||
plugins.smartfile.fs.ensureDir(destinationDirArg)
|
||||
plugins.shelljs.exec(`cd destinationDirArg && git init`)
|
||||
let newRepo = new GitRepo(destinationDirArg)
|
||||
done.resolve(newRepo)
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
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;
|
||||
}
|
||||
}
|
@ -1,7 +1,17 @@
|
||||
import 'typings-global'
|
||||
export import path = require('path')
|
||||
export import beautylog = require('beautylog')
|
||||
export import shelljs = require('shelljs')
|
||||
export import smartfile = require('smartfile')
|
||||
export import smartpath = require('smartpath')
|
||||
export import smartstring = require('smartstring')
|
||||
// node native
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
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';
|
||||
|
||||
export { smartenv, smartfile, smartpath, smartpromise, smartstring };
|
||||
|
||||
// third party
|
||||
import isomorphicGit from 'isomorphic-git';
|
||||
|
||||
export { isomorphicGit };
|
||||
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user