File tree Expand file tree Collapse file tree 3 files changed +29
-21
lines changed Expand file tree Collapse file tree 3 files changed +29
-21
lines changed Original file line number Diff line number Diff line change 1
- import {
2
- type DiscoveredModule ,
3
- DiscoveryService ,
4
- } from '@golevelup/nestjs-discovery' ;
5
1
import { Injectable } from '@nestjs/common' ;
6
- import { Command } from 'clipanion' ;
2
+ import { type Command } from 'clipanion' ;
3
+ import { MetadataDiscovery } from '~/core/discovery' ;
4
+ import { CommandWatermark } from './decorator' ;
7
5
8
6
@Injectable ( )
9
7
export class CommandDiscovery {
10
- constructor ( private readonly discovery : DiscoveryService ) { }
8
+ constructor ( private readonly discovery : MetadataDiscovery ) { }
11
9
12
10
async discover ( ) {
13
- const discovered = await this . discovery . providersWithMetaAtKey (
14
- Command as any ,
15
- ) ;
16
- return discovered . map ( ( d ) => {
17
- const command = d . discoveredClass as DiscoveredModule < Command > ;
18
- return new Proxy ( command . dependencyType , {
19
- construct ( ) {
20
- return command . instance ;
21
- } ,
22
- } ) ;
23
- } ) ;
11
+ return this . discovery
12
+ . discover ( CommandWatermark )
13
+ . classes < Command > ( )
14
+ . map (
15
+ ( { instance : command } ) =>
16
+ new Proxy ( command . constructor , {
17
+ construct ( ) {
18
+ return command ;
19
+ } ,
20
+ } ) ,
21
+ ) ;
24
22
}
25
23
}
Original file line number Diff line number Diff line change 1
- import { applyDecorators , Injectable , SetMetadata } from '@nestjs/common' ;
2
- import { Command } from 'clipanion' ;
1
+ import { Injectable } from '@nestjs/common' ;
2
+ import { createMetadataDecorator } from '@seedcompany/nest' ;
3
+ import { type Command } from 'clipanion' ;
3
4
import { type AbstractClass } from 'type-fest' ;
4
5
6
+ export const CommandWatermark = createMetadataDecorator ( {
7
+ types : [ 'class' ] ,
8
+ additionalDecorators : [ Injectable ( ) ] ,
9
+ } ) ;
10
+
5
11
export const InjectableCommand = ( ) => ( cls : AbstractClass < Command > ) =>
6
- applyDecorators ( Injectable ( ) , SetMetadata ( Command , true ) ) ( cls ) ;
12
+ CommandWatermark ( ) ( cls ) ;
Original file line number Diff line number Diff line change
1
+ import { Injectable } from '@nestjs/common' ;
1
2
import { Command , Option } from 'clipanion' ;
2
3
import { $ , execa } from 'execa' ;
3
4
import { realpath } from 'node:fs/promises' ;
4
5
import { tmpdir as getTempDir } from 'node:os' ;
5
6
import { InjectableCommand } from '~/core' ;
6
7
import { GelAccessPolicyInjector } from './access-policy.injector' ;
7
8
8
- @InjectableCommand ( )
9
+ @Injectable ( )
9
10
abstract class ApCommand extends Command {
10
11
constructor ( protected readonly injector : GelAccessPolicyInjector ) {
11
12
super ( ) ;
12
13
}
13
14
}
14
15
16
+ @InjectableCommand ( )
15
17
export class GelAccessPolicyWrapCommand extends ApCommand {
16
18
static paths = [ [ 'gel' ] ] ;
17
19
static usage = Command . Usage ( {
@@ -51,6 +53,7 @@ export class GelAccessPolicyWrapCommand extends ApCommand {
51
53
}
52
54
}
53
55
56
+ @InjectableCommand ( )
54
57
export class GelAccessPolicyInjectCommand extends ApCommand {
55
58
static paths = [ [ 'gel' , 'ap' , 'inject' ] ] ;
56
59
static usage = Command . Usage ( {
@@ -63,6 +66,7 @@ export class GelAccessPolicyInjectCommand extends ApCommand {
63
66
}
64
67
}
65
68
69
+ @InjectableCommand ( )
66
70
export class GelAccessPolicyEjectCommand extends ApCommand {
67
71
static paths = [ [ 'gel' , 'ap' , 'eject' ] ] ;
68
72
static usage = Command . Usage ( {
You can’t perform that action at this time.
0 commit comments