feat(nx-plugin): update executor generator to have context (#16982)
Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com>
This commit is contained in:
parent
a1c26d51ab
commit
6d2e7cd2cf
26
docs/generated/devkit/AsyncIteratorExecutor.md
Normal file
26
docs/generated/devkit/AsyncIteratorExecutor.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Type alias: AsyncIteratorExecutor\<T\>
|
||||||
|
|
||||||
|
Ƭ **AsyncIteratorExecutor**\<`T`\>: (`options`: `T`, `context`: [`ExecutorContext`](../../devkit/documents/ExecutorContext)) => `AsyncIterableIterator`\<\{ `success`: `boolean` }\>
|
||||||
|
|
||||||
|
An executor implementation that returns an async iterator
|
||||||
|
|
||||||
|
#### Type parameters
|
||||||
|
|
||||||
|
| Name | Type |
|
||||||
|
| :--- | :---- |
|
||||||
|
| `T` | `any` |
|
||||||
|
|
||||||
|
#### Type declaration
|
||||||
|
|
||||||
|
▸ (`options`, `context`): `AsyncIterableIterator`\<\{ `success`: `boolean` }\>
|
||||||
|
|
||||||
|
##### Parameters
|
||||||
|
|
||||||
|
| Name | Type |
|
||||||
|
| :-------- | :---------------------------------------------------------- |
|
||||||
|
| `options` | `T` |
|
||||||
|
| `context` | [`ExecutorContext`](../../devkit/documents/ExecutorContext) |
|
||||||
|
|
||||||
|
##### Returns
|
||||||
|
|
||||||
|
`AsyncIterableIterator`\<\{ `success`: `boolean` }\>
|
||||||
@ -1,6 +1,6 @@
|
|||||||
# Type alias: Executor\<T\>
|
# Type alias: Executor\<T\>
|
||||||
|
|
||||||
Ƭ **Executor**\<`T`\>: (`options`: `T`, `context`: [`ExecutorContext`](../../devkit/documents/ExecutorContext)) => `Promise`\<\{ `success`: `boolean` }\> \| `AsyncIterableIterator`\<\{ `success`: `boolean` }\>
|
Ƭ **Executor**\<`T`\>: [`PromiseExecutor`](../../devkit/documents/PromiseExecutor)\<`T`\> \| [`AsyncIteratorExecutor`](../../devkit/documents/AsyncIteratorExecutor)\<`T`\>
|
||||||
|
|
||||||
Implementation of a target of a project
|
Implementation of a target of a project
|
||||||
|
|
||||||
@ -9,18 +9,3 @@ Implementation of a target of a project
|
|||||||
| Name | Type |
|
| Name | Type |
|
||||||
| :--- | :---- |
|
| :--- | :---- |
|
||||||
| `T` | `any` |
|
| `T` | `any` |
|
||||||
|
|
||||||
#### Type declaration
|
|
||||||
|
|
||||||
▸ (`options`, `context`): `Promise`\<\{ `success`: `boolean` }\> \| `AsyncIterableIterator`\<\{ `success`: `boolean` }\>
|
|
||||||
|
|
||||||
##### Parameters
|
|
||||||
|
|
||||||
| Name | Type |
|
|
||||||
| :-------- | :---------------------------------------------------------- |
|
|
||||||
| `options` | `T` |
|
|
||||||
| `context` | [`ExecutorContext`](../../devkit/documents/ExecutorContext) |
|
|
||||||
|
|
||||||
##### Returns
|
|
||||||
|
|
||||||
`Promise`\<\{ `success`: `boolean` }\> \| `AsyncIterableIterator`\<\{ `success`: `boolean` }\>
|
|
||||||
|
|||||||
26
docs/generated/devkit/PromiseExecutor.md
Normal file
26
docs/generated/devkit/PromiseExecutor.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Type alias: PromiseExecutor\<T\>
|
||||||
|
|
||||||
|
Ƭ **PromiseExecutor**\<`T`\>: (`options`: `T`, `context`: [`ExecutorContext`](../../devkit/documents/ExecutorContext)) => `Promise`\<\{ `success`: `boolean` }\>
|
||||||
|
|
||||||
|
An executor implementation that returns a promise
|
||||||
|
|
||||||
|
#### Type parameters
|
||||||
|
|
||||||
|
| Name | Type |
|
||||||
|
| :--- | :---- |
|
||||||
|
| `T` | `any` |
|
||||||
|
|
||||||
|
#### Type declaration
|
||||||
|
|
||||||
|
▸ (`options`, `context`): `Promise`\<\{ `success`: `boolean` }\>
|
||||||
|
|
||||||
|
##### Parameters
|
||||||
|
|
||||||
|
| Name | Type |
|
||||||
|
| :-------- | :---------------------------------------------------------- |
|
||||||
|
| `options` | `T` |
|
||||||
|
| `context` | [`ExecutorContext`](../../devkit/documents/ExecutorContext) |
|
||||||
|
|
||||||
|
##### Returns
|
||||||
|
|
||||||
|
`Promise`\<\{ `success`: `boolean` }\>
|
||||||
@ -65,6 +65,7 @@ It only uses language primitives and immutable objects
|
|||||||
|
|
||||||
### Type Aliases
|
### Type Aliases
|
||||||
|
|
||||||
|
- [AsyncIteratorExecutor](../../devkit/documents/AsyncIteratorExecutor)
|
||||||
- [CreateDependencies](../../devkit/documents/CreateDependencies)
|
- [CreateDependencies](../../devkit/documents/CreateDependencies)
|
||||||
- [CreateMetadata](../../devkit/documents/CreateMetadata)
|
- [CreateMetadata](../../devkit/documents/CreateMetadata)
|
||||||
- [CreateMetadataContext](../../devkit/documents/CreateMetadataContext)
|
- [CreateMetadataContext](../../devkit/documents/CreateMetadataContext)
|
||||||
@ -91,6 +92,7 @@ It only uses language primitives and immutable objects
|
|||||||
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
|
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
|
||||||
- [ProjectType](../../devkit/documents/ProjectType)
|
- [ProjectType](../../devkit/documents/ProjectType)
|
||||||
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
|
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
|
||||||
|
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)
|
||||||
- [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency)
|
- [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency)
|
||||||
- [StaticDependency](../../devkit/documents/StaticDependency)
|
- [StaticDependency](../../devkit/documents/StaticDependency)
|
||||||
- [StringChange](../../devkit/documents/StringChange)
|
- [StringChange](../../devkit/documents/StringChange)
|
||||||
|
|||||||
@ -65,6 +65,7 @@ It only uses language primitives and immutable objects
|
|||||||
|
|
||||||
### Type Aliases
|
### Type Aliases
|
||||||
|
|
||||||
|
- [AsyncIteratorExecutor](../../devkit/documents/AsyncIteratorExecutor)
|
||||||
- [CreateDependencies](../../devkit/documents/CreateDependencies)
|
- [CreateDependencies](../../devkit/documents/CreateDependencies)
|
||||||
- [CreateMetadata](../../devkit/documents/CreateMetadata)
|
- [CreateMetadata](../../devkit/documents/CreateMetadata)
|
||||||
- [CreateMetadataContext](../../devkit/documents/CreateMetadataContext)
|
- [CreateMetadataContext](../../devkit/documents/CreateMetadataContext)
|
||||||
@ -91,6 +92,7 @@ It only uses language primitives and immutable objects
|
|||||||
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
|
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
|
||||||
- [ProjectType](../../devkit/documents/ProjectType)
|
- [ProjectType](../../devkit/documents/ProjectType)
|
||||||
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
|
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
|
||||||
|
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)
|
||||||
- [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency)
|
- [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency)
|
||||||
- [StaticDependency](../../devkit/documents/StaticDependency)
|
- [StaticDependency](../../devkit/documents/StaticDependency)
|
||||||
- [StringChange](../../devkit/documents/StringChange)
|
- [StringChange](../../devkit/documents/StringChange)
|
||||||
|
|||||||
@ -106,17 +106,31 @@ export interface ExecutorConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of a target of a project
|
* An executor implementation that returns a promise
|
||||||
*/
|
*/
|
||||||
export type Executor<T = any> = (
|
export type PromiseExecutor<T = any> = (
|
||||||
/**
|
/**
|
||||||
* Options that users configure or pass via the command line
|
* Options that users configure or pass via the command line
|
||||||
*/
|
*/
|
||||||
options: T,
|
options: T,
|
||||||
context: ExecutorContext
|
context: ExecutorContext
|
||||||
) =>
|
) => Promise<{ success: boolean }>;
|
||||||
| Promise<{ success: boolean }>
|
|
||||||
| AsyncIterableIterator<{ success: boolean }>;
|
/**
|
||||||
|
* An executor implementation that returns an async iterator
|
||||||
|
*/
|
||||||
|
export type AsyncIteratorExecutor<T = any> = (
|
||||||
|
/**
|
||||||
|
* Options that users configure or pass via the command line
|
||||||
|
*/
|
||||||
|
options: T,
|
||||||
|
context: ExecutorContext
|
||||||
|
) => AsyncIterableIterator<{ success: boolean }>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of a target of a project
|
||||||
|
*/
|
||||||
|
export type Executor<T = any> = PromiseExecutor<T> | AsyncIteratorExecutor<T>;
|
||||||
|
|
||||||
export interface HasherContext {
|
export interface HasherContext {
|
||||||
hasher: TaskHasher;
|
hasher: TaskHasher;
|
||||||
|
|||||||
@ -27,6 +27,8 @@ export type {
|
|||||||
export type {
|
export type {
|
||||||
Generator,
|
Generator,
|
||||||
GeneratorCallback,
|
GeneratorCallback,
|
||||||
|
PromiseExecutor,
|
||||||
|
AsyncIteratorExecutor,
|
||||||
Executor,
|
Executor,
|
||||||
ExecutorContext,
|
ExecutorContext,
|
||||||
TaskGraphExecutor,
|
TaskGraphExecutor,
|
||||||
|
|||||||
@ -1,11 +1,18 @@
|
|||||||
|
import { ExecutorContext } from '@nx/devkit';
|
||||||
|
|
||||||
import { <%= className %>ExecutorSchema } from './schema';
|
import { <%= className %>ExecutorSchema } from './schema';
|
||||||
import executor from './executor';
|
import executor from './executor';
|
||||||
|
|
||||||
const options: <%= className %>ExecutorSchema = {};
|
const options: <%= className %>ExecutorSchema = {};
|
||||||
|
const context: ExecutorContext = {
|
||||||
|
root: '',
|
||||||
|
cwd: process.cwd(),
|
||||||
|
isVerbose: false,
|
||||||
|
};
|
||||||
|
|
||||||
describe('<%= className %> Executor', () => {
|
describe('<%= className %> Executor', () => {
|
||||||
it('can run', async () => {
|
it('can run', async () => {
|
||||||
const output = await executor(options);
|
const output = await executor(options, context);
|
||||||
expect(output.success).toBe(true);
|
expect(output.success).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -1,11 +1,11 @@
|
|||||||
|
import { PromiseExecutor } from "@nx/devkit";
|
||||||
import { <%= className %>ExecutorSchema } from './schema';
|
import { <%= className %>ExecutorSchema } from './schema';
|
||||||
|
|
||||||
export default async function runExecutor(
|
const runExecutor: PromiseExecutor<<%= className %>ExecutorSchema> = async (options) => {
|
||||||
options: <%= className %>ExecutorSchema,
|
|
||||||
) {
|
|
||||||
console.log('Executor ran for <%= className %>', options);
|
console.log('Executor ran for <%= className %>', options);
|
||||||
return {
|
return {
|
||||||
success: true
|
success: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default runExecutor;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user