Skip to content

Commit

Permalink
feat: add importAll REPL helper
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 22, 2023
1 parent 11c5448 commit 434faf6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions providers/repl_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { homedir } from 'node:os'

import { Repl } from '../modules/repl.js'
import type { ApplicationService, ContainerBindings } from '../src/types.js'
import { fsImportAll } from '@poppinss/utils'

/**
* Resolves a container binding and sets it on the REPL
Expand Down Expand Up @@ -60,6 +61,18 @@ export default class ReplServiceProvider {
}
)

repl.addMethod(
'importAll',
(_, dirPath: string) => {
return fsImportAll(this.app.makeURL(dirPath), {
ignoreMissingRoot: false,
})
},
{
description: 'Import all files from a directory and assign them to a variable',
}
)

repl.addMethod(
'make',
(_, service: any, runtimeValues?: any[]) => {
Expand Down
12 changes: 12 additions & 0 deletions tests/bindings/repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,17 @@ test.group('Bindings | Repl', () => {

const router = await methods.make.handler(repl, 'router')
assert.deepEqual(router, await app.container.make('router'))

const exportedMods = await methods.importAll.handler(repl, '../../../factories')
assert.properties(exportedMods, [
'core',
'app',
'bodyparser',
'encryption',
'events',
'hash',
'logger',
'http',
])
})
})

0 comments on commit 434faf6

Please sign in to comment.