Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(exec): Allow listing of scripts with rw exec to improve dx #4600

Merged
merged 2 commits into from
Feb 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions packages/cli/src/commands/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const runScript = async (scriptPath, scriptArgs) => {
return
}

export const command = 'exec <name>'
export const command = 'exec [name]'
export const description = 'Run scripts generated with yarn generate script'
export const builder = (yargs) => {
yargs
Expand All @@ -41,6 +41,12 @@ export const builder = (yargs) => {
default: true,
description: 'Generate the Prisma client',
})
.option('list', {
alias: 'l',
type: 'boolean',
default: false,
description: 'List available scripts',
})
.strict(false)
.epilogue(
`Also see the ${terminalLink(
Expand All @@ -50,8 +56,22 @@ export const builder = (yargs) => {
)
}

const printAvailableScriptsToConsole = () => {
console.log('Available scripts:')
findScripts().forEach((scriptPath) => {
const { name } = path.parse(scriptPath)
console.log(c.info(`- ${name}`))
})
console.log()
}

export const handler = async (args) => {
const { name, prisma, ...scriptArgs } = args
const { name, prisma, list, ...scriptArgs } = args
if (list || !name) {
printAvailableScriptsToConsole()
return
}

const scriptPath = path.join(getPaths().scripts, name)

const {
Expand Down Expand Up @@ -120,12 +140,7 @@ export const handler = async (args) => {
c.error(`\nNo script called ${c.underline(name)} in ./scripts folder.\n`)
)

console.log('Available scripts:')
findScripts().forEach((scriptPath) => {
const { name } = path.parse(scriptPath)
console.log(c.info(`- ${name}`))
})
console.log()
printAvailableScriptsToConsole()
process.exit(1)
}

Expand Down