@cyberalien/git-utils
Advanced tools
+12
-3
| import { GitRepoConfig } from "./types.js"; | ||
| type GitRepoFilesList = Record<string, string | null | Record<string, unknown> | Array<unknown>>; | ||
| interface CreateGitRepoParams { | ||
| target: string; | ||
| isNew: boolean; | ||
| } | ||
| interface CreateGitRepoResult { | ||
@@ -7,9 +12,13 @@ packageJSON?: Record<string, unknown>; | ||
| bumpVersion?: string | ((currentVersion: string) => string); | ||
| files?: Record<string, string | null | Record<string, unknown> | Array<unknown>>; | ||
| files?: GitRepoFilesList; | ||
| commit?: string; | ||
| } | ||
| /** | ||
| * Helper function to add directory to git repository | ||
| */ | ||
| declare function addDirectoryToGitRepo(target: GitRepoFilesList, sourceDir: string, destDir?: string, filter?: (filename: string) => boolean): Promise<string[]>; | ||
| /** | ||
| * Create or update git repository | ||
| */ | ||
| declare function createGitRepo(repo: GitRepoConfig, target: string, callback: (isNew: boolean) => Promise<CreateGitRepoResult>, dryRun?: boolean): Promise<boolean>; | ||
| export { CreateGitRepoResult, createGitRepo }; | ||
| declare function createGitRepo(repo: GitRepoConfig, target: string, callback: (params: CreateGitRepoParams) => Promise<CreateGitRepoResult>, dryRun?: boolean): Promise<boolean>; | ||
| export { CreateGitRepoParams, CreateGitRepoResult, GitRepoFilesList, addDirectoryToGitRepo, createGitRepo }; |
+21
-3
@@ -10,4 +10,19 @@ import { cloneGitRepo } from "./clone.js"; | ||
| import { join } from "node:path"; | ||
| import { rm } from "node:fs/promises"; | ||
| import { readFile, rm } from "node:fs/promises"; | ||
| /** | ||
| * Helper function to add directory to git repository | ||
| */ | ||
| async function addDirectoryToGitRepo(target, sourceDir, destDir = "", filter) { | ||
| const files = await scanDirectory(sourceDir); | ||
| const addedFiles = []; | ||
| for (const file of files) { | ||
| if (filter && !filter(file)) continue; | ||
| const content = await readFile(join(sourceDir, file), "utf8"); | ||
| const filename = join(destDir, file); | ||
| addedFiles.push(filename); | ||
| target[filename] = content; | ||
| } | ||
| return addedFiles; | ||
| } | ||
| /** | ||
| * Create or update git repository | ||
@@ -20,3 +35,6 @@ */ | ||
| const filesToRemove = new Set(oldFiles.filter((file) => !file.startsWith(".git/"))); | ||
| const result = await callback(!cloneResult); | ||
| const result = await callback({ | ||
| isNew: !cloneResult, | ||
| target | ||
| }); | ||
| if (result.packageJSON) { | ||
@@ -52,2 +70,2 @@ if ("version" in result.packageJSON && oldFiles.includes("package.json")) try { | ||
| } | ||
| export { createGitRepo }; | ||
| export { addDirectoryToGitRepo, createGitRepo }; |
+1
-1
@@ -6,3 +6,3 @@ { | ||
| "author": "Vjacheslav Trushkin", | ||
| "version": "0.0.5", | ||
| "version": "0.0.6", | ||
| "license": "UNLICENSED", | ||
@@ -9,0 +9,0 @@ "bugs": "https://github.com/cyberalien/svg-utils/issues", |
14535
6.9%415
6.96%