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

fix: clean up web generator #19

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ export function useUserFindOneTest({ testId }: { testId: string }) {
`;

exports[`web-feature generator should run successfully with crud 9`] = `
"export const AdminTestFeature = lazy(() => import('./lib/admin-test.routes'));
import { lazy } from 'react';
"import { lazy } from 'react';
export const AdminTestFeature = lazy(() => import('./lib/admin-test.routes'));

export const UserTestFeature = lazy(() => import('./lib/user-test.routes'));
"
Expand Down
12 changes: 6 additions & 6 deletions libs/tools/src/lib/web-crud/generate-web-crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ export function generateWebCrud(tree: Tree, options: NormalizedApiCrudSchema) {

const [dataAccess, feature, ui, shellFeature] = projects

const requiredFields = [
const requiredFiles = [
`${shellFeature.sourceRoot}/lib/shell-${vars.actor.fileName}.routes.tsx`,
`${shellFeature.sourceRoot}/lib/shell-${vars.actor.fileName}.routes.tsx`,
`${feature.sourceRoot}/index.ts`,
]
for (const field of requiredFields) {
if (!tree.exists(field)) {
throw new Error(`Required file not found: ${field}`)
for (const file of requiredFiles) {
if (!tree.exists(file)) {
throw new Error(`Required file not found: ${file}`)
}
}

const [adminRoutes, userRoutes, featureIndex] = requiredFields
const [adminRoutes, userRoutes, featureIndex] = requiredFiles

const routesFile = vars.actorAdmin ? adminRoutes : userRoutes

Expand All @@ -68,7 +68,7 @@ export function generateWebCrud(tree: Tree, options: NormalizedApiCrudSchema) {
const importSnippet = `import { lazy } from 'react'`
// Check if the featureIndex file already has the above import featureIndex
if (!tree.read(featureIndex).toString().includes(importSnippet)) {
imports.push(importSnippet)
imports.unshift(importSnippet)
}

// Add the imports to the featureIndex file
Expand Down
1 change: 1 addition & 0 deletions libs/tools/src/lib/web/create-mock-web-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ function createMockComponent(tree: Tree, project: string, name: string) {
nameAndDirectoryFormat: 'as-provided',
style: 'none',
skipTests: true,
skipFormat: true,
})
}
Loading