diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.ts index bdd47d4d..bb8e1f72 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/git.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/git.ts @@ -1,24 +1,9 @@ -import type { SimpleGit } from 'simple-git'; -import { simpleGit } from 'simple-git'; +import {simpleGit} from 'simple-git'; -export const gitClient: SimpleGit = simpleGit(); - -export async function cleanGitHistoryForFolder( - environmentRoot: string, - options?: { verbose?: boolean }, - git: SimpleGit = gitClient -): Promise { - await git.show(['--oneline']); -} - -export async function isFolderInRepo(folderPath: string): Promise { +export async function isFolderInGit(folderPath: string): Promise { try { - // Initialize simple-git with the folder path const git = simpleGit(folderPath); - // Check if the folder is a git repository - const isRepo = (await git.checkIgnore(folderPath)).length === 0; - // console.log(`${folderPath} is ${isRepo ? '' : 'not '} in Git repository.`); - return isRepo; + return (await git.checkIgnore(folderPath)).length === 0; } catch (error) { if ( (error as Error).message.includes( diff --git a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts index 50a45242..fa4650e5 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -1,15 +1,15 @@ -import { Environment } from '../env-bootstrap/npm'; -import { simpleGit, type SimpleGit } from 'simple-git'; -import { isFolderInRepo } from './git'; -import { ExecutorContext, logger } from '@nx/devkit'; -import { join } from 'node:path'; -import { VERDACCIO_REGISTRY_JSON } from '../env-bootstrap/constants'; -import { fileExists } from '../../internal/file-system'; -import { rm } from 'node:fs/promises'; +import type {Environment} from '../env-bootstrap/npm'; +import {simpleGit, type SimpleGit} from 'simple-git'; +import {isFolderInGit} from './git'; +import type {ExecutorContext, logger} from '@nx/devkit'; +import {join} from 'node:path'; +import {VERDACCIO_REGISTRY_JSON} from '../env-bootstrap/constants'; +import {fileExists} from '../../internal/file-system'; +import {rm} from 'node:fs/promises'; import runKillProcessExecutor from '../kill-process/executor'; -import { DEFAULT_ENVIRONMENTS_OUTPUT_DIR } from '../../plugin/constants'; -import { ExpandedPluginConfiguration } from 'nx/src/config/nx-json'; -import type { NxVerdaccioCreateNodeOptions } from '../../plugin/schema'; +import {DEFAULT_ENVIRONMENTS_OUTPUT_DIR} from '../../plugin/constants'; +import type {ExpandedPluginConfiguration} from 'nx/src/config/nx-json'; +import type {NxVerdaccioCreateNodeOptions} from '../../plugin/schema'; export const gitClient: SimpleGit = simpleGit(process.cwd()); export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; @@ -44,15 +44,13 @@ export async function teardownEnvironment( return; } - // clean environmentRoot - const environmentRootInRepo = await isFolderInRepo(environmentRoot); - if (environmentRootInRepo) { - // await git.checkout([environmentRoot]); - // await git.clean('f', [environmentRoot]); + const environmentRootInGit = await isFolderInGit(environmentRoot); + if (environmentRootInGit) { + await git.checkout([environmentRoot]); + await git.clean('f', [environmentRoot]); logger.info(`Cleaned git history in ${environmentRoot}`); } else { try { - const registryFiles = [join(environmentRoot)]; await rm(environmentRoot, { recursive: true, force: true,