Skip to content

Add path specification to scaffolds#423

Merged
cannikin merged 4 commits intoredwoodjs:masterfrom
jtoar:ds-dir-prefix
May 12, 2020
Merged

Add path specification to scaffolds#423
cannikin merged 4 commits intoredwoodjs:masterfrom
jtoar:ds-dir-prefix

Conversation

@jtoar
Copy link
Copy Markdown
Contributor

@jtoar jtoar commented Apr 12, 2020

This PR proposes the following change to the g scaffold command:

yarn rw g scaffold <path/model>

E.g. given the model user, running yarn rw g scaffold admin/user will output:

yarn run v1.22.4
$ /home/dominic/projects/redwood/redwood-test/node_modules/.bin/rw g scaffold admin/users
  ✔ Generating scaffold files...
    ✔ Writing `./api/src/graphql/users.sdl.js`...
    ✔ Writing `./api/src/services/users/users.test.js`...
    ✔ Writing `./api/src/services/users/users.js`...
    ✔ Writing `./web/src/scaffold.css`...
    ✔ Writing `./web/src/layouts/UsersLayout/UsersLayout.js`...
    ✔ Writing `./web/src/pages/Admin/EditUserPage/EditUserPage.js`...
    ✔ Writing `./web/src/pages/Admin/UserPage/UserPage.js`...
    ✔ Writing `./web/src/pages/Admin/UsersPage/UsersPage.js`...
    ✔ Writing `./web/src/pages/Admin/NewUserPage/NewUserPage.js`...
    ✔ Writing `./web/src/components/Admin/EditUserCell/EditUserCell.js`...
    ✔ Writing `./web/src/components/Admin/User/User.js`...
    ✔ Writing `./web/src/components/Admin/UserCell/UserCell.js`...
    ✔ Writing `./web/src/components/Admin/UserForm/UserForm.js`...
    ✔ Writing `./web/src/components/Admin/Users/Users.js`...
    ✔ Writing `./web/src/components/Admin/UsersCell/UsersCell.js`...
    ✔ Writing `./web/src/components/Admin/NewUser/NewUser.js`...
  ✔ Adding scaffold routes...
  ✔ Adding scaffold asset imports...
Done in 1.07s.

Motivation

Scaffolds are amazing and could be a bit more amazing. The knock against scaffolds this PR addresses is their tendency to pollute the namespace.

The specific problem I had was suddenly having to contrive names for my app's real components and pages. I.e. I had a model called notes, and scaffolding this out gave me a CRUD, but key names were taken: Note and Notes as components, NotePage and NotesPages as a pages, etc. I wanted to keep the scaffold as a CRUD while fleshing things out, but having to manually change everything seemed like a lot of work that I thought redwood should've made trivial from the get-go. Specifying a path can make the kind of admin organization seen in example-blog possible right away.

There's an understandably tight link between a model's name and the scaffold generated. But this coupling must be loosened a bit. Specifying a path is one way of doing this. Another that's been thrown around involves a --prefix flag to literally add a prefix to component and page names.

This PR stems from discussions on discourse: see How to Think About Scaffolds and The scaffolding command makes it hard to delete files and folders later.

I'll continue to scheme/push changes, but wanted to get this out to start a discussion/get help before moving too far in any one direction. Thanks/please help @cannikin @thedavidprice @olance.

Questions

  • The way I finagled yargs command seems very suspect?
  • Maybe I should just make another Listr task to move it all after it's been generated? Right now I'm making changes to the first task (Generating scaffold files...).
  • Should the generated layout be in a nested dir too? Can it even be?

@olance
Copy link
Copy Markdown
Contributor

olance commented Apr 12, 2020

That looks quite nice to me!
You should probably add some tests to ensure things are created with the correct paths, names and imports for a few different cases.

As for the command-line itself, I'm wondering whether going for path/model is the "right thing" to do. It certainly works, but in terms of semantics and use case I wonder if a --prefix or --path option wouldn't make more sense?

My reasoning is the following (hopefully I make it clear enough):

  • As a developer, I'm using this generator to create a new model for my app, along with useful ready-to-use CRUD pages. Which means it's the model that I'm mainly interested in. As you mentioned yourself, I might want to get rid of those scaffolds later, or hide them behind an admin login... but the model itself would remain.
  • Said differently, I am not interested in creating a "admin user" model, but a "user" model for which I want CRUD pages to be considered admin pages

I think this kinda shows in the fact that everything generated on the api side doesn't use the admin prefix, whereas everything on the web side does.

So with that logic in mind, I'm thinking yarn rw g scaffold --path admin user might be a better candidate. wdyt?

I'd still use a namespacing via nested paths as you did though, rather than prefixing the classes names. Otherwise I feel the components and pages directories would get cluttered very quickly.

@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented Apr 13, 2020

@olance quick clarification:

As a developer, I'm using this generator to create a new model for my app, along with useful ready-to-use CRUD pages.

I think yarn rw g scaffold doesn't actually create a new model. I.e. if I run yarn rw g scaffold user without having a model User in my schema.prisma, the command will fail:

Cannot create property 'context' on string 'No schema definition found for `User` in schema.prisma file'

Said differently, I am not interested in creating a "admin user" model, but a "user" model for which I want CRUD pages to be considered admin pages

That's exactly what I'm interested too. I'll quote @cannikin here (pulling from the discourse thread)--I was basically implementing his suggestion since I thought it more declarative:

One way may be to simply include a path where you want the generated files to live right in the name of the model itself:

yarn rw g scaffold admin/post

The last part of the path would have to match a model in your database, but everything before that would be up to you. This would put pages, components and routes in the admin subdirectory. So you still end up with PostsCell but when importing it it would be in src/components/admin/PostsCell.

A flag was what I originally had in mind, but it was a --prefix flag instead of a --path flag. I'm ready to put the --prefix flag to rest as, as you mentioned at the end, nested paths > prefix.

@olance
Copy link
Copy Markdown
Contributor

olance commented Apr 13, 2020

I think yarn rw g scaffold doesn't actually create a new model. I.e. if I run yarn rw g scaffold user without having a model User in my schema.prisma, the command will fail:

Oooh my bad... Rails scaffold generator does create the model if it's missing, so I assumed Redwood's one would do the same!

@cannikin what's your take on the --path versus admin/post approach?

@thedavidprice
Copy link
Copy Markdown
Contributor

FYI: we’ve added a CI runner for Windows and changed PR settings to require checks to pass before merging. Pulling in changes from master should resolve current warnings.

@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented Apr 15, 2020

@thedavidprice Thank you, resolved!

@thedavidprice
Copy link
Copy Markdown
Contributor

@cannikin this one’s ready for review

Copy link
Copy Markdown
Contributor

@cannikin cannikin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see some tests that exercise all this new code! You'll see we have tests in place that check both that file is created in the correct file path, and that the contents of the file match a fixture in the test directory.

I'd test the simple case of admin/post but also a multiword path like admin_pages/post and multiple directories like admin/pages/post.

Also does this cover all the possible cases, like admin/post and Admin/Post, or for multiword ones AdminPages/Post, adminPages/post, admin-pages/post...

@thedavidprice
Copy link
Copy Markdown
Contributor

@jtoar just checking back on this to make sure it doesn’t get lost in the shuffle. No urgency implied.

But let us know if you’d like to take on the tests and need any help doing so.

@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented Apr 30, 2020

@thedavidprice thanks, I've started taking on the tests but could use a little feedback @cannikin. Here's a quick update:

  • Path nesting can be > 1 (i.e. super/admin/user will work)
  • I added some tests
    • Do I need to make all these fixtures dirs? Is there a better way?
  • I had to make a change in redwood's internal package

I added some tests (scaffoldPathSlashModel.test.js, scaffoldPathSlashModelNested.test.js) for the following inputs:

  • admin/post
  • super/admin/post

These tests are me literally copying your scaffold.test.js and adapting it to the new input. Which means I made more fixtures directories (fixturesPathSlashModel, fixturesPathSlashModelNested). Is this the best way to do it? Because if I test the other inputs you mentioned (admin_pages/post, Admin/Post, AdminPages/Post), I'll be making three more fixtures that, like the previous two, aren't really that different from each other (the difference mainly being in the import statements).


I couldn't get doubly-nested paths like Super/Admin/Post to be automatically imported correctly into in Routes.js.

The error I was getting:

routes-error

I applied a fix in the internal package's paths.ts. It's definitely more of a hack and should probably be thought through a little more.

@cannikin
Copy link
Copy Markdown
Contributor

cannikin commented May 1, 2020

@jtoar Yeah that's getting to be a lot of fixtures. I'd be happy with just testing that the file was created at the correct location, with a test like:

expect(files).toHaveProperty([
  '/path/to/project/web/src/pages/Admin/UsersPage/UsersPage.js',
])

And then a test that the file content contains the expected import statement. Something like:

expect(files['/path/to/project/web/src/pages/Admin/UsersPage/UsersPage.js'])
  .toMatch(`import UsersCell from 'src/components/Admin/UsersCell'`)

How does that feel? You can get rid of all those copied fixture files, sorry about that!

@cannikin
Copy link
Copy Markdown
Contributor

cannikin commented May 1, 2020

@peterp Any ideas about this?

I couldn't get doubly-nested paths like Super/Admin/Post to be automatically imported correctly into in Routes.js.

The error I was getting:
image
I applied a fix in the internal package's paths.ts. It's definitely more of a hack and should probably be thought through a little more.

@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented May 2, 2020

@cannikin Tests are here!

  • scaffoldPath.test.js tests the Admin/Post case (i.e. just one level of nesting)
  • scaffoldPathMultiword.test.js tests the AdminPages/Post case (variations on a one-level nest)
  • scaffoldPathNested.test.js tests the Admin/Pages/Post case (two levels)

The structure of the tests are largely the same, so at first I tried to save my fingers by using jest's test.each / for loops / any kind of iteration, but I just couldn't get anything to work. Hence the +2.5k lines. 😬

I need to do more research, but based on the way our beforeAll's set up, it looks like jest just doesn't support it. The last line of jest's troubleshooting page:

Note: This means when you are using test.each you cannot set the table asynchronously within a beforeEach / beforeAll.

And I think that's what we do. So even though the tests seem to work, I'd be interested in knowing if there's a way I could've done them better!


@peterp The fix is in packages/internal/src/paths.ts. Here's the (poorly reproduced) diff for convenience:

- importStatement: `const ${importName} = { name: '${importName}', loader: () => import('${importFile}') }`,
+ importStatement: `const ${importName.split(',').join('')} = { name: '${importName.split(',').join('')}', loader: () => import('${importFile}') }`,

@peterp
Copy link
Copy Markdown
Member

peterp commented May 3, 2020

@jtoar Got it, so importName changed from something like this: 'Admin,Pages,Post', to this 'AdminPagesPost'?

@cannikin It looks good to me.

@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented May 3, 2020

@peterp Exactly. Routes.js has a preamble saying you can nest components in however many directories you want as long as you prefix the component with the directory names:

// In this file, all Page components from 'src/pages` are auto-imported. Nested
// directories are supported, and should be uppercase. Each subdirectory will be
// prepended onto the component name.
//
// Examples:
//
// 'src/pages/HomePage/HomePage.js'         -> HomePage
// 'src/pages/Admin/BooksPage/BooksPage.js' -> AdminBooksPage

I found this to be not the case when it was nested in > 1 directory. I.e. if it was

// 'src/pages/Super/Admin/BooksPage/BooksPage.js' -> SuperAdminBooksPage

It wouldn't work, the error being Super,AdminBooksPage.

@peterp peterp added this to the next release milestone May 5, 2020
@thedavidprice
Copy link
Copy Markdown
Contributor

@jtoar is this ready for review? If so, please loop in Rob for the final check. Thanks!

@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented May 6, 2020

@cannikin This one's ready for another review. The fixture-less tests have been added and @peterp okayed the change made in internals.

One last thing I wanted to make sure of: everyone prefers this syntax? The path/model syntax:

yarn rw g scaffold admin/posts

Instead of the path flag, which would be

yarn rw g scaffold posts --path=admin

@thedavidprice
Copy link
Copy Markdown
Contributor

+1 for path/model as much more intuitive re: DX. I have to think about --path=admin

Haven't looked at the code. But would it be too much to accept either?

@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented May 6, 2020

Great! And I don't think that'd be too hard; I'll work on that in the mean time.

@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented May 7, 2020

@thedavidprice Added (tests still pass).

I wrote it so that if the path's specified by both pathSlashModel and the path flag, the path flag will prevail since it's more explicit. Is that the design we want?

@thedavidprice
Copy link
Copy Markdown
Contributor

@jtoar I think that's great! Thanks for taking the time to figure that part out. For a next step after this PR, we are going to need documentation for this.

  • Yargs does allow a 'description' for options, but we need to fix something with our Yargs directory structure to allow help text to display for specific rw generate types. E.g. yarn rw g scaffold --help displays the same output as yarn rw g --help.
  • We need to add full Documentation for CLI commands and add to the Reference section of Website. Aryan started this in Add current CLI commands to packages/cli/README.md #310 and we weren't quite ready for it. But seems like it might be a good time to pick up again.

@cannikin this one looks good to me! However, I haven't run any local tests myself. And/or checked the new Jest tests.

@thedavidprice thedavidprice requested a review from cannikin May 9, 2020 04:36
@peterp peterp force-pushed the master branch 4 times, most recently from f6a1008 to a728f83 Compare May 10, 2020 09:44
@peterp peterp force-pushed the master branch 2 times, most recently from 711c520 to 2341368 Compare May 10, 2020 10:07
@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented May 10, 2020

@thedavidprice I can't get enough docs so I'll start the conversation up again over there.

@cannikin I haven't changed the routes' names, so even if you generate the scaffold with something like admin/user, the names still revolve around the model. E.g.:

<Route path="/admin/users" page={AdminUsersPage} name="users" />

Should the name now be adminUsers?

@cannikin
Copy link
Copy Markdown
Contributor

@jtoar

Should the name now be adminUsers?

I would expect so, yes. The name should get namespaced just like the directory structure and the name of the component itself.

Dominic added 4 commits May 11, 2020 17:49
This commit modifies scaffold.js to let the user specify a path via:

- the argument (I.e. yarn rw g scaffold admin/user)
- a path flag (E.g. yarn rw g scaffold user --path=admin)

This entailed:

1) modifying the files/routes commands to accept a new
(optional) param: scaffoldPath

2) defining a lot of constants like "pascalScaffoldPath" or
"camelScaffoldPath" to plug in to the templates/routes.
In the Routes.js file, routes are imported automatically, and if they're
nested,
the user is just supposed to append the directory names to the
component.
That only works if it's nested "one-dir" deep.
This fix lets it work for indefinite nesitng.
For the imports/routes I had to add/change the vars in the templates respectively.

Getting imports to work required me to add one--pascalScaffoldPath.
And for routes, I had to make that var in the scaffold.js file,
So I had to add new route vars--e.g. routes.${newRouteName}(), etc.
These three tests check to see if files are 1) named correctly,
2) imports correctly, and 3) "routed" correctly.

They mostly reuse tests from the original scaffold.test.js.

The tests cover three scenarios:

1) One-level nesting (scaffoldPath): 'admin/post'
2) One-level nesting, multiworld (ScaffoldPathMultiword): 'adminPages/post'
3) Two-level nesting (scaffoldPathNested): 'admin/pages/post'
@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented May 12, 2020

@cannikin The route names are configured correctly now.

I also tried to organize a bit--squashed/split everything into four commits. Sorry if I'm tripping over git while doing this (if I'm inconveniencing you guys please let me know!)

Summary

Just to summarize the work to date, you can now do something like:

yarn rw g scaffold admin/user

and/or

yarn rw g scaffold user --path=admin

and get this output:

~/redwood-app$ yarn rw g scaffold admin/user
yarn run v1.22.4
$ ~/redwood-app/node_modules/.bin/rw g scaffold admin/user
  ✔ Generating scaffold files...
    ✔ Writing `./api/src/graphql/users.sdl.js`...
    ✔ Writing `./api/src/services/users/users.test.js`...
    ✔ Writing `./api/src/services/users/users.js`...
    ✔ Writing `./web/src/scaffold.css`...
    ✔ Writing `./web/src/layouts/Admin/UsersLayout/UsersLayout.js`...
    ✔ Writing `./web/src/pages/Admin/EditUserPage/EditUserPage.js`...
    ✔ Writing `./web/src/pages/Admin/UserPage/UserPage.js`...
    ✔ Writing `./web/src/pages/Admin/UsersPage/UsersPage.js`...
    ✔ Writing `./web/src/pages/Admin/NewUserPage/NewUserPage.js`...
    ✔ Writing `./web/src/components/Admin/EditUserCell/EditUserCell.js`...
    ✔ Writing `./web/src/components/Admin/User/User.js`...
    ✔ Writing `./web/src/components/Admin/UserCell/UserCell.js`...
    ✔ Writing `./web/src/components/Admin/UserForm/UserForm.js`...
    ✔ Writing `./web/src/components/Admin/Users/Users.js`...
    ✔ Writing `./web/src/components/Admin/UsersCell/UsersCell.js`...
    ✔ Writing `./web/src/components/Admin/NewUser/NewUser.js`...
  ✔ Adding scaffold routes...
  ✔ Adding scaffold asset imports...
Done in 1.14s.

Basically the sdl, services, and scaffold.css are left unaffected while layouts, pages, and components, are nested in dirs.

Expand to see sample tree output of web/src/
web/src/
├── components
│   └── Admin
│       ├── EditUserCell
│       │   └── EditUserCell.js
│       ├── NewUser
│       │   └── NewUser.js
│       ├── User
│       │   └── User.js
│       ├── UserCell
│       │   └── UserCell.js
│       ├── UserForm
│       │   └── UserForm.js
│       ├── Users
│       │   └── Users.js
│       └── UsersCell
│           └── UsersCell.js
├── index.css
├── index.html
├── index.js
├── layouts
│   └── Admin
│       └── UsersLayout
│           └── UsersLayout.js
├── pages
│   ├── Admin
│   │   ├── EditUserPage
│   │   │   └── EditUserPage.js
│   │   ├── NewUserPage
│   │   │   └── NewUserPage.js
│   │   ├── UserPage
│   │   │   └── UserPage.js
│   │   └── UsersPage
│   │       └── UsersPage.js
│   ├── FatalErrorPage
│   │   └── FatalErrorPage.js
│   └── NotFoundPage
│       └── NotFoundPage.js
├── Routes.js
└── scaffold.css

I'm not sure if it'll add much value, but here's an example repo that has the output of running this modified scaffold command.

Quick summary of the changes I made to scaffold.js

  1. Modifying the files/routes functions to accept a new
    (optional) parameter: scaffoldPath

  2. Defining a lot of constants like "pascalScaffoldPath" or
    "camelScaffoldPath" to plug in to the templates/routes.

Tests

I've added three tests that check to see if files are 1) named correctly, 2) imported correctly, and 3) "routed" correctly. They mostly reuse tests from the existing scaffold.test.js with some modifications (i.e. they're fixture-less). The tests cover three scenarios:

  • One-level nesting (scaffoldPath.test.js): admin/post
  • Multiword one-level nesting (scaffoldPathMultiword.test.js): adminPages/post
  • Two-level nesting (scaffoldPathNested.test.js): admin/pages/post

You can run the tests by navigating to the @redwoodjs/cli package and running

yarn test scaffold

I think we're getting close to the end? I'll keep looking the code over for mistakes/better ways to do things, but let me know if I can do anything else and thanks for your feedback!

export const handler = async ({ model, force }) => {
// 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 }) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible to add a Yargs 'description' key in here? It won't display correctly yet, e.g. yarn rw g scaffold --help currently shows help for yarn rw g only. But it helps code now and will be available via CLI in future once we re-structure Yargs:
https://yargs.js.org/docs/#api-optionskey-opt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the path flag, how does path to put generated files in sound? Alternatives:

  • path to generated files
  • path to nest generated files under
  • directory(ies) to nest generated files under

And the command's description could change from/to Generates pages, SDL, and a services object => Generates and optionally nests pages, SDL, and a services object

@thedavidprice
Copy link
Copy Markdown
Contributor

Just ran through this locally -- it's really great behavior! I used the admin/user option, which is intuitive. And then also created admin/contact. Everything structured accordingly. And I tested admin/foo/user as well... works great.

This really needs docs, especially because the yarn rw g scaffold --help is broken. I added one inline review note about Yargs description key:value for Options. But for CLI documentation, this would be a good prompt to start chipping away a piece at a time. (Note: don't let docs block this from merging. But lets at least start a new Issue if we haven't already.)

@cannikin I did not review the code, just the behavior. Handing off to you!

@jtoar
Copy link
Copy Markdown
Contributor Author

jtoar commented May 12, 2020

@thedavidprice reached out about docs at #310; will start a google doc. Stay tuned for an issue most likely later today.

@cannikin cannikin merged commit 277c724 into redwoodjs:master May 12, 2020
@cannikin
Copy link
Copy Markdown
Contributor

Great work! This has gotta be the biggest PR we've merged, 2,000+ lines 😮

@cannikin cannikin mentioned this pull request May 12, 2020
@jtoar jtoar mentioned this pull request May 12, 2020
4 tasks
antonmoiseev added a commit to antonmoiseev/redwood that referenced this pull request May 18, 2020
jmreidy pushed a commit to jmreidy/redwood that referenced this pull request May 19, 2020
* Add path specification via argument and flag

This commit modifies scaffold.js to let the user specify a path via:

- the argument (I.e. yarn rw g scaffold admin/user)
- a path flag (E.g. yarn rw g scaffold user --path=admin)

This entailed:

1) modifying the files/routes commands to accept a new
(optional) param: scaffoldPath

2) defining a lot of constants like "pascalScaffoldPath" or
"camelScaffoldPath" to plug in to the templates/routes.

* Add build-time route-import fix to @redwoodjs/internal

In the Routes.js file, routes are imported automatically, and if they're
nested,
the user is just supposed to append the directory names to the
component.
That only works if it's nested "one-dir" deep.
This fix lets it work for indefinite nesitng.

* Add/change vars in templates

For the imports/routes I had to add/change the vars in the templates respectively.

Getting imports to work required me to add one--pascalScaffoldPath.
And for routes, I had to make that var in the scaffold.js file,
So I had to add new route vars--e.g. routes.${newRouteName}(), etc.

* Add three path-specification tests

These three tests check to see if files are 1) named correctly,
2) imports correctly, and 3) "routed" correctly.

They mostly reuse tests from the original scaffold.test.js.

The tests cover three scenarios:

1) One-level nesting (scaffoldPath): 'admin/post'
2) One-level nesting, multiworld (ScaffoldPathMultiword): 'adminPages/post'
3) Two-level nesting (scaffoldPathNested): 'admin/pages/post'
@jmreidy
Copy link
Copy Markdown

jmreidy commented May 19, 2020

Love this! Can't wait to put it to use. Thanks @jtoar !

jmreidy pushed a commit to jmreidy/redwood that referenced this pull request May 30, 2020
* Add path specification via argument and flag

This commit modifies scaffold.js to let the user specify a path via:

- the argument (I.e. yarn rw g scaffold admin/user)
- a path flag (E.g. yarn rw g scaffold user --path=admin)

This entailed:

1) modifying the files/routes commands to accept a new
(optional) param: scaffoldPath

2) defining a lot of constants like "pascalScaffoldPath" or
"camelScaffoldPath" to plug in to the templates/routes.

* Add build-time route-import fix to @redwoodjs/internal

In the Routes.js file, routes are imported automatically, and if they're
nested,
the user is just supposed to append the directory names to the
component.
That only works if it's nested "one-dir" deep.
This fix lets it work for indefinite nesitng.

* Add/change vars in templates

For the imports/routes I had to add/change the vars in the templates respectively.

Getting imports to work required me to add one--pascalScaffoldPath.
And for routes, I had to make that var in the scaffold.js file,
So I had to add new route vars--e.g. routes.${newRouteName}(), etc.

* Add three path-specification tests

These three tests check to see if files are 1) named correctly,
2) imports correctly, and 3) "routed" correctly.

They mostly reuse tests from the original scaffold.test.js.

The tests cover three scenarios:

1) One-level nesting (scaffoldPath): 'admin/post'
2) One-level nesting, multiworld (ScaffoldPathMultiword): 'adminPages/post'
3) Two-level nesting (scaffoldPathNested): 'admin/pages/post'
jmreidy pushed a commit to jmreidy/redwood that referenced this pull request May 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants