Skip to content

Commit

Permalink
refactor: configure command to display dialect name in prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jun 19, 2024
1 parent 62e3c2f commit 596c153
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
7 changes: 6 additions & 1 deletion configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export async function configure(command: Configure) {
if (dialect === undefined) {
dialect = await command.prompt.choice(
'Select the database you want to use',
Object.keys(DIALECTS),
Object.keys(DIALECTS).map((dialectKey) => {
return {
name: dialectKey,
message: DIALECTS[dialectKey as keyof typeof DIALECTS].name,
}
}),
{
validate(value) {
return !!value
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@swc/core": "^1.6.1",
"@types/chance": "^1.1.6",
"@types/luxon": "^3.4.2",
"@types/node": "^20.14.4",
"@types/node": "^20.14.5",
"@types/pretty-hrtime": "^1.0.3",
"@types/qs": "^6.9.15",
"@vinejs/vine": "^2.1.0",
Expand All @@ -90,7 +90,7 @@
"husky": "^9.0.11",
"luxon": "^3.4.4",
"mysql2": "^3.10.1",
"np": "^10.0.5",
"np": "^10.0.6",
"pg": "^8.12.0",
"prettier": "^3.3.2",
"reflect-metadata": "^0.2.2",
Expand All @@ -100,7 +100,7 @@
"typescript": "^5.4.5"
},
"dependencies": {
"@adonisjs/presets": "^2.4.1",
"@adonisjs/presets": "^2.5.1",
"@faker-js/faker": "^8.4.1",
"@poppinss/hooks": "^7.2.3",
"@poppinss/macroable": "^1.0.2",
Expand Down
41 changes: 39 additions & 2 deletions test/configure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,42 @@ test.group('Configure', (group) => {

const ace = await app.container.make('ace')
ace.prompt.trap('Select the database you want to use').chooseOption(0)
ace.prompt.trap('Do you want to install additional packages required by "@adonisjs/lucid"?')
ace.prompt
.trap('Do you want to install additional packages required by "@adonisjs/lucid"?')
.reject()

const command = await ace.create(Configure, ['../../index.js'])
await command.exec()

await assert.dirExists('tmp')
})

test('create tmp directory for libsql dialect', async ({ fs, assert }) => {
const ignitor = new IgnitorFactory()
.withCoreProviders()
.withCoreConfig()
.create(BASE_URL, {
importer: (filePath) => {
if (filePath.startsWith('./') || filePath.startsWith('../')) {
return import(new URL(filePath, BASE_URL).href)
}

return import(filePath)
},
})

const app = ignitor.createApp('web')
await app.init()
await app.boot()

await fs.createJson('tsconfig.json', {})
await fs.create('adonisrc.ts', `export default defineConfig({})`)

const ace = await app.container.make('ace')
ace.prompt.trap('Select the database you want to use').chooseOption(1)
ace.prompt
.trap('Do you want to install additional packages required by "@adonisjs/lucid"?')
.reject()

const command = await ace.create(Configure, ['../../index.js'])
await command.exec()
Expand Down Expand Up @@ -165,7 +200,9 @@ test.group('Configure', (group) => {

const ace = await app.container.make('ace')
ace.prompt.trap('Select the database you want to use').chooseOption(0)
ace.prompt.trap('Do you want to install additional packages required by "@adonisjs/lucid"?')
ace.prompt
.trap('Do you want to install additional packages required by "@adonisjs/lucid"?')
.reject()

const command = await ace.create(Configure, ['../../index.js'])
await command.exec()
Expand Down

0 comments on commit 596c153

Please sign in to comment.