create-fullstack-scaffold 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +72 -0
- package/dist/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/template/drizzle.config.ts +2 -0
- package/template/eslint.config.js +4 -1
- package/template/package.json +1 -1
- package/template/src/client/entry-server.tsx +20 -11
- package/template/src/client/main.tsx +18 -5
- package/template/src/client/pages/ContentDetailPage.tsx +13 -2
- package/template/src/client/pages/ContentListPage.tsx +13 -2
- package/template/src/client/ssr-pages.ts +44 -0
- package/template/src/client/stores/entry-stores.ts +3 -0
- package/template/src/server/config.ts +1 -3
- package/template/src/server/core/isr-renderer.ts +8 -2
- package/template/src/server/entries/cloudflare.ts +2 -2
- package/template/src/server/entries/node.ts +3 -1
package/dist/cli/index.js
CHANGED
|
@@ -286,6 +286,7 @@ function getGeneratedFiles(resolved) {
|
|
|
286
286
|
"src/server/rpc-surface.ts",
|
|
287
287
|
"src/server/isr-modules.ts",
|
|
288
288
|
"src/client/stores/entry-stores.ts",
|
|
289
|
+
"src/client/ssr-pages.ts",
|
|
289
290
|
"src/server/db/schema/index.ts",
|
|
290
291
|
"src/shared/modules/index.ts",
|
|
291
292
|
"src/shared/schemas/index.ts",
|
|
@@ -630,6 +631,72 @@ export function restoreEntryStores(snapshot: EntryStoreSnapshot): void {
|
|
|
630
631
|
`;
|
|
631
632
|
}
|
|
632
633
|
|
|
634
|
+
// src/generators/ssr-pages.ts
|
|
635
|
+
var SSR_PAGE_MAP = [
|
|
636
|
+
{ file: "TodoPage", component: "TodoPage", route: "/todos" },
|
|
637
|
+
{ file: "ContentListPage", component: "ContentListPage", route: "/content" },
|
|
638
|
+
{
|
|
639
|
+
file: "ContentDetailPage",
|
|
640
|
+
component: "ContentDetailPage",
|
|
641
|
+
route: "/content/:id",
|
|
642
|
+
pattern: "/content/"
|
|
643
|
+
},
|
|
644
|
+
{ file: "TopicsPage", component: "TopicsPage", route: "/topics" }
|
|
645
|
+
];
|
|
646
|
+
function generateSsrPages(resolved, pageFileExists) {
|
|
647
|
+
const pages = getClientPages(resolved);
|
|
648
|
+
const available = new Set(pages.map((p) => p.name));
|
|
649
|
+
const imports = [];
|
|
650
|
+
const entries = [];
|
|
651
|
+
const patterns = [];
|
|
652
|
+
for (const m of SSR_PAGE_MAP) {
|
|
653
|
+
if (!available.has(m.file) && !pageFileExists(m.file)) continue;
|
|
654
|
+
imports.push(`import { ${m.component} } from './pages/${m.file}'`);
|
|
655
|
+
entries.push(` '${m.route}': ${m.component},`);
|
|
656
|
+
if (m.pattern) {
|
|
657
|
+
patterns.push(` { prefix: '${m.pattern}', component: ${m.component} },`);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
const noPages = imports.length === 0;
|
|
661
|
+
return `/**
|
|
662
|
+
* SSR \u9759\u6001\u9875\u9762\u6CE8\u518C\u8868\uFF08\u672C\u6587\u4EF6\u7531 CLI \u751F\u6210\uFF0C\u52FF\u624B\u6539\uFF09\u3002
|
|
663
|
+
* \u751F\u6210\u5668: src/generators/ssr-pages.ts
|
|
664
|
+
*
|
|
665
|
+
* renderToString \u89E3\u6790\u4E0D\u4E86 React.lazy\u2014\u2014ISR \u8DEF\u7531\u7684\u9875\u9762\u7EA7 SSR \u4F9D\u8D56\u8FD9\u91CC\u7684
|
|
666
|
+
* \u9759\u6001\u540C\u6784\u7EC4\u4EF6\u3002\u53EA\u5BFC\u5165\u672C preset \u5B9E\u9645\u5305\u542B\u7684\u9875\u9762\uFF08\u6A21\u677F\u5168\u91CF\u7248\u4F1A\u88AB\u8986\u76D6\uFF09\u3002
|
|
667
|
+
*/
|
|
668
|
+
|
|
669
|
+
import type { ComponentType } from 'react'
|
|
670
|
+
${noPages ? `
|
|
671
|
+
// \u672C preset \u6CA1\u6709\u5173\u8054\u7684 ISR \u9875\u9762\u2014\u2014SSR \u8F93\u51FA\u5E03\u5C40\u58F3 + meta\uFF08\u5408\u7406\uFF1A
|
|
672
|
+
// \u8BE5 preset \u7684\u9875\u9762\u65E0\u9700 SEO \u6216\u5747\u4E3A\u7BA1\u7406/\u5DE5\u5177\u578B\uFF09
|
|
673
|
+
export const SSR_PAGES: Record<string, ComponentType> = {}
|
|
674
|
+
|
|
675
|
+
export function getSsrPage(_pathname: string): ComponentType | null {
|
|
676
|
+
return null
|
|
677
|
+
}
|
|
678
|
+
` : `
|
|
679
|
+
${imports.join("\n")}
|
|
680
|
+
|
|
681
|
+
export const SSR_PAGES: Record<string, ComponentType> = {
|
|
682
|
+
${entries.join("\n")}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const SSR_PATTERNS: Array<{ prefix: string; component: ComponentType }> = [
|
|
686
|
+
${patterns.join("\n")}
|
|
687
|
+
]
|
|
688
|
+
|
|
689
|
+
/** ISR \u8DEF\u5F84\u662F\u5426\u6709\u5173\u8054\u9759\u6001\u7EC4\u4EF6\uFF08\u51B3\u5B9A body \u6E32\u67D3\u771F\u5B9E\u5185\u5BB9\u8FD8\u662F\u4EC5 meta\uFF09 */
|
|
690
|
+
export function getSsrPage(pathname: string): ComponentType | null {
|
|
691
|
+
if (SSR_PAGES[pathname]) return SSR_PAGES[pathname]
|
|
692
|
+
for (const p of SSR_PATTERNS) {
|
|
693
|
+
if (pathname.startsWith(p.prefix)) return p.component
|
|
694
|
+
}
|
|
695
|
+
return null
|
|
696
|
+
}
|
|
697
|
+
`}`;
|
|
698
|
+
}
|
|
699
|
+
|
|
633
700
|
// src/generators/client-navigation.ts
|
|
634
701
|
var DEFAULT_ICON = "Circle";
|
|
635
702
|
var ICON_MAP = {
|
|
@@ -4232,6 +4299,11 @@ async function createProject(projectNameOrOptions, useCurrentDir = false, preset
|
|
|
4232
4299
|
path.join(targetDir, "src/client/stores/entry-stores.ts"),
|
|
4233
4300
|
entryStoresContent
|
|
4234
4301
|
);
|
|
4302
|
+
const ssrPagesContent = generateSsrPages(
|
|
4303
|
+
resolved,
|
|
4304
|
+
(name) => fs.existsSync(path.join(targetDir, "src/client/pages", `${name}.tsx`))
|
|
4305
|
+
);
|
|
4306
|
+
await fs.writeFile(path.join(targetDir, "src/client/ssr-pages.ts"), ssrPagesContent);
|
|
4235
4307
|
}
|
|
4236
4308
|
const dbSchemaContent = generateDbSchemaBarrel(resolved);
|
|
4237
4309
|
await fs.writeFile(path.join(targetDir, "src/server/db/schema/index.ts"), dbSchemaContent);
|