npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-sync-js

v2.0.5

Published

JS implementation for Git-Sync, a handy script that backup your notes in a git repo to the remote git services.

Downloads

49

Readme

git-sync-js

Documentation Site

JS implementation for Git-Sync, a handy script that backup your notes in a git repo to the remote git services.

Used by OpenSource free bi-link second brain note taking & knowledge map app TidGi-Desktop, refactor out to be a npm package.

npm i git-sync-js

Major Functions

There are three major functions: initGit, clone, commitAndSync, but you may import other helper functions and Error types, and GitStep types:

import {
  initGit,
  clone,
  commitAndSync,
  AssumeSyncError,
  CantSyncGitNotInitializedError,
  CantSyncInSpecialGitStateAutoFixFailed,
  getModifiedFileList,
  getRemoteUrl,
  GitPullPushError,
  GitStep,
  ILoggerContext,
  ModifiedFileList,
  SyncParameterMissingError,
  SyncScriptIsInDeadLoopError,
} from 'git-sync-js';

See api docs for full list of them.

You can see TidGi-Desktop's usage for full example.

initGit

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.

try {
  await initGit({
    dir: wikiFolderPath,
    remoteUrl,
    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 }),
      info: (message: GitStep, context: ILoggerContext): void => {
        logger.notice(this.translateMessage(message), {
          handler: WikiChannel.syncProgress,
          callerFunction: 'initWikiGit',
          ...context,
        });
      },
    },
  });
} catch (error) {
  this.translateErrorMessage(error);
}

commitAndSync

commitAndSync() is the Core feature of git-sync, commit all unstaged files, and try rebase on remote, and push to the remote.

try {
  await commitAndSync({
    dir: wikiFolderPath,
    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 }),
      info: (message: GitStep, context: ILoggerContext): void => {
        logger.notice(this.translateMessage(message), {
          handler: WikiChannel.syncProgress,
          callerFunction: 'commitAndSync',
          ...context,
        });
      },
    },
    filesToIgnore,
  });
} catch (error) {
  this.translateErrorMessage(error);
}

clone

clone() will Clone a remote repo to a local location.

try {
  await clone({
    dir: repoFolderPath,
    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 }),
      info: (message: GitStep, context: ILoggerContext): void => {
        logger.notice(this.translateMessage(message), {
          handler: WikiChannel.syncProgress,
          callerFunction: 'clone',
          ...context,
        });
      },
    },
  });
} catch (error) {
  this.translateErrorMessage(error);
}

Inspect helpers

getModifiedFileList

Get modified files and modify type in a folder

await getModifiedFileList(wikiFolderPath);

getDefaultBranchName

getSyncState

assumeSync

getGitRepositoryState

getGitDirectory

hasGit

Check if dir has .git.

Sync helpers

commitFiles

continueRebase

Steps

These is a git sync steps enum GitStep, 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.

StartGitInitialization
PrepareCloneOnlineWiki
GitRepositoryConfigurationFinished
StartConfiguringGithubRemoteRepository
StartBackupToGitRemote
PrepareSync
HaveThingsToCommit
AddingFiles
AddComplete
CommitComplete
PreparingUserInfo
FetchingData
NoNeedToSync
LocalAheadStartUpload
CheckingLocalSyncState
CheckingLocalGitRepoSanity
LocalStateBehindSync
LocalStateDivergeRebase
RebaseResultChecking
RebaseConflictNeedsResolve
RebaseSucceed
GitPushFailed
GitMergeFailed
SyncFailedAlgorithmWrong
PerformLastCheckBeforeSynchronizationFinish
SynchronizationFinish
StartFetchingFromGithubRemote
CantSyncInSpecialGitStateAutoFixSucceed

Errors

These are the errors like AssumeSyncError 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.

AssumeSyncError
SyncParameterMissingError
GitPullPushError
CantSyncGitNotInitializedError
SyncScriptIsInDeadLoopError
CantSyncInSpecialGitStateAutoFixFailed