jbilcke-hf HF staff commited on
Commit
b9bda01
β€’
1 Parent(s): fb7bd9c
Files changed (3) hide show
  1. src/getReactApp.mts +25 -4
  2. src/parseTutorial.mts +1 -1
  3. src/typescript.mts +28 -0
src/getReactApp.mts CHANGED
@@ -1,6 +1,7 @@
1
  import { alpine } from "./alpine.mts"
2
  import { daisy } from "./daisy.mts"
3
  import { dockerfile } from "./docker.mts"
 
4
 
5
  export function getReactApp(prompt: string) {
6
  const prefix = `# In src/pages/index.tsx:\n\`\`\``
@@ -8,18 +9,38 @@ export function getReactApp(prompt: string) {
8
  {
9
  path: `Dockerfile`,
10
  content: dockerfile,
 
 
 
 
11
  }
12
  ]
13
  const instructions = [
14
  {
15
  role: "system",
16
  content: [
17
- `You are a TypeScript developer, expert at crafting NextJS and React applications, using TailwindCSS utility classes.`,
 
 
 
 
 
 
 
 
 
 
 
 
18
  ].filter(item => item).join("\n")
19
  },
20
  {
21
  role: "user",
22
- content: `Think step by step, you got this! Please write, file by file, the source code for a Next 12 application.
 
 
 
 
23
  The app should be buildable when we run this in command line:
24
  \`\`\`
25
  npm install
@@ -42,9 +63,9 @@ Important rules:
42
  - you need to leave: "sdk: docker" as-is, but replace: "<APPNAME>" with an actual name, please.
43
  - Don't forget to write a valid package.json file!
44
 
45
- The app is about: ${prompt}.
46
 
47
- Remember: don't forget to edit the README.me and a package.json file!`,
48
  }
49
  ]
50
 
 
1
  import { alpine } from "./alpine.mts"
2
  import { daisy } from "./daisy.mts"
3
  import { dockerfile } from "./docker.mts"
4
+ import { tsconfig } from "./typescript.mts"
5
 
6
  export function getReactApp(prompt: string) {
7
  const prefix = `# In src/pages/index.tsx:\n\`\`\``
 
9
  {
10
  path: `Dockerfile`,
11
  content: dockerfile,
12
+ },
13
+ {
14
+ path: "tsconfig.json",
15
+ content: tsconfig
16
  }
17
  ]
18
  const instructions = [
19
  {
20
  role: "system",
21
  content: [
22
+ `You are a TypeScript developer, expert at crafting NextJS and React applications, using TailwindCSS utility classes.
23
+ You usually use the following dependencies:
24
+
25
+ \`\`\`
26
+ "@types/node": "20.4.2",
27
+ "@types/react": "18.2.15",
28
+ "@types/react-dom": "18.2.7",
29
+ "react": "18.2.0",
30
+ "react-dom": "18.2.0",
31
+ "typescript": "5.1.6",
32
+ \`\`\`
33
+
34
+ `,
35
  ].filter(item => item).join("\n")
36
  },
37
  {
38
  role: "user",
39
+ content: `
40
+ You need to write the list of files for a new NextJS 12 application.
41
+ The app is about: ${prompt}.
42
+ Think step by step, you got this!
43
+ Please write, file by file, the source code for a Next 12 application.
44
  The app should be buildable when we run this in command line:
45
  \`\`\`
46
  npm install
 
63
  - you need to leave: "sdk: docker" as-is, but replace: "<APPNAME>" with an actual name, please.
64
  - Don't forget to write a valid package.json file!
65
 
66
+ Remember, the app is about: ${prompt}.
67
 
68
+ Remember: don't forget to define the README.md and the package.json file!`,
69
  }
70
  ]
71
 
src/parseTutorial.mts CHANGED
@@ -1,6 +1,6 @@
1
  export function parseTutorial(text: string): Array<{ filename: string; content: string }> {
2
  const result: { filename: string; content: string; }[] = [];
3
- const regex = /# In (?:the )?(.*):\n```(?:\w+\n)?([\s\S]*?)```/g;
4
  let match: RegExpExecArray | null;
5
  while ((match = regex.exec(text)) !== null) {
6
  result.push({
 
1
  export function parseTutorial(text: string): Array<{ filename: string; content: string }> {
2
  const result: { filename: string; content: string; }[] = [];
3
+ const regex = /#\s+(?:And finally,\s+)?in\s+(?:(?:the|your)\s+)?(.*)(?:, add the following code)?:\n```(?:\w+\n)?([\s\S]*?)```/gi;
4
  let match: RegExpExecArray | null;
5
  while ((match = regex.exec(text)) !== null) {
6
  result.push({
src/typescript.mts ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export const tsconfig = `{
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "noEmit": true,
10
+ "esModuleInterop": true,
11
+ "module": "esnext",
12
+ "moduleResolution": "node",
13
+ "resolveJsonModule": true,
14
+ "isolatedModules": true,
15
+ "jsx": "preserve",
16
+ "incremental": true,
17
+ "plugins": [
18
+ {
19
+ "name": "next"
20
+ }
21
+ ],
22
+ "paths": {
23
+ "@/*": ["./src/*"]
24
+ }
25
+ },
26
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
27
+ "exclude": ["node_modules"]
28
+ }`