Skip to content

Latest commit

 

History

History
53 lines (34 loc) · 1.42 KB

git.md

File metadata and controls

53 lines (34 loc) · 1.42 KB

Git API

English | 简体中文

The Git API is provided by the @modern-js/codesmith-api-git package, which provides methods for initializing Git repositories, committing Git commits, etc.

Usage

import { GitAPI } from '@modern-js/codesmith-api-git';

export default async (context: GeneratorContext, generator: GeneratorCore) => {
  const gitApi = new GitAPI(generatorCore, generatorContext);
  await gitApi.initGitRepo();
};
  • Create an instance of GitAPI with the same parameters as the micro-generator.
  • Call the API methods provided on the instance.

API

isInGitRepo

Determine if the current project is a git repository. It is defined as follows:

isInGitRepo: (cwd?: string) => Promise<boolean>;
  • cwd: The project directory, with a default value of generator.outputPath.

initGitRepo

Initialize the current project as a git repository. It is defined as follows:

initGitRepo(cwd?: string, force?: boolean): Promise<void>;
  • cwd: The project directory, with a default value of generator.outputPath.
  • force: Whether to force initialization if the current directory is already a git repository.

addAndCommit

Commit current changes. It is defined as follows:

addAndCommit(commitMessage: string, cwd?: string): Promise<void>;
  • commitMessage: The commit message.
  • cwd: The project directory, with a default value of generator.outputPath.