File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 77 * file that was distributed with this source code.
88*/
99
10- import { args } from '@adonisjs/ace'
10+ import { args , flags } from '@adonisjs/ace'
1111import { join , extname } from 'path'
1212import { RcFile as SinkRcFile } from '@adonisjs/sink'
1313import { RcFile } from '@ioc:Adonis/Core/Application'
@@ -36,6 +36,9 @@ export default class MakeProvider extends BaseGenerator {
3636 @args . string ( { description : 'Make of the provider class' } )
3737 public name : string
3838
39+ @flags . boolean ( { description : 'Register provider under the ace providers array' } )
40+ public ace : boolean
41+
3942 /**
4043 * Returns the template stub path
4144 */
@@ -66,7 +69,13 @@ export default class MakeProvider extends BaseGenerator {
6669
6770 const relativePath = file . toJSON ( ) . relativepath
6871 const rcFile = new SinkRcFile ( ADONIS_ACE_CWD ( ) ! )
69- rcFile . addProvider ( `./${ relativePath . replace ( extname ( relativePath ) , '' ) } ` )
72+
73+ if ( this . ace ) {
74+ rcFile . addAceProvider ( `./${ relativePath . replace ( extname ( relativePath ) , '' ) } ` )
75+ } else {
76+ rcFile . addProvider ( `./${ relativePath . replace ( extname ( relativePath ) , '' ) } ` )
77+ }
78+
7079 rcFile . commit ( )
7180 }
7281}
Original file line number Diff line number Diff line change @@ -104,4 +104,27 @@ test.group('Make Provider', (group) => {
104104 providers : [ './providers/auth/AppProvider' ] ,
105105 } )
106106 } )
107+
108+ test ( 'make ace provider' , async ( assert ) => {
109+ await fs . add ( '.adonisrc.json' , JSON . stringify ( { } ) )
110+
111+ const app = new Application ( fs . basePath , new Ioc ( ) , { } , { } )
112+
113+ const provider = new MakeProvider ( app )
114+ provider . name = 'app'
115+ provider . ace = true
116+ await provider . handle ( )
117+
118+ const AppProvider = await fs . get ( 'providers/AppProvider.ts' )
119+ const ProviderTemplate = await templates . get ( 'provider.txt' )
120+ assert . deepEqual (
121+ toNewlineArray ( AppProvider ) ,
122+ toNewlineArray ( ProviderTemplate . replace ( '${filename}' , 'AppProvider' ) ) ,
123+ )
124+
125+ const rcContents = await fs . get ( '.adonisrc.json' )
126+ assert . deepEqual ( JSON . parse ( rcContents ) , {
127+ aceProviders : [ './providers/AppProvider' ] ,
128+ } )
129+ } )
107130} )
You can’t perform that action at this time.
0 commit comments