Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feat/simplifyRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
Xy2002 committed Dec 24, 2024
2 parents 7d82337 + b938cb5 commit 199ecd8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/sync/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from 'fs';
import { join, relative } from 'path';
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';
Expand Down Expand Up @@ -62,7 +62,7 @@ export async function sync(opts: SyncOptions) {
fs.mkdirSync(tmpPath, { recursive: true });
}

await writeAi({ context });
await writeDocs({ context });
await writeTypes({ context });
if (!context.config?.router?.routeFileSimplify) {
await writeRouteTree({ context });
Expand Down
38 changes: 29 additions & 9 deletions src/sync/write_ai.ts → src/sync/write_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@ 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.`,
`- 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.`);
Expand All @@ -33,12 +40,22 @@ 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'),
path.join(docsPath, 'general.md'),
`
## General
Expand All @@ -64,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,
});
}

0 comments on commit 199ecd8

Please sign in to comment.