Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Oct 13, 2024
1 parent a288137 commit 20a57e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
21 changes: 3 additions & 18 deletions projects/nx-verdaccio/src/executors/env-teardown/git.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
await git.show(['--oneline']);
}

export async function isFolderInRepo(folderPath: string): Promise<boolean> {
export async function isFolderInGit(folderPath: string): Promise<boolean> {
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(
Expand Down
32 changes: 15 additions & 17 deletions projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts
Original file line number Diff line number Diff line change
@@ -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 };
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 20a57e2

Please sign in to comment.