From 0354cdbe2ea5eab16eb1e6cdc9c63d601fd2e823 Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Thu, 9 Oct 2025 18:25:49 +0200 Subject: [PATCH 1/2] refactor: update the routes folder format for the init command --- .changeset/cyan-beds-hang.md | 5 ++ src/cli/commands/plugin/init/files/server.ts | 66 ++++++++++---------- 2 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 .changeset/cyan-beds-hang.md diff --git a/.changeset/cyan-beds-hang.md b/.changeset/cyan-beds-hang.md new file mode 100644 index 0000000..d87342a --- /dev/null +++ b/.changeset/cyan-beds-hang.md @@ -0,0 +1,5 @@ +--- +'@strapi/sdk-plugin': minor +--- + +refactor: update the routes folder format for the init command diff --git a/src/cli/commands/plugin/init/files/server.ts b/src/cli/commands/plugin/init/files/server.ts index 2160f78..8d7d5bf 100644 --- a/src/cli/commands/plugin/init/files/server.ts +++ b/src/cli/commands/plugin/init/files/server.ts @@ -130,31 +130,32 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [ `, }, { - name: 'server/src/routes/content-api.ts', + name: 'server/src/routes/content-api/index.ts', contents: outdent` - export default [ - { - method: 'GET', - path: '/', - // name of the controller file & the method. - handler: 'controller.index', - config: { - policies: [], - }, - }, - ]; + export default () => ({ + type: 'content-api', + routes: [], + }); + `, + }, + { + name: 'server/src/routes/admin/index.ts', + contents: outdent` + export default () => ({ + type: 'admin', + routes: [], + }); `, }, { name: 'server/src/routes/index.ts', contents: outdent` import contentAPIRoutes from './content-api'; + import adminAPIRoutes from './admin'; const routes = { - 'content-api': { - type: 'content-api', - routes: contentAPIRoutes, - }, + 'content-api': contentAPIRoutes, + admin: adminAPIRoutes, }; export default routes; @@ -307,31 +308,32 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [ `, }, { - name: 'server/src/routes/content-api.js', + name: 'server/src/routes/content-api/index.js', contents: outdent` - export default [ - { - method: 'GET', - path: '/', - // name of the controller file & the method. - handler: 'controller.index', - config: { - policies: [], - }, - }, - ]; + export default () => ({ + type: 'content-api', + routes: [], + }); + `, + }, + { + name: 'server/src/routes/admin/index.js', + contents: outdent` + export default () => ({ + type: 'admin', + routes: [], + }); `, }, { name: 'server/src/routes/index.js', contents: outdent` import contentAPIRoutes from './content-api'; + import adminAPIRoutes from './admin'; const routes = { - 'content-api': { - type: 'content-api', - routes: contentAPIRoutes, - }, + 'content-api': contentAPIRoutes, + admin: adminAPIRoutes, }; export default routes; From 5a2fb6231d328a09c929b6a63a0c22a576d9f67b Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Mon, 27 Oct 2025 09:20:10 +0100 Subject: [PATCH 2/2] feat: add back the example route to the content-api routes --- src/cli/commands/plugin/init/files/server.ts | 24 ++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/plugin/init/files/server.ts b/src/cli/commands/plugin/init/files/server.ts index 8d7d5bf..9f4de8e 100644 --- a/src/cli/commands/plugin/init/files/server.ts +++ b/src/cli/commands/plugin/init/files/server.ts @@ -134,7 +134,17 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [ contents: outdent` export default () => ({ type: 'content-api', - routes: [], + routes: [ + { + method: 'GET', + path: '/', + // name of the controller file & the method. + handler: 'controller.index', + config: { + policies: [], + }, + }, + ], }); `, }, @@ -312,7 +322,17 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [ contents: outdent` export default () => ({ type: 'content-api', - routes: [], + routes: [ + { + method: 'GET', + path: '/', + // name of the controller file & the method. + handler: 'controller.index', + config: { + policies: [], + }, + }, + ], }); `, },