Skip to content

Commit

Permalink
fix: add dotenv-defaults, start plugging into cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jtoar committed Aug 30, 2023
1 parent 2d6b93d commit 4dc4e35
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 16 deletions.
4 changes: 1 addition & 3 deletions packages/cli-packages/dataMigrate/e2eTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ await execa.command('yarn rw g data-migration test', {
stdio: 'inherit',
})

await execa.command('yarn rw data-migrate up', {
stdio: 'inherit',
})
await execa.command(command)

// check that up worked...
1 change: 1 addition & 0 deletions packages/cli-packages/dataMigrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@redwoodjs/project-config": "6.0.7",
"@redwoodjs/telemetry": "6.0.7",
"chalk": "4.1.2",
"dotenv-defaults": "5.0.2",
"execa": "5.1.1",
"fs-extra": "11.1.1",
"listr2": "6.6.0",
Expand Down
12 changes: 12 additions & 0 deletions packages/cli-packages/dataMigrate/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import path from 'path'

// @ts-expect-error other packages use this and don't provide the types
import { config } from 'dotenv-defaults'
import { hideBin } from 'yargs/helpers'
import yargs from 'yargs/yargs'

import { getPaths } from '@redwoodjs/project-config'

import { description, builder } from './commands/up'
import { handler } from './commands/upHandler'

config({
path: path.join(getPaths().base, '.env'),
defaults: path.join(getPaths().base, '.env.defaults'),
multiline: true,
})

yargs(hideBin(process.argv))
.scriptName('data-migrate')
// @ts-expect-error not sure why
Expand Down
34 changes: 24 additions & 10 deletions packages/cli-packages/dataMigrate/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import terminalLink from 'terminal-link'
import type { Argv } from 'yargs'

import {
command as installCommand,
description as installDescription,
Expand All @@ -11,17 +14,28 @@ import {
handler as upHandler,
} from './commands/up'

const command = 'data-migrate <command>'
const aliases = ['dataMigrate', 'dm']
const description = 'Migrate the data in your database'

function builder(yargs: Argv) {
yargs
.command(installCommand, installDescription, installBuilder, installHandler)
// @ts-expect-error wip
.command(upCommand, upDescription, upBuilder, upHandler)
.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference',
'https://redwoodjs.com/docs/cli-commands#datamigrate'
)}`
)
}

export const commands = [
{
command: installCommand,
description: installDescription,
builder: installBuilder,
handler: installHandler,
},
{
command: upCommand,
description: upDescription,
builder: upBuilder,
handler: upHandler,
command,
aliases,
description,
builder,
},
]
9 changes: 6 additions & 3 deletions packages/cli/src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const PLUGIN_CACHE_DEFAULT = {
'Launch Storybook: a tool for building UI components and pages in isolation',
},
},
'@redwoodjs/cli-data-migrate': {
'data-migrate': {
aliases: ['dataMigrate', 'dm'],
description: 'Migrate the data in your database',
},
},
}

const PLUGIN_CACHE_BUILTIN = [
Expand All @@ -27,9 +33,6 @@ const PLUGIN_CACHE_BUILTIN = [
'diagnostics',
'console',
'c',
'data-migrate',
'dm',
'dataMigrate',
'deploy',
'destroy',
'd',
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7876,6 +7876,7 @@ __metadata:
"@types/fs-extra": 11.0.1
"@types/yargs": 17.0.24
chalk: 4.1.2
dotenv-defaults: 5.0.2
esbuild: 0.18.19
execa: 5.1.1
fast-glob: 3.3.1
Expand Down

0 comments on commit 4dc4e35

Please sign in to comment.