From 3e8f7d6608602c8b8cf1cfc45bbb3a8bda278d09 Mon Sep 17 00:00:00 2001 From: sorrycc Date: Mon, 23 Dec 2024 16:09:51 +0800 Subject: [PATCH 1/2] chore(ai): improve how to organize the app --- src/sync/write_ai.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/sync/write_ai.ts b/src/sync/write_ai.ts index 678ac0c..439fb6d 100644 --- a/src/sync/write_ai.ts +++ b/src/sync/write_ai.ts @@ -17,6 +17,13 @@ export async function writeAi(opts: { context: Context }) { `- Use @tanstack/react-router for routing.`, `- Don't be lazy, write all the code to implement features I ask for.`, `- Keep a log of what, why and how you did what you did in "fyi.md". Keep it updated.`, + `- Use zod to validate api response.`, + `- Keep ui components simple and pure.`, + `- Extract logic from ui components to hooks, deep module is preferred.`, + `- Use hooks to format data.`, + `- Hard code values should be replaced by variables with meaningful names.`, + `- Extract api logic to services, keep services simple.`, + `- Use react-i18next for internationalization.`, ]; if (deps['@tanstack/react-query']) { generals.push(`- Use @tanstack/react-query for data fetching.`); @@ -33,9 +40,19 @@ export async function writeAi(opts: { context: Context }) { `- src/pages/: Pages.`, `- src/components/: Components.`, `- src/hooks/: Hooks.`, + `- src/services/: Services.`, `- src/utils/: Utils.`, `- src/types/: Types.`, + `- mock/: Mock data.`, + `- public/: Static files.`, ]; + fileDirs.push(''); + fileDirs.push( + `- Components under src/components/ directory should be named using upper camel case and using tsx, e.g. \`FooBar.tsx\`.`, + ); + fileDirs.push( + `- Mock files are js only, ts is not allowed. Content example: \`module.exports = { 'GET /api/foo': (req, res) => { res.json(data); } }\``, + ); writeFileSync( path.join(aiPath, 'general.md'), From b938cb55d393f677b98481c80c9c9ba8026c7492 Mon Sep 17 00:00:00 2001 From: sorrycc Date: Tue, 24 Dec 2024 09:53:20 +0800 Subject: [PATCH 2/2] chore: ai > docs --- src/sync/sync.ts | 4 ++-- src/sync/{write_ai.ts => write_docs.ts} | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) rename src/sync/{write_ai.ts => write_docs.ts} (83%) diff --git a/src/sync/sync.ts b/src/sync/sync.ts index bcf5050..b906362 100644 --- a/src/sync/sync.ts +++ b/src/sync/sync.ts @@ -1,8 +1,8 @@ import fs from 'fs'; import * as logger from '../fishkit/logger'; import type { Context } from '../types'; -import { writeAi } from './write_ai'; import { writeClientEntry } from './write_client_entry'; +import { writeDocs } from './write_docs'; import { writeGlobalStyle } from './write_global_style'; import { writeRouteTree } from './write_route_tree'; import { writeRouter } from './write_router'; @@ -24,7 +24,7 @@ export async function sync(opts: SyncOptions) { fs.mkdirSync(tmpPath, { recursive: true }); } - await writeAi({ context }); + await writeDocs({ context }); await writeTypes({ context }); await writeRouteTree({ context }); const globalStyleImportPath = writeGlobalStyle({ context }); diff --git a/src/sync/write_ai.ts b/src/sync/write_docs.ts similarity index 83% rename from src/sync/write_ai.ts rename to src/sync/write_docs.ts index 439fb6d..d99ce41 100644 --- a/src/sync/write_ai.ts +++ b/src/sync/write_docs.ts @@ -3,14 +3,14 @@ import path from 'pathe'; import type { Context } from '../types'; import { writeFileSync } from './fs'; -export async function writeAi(opts: { context: Context }) { +export async function writeDocs(opts: { context: Context }) { const { context } = opts; - const aiPath = path.join(context.paths.tmpPath, 'ai'); + const docsPath = path.join(context.paths.tmpPath, 'docs'); const deps = { ...context.pkg.dependencies, ...context.pkg.devDependencies, }; - fs.mkdirSync(aiPath, { recursive: true }); + fs.mkdirSync(docsPath, { recursive: true }); const generals = [ `- This a react project.`, @@ -55,7 +55,7 @@ export async function writeAi(opts: { context: Context }) { ); writeFileSync( - path.join(aiPath, 'general.md'), + path.join(docsPath, 'general.md'), ` ## General @@ -81,20 +81,23 @@ ${fileDirs.join('\n')} path.join(__dirname, '../../README.md'), 'utf-8', ); - writeFileSync(path.join(aiPath, 'tnf.md'), tnfContent); + writeFileSync(path.join(docsPath, 'tnf.md'), tnfContent); writeFileSync( - path.join(aiPath, 'best_practices.md'), + path.join(docsPath, 'best_practices.md'), '/* TODO: best practices */', ); - writeFileSync(path.join(aiPath, 'engineering.md'), '/* TODO: engineering */'); + writeFileSync( + path.join(docsPath, 'engineering.md'), + '/* TODO: engineering */', + ); - writeFileSync(path.join(aiPath, 'routing.md'), '/* TODO: routing */'); + writeFileSync(path.join(docsPath, 'routing.md'), '/* TODO: routing */'); // copy third-party docs const docsDir = path.join(__dirname, '../../third-party-docs'); - fs.cpSync(docsDir, path.join(aiPath, 'third-party-docs'), { + fs.cpSync(docsDir, path.join(docsPath, 'third-party-docs'), { recursive: true, }); }