Skip to content

Commit d46ba86

Browse files
committed
feat: add support for registering provider inside aceProviders array
1 parent 7628e04 commit d46ba86

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

commands/Make/Provider.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import { args } from '@adonisjs/ace'
10+
import { args, flags } from '@adonisjs/ace'
1111
import { join, extname } from 'path'
1212
import { RcFile as SinkRcFile } from '@adonisjs/sink'
1313
import { 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
}

test/make-provider.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)