Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Scaffold file routes in the plugin template

Damian Legawiec143e2837c6fe
diff --git a/packages/cli/templates/plugin/packages/dashboard/package.json.tt b/packages/cli/templates/plugin/packages/dashboard/package.json.tt
index e5b9627360..96639dabec 100644
--- a/packages/cli/templates/plugin/packages/dashboard/package.json.tt
+++ b/packages/cli/templates/plugin/packages/dashboard/package.json.tt
@@ -23,7 +23,8 @@
},
"spree": {
"dashboard": {
- "plugin": true
+ "plugin": true,
+ "routes": "./src/routes"
}
},
"peerDependencies": {
diff --git a/packages/cli/templates/plugin/packages/dashboard/src/index.tsx.tt b/packages/cli/templates/plugin/packages/dashboard/src/index.tsx.tt
index 5c68dab3e6..093d2f259b 100644
--- a/packages/cli/templates/plugin/packages/dashboard/src/index.tsx.tt
+++ b/packages/cli/templates/plugin/packages/dashboard/src/index.tsx.tt
@@ -16,7 +16,6 @@ import { RelativeTime } from '@spree/dashboard-ui'
import { PackageIcon } from 'lucide-react'
import { {{module_name}}Client } from './client'
import en from './locales/en.json'
-import { {{module_name}}ListPage } from './routes/{{name}}-list'
import { {{module_name}}Card } from './slots/product-{{name}}-card'
import type { {{module_name}} } from './types'
@@ -70,13 +69,9 @@ defineDashboardPlugin({
position: 50,
},
],
- routes: [
- {
- key: '{{name}}',
- path: '/{{name}}',
- component: {{module_name}}ListPage,
- },
- ],
+ // Routes ship as file routes in src/routes/ (see the package.json marker)
+ // and are compiled into the host's typed route tree. The `routes:` registry
+ // option remains available for dynamic host-app cases.
slots: {
'product.form_sidebar': [
{
diff --git a/packages/cli/templates/plugin/packages/dashboard/src/routes/{{name}}.index.tsx.tt b/packages/cli/templates/plugin/packages/dashboard/src/routes/{{name}}.index.tsx.tt
new file mode 100644
index 0000000000..f8565222e4
--- /dev/null
+++ b/packages/cli/templates/plugin/packages/dashboard/src/routes/{{name}}.index.tsx.tt
@@ -0,0 +1,26 @@
+/**
+ * File route for the {{name}} list — compiled into the host's typed route
+ * tree by `spreeDashboardPlugin()`. This directory is declared via the
+ * package.json marker (`"spree": { "dashboard": { "routes": "./src/routes" } }`).
+ *
+ * The path literal is the FINAL composed path (plugin routes mount under the
+ * dashboard's `_authenticated/$storeId` layout) — commit it exactly; the
+ * route generator verifies it.
+ *
+ * Route files type-check through a host app's build (they need a generated
+ * route tree in the program), so they're excluded from this package's
+ * standalone `tsc` run — develop against a dashboard host.
+ */
+import { resourceSearchSchema } from '@spree/dashboard-core'
+import { createFileRoute } from '@tanstack/react-router'
+import { {{module_name}}ListPage } from '../pages/{{name}}-list'
+
+export const Route = createFileRoute('/_authenticated/$storeId/{{name}}/')({
+ validateSearch: resourceSearchSchema,
+ component: {{module_name}}Route,
+})
+
+function {{module_name}}Route() {
+ const searchParams = Route.useSearch()
+ return <{{module_name}}ListPage searchParams={searchParams} />
+}
diff --git a/packages/cli/templates/plugin/packages/dashboard/tsconfig.json b/packages/cli/templates/plugin/packages/dashboard/tsconfig.json
index fbb2ea3e56..9a926fd6c6 100644
--- a/packages/cli/templates/plugin/packages/dashboard/tsconfig.json
+++ b/packages/cli/templates/plugin/packages/dashboard/tsconfig.json
@@ -21,5 +21,6 @@
"noUncheckedSideEffectImports": true,
"resolveJsonModule": true
},
- "include": ["src"]
+ "include": ["src"],
+ "exclude": ["src/routes"]
}
diff --git a/packages/cli/tests/plugin-template.test.ts b/packages/cli/tests/plugin-template.test.ts
index a8fa947920..eb1ae54623 100644
--- a/packages/cli/tests/plugin-template.test.ts
+++ b/packages/cli/tests/plugin-template.test.ts
@@ -55,7 +55,8 @@ describe('bundled plugin template', () => {
expect(fs.existsSync(path.join(dst, 'packages/dashboard/src/client.ts'))).toBe(true)
expect(fs.existsSync(path.join(dst, 'packages/dashboard/src/types.ts'))).toBe(true)
- expect(fs.existsSync(path.join(dst, 'packages/dashboard/src/routes/brands-list.tsx'))).toBe(
+ expect(fs.existsSync(path.join(dst, 'packages/dashboard/src/pages/brands-list.tsx'))).toBe(true)
+ expect(fs.existsSync(path.join(dst, 'packages/dashboard/src/routes/brands.index.tsx'))).toBe(
true,
)
expect(
@@ -91,13 +92,24 @@ describe('bundled plugin template', () => {
const index = fs.readFileSync(path.join(dst, 'packages/dashboard/src/index.tsx'), 'utf8')
expect(index).toContain("from './client'")
- expect(index).toContain("from './routes/brands-list'")
expect(index).toContain("from './slots/product-brands-card'")
expect(index).toContain('SpreeBrandsClient')
- expect(index).toContain('SpreeBrandsListPage')
expect(index).toContain('SpreeBrandsCard')
expect(index).toContain("path: '/brands'")
expect(index).toContain('admin.brands_plugin')
+
+ // Routes ship as file routes: full final path literal + marker, and the
+ // route file wires the page component from pages/.
+ const routeFile = fs.readFileSync(
+ path.join(dst, 'packages/dashboard/src/routes/brands.index.tsx'),
+ 'utf8',
+ )
+ expect(routeFile).toContain("createFileRoute('/_authenticated/$storeId/brands/')")
+ expect(routeFile).toContain("from '../pages/brands-list'")
+ const pkg = JSON.parse(
+ fs.readFileSync(path.join(dst, 'packages/dashboard/package.json'), 'utf8'),
+ )
+ expect(pkg.spree.dashboard.routes).toBe('./src/routes')
})
it('substitutes the README', () => {