Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Dec 30, 2023
1 parent 9c35d3f commit 09f0c8f
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

JS implementation for [Git-Sync](https://github.com/simonthum/git-sync), a handy script that backup your notes in a git repo to the remote git services.

Used by [TiddlyGit-Desktop](https://github.com/tiddly-gittly/TiddlyGit-Desktop), refactor out to be a npm package.
Used by OpenSource free bi-link second brain note taking & knowledge map app [TidGi-Desktop](https://github.com/tiddly-gittly/TidGi-Desktop), refactor out to be a npm package.

```shell
npm i git-sync-js
Expand Down Expand Up @@ -31,11 +31,13 @@ import {
} from 'git-sync-js';
```

You can see [TiddlyGit Desktop's usage](https://github.com/tiddly-gittly/TiddlyGit-Desktop/blob/37fd560badd7a63cced8ece7c68d6d384b6612a0/src/services/git/index.ts) for full example.
See [api docs](./docs/api/) for full list of them.

You can see [TidGi-Desktop's usage](https://github.com/tiddly-gittly/TidGi-Desktop/blob/9e73bbf96deb5a4c085bbf9c56dc38e62efdd550/src/services/git/gitWorker.ts) for full example.

### initGit

Initialize a new `.git` on a folder. If set `syncImmediately` to `true`, it will push local git to remote immediately after init, you should provide `userInfo.accessToken` and `remoteUrl`, otherwise they are optional.
[initGit()](./docs/api/modules/initGit.md) Initialize a new `.git` on a folder. If set `syncImmediately` to `true`, it will push local git to remote immediately after init, you should provide `userInfo.accessToken` and `remoteUrl`, otherwise they are optional.

```ts
try {
Expand All @@ -45,10 +47,16 @@ try {
syncImmediately: isSyncedWiki,
userInfo: { ...defaultGitInfo, ...userInfo },
logger: {
log: (message: string, context: ILoggerContext): unknown => logger.info(message, { callerFunction: 'initWikiGit', ...context }),
warn: (message: string, context: ILoggerContext): unknown => logger.warn(message, { callerFunction: 'initWikiGit', ...context }),
log: (message: string, context: ILoggerContext): unknown =>
logger.info(message, { callerFunction: 'initWikiGit', ...context }),
warn: (message: string, context: ILoggerContext): unknown =>
logger.warn(message, { callerFunction: 'initWikiGit', ...context }),
info: (message: GitStep, context: ILoggerContext): void => {
logger.notice(this.translateMessage(message), { handler: WikiChannel.syncProgress, callerFunction: 'initWikiGit', ...context });
logger.notice(this.translateMessage(message), {
handler: WikiChannel.syncProgress,
callerFunction: 'initWikiGit',
...context,
});
},
},
});
Expand All @@ -59,7 +67,7 @@ try {

### commitAndSync

Core feature of git-sync, commit all unstaged files, and try rebase on remote, and push to the remote.
[commitAndSync()](./docs/api/modules/commitAndSync.md) is the Core feature of git-sync, commit all unstaged files, and try rebase on remote, and push to the remote.

```ts
try {
Expand All @@ -68,10 +76,16 @@ try {
remoteUrl,
userInfo: { ...defaultGitInfo, ...userInfo },
logger: {
log: (message: string, context: ILoggerContext): unknown => logger.info(message, { callerFunction: 'commitAndSync', ...context }),
warn: (message: string, context: ILoggerContext): unknown => logger.warn(message, { callerFunction: 'commitAndSync', ...context }),
log: (message: string, context: ILoggerContext): unknown =>
logger.info(message, { callerFunction: 'commitAndSync', ...context }),
warn: (message: string, context: ILoggerContext): unknown =>
logger.warn(message, { callerFunction: 'commitAndSync', ...context }),
info: (message: GitStep, context: ILoggerContext): void => {
logger.notice(this.translateMessage(message), { handler: WikiChannel.syncProgress, callerFunction: 'commitAndSync', ...context });
logger.notice(this.translateMessage(message), {
handler: WikiChannel.syncProgress,
callerFunction: 'commitAndSync',
...context,
});
},
},
filesToIgnore,
Expand All @@ -83,7 +97,7 @@ try {

### clone

Clone a remote repo to a local location.
[clone()](./docs/api/modules/clone.md) will Clone a remote repo to a local location.

```ts
try {
Expand All @@ -92,10 +106,16 @@ try {
remoteUrl,
userInfo: { ...defaultGitInfo, ...userInfo },
logger: {
log: (message: string, context: ILoggerContext): unknown => logger.info(message, { callerFunction: 'clone', ...context }),
warn: (message: string, context: ILoggerContext): unknown => logger.warn(message, { callerFunction: 'clone', ...context }),
log: (message: string, context: ILoggerContext): unknown =>
logger.info(message, { callerFunction: 'clone', ...context }),
warn: (message: string, context: ILoggerContext): unknown =>
logger.warn(message, { callerFunction: 'clone', ...context }),
info: (message: GitStep, context: ILoggerContext): void => {
logger.notice(this.translateMessage(message), { handler: WikiChannel.syncProgress, callerFunction: 'clone', ...context });
logger.notice(this.translateMessage(message), {
handler: WikiChannel.syncProgress,
callerFunction: 'clone',
...context,
});
},
},
});
Expand Down Expand Up @@ -161,7 +181,7 @@ Check if dir has `.git`.
## Steps
These are git sync steps enum, that will log to logger when steps happened. You can write switch case on them in your custom logger, and translate them into user readable info.
These is a git sync steps enum [GitStep](./docs/api/enums/interface.GitStep.md), that will log to logger when steps happened. You can write switch case on them in your custom logger, and translate them into user readable info.
```shell
StartGitInitialization
Expand Down Expand Up @@ -196,7 +216,7 @@ CantSyncInSpecialGitStateAutoFixSucceed
## Errors
These are the errors throw on git sync gets into fatal situations. You can try catch on major functions to get these errors, and `instanceof` these error to translate their message for user to read and report.
These are the errors like [AssumeSyncError](./docs/api/classes/errors.AssumeSyncError.md) that will throw on git sync gets into fatal situations. You can try catch on major functions to get these errors, and `instanceof` these error to translate their message for user to read and report.
```shell
AssumeSyncError
Expand Down

0 comments on commit 09f0c8f

Please sign in to comment.