@@ -59,12 +59,44 @@ describe('makeLeanProfile', () => {
5959 ' error.message = `${cause.getModelName()} not found!`' ,
6060 ' }' ,
6161 '' ,
62+ ' if (!(err instanceof ValidationException) &&\n !(err instanceof ModelNotFoundException)) {' ,
63+ ' error.stack = (cause as Error).stack' ,
64+ ' }' ,
65+ '' ,
6266 ' return error' ,
6367 '}' ,
6468 '' ,
6569 ] . join ( '\n' ) ,
6670 )
6771
72+ await writeFile (
73+ join ( location , 'src/core/router.ts' ) ,
74+ [
75+ 'import { Router as ClearRouter } from \'clear-router/express\'' ,
76+ '' ,
77+ 'export class Router extends ClearRouter {' ,
78+ ' static async bind () {' ,
79+ ' const router = ClearRouter.express.Router()' ,
80+ '' ,
81+ ' // Register API routes' ,
82+ ' await ClearRouter.group(\'/api\', async () => {' ,
83+ ' await import(pathToFileURL(join(process.cwd(), \'src/routes/api.ts\')).href)' ,
84+ ' })' ,
85+ '' ,
86+ ' // Register web routes' ,
87+ ' await ClearRouter.group(\'/\', async () => {' ,
88+ ' await import(pathToFileURL(join(process.cwd(), \'src/routes/web.ts\')).href)' ,
89+ ' })' ,
90+ '' ,
91+ ' // Apply the registered routes to the Express application' ,
92+ ' ClearRouter.apply(router)' ,
93+ '' ,
94+ ' return router' ,
95+ ' }' ,
96+ '}' ,
97+ ] . join ( '\n' ) ,
98+ )
99+
68100 await writeFile (
69101 join ( location , 'src/routes/api.ts' ) ,
70102 'Router.get(\'/stale\', () => [])\n' ,
@@ -93,7 +125,8 @@ describe('makeLeanProfile', () => {
93125 const actions = new Actions ( location )
94126 await actions . makeLeanProfile ( 'express' )
95127
96- expect ( existsSync ( join ( location , 'src/app' ) ) ) . toBe ( false )
128+ expect ( existsSync ( join ( location , 'src/app/http/controllers' ) ) ) . toBe ( false )
129+ expect ( existsSync ( join ( location , 'src/app/http/resources' ) ) ) . toBe ( false )
97130 expect ( existsSync ( join ( location , 'src/routes/api.ts' ) ) ) . toBe ( false )
98131 expect ( existsSync ( join ( location , 'src/core/database.ts' ) ) ) . toBe ( false )
99132 expect ( existsSync ( join ( location , 'prisma.config.ts' ) ) ) . toBe ( false )
@@ -114,5 +147,7 @@ describe('makeLeanProfile', () => {
114147 expect ( handlersContent ) . not . toContain ( 'ModelNotFoundException' )
115148 expect ( handlersContent ) . not . toContain ( 'not found!' )
116149
150+ const routerContent = await readFile ( join ( location , 'src/core/router.ts' ) , 'utf-8' )
151+ expect ( routerContent ) . not . toContain ( 'await ClearRouter.group(\'/api\'' )
117152 } )
118153} )
0 commit comments