-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
468 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
projects/nx-verdaccio/src/executors/env-teardown/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Teardown Environment Executor | ||
|
||
This executor helps to cleanup a [environment](../../../../../README.md#-environment-folders-to-isolate-files-during-e2e-tests) of a given folder. | ||
If a server is running for the given environment, it will be stopped. | ||
If this folder is checked into github all it's changes will be reverted, if it is not checked into github, the folder will be deleted. | ||
|
||
**Environment folder** | ||
|
||
#### @push-based/nx-verdaccio:env-teardown | ||
|
||
## Usage | ||
|
||
// project.json | ||
|
||
```json | ||
{ | ||
"name": "my-project", | ||
"targets": { | ||
"env-teardown": { | ||
"executor": "@push-based/nx-verdaccio:env-teardown" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
By default, the Nx executor will derive the options from the executor options. | ||
|
||
```jsonc | ||
{ | ||
"name": "my-project", | ||
"targets": { | ||
"env-teardown": { | ||
"executor": "@code-pushup/nx-verdaccio:env-teardown", | ||
"options": { | ||
"envRoot": "/tmp/test-npm-workspace" | ||
"verbose": true, | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Show what will be executed without actually executing it: | ||
|
||
`nx run my-project:env-teardown --print-config` | ||
|
||
## Options | ||
|
||
| Name | type | description | | ||
| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | | ||
| **envRoot** | `string` (REQUIRED) | The folder in which the package should get published. This folder is the environment folder and contains a configured `.npmrc` file. | | ||
| **verbose** | `boolean` | Show more verbose logs | | ||
| **printConfig** | `boolean` | Print config without executing | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const EXECUTOR_ENVIRONMENT_TEARDOWN = 'env-teardown'; |
42 changes: 42 additions & 0 deletions
42
projects/nx-verdaccio/src/executors/env-teardown/executor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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 { ExecutorOutput } from '../internal/executor-output'; | ||
|
||
export async function teardownExecutor( | ||
options: TeardownExecutorOptions, | ||
context: ExecutorContext | ||
): Promise<ExecutorOutput> { | ||
const { environmentRoot, verbose } = options; | ||
|
||
if (verbose) { | ||
logger.info( | ||
`Execute ${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN} with options: ${JSON.stringify( | ||
options, | ||
null, | ||
2 | ||
)}` | ||
); | ||
} | ||
try { | ||
await teardownEnvironment(context, { | ||
environmentRoot, | ||
verbose, | ||
}); | ||
} catch (error) { | ||
logger.error(error); | ||
return { | ||
success: false, | ||
command: error?.message ?? (error as Error).toString(), | ||
}; | ||
} | ||
|
||
return { | ||
success: true, | ||
command: 'Teared down environment successfully.', | ||
}; | ||
} | ||
|
||
export default teardownExecutor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {simpleGit} from 'simple-git'; | ||
|
||
export async function isFolderInGit(folderPath: string): Promise<boolean> { | ||
try { | ||
const git = simpleGit(folderPath); | ||
// Check if the folder is a git repository | ||
const isRepo = (await git.checkIgnore(folderPath)).length === 0; | ||
return isRepo; | ||
} catch (error) { | ||
if ( | ||
(error as Error).message.includes( | ||
'Cannot use simple-git on a directory that does not exist' | ||
) | ||
) { | ||
return true; | ||
} | ||
console.log(`${error}`); | ||
return false; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
projects/nx-verdaccio/src/executors/env-teardown/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "TeardownExecutorOptions", | ||
"title": "Environment teardown executor options", | ||
"type": "object", | ||
"properties": { | ||
"environmentRoot": { | ||
"type": "string", | ||
"description": "The root directory of the environment", | ||
"aliases": ["envRoot", "e"] | ||
}, | ||
"verbose": { | ||
"type": "boolean", | ||
"description": "Print additional logs" | ||
} | ||
}, | ||
"additionalProperties": true, | ||
"required": [] | ||
} |
Oops, something went wrong.