Skip to content

Commit

Permalink
Merge pull request #559 from jtoar/fix-scaffold-path
Browse files Browse the repository at this point in the history
Rename pathSlashModel to model and remove path flag
  • Loading branch information
thedavidprice authored May 19, 2020
2 parents 0f0f99b + eb77355 commit 1194d3f
Showing 1 changed file with 17 additions and 20 deletions.
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

0 comments on commit 1194d3f

Please sign in to comment.