File size: 19,158 Bytes
ccb935d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
"""Dockerfile and package.json generator for JS/TS frameworks.

Auto-generates Dockerfile, package.json, and .dockerignore for
React, Next.js, Vue.js, Express, NestJS, and plain Node.js projects
so they can be pushed to HuggingFace Docker Spaces.
"""

from __future__ import annotations

import re
from typing import Any

# ─── Framework Detection ────────────────────────────────────────────────

# Keywords in code that identify a framework
FRAMEWORK_SIGNALS: dict[str, list[str]] = {
    "nextjs": [
        "from 'next", 'from "next',
        "next/link", "next/image", "next/router", "next/head",
        "NextResponse", "NextRequest", "next/navigation",
        "getServerSideProps", "getStaticProps",
    ],
    "react": [
        "from 'react", 'from "react',
        "react-dom", "ReactDOM", "useState", "useEffect",
        "jsx", "tsx", "React.Component", "React.createElement",
    ],
    "vue": [
        "from 'vue", 'from "vue',
        "createApp", "Vue.createApp", "<template>",
        "defineComponent", "ref(", "reactive(",
    ],
    "express": [
        "require('express')", 'require("express")',
        "from 'express", 'from "express',
        "express()", "express.Router",
    ],
    "nestjs": [
        "@Module", "@Controller", "@Get", "@Post", "@Put", "@Delete",
        "from '@nestjs", 'from "@nestjs',
        "NestFactory.create",
    ],
    "nodejs": [
        "require('http')", "http.createServer",
        "const http = require", "import http from",
    ],
}


def detect_framework(files: dict[str, str]) -> str:
    """Detect the JS/TS framework from project files.

    Returns one of: 'nextjs', 'react', 'vue', 'express', 'nestjs', 'nodejs', 'static'
    """
    all_code = "\n".join(files.values())

    # Check file names first (strong signal)
    has_next_config = any(
        f.startswith("next.config") for f in files
    )
    if has_next_config:
        return "nextjs"

    # Check package.json if present
    for fname, content in files.items():
        if fname == "package.json" or fname.endswith("/package.json"):
            try:
                import json
                pkg = json.loads(content)
                deps = {**pkg.get("dependencies", {}), **pkg.get("devDependencies", {})}
                if "next" in deps:
                    return "nextjs"
                if "vue" in deps or "@vue/cli-service" in deps:
                    return "vue"
                if "@nestjs/core" in deps:
                    return "nestjs"
                if "express" in deps:
                    return "express"
                if "react" in deps or "react-dom" in deps:
                    return "react"
            except Exception:
                pass

    # Check code content for framework signals
    for fw, signals in FRAMEWORK_SIGNALS.items():
        for signal in signals:
            if signal in all_code:
                return fw

    # Check file extensions
    has_jsx_tsx = any(f.endswith((".jsx", ".tsx")) for f in files)
    has_vue = any(f.endswith(".vue") for f in files)

    if has_vue:
        return "vue"
    if has_jsx_tsx:
        return "react"

    return "static"


def is_js_project(files: dict[str, str]) -> bool:
    """Check if the project is a JavaScript/TypeScript project."""
    js_extensions = {".js", ".jsx", ".ts", ".tsx", ".vue", ".mjs", ".cjs"}
    has_package_json = any("package.json" in f for f in files)
    has_js_files = any(
        any(f.endswith(ext) for ext in js_extensions)
        for f in files
    )
    return has_package_json or has_js_files


# ─── Dockerfile Templates ───────────────────────────────────────────────

def _dockerfile_nextjs() -> str:
    """Dockerfile for Next.js projects."""
    return """FROM node:20-slim AS base

# Install dependencies only when needed
FROM base AS deps
WORKDIR /app
COPY package.json package-lock.json* yarn.lock* pnpm-lock.yaml* ./
RUN \\
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \\
  elif [ -f package-lock.json ]; then npm ci; \\
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \\
  else npm i; \\
  fi

# Rebuild source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

# Production image
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
"""


def _dockerfile_react() -> str:
    """Dockerfile for React (Vite/CRA) projects β€” served with nginx."""
    return """FROM node:20-slim AS build
WORKDIR /app
COPY package.json package-lock.json* yarn.lock* pnpm-lock.yaml* ./
RUN \\
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \\
  elif [ -f package-lock.json ]; then npm ci; \\
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \\
  else npm i; \\
  fi
COPY . .
RUN npm run build

FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY --from=build /app/dist /usr/share/nginx/html 2>/dev/null || true
RUN cat > /etc/nginx/conf.d/default.conf << 'EOF'
server {
    listen 7860;
    server_name localhost;
    root /usr/share/nginx/html;
    index index.html;
    location / {
        try_files $uri $uri/ /index.html;
    }
}
EOF
EXPOSE 7860
CMD ["nginx", "-g", "daemon off;"]
"""


def _dockerfile_vue() -> str:
    """Dockerfile for Vue.js projects β€” served with nginx."""
    return """FROM node:20-slim AS build
WORKDIR /app
COPY package.json package-lock.json* yarn.lock* pnpm-lock.yaml* ./
RUN \\
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \\
  elif [ -f package-lock.json ]; then npm ci; \\
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \\
  else npm i; \\
  fi
COPY . .
RUN npm run build

FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
RUN cat > /etc/nginx/conf.d/default.conf << 'EOF'
server {
    listen 7860;
    server_name localhost;
    root /usr/share/nginx/html;
    index index.html;
    location / {
        try_files $uri $uri/ /index.html;
    }
}
EOF
EXPOSE 7860
CMD ["nginx", "-g", "daemon off;"]
"""


def _dockerfile_express() -> str:
    """Dockerfile for Express/Node.js server projects."""
    return """FROM node:20-slim
WORKDIR /app
COPY package.json package-lock.json* yarn.lock* pnpm-lock.yaml* ./
RUN \\
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \\
  elif [ -f package-lock.json ]; then npm ci; \\
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \\
  else npm i; \\
  fi
COPY . .
RUN addgroup --system --gid 1001 appuser && adduser --system --uid 1001 appuser
USER appuser
EXPOSE 7860
ENV PORT=7860
ENV HOST=0.0.0.0
CMD ["node", "index.js"]
"""


def _dockerfile_nestjs() -> str:
    """Dockerfile for NestJS projects."""
    return """FROM node:20-slim AS build
WORKDIR /app
COPY package.json package-lock.json* yarn.lock* pnpm-lock.yaml* ./
RUN \\
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \\
  elif [ -f package-lock.json ]; then npm ci; \\
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \\
  else npm i; \\
  fi
COPY . .
RUN npm run build

FROM node:20-slim
WORKDIR /app
COPY package.json package-lock.json* yarn.lock* pnpm-lock.yaml* ./
RUN \\
  if [ -f yarn.lock ]; then yarn --frozen-lockfile --production; \\
  elif [ -f package-lock.json ]; then npm ci --only=production; \\
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile --prod; \\
  else npm i --only=production; \\
  fi
COPY --from=build /app/dist ./dist
RUN addgroup --system --gid 1001 appuser && adduser --system --uid 1001 appuser
USER appuser
EXPOSE 7860
ENV PORT=7860
CMD ["node", "dist/main.js"]
"""


def generate_dockerfile(framework: str) -> str:
    """Generate a Dockerfile for the given framework.

    Args:
        framework: One of 'nextjs', 'react', 'vue', 'express', 'nestjs', 'nodejs', 'static'

    Returns:
        Dockerfile content as string.
    """
    templates = {
        "nextjs": _dockerfile_nextjs,
        "react": _dockerfile_react,
        "vue": _dockerfile_vue,
        "express": _dockerfile_express,
        "nestjs": _dockerfile_nestjs,
        "nodejs": _dockerfile_express,  # Same as express for plain Node
    }
    gen = templates.get(framework)
    if gen:
        return gen()
    # Fallback: generic node server
    return _dockerfile_express()


# ─── package.json Generator ─────────────────────────────────────────────

def _scan_js_imports(code: str) -> set[str]:
    """Scan JS/TS code for import/require statements and return package names."""
    packages = set()

    # ESM: import xxx from 'pkg' / import 'pkg'
    for m in re.finditer(r"import\s+.*?\s+from\s+['\"](@?[\w-]+/[\w-]+|[\w-]+)", code):
        packages.add(m.group(1))

    # ESM: import 'pkg'
    for m in re.finditer(r"import\s+['\"](@?[\w-]+/[\w-]+|[\w-]+)['\"]", code):
        packages.add(m.group(1))

    # CJS: require('pkg')
    for m in re.finditer(r"require\s*\(\s*['\"](@?[\w-]+/[\w-]+|[\w-]+)['\"]\s*\)", code):
        packages.add(m.group(1))

    return packages


# Known packages that should NOT go in dependencies (built-in or types)
_SKIP_PACKAGES = {
    "react", "react-dom", "next", "vue", "express",
    "path", "fs", "http", "https", "url", "os", "crypto",
    "stream", "util", "events", "buffer", "child_process",
    "net", "tls", "zlib", "assert", "querystring",
}

# Framework-specific dependency sets
_FRAMEWORK_DEPS: dict[str, dict[str, str]] = {
    "nextjs": {
        "next": "14.2.0",
        "react": "^18.3.0",
        "react-dom": "^18.3.0",
    },
    "react": {
        "react": "^18.3.0",
        "react-dom": "^18.3.0",
        "react-scripts": "5.0.1",
    },
    "vue": {
        "vue": "^3.4.0",
    },
    "express": {
        "express": "^4.19.0",
    },
    "nestjs": {
        "@nestjs/core": "^10.3.0",
        "@nestjs/common": "^10.3.0",
        "@nestjs/platform-express": "^10.3.0",
        "reflect-metadata": "^0.2.0",
        "rxjs": "^7.8.0",
    },
    "nodejs": {},
}

# Common package version mapping
_PACKAGE_VERSIONS: dict[str, str] = {
    "axios": "^1.6.0",
    "lodash": "^4.17.21",
    "cors": "^2.8.5",
    "dotenv": "^16.4.0",
    "mongoose": "^8.2.0",
    "prisma": "^5.10.0",
    "@prisma/client": "^5.10.0",
    "zod": "^3.22.0",
    "socket.io": "^4.7.0",
    "multer": "^1.4.4",
    "cookie-parser": "^1.4.6",
    "express-session": "^1.18.0",
    "jsonwebtoken": "^9.0.0",
    "bcrypt": "^5.1.0",
    "uuid": "^9.0.0",
    "dayjs": "^1.11.10",
    "chart.js": "^4.4.0",
    "framer-motion": "^11.0.0",
    "lucide-react": "^0.350.0",
    "tailwindcss": "^3.4.0",
    "postcss": "^8.4.0",
    "autoprefixer": "^10.4.0",
    "@vitejs/plugin-react": "^4.2.0",
    "vite": "^5.1.0",
    "typescript": "^5.3.0",
    "@types/react": "^18.3.0",
    "@types/react-dom": "^18.3.0",
    "@types/node": "^20.11.0",
    "tailwind-merge": "^2.2.0",
    "clsx": "^2.1.0",
    "class-variance-authority": "^0.7.0",
    "@radix-ui/react-slot": "^1.0.2",
    "next-themes": "^0.3.0",
    "recharts": "^2.12.0",
    "react-hook-form": "^7.50.0",
    "@hookform/resolvers": "^3.3.0",
    "zustand": "^4.5.0",
    "jotai": "^2.6.0",
    "tanstack": "^5.24.0",
    "@tanstack/react-query": "^5.24.0",
    "swr": "^2.2.0",
    "nodemon": "^3.1.0",
    "ts-node": "^10.9.0",
    "ts-node-dev": "^2.0.0",
}


def generate_package_json(
    framework: str,
    project_name: str = "my-app",
    extra_deps: set[str] | None = None,
    existing_content: str | None = None,
) -> str:
    """Generate a package.json for the given framework.

    If existing_content is provided, merges dependencies into it.
    """
    import json

    # Start with existing or fresh
    if existing_content:
        try:
            pkg = json.loads(existing_content)
        except Exception:
            pkg = {}
    else:
        pkg = {}

    pkg.setdefault("name", project_name)
    pkg.setdefault("version", "1.0.0")
    pkg.setdefault("private", True)

    deps = pkg.get("dependencies", {})
    dev_deps = pkg.get("devDependencies", {})

    # Add framework core deps
    fw_deps = _FRAMEWORK_DEPS.get(framework, {})
    for name, version in fw_deps.items():
        deps[name] = version

    # Add scanned extra deps
    if extra_deps:
        for dep in extra_deps:
            if dep in _SKIP_PACKAGES:
                continue
            if dep in deps or dep in dev_deps:
                continue
            version = _PACKAGE_VERSIONS.get(dep, "^1.0.0")
            # Dev deps
            if dep.startswith("@types/") or dep in {"typescript", "nodemon", "ts-node", "ts-node-dev"}:
                dev_deps[dep] = version
            else:
                deps[dep] = version

    pkg["dependencies"] = deps
    if dev_deps:
        pkg["devDependencies"] = dev_deps

    # Add scripts based on framework
    scripts = pkg.get("scripts", {})
    if framework == "nextjs":
        scripts.setdefault("dev", "next dev")
        scripts.setdefault("build", "next build")
        scripts.setdefault("start", "next start -p 7860")
    elif framework in ("react",):
        scripts.setdefault("dev", "vite")
        scripts.setdefault("build", "vite build")
        scripts.setdefault("start", "vite preview --port 7860 --host 0.0.0.0")
        # Ensure vite is in devDeps
        if "vite" not in dev_deps and "vite" not in deps:
            dev_deps["vite"] = "^5.1.0"
        if "@vitejs/plugin-react" not in dev_deps:
            dev_deps["@vitejs/plugin-react"] = "^4.2.0"
    elif framework == "vue":
        scripts.setdefault("dev", "vite")
        scripts.setdefault("build", "vite build")
        scripts.setdefault("start", "vite preview --port 7860 --host 0.0.0.0")
        if "vite" not in dev_deps and "vite" not in deps:
            dev_deps["vite"] = "^5.1.0"
    elif framework in ("express", "nodejs"):
        scripts.setdefault("dev", "node index.js")
        scripts.setdefault("start", "node index.js")
    elif framework == "nestjs":
        scripts.setdefault("build", "nest build")
        scripts.setdefault("start", "node dist/main.js")

    pkg["scripts"] = scripts
    pkg["dependencies"] = deps
    if dev_deps:
        pkg["devDependencies"] = dev_deps

    return json.dumps(pkg, indent=2) + "\n"


# ─── .dockerignore ──────────────────────────────────────────────────────

DOCKERIGNORE = """node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.next
.git
.gitignore
README.md
.env
.env.local
.env.production
.DS_Store
"""


# ─── Vite Config Generators ─────────────────────────────────────────────

def generate_vite_config(framework: str) -> str | None:
    """Generate a vite.config.js/ts if needed for React or Vue."""
    if framework == "react":
        return """import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  server: {
    host: '0.0.0.0',
    port: 7860,
  },
})
"""
    if framework == "vue":
        return """import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  server: {
    host: '0.0.0.0',
    port: 7860,
  },
})
"""
    return None


# ─── Next.js Config ────────────────────────────────────────────────────

def generate_next_config() -> str:
    """Generate next.config.js with standalone output for Docker."""
    return """/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'standalone',
}

module.exports = nextConfig
"""


# ─── Public index.html for Vite ─────────────────────────────────────────

def generate_index_html(title: str = "App") -> str:
    """Generate a minimal index.html for Vite projects."""
    return f"""<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>{title}</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>
"""


# ─── Full Project Scaffold ──────────────────────────────────────────────

def scaffold_js_project(
    files: dict[str, str],
    framework: str,
    project_name: str = "my-app",
) -> dict[str, str]:
    """Add Dockerfile, package.json, and config files to a JS project.

    Takes existing generated files and returns an augmented dict with
    Docker support files added.
    """
    augmented = dict(files)

    # Detect imports from all JS/TS files
    all_js_code = "\n".join(
        content for fname, content in files.items()
        if fname.endswith((".js", ".jsx", ".ts", ".tsx", ".vue", ".mjs"))
    )
    extra_deps = _scan_js_imports(all_js_code)

    # Add Dockerfile
    if "Dockerfile" not in augmented:
        augmented["Dockerfile"] = generate_dockerfile(framework)

    # Add .dockerignore
    if ".dockerignore" not in augmented:
        augmented[".dockerignore"] = DOCKERIGNORE

    # Add or merge package.json
    if "package.json" in augmented:
        augmented["package.json"] = generate_package_json(
            framework=framework,
            project_name=project_name,
            extra_deps=extra_deps,
            existing_content=augmented["package.json"],
        )
    else:
        augmented["package.json"] = generate_package_json(
            framework=framework,
            project_name=project_name,
            extra_deps=extra_deps,
        )

    # Framework-specific config files
    if framework == "nextjs" and "next.config.js" not in augmented and "next.config.mjs" not in augmented:
        augmented["next.config.js"] = generate_next_config()

    if framework in ("react", "vue"):
        vite_cfg = generate_vite_config(framework)
        if vite_cfg and "vite.config.js" not in augmented and "vite.config.ts" not in augmented:
            augmented["vite.config.js"] = vite_cfg

        # Add index.html entry point for Vite if not present
        if "index.html" not in augmented:
            augmented["index.html"] = generate_index_html(project_name)

    return augmented