Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/cyan-beds-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/sdk-plugin': minor
---

refactor: update the routes folder format for the init command
50 changes: 36 additions & 14 deletions src/cli/commands/plugin/init/files/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
`,
},
{
name: 'server/src/routes/content-api.ts',
name: 'server/src/routes/content-api/index.ts',
contents: outdent`
export default [
export default () => ({
type: 'content-api',
routes: [
{
method: 'GET',
path: '/',
Expand All @@ -142,19 +144,28 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
policies: [],
},
},
];
],
});
`,
},
{
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;
Expand Down Expand Up @@ -307,9 +318,11 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [
`,
},
{
name: 'server/src/routes/content-api.js',
name: 'server/src/routes/content-api/index.js',
contents: outdent`
export default [
export default () => ({
type: 'content-api',
routes: [
{
method: 'GET',
path: '/',
Expand All @@ -319,19 +332,28 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [
policies: [],
},
},
];
],
});
`,
},
{
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;
Expand Down