Skip to content

Commit

Permalink
fix: add skipTeardown to env-teardown executor
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton authored Oct 23, 2024
2 parents e487162 + f257ebb commit 664c6bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
42 changes: 24 additions & 18 deletions projects/nx-verdaccio/src/executors/env-teardown/executor.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { type ExecutorContext, logger } from '@nx/devkit';
import type { TeardownExecutorOptions } from './schema';
import { teardownEnvironment } from './teardown-env';
import { PACKAGE_NAME } from '../../plugin/constants';
import { EXECUTOR_ENVIRONMENT_TEARDOWN } from './constants';
import { type ExecutorOutput } from '../internal/executor-output';
import {type ExecutorContext, logger} from '@nx/devkit';
import type {TeardownExecutorOptions} from './schema';
import {teardownEnvironment} from './teardown-env';
import {PACKAGE_NAME} from '../../plugin/constants';
import {EXECUTOR_ENVIRONMENT_TEARDOWN} from './constants';
import {type ExecutorOutput} from '../internal/executor-output';
import {getEnvironmentRoot} from "../../internal/environment-root";

export async function teardownExecutor(
options: TeardownExecutorOptions,
context: ExecutorContext
): Promise<ExecutorOutput> {
const { environmentRoot, verbose } = options;
const {verbose, skipTeardown} = options;
const environmentRoot = getEnvironmentRoot(context, options);

if (verbose) {
logger.info(
Expand All @@ -20,17 +22,21 @@ export async function teardownExecutor(
)}`
);
}
try {
await teardownEnvironment(context, {
environmentRoot,
verbose,
});
} catch (error) {
logger.error(error);
return {
success: false,
command: error?.message ?? (error as Error).toString(),
};
if (!skipTeardown) {
try {
await teardownEnvironment(context, {
environmentRoot,
verbose,
});
} catch (error) {
logger.error(error);
return {
success: false,
command: error?.message ?? (error as Error).toString(),
};
}
} else {
logger.info(`Skip teardown environment in ${environmentRoot}`);
}

return {
Expand Down
5 changes: 5 additions & 0 deletions projects/nx-verdaccio/src/executors/env-teardown/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"verbose": {
"type": "boolean",
"description": "Print additional logs"
},
"skipTeardown": {
"type": "boolean",
"description": "Skip cleanup folders and files generated by nx-verdaccio",
"default": false
}
},
"additionalProperties": true,
Expand Down
7 changes: 4 additions & 3 deletions projects/nx-verdaccio/src/executors/env-teardown/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { type Environment } from '../env-bootstrap/npm';
import {type Environment} from '../env-bootstrap/npm';

export type TeardownExecutorOptions = Partial<
Environment & {
verbose: boolean;
}
verbose: boolean;
skipTeardown: boolean;
}
>;

0 comments on commit 664c6bd

Please sign in to comment.