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

Rename pathSlashModel to model and remove path flag #559

Merged
merged 2 commits into from
May 19, 2020
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
37 changes: 17 additions & 20 deletions packages/cli/src/commands/generate/scaffold/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,25 @@ const addScaffoldImport = () => {
return 'Added scaffold import to index.js'
}

export const command = 'scaffold <pathSlashModel>'
export const desc = 'Generate pages, SDL, and a services object.'
export const builder = {
force: { type: 'boolean', default: false },
// So the user can specify a path to nest the generated files under.
// E.g. yarn rw g scaffold post --path=admin
path: { type: 'string', default: false },
export const command = 'scaffold <model>'
export const desc =
'Generate Pages, SDL, and Services files based on a given DB schema Model. Also accepts <path/model>.'
export const builder = (yargs) => {
yargs.positional('model', {
description:
"Model to scaffold. You can also use <path/model> to nest files by type at the given path directory (or directories). For example, 'rw g scaffold admin/post'.",
})
yargs.option('force', {
default: false,
type: 'boolean',
})
}
// The user can also specify a path in the argument.
// E.g. yarn rw g scaffold admin/post
export const handler = async ({ pathSlashModel, force, path: pathFlag }) => {
let path
// If path is specified by both pathSlashModel and pathFlag,
// we give pathFlag precedence.
pathFlag
? (path = pathFlag)
: (path = pathSlashModel.split('/').slice(0, -1).join('/'))

// This code will work whether or not there's a path in pathSlashModel
// E.g. if pathSlashModel is just 'post',
export const handler = async ({ model: modelArg, force }) => {
let path = modelArg.split('/').slice(0, -1).join('/')
// This code will work whether or not there's a path in model
// E.g. if model is just 'post',
// path.split('/') will return ['post'].
const model = pathSlashModel.split('/').pop()
const model = modelArg.split('/').pop()

const tasks = new Listr(
[
Expand Down