@decocms/start 0.39.0 → 0.40.0
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/.agents/skills/deco-migrate-script/SKILL.md +434 -0
- package/.agents/skills/deco-to-tanstack-migration/SKILL.md +382 -0
- package/.agents/skills/deco-to-tanstack-migration/references/admin-cms.md +154 -0
- package/{.cursor/skills/deco-async-rendering-site-guide/SKILL.md → .agents/skills/deco-to-tanstack-migration/references/async-rendering.md} +296 -31
- package/.agents/skills/deco-to-tanstack-migration/references/codemod-commands.md +174 -0
- package/.agents/skills/deco-to-tanstack-migration/references/commerce/README.md +78 -0
- package/.agents/skills/deco-to-tanstack-migration/references/css-styling.md +156 -0
- package/.agents/skills/deco-to-tanstack-migration/references/deco-framework/README.md +128 -0
- package/.agents/skills/deco-to-tanstack-migration/references/gotchas.md +13 -0
- package/{.cursor/skills/deco-tanstack-hydration-fixes/SKILL.md → .agents/skills/deco-to-tanstack-migration/references/hydration-fixes.md} +139 -4
- package/.agents/skills/deco-to-tanstack-migration/references/imports/README.md +70 -0
- package/{.cursor/skills/deco-islands-migration/SKILL.md → .agents/skills/deco-to-tanstack-migration/references/islands.md} +0 -14
- package/.agents/skills/deco-to-tanstack-migration/references/jsx-migration.md +80 -0
- package/.agents/skills/deco-to-tanstack-migration/references/matchers.md +1064 -0
- package/{.cursor/skills/deco-tanstack-navigation/SKILL.md → .agents/skills/deco-to-tanstack-migration/references/navigation.md} +1 -16
- package/.agents/skills/deco-to-tanstack-migration/references/platform-hooks/README.md +154 -0
- package/.agents/skills/deco-to-tanstack-migration/references/react-hooks-patterns.md +142 -0
- package/.agents/skills/deco-to-tanstack-migration/references/react-signals-state.md +72 -0
- package/{.cursor/skills/deco-tanstack-search/SKILL.md → .agents/skills/deco-to-tanstack-migration/references/search.md} +1 -13
- package/.agents/skills/deco-to-tanstack-migration/references/signals/README.md +220 -0
- package/{.cursor/skills/deco-tanstack-storefront-patterns/SKILL.md → .agents/skills/deco-to-tanstack-migration/references/storefront-patterns.md} +1 -137
- package/.agents/skills/deco-to-tanstack-migration/references/vite-config/README.md +78 -0
- package/.agents/skills/deco-to-tanstack-migration/references/vtex-commerce.md +165 -0
- package/.agents/skills/deco-to-tanstack-migration/references/worker-cloudflare.md +209 -0
- package/.agents/skills/deco-to-tanstack-migration/templates/package-json.md +55 -0
- package/.agents/skills/deco-to-tanstack-migration/templates/root-route.md +110 -0
- package/.agents/skills/deco-to-tanstack-migration/templates/router.md +96 -0
- package/.agents/skills/deco-to-tanstack-migration/templates/setup-ts.md +167 -0
- package/.agents/skills/deco-to-tanstack-migration/templates/vite-config.md +122 -0
- package/.agents/skills/deco-to-tanstack-migration/templates/worker-entry.md +67 -0
- package/README.md +45 -0
- package/package.json +1 -1
- package/.cursor/skills/deco-async-rendering-architecture/SKILL.md +0 -270
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deco-migrate-script
|
|
3
|
+
description: Automated migration script that converts Deco storefronts from Fresh/Preact/Deno to TanStack Start/React/Cloudflare Workers. Runs 7 phases (analyze, scaffold, transform, cleanup, report, verify, bootstrap). Use when running the migration script, debugging its output, extending it with new transforms, or understanding what it does. Located at scripts/migrate.ts in @decocms/start.
|
|
4
|
+
globs:
|
|
5
|
+
- "scripts/migrate.ts"
|
|
6
|
+
- "scripts/migrate/**/*"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Deco Migration Script
|
|
10
|
+
|
|
11
|
+
Automated TypeScript script that converts a Deco storefront from Fresh/Preact/Deno to TanStack Start/React/Cloudflare Workers in one pass.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# From the NEW site root (already has @decocms/start installed):
|
|
17
|
+
npx tsx node_modules/@decocms/start/scripts/migrate.ts --source /path/to/old-site
|
|
18
|
+
|
|
19
|
+
# Dry run first:
|
|
20
|
+
npx tsx node_modules/@decocms/start/scripts/migrate.ts --source /path/to/old-site --dry-run --verbose
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Options
|
|
24
|
+
|
|
25
|
+
| Flag | Description |
|
|
26
|
+
|------|-------------|
|
|
27
|
+
| `--source <dir>` | Source site directory (default: `.`) |
|
|
28
|
+
| `--dry-run` | Preview changes without writing files |
|
|
29
|
+
| `--verbose` | Show detailed per-file output |
|
|
30
|
+
| `--help` | Show help |
|
|
31
|
+
|
|
32
|
+
## Architecture
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
scripts/migrate.ts ← Entry point, runs all phases
|
|
36
|
+
scripts/migrate/
|
|
37
|
+
├── types.ts ← MigrationContext, FileRecord, DetectedPattern
|
|
38
|
+
├── colors.ts ← Terminal output formatting
|
|
39
|
+
├── phase-analyze.ts ← Phase 1: scan source, detect patterns
|
|
40
|
+
├── phase-scaffold.ts ← Phase 2: generate config files
|
|
41
|
+
├── phase-transform.ts ← Phase 3: apply code transforms
|
|
42
|
+
├── phase-cleanup.ts ← Phase 4: delete old artifacts
|
|
43
|
+
├── phase-report.ts ← Phase 5: generate MIGRATION_REPORT.md
|
|
44
|
+
├── phase-verify.ts ← Phase 6: smoke tests
|
|
45
|
+
├── transforms/ ← Transform modules (applied in order)
|
|
46
|
+
│ ├── imports.ts ← 70+ import rewriting rules
|
|
47
|
+
│ ├── jsx.ts ← JSX attribute fixes
|
|
48
|
+
│ ├── fresh-apis.ts ← Fresh framework API removal
|
|
49
|
+
│ ├── deno-isms.ts ← Deno-specific cleanup
|
|
50
|
+
│ ├── dead-code.ts ← Old cache/loader system removal
|
|
51
|
+
│ └── tailwind.ts ← Tailwind v3→v4 + DaisyUI v4→v5
|
|
52
|
+
└── templates/ ← Config file generators
|
|
53
|
+
├── package-json.ts ← Auto-fetches latest npm versions
|
|
54
|
+
├── tsconfig.ts
|
|
55
|
+
├── vite-config.ts
|
|
56
|
+
├── wrangler.ts
|
|
57
|
+
├── knip-config.ts
|
|
58
|
+
├── routes.ts ← __root, index, $, deco/* routes
|
|
59
|
+
├── setup.ts ← CMS block registry
|
|
60
|
+
└── server-entry.ts ← server.ts + worker-entry.ts
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Phases
|
|
64
|
+
|
|
65
|
+
### Phase 1: Analyze
|
|
66
|
+
|
|
67
|
+
Scans the source directory to build a `MigrationContext`:
|
|
68
|
+
|
|
69
|
+
**Pattern detection** — 21 regex patterns:
|
|
70
|
+
- `preact-hooks`, `preact-compat`, `preact-signals`
|
|
71
|
+
- `fresh-runtime`, `fresh-head`, `fresh-islands`
|
|
72
|
+
- `deco-hooks`, `deco-blocks`, `deco-types`
|
|
73
|
+
- `apps-commerce`, `apps-website`, `apps-admin`
|
|
74
|
+
- `site-alias` (`$store/`, `deco-sites/`, `site/`)
|
|
75
|
+
- `class-attr`, `for-attr`, `svg-attrs`
|
|
76
|
+
- `use-signal`, `use-computed`
|
|
77
|
+
|
|
78
|
+
**File categorization**:
|
|
79
|
+
- `section` — `src/sections/**/*.tsx`
|
|
80
|
+
- `island` — `src/islands/**/*.tsx`
|
|
81
|
+
- `component` — `src/components/**/*.tsx`
|
|
82
|
+
- `sdk` — `src/sdk/**/*.ts`
|
|
83
|
+
- `loader` — `src/loaders/**/*.ts`
|
|
84
|
+
- `action` — `src/actions/**/*.ts`
|
|
85
|
+
- `route` — `routes/**/*.ts` (marked for deletion)
|
|
86
|
+
- `static` — `static/**/*` (marked for move → `public/`)
|
|
87
|
+
- `config` — `deno.json`, `fresh.gen.ts`, etc. (marked for deletion)
|
|
88
|
+
|
|
89
|
+
**Metadata extraction**:
|
|
90
|
+
- Site name (from `deno.json` or directory name)
|
|
91
|
+
- Platform (VTEX, Shopify, etc. from `apps/site.ts`)
|
|
92
|
+
- GTM ID (from `routes/_app.tsx`)
|
|
93
|
+
- Theme colors & fonts (from `.deco/blocks/` CMS JSON)
|
|
94
|
+
- NPM dependencies (from `npm:` imports and import map)
|
|
95
|
+
|
|
96
|
+
### Phase 2: Scaffold
|
|
97
|
+
|
|
98
|
+
Generates 14+ configuration and infrastructure files:
|
|
99
|
+
|
|
100
|
+
| File | Generator | Notes |
|
|
101
|
+
|------|-----------|-------|
|
|
102
|
+
| `package.json` | `templates/package-json.ts` | Auto-fetches latest npm versions, extracts deps from deno.json |
|
|
103
|
+
| `tsconfig.json` | `templates/tsconfig.ts` | |
|
|
104
|
+
| `vite.config.ts` | `templates/vite-config.ts` | Plugins, aliases, manual chunks, meta.gen stub |
|
|
105
|
+
| `wrangler.jsonc` | `templates/wrangler.ts` | Cloudflare Worker config |
|
|
106
|
+
| `knip.config.ts` | `templates/knip-config.ts` | Unused code detection |
|
|
107
|
+
| `src/router.tsx` | `templates/routes.ts` | TanStack Router with search serialization |
|
|
108
|
+
| `src/routes/__root.tsx` | `templates/routes.ts` | Layout + GTM + analytics + NavigationProgress |
|
|
109
|
+
| `src/routes/index.tsx` | `templates/routes.ts` | Home page with CMS loader |
|
|
110
|
+
| `src/routes/$.tsx` | `templates/routes.ts` | Catch-all CMS route |
|
|
111
|
+
| `src/routes/deco/meta.ts` | `templates/routes.ts` | Admin schema endpoint |
|
|
112
|
+
| `src/routes/deco/invoke.$.ts` | `templates/routes.ts` | RPC handler |
|
|
113
|
+
| `src/routes/deco/render.ts` | `templates/routes.ts` | Preview renderer |
|
|
114
|
+
| `src/server.ts` | `templates/server-entry.ts` | TanStack handler |
|
|
115
|
+
| `src/worker-entry.ts` | `templates/server-entry.ts` | Cloudflare wrapper with admin handlers |
|
|
116
|
+
| `src/setup.ts` | `templates/setup.ts` | CMS block registry via `import.meta.glob` |
|
|
117
|
+
| `src/runtime.ts` | `templates/server-entry.ts` | Invoke proxy for RPC calls |
|
|
118
|
+
| `src/styles/app.css` | inline | DaisyUI v5 CSS with extracted theme colors |
|
|
119
|
+
|
|
120
|
+
### Phase 3: Transform
|
|
121
|
+
|
|
122
|
+
Applies 6 transforms in sequence to every source file:
|
|
123
|
+
|
|
124
|
+
#### 1. `imports.ts` — Import Rewriting (70+ rules)
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
preact/hooks → react
|
|
128
|
+
preact/compat → react
|
|
129
|
+
preact → react
|
|
130
|
+
@preact/signals → @decocms/start/sdk/signal
|
|
131
|
+
@deco/deco/hooks → @decocms/start/sdk/useScript
|
|
132
|
+
@deco/deco/blocks→ @decocms/start/types
|
|
133
|
+
apps/commerce/* → @decocms/apps/commerce/*
|
|
134
|
+
apps/website/* → ~/components/ui/* or @decocms/apps/*
|
|
135
|
+
site/* → ~/*
|
|
136
|
+
$store/* → ~/*
|
|
137
|
+
deco-sites/NAME/ → ~/
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Also removes `npm:` prefix, handles relative imports to deleted SDK files (clx, useId, useOffer).
|
|
141
|
+
|
|
142
|
+
#### 2. `jsx.ts` — JSX Compatibility
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
class= → className=
|
|
146
|
+
onInput= → onChange=
|
|
147
|
+
for= → htmlFor= (on labels)
|
|
148
|
+
tabindex= → tabIndex=
|
|
149
|
+
referrerpolicy= → referrerPolicy=
|
|
150
|
+
ComponentChildren→ ReactNode
|
|
151
|
+
JSX.SVGAttributes→ React.SVGAttributes
|
|
152
|
+
setTimeout → window.setTimeout (type safety)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### 3. `fresh-apis.ts` — Fresh Framework Removal
|
|
156
|
+
|
|
157
|
+
- `asset(url)` → `url` (identity function)
|
|
158
|
+
- `scriptAsDataURI()` → detection + warning
|
|
159
|
+
- `<Head>` component → flagged for manual review
|
|
160
|
+
- `defineApp()` → unwrapped
|
|
161
|
+
- `IS_BROWSER` → `typeof window !== "undefined"`
|
|
162
|
+
- `Context.active()` → removed
|
|
163
|
+
|
|
164
|
+
#### 4. `dead-code.ts` — Old Deco Patterns
|
|
165
|
+
|
|
166
|
+
- Removes: `export const cache`, `export const cacheKey`, `export const loader` (old caching system)
|
|
167
|
+
- Handles: `crypto.subtle.digestSync` (Deno-only → async)
|
|
168
|
+
- Preserves: `invoke.*` calls (runtime.ts proxy)
|
|
169
|
+
|
|
170
|
+
#### 5. `deno-isms.ts` — Deno Cleanup
|
|
171
|
+
|
|
172
|
+
- `deno-lint-ignore` comments → removed
|
|
173
|
+
- `npm:` prefix → removed
|
|
174
|
+
- `@ts-ignore` → `@ts-expect-error`
|
|
175
|
+
- `Deno.*` API usage → flagged
|
|
176
|
+
- `/// <reference>` directives → removed
|
|
177
|
+
|
|
178
|
+
#### 6. `tailwind.ts` — Tailwind v3→v4 + DaisyUI v4→v5
|
|
179
|
+
|
|
180
|
+
**23 Tailwind class renames:**
|
|
181
|
+
```
|
|
182
|
+
flex-grow-0 → grow-0
|
|
183
|
+
flex-shrink → shrink
|
|
184
|
+
decoration-clone → box-decoration-clone
|
|
185
|
+
transform → (removed, implicit in v4)
|
|
186
|
+
filter → (removed, implicit in v4)
|
|
187
|
+
ring → ring-3 (default changed)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**15 DaisyUI v4→v5 renames:**
|
|
191
|
+
```
|
|
192
|
+
badge-ghost → badge-soft
|
|
193
|
+
card-compact → card-sm
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Arbitrary value simplification:**
|
|
197
|
+
```
|
|
198
|
+
px-[16px] → px-4
|
|
199
|
+
text-[12px] → text-xs
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Opacity modifier consolidation:**
|
|
203
|
+
```
|
|
204
|
+
bg-black bg-opacity-20 → bg-black/20
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Critical z-index fix** (Tailwind v4 + React stacking contexts):
|
|
208
|
+
- `-z-{n}` on `<img>` / `<Image>` → `z-0` + `inset-0`
|
|
209
|
+
- Extracts `backgroundColor` into separate overlay div
|
|
210
|
+
- Bumps content div to `relative z-20`
|
|
211
|
+
|
|
212
|
+
### Phase 4: Cleanup
|
|
213
|
+
|
|
214
|
+
**Deletes directories:**
|
|
215
|
+
- `islands/`, `routes/`, `apps/deco/`, `sdk/cart/`
|
|
216
|
+
|
|
217
|
+
**Deletes root files:**
|
|
218
|
+
- `deno.json`, `fresh.gen.ts`, `main.ts`, `dev.ts`, `tailwind.config.ts`, `runtime.ts`, `constants.ts`
|
|
219
|
+
|
|
220
|
+
**Deletes SDK files** (now in @decocms/start or @decocms/apps):
|
|
221
|
+
- `sdk/clx.ts`, `sdk/useId.ts`, `sdk/useOffer.ts`, `sdk/useVariantPossiblities.ts`, `sdk/usePlatform.tsx`
|
|
222
|
+
|
|
223
|
+
**Moves:**
|
|
224
|
+
- `static/` → `public/` (preserves directory structure)
|
|
225
|
+
|
|
226
|
+
### Phase 5: Report
|
|
227
|
+
|
|
228
|
+
Generates `MIGRATION_REPORT.md` with:
|
|
229
|
+
- Summary table (files analyzed / scaffolded / transformed / deleted / moved)
|
|
230
|
+
- Categorized file lists
|
|
231
|
+
- Manual review items with severity
|
|
232
|
+
- Always-check section (FormEmail, Slider, Theme, DaisyUI, Tailwind)
|
|
233
|
+
- Known issues (z-index stacking, opacity modifiers)
|
|
234
|
+
- Framework findings (patterns to consolidate into @decocms/start)
|
|
235
|
+
- Next steps
|
|
236
|
+
|
|
237
|
+
### Phase 6: Verify
|
|
238
|
+
|
|
239
|
+
18+ smoke tests in two tiers:
|
|
240
|
+
|
|
241
|
+
**Critical (blocks migration):**
|
|
242
|
+
- Scaffolded files exist (package.json, vite.config.ts, setup.ts, etc.)
|
|
243
|
+
- Old artifacts removed (deno.json, fresh.gen.ts, etc.)
|
|
244
|
+
- No preact imports remain
|
|
245
|
+
- No `$fresh` imports remain
|
|
246
|
+
- No relative imports to deleted SDK files
|
|
247
|
+
- package.json has required dependencies
|
|
248
|
+
|
|
249
|
+
**Warnings (manual review):**
|
|
250
|
+
- No `class=` (should be `className=`)
|
|
251
|
+
- No `for=` (should be `htmlFor=`)
|
|
252
|
+
- No negative z-index on non-images
|
|
253
|
+
- No dead `cache`/`cacheKey`/`loader` exports
|
|
254
|
+
- No HTMX attributes (`hx-*`)
|
|
255
|
+
- No `site/` imports (should use `~/`)
|
|
256
|
+
- No `.ts`/`.tsx` extensions in imports
|
|
257
|
+
- `.gitignore` has new stack entries
|
|
258
|
+
- `public/` has sprites.svg + favicon.ico
|
|
259
|
+
|
|
260
|
+
### Phase 7: Bootstrap
|
|
261
|
+
|
|
262
|
+
Runs automatically after all phases (skipped in `--dry-run`):
|
|
263
|
+
1. `npm install` (or `bun install`)
|
|
264
|
+
2. `npx tsx node_modules/@decocms/start/scripts/generate-blocks.ts`
|
|
265
|
+
3. `npx tsr generate`
|
|
266
|
+
|
|
267
|
+
## Key Design Decisions
|
|
268
|
+
|
|
269
|
+
### MigrationContext (types.ts)
|
|
270
|
+
|
|
271
|
+
Central state object threaded through all phases:
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
interface MigrationContext {
|
|
275
|
+
sourceDir: string;
|
|
276
|
+
dryRun: boolean;
|
|
277
|
+
verbose: boolean;
|
|
278
|
+
files: Map<string, FileRecord>; // path → metadata + action
|
|
279
|
+
metadata: {
|
|
280
|
+
siteName: string;
|
|
281
|
+
platform: Platform; // vtex | shopify | wake | ...
|
|
282
|
+
gtmId?: string;
|
|
283
|
+
themeColors: Record<string, string>;
|
|
284
|
+
themeFonts: string[];
|
|
285
|
+
npmDeps: Map<string, string>; // extracted from deno.json
|
|
286
|
+
};
|
|
287
|
+
report: {
|
|
288
|
+
scaffolded: string[];
|
|
289
|
+
transformed: string[];
|
|
290
|
+
deleted: string[];
|
|
291
|
+
moved: string[];
|
|
292
|
+
manualReview: { file: string; reason: string; severity: string }[];
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### FileRecord
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
interface FileRecord {
|
|
301
|
+
relativePath: string;
|
|
302
|
+
category: "section" | "island" | "component" | "sdk" | "loader" | "action" | "route" | "static" | "config";
|
|
303
|
+
patterns: DetectedPattern[]; // which old-stack patterns were found
|
|
304
|
+
action: "transform" | "delete" | "move" | "scaffold" | "skip";
|
|
305
|
+
targetPath?: string; // for moves
|
|
306
|
+
notes: string[]; // per-file migration notes
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Platform Detection
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
// From apps/site.ts or deno.json imports:
|
|
314
|
+
type Platform = "vtex" | "shopify" | "wake" | "vnda" | "linx" | "nuvemshop" | "custom";
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Platform affects: commerce type imports, loader registration, setup.ts template, API proxy configuration.
|
|
318
|
+
|
|
319
|
+
## Extending the Script
|
|
320
|
+
|
|
321
|
+
### Adding a New Transform
|
|
322
|
+
|
|
323
|
+
1. Create `scripts/migrate/transforms/my-transform.ts`:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
import type { TransformResult } from "../types";
|
|
327
|
+
|
|
328
|
+
export function myTransform(content: string, filePath: string): TransformResult {
|
|
329
|
+
let changed = false;
|
|
330
|
+
const notes: string[] = [];
|
|
331
|
+
let result = content;
|
|
332
|
+
|
|
333
|
+
// Apply your regex/string replacements
|
|
334
|
+
const next = result.replace(/oldPattern/g, "newPattern");
|
|
335
|
+
if (next !== result) {
|
|
336
|
+
changed = true;
|
|
337
|
+
notes.push("Replaced oldPattern → newPattern");
|
|
338
|
+
result = next;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return { content: result, changed, notes };
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
2. Import and add to the pipeline in `phase-transform.ts`:
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
import { myTransform } from "./transforms/my-transform";
|
|
349
|
+
|
|
350
|
+
// In the transform pipeline array:
|
|
351
|
+
const transforms = [imports, jsx, freshApis, deadCode, denoIsms, tailwind, myTransform];
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Adding a New Template
|
|
355
|
+
|
|
356
|
+
1. Create `scripts/migrate/templates/my-file.ts`:
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
import type { MigrationContext } from "../types";
|
|
360
|
+
|
|
361
|
+
export function generateMyFile(ctx: MigrationContext): string {
|
|
362
|
+
return `// Generated by migration script
|
|
363
|
+
export const siteName = "${ctx.metadata.siteName}";
|
|
364
|
+
`;
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
2. Call from `phase-scaffold.ts`:
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
import { generateMyFile } from "./templates/my-file";
|
|
372
|
+
writeScaffolded(ctx, "src/my-file.ts", generateMyFile(ctx));
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Adding a Smoke Test
|
|
376
|
+
|
|
377
|
+
In `phase-verify.ts`:
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
checks.push({
|
|
381
|
+
name: "No foo imports",
|
|
382
|
+
level: "critical", // or "warning"
|
|
383
|
+
test: () => !grepFiles(ctx, /from ["']foo["']/).length,
|
|
384
|
+
message: "Found foo imports — should be replaced with bar",
|
|
385
|
+
});
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## Common Issues & Debugging
|
|
389
|
+
|
|
390
|
+
### Script fails at Phase 1 (Analyze)
|
|
391
|
+
|
|
392
|
+
**Cause**: Source directory structure doesn't match expected Deco layout.
|
|
393
|
+
**Fix**: Ensure source has `src/sections/` or `sections/`, `deno.json` or `import_map.json`.
|
|
394
|
+
|
|
395
|
+
### Transform misses some files
|
|
396
|
+
|
|
397
|
+
**Cause**: Files outside standard directories (`src/`, `components/`, etc.).
|
|
398
|
+
**Fix**: Check `phase-analyze.ts` categorization logic — add new glob patterns if needed.
|
|
399
|
+
|
|
400
|
+
### Z-index stacking issues after migration
|
|
401
|
+
|
|
402
|
+
**Cause**: Tailwind v4 changed stacking context behavior. The script auto-fixes `-z-{n}` on images but may miss custom patterns.
|
|
403
|
+
**Fix**: Search for remaining `-z-` classes and apply the overlay div pattern from `transforms/tailwind.ts`.
|
|
404
|
+
|
|
405
|
+
### Opacity modifier not consolidated
|
|
406
|
+
|
|
407
|
+
**Cause**: Non-adjacent `bg-{color}` + `bg-opacity-{n}` pairs can't be safely consolidated.
|
|
408
|
+
**Fix**: Check `MIGRATION_REPORT.md` for flagged opacity items and fix manually.
|
|
409
|
+
|
|
410
|
+
### Bootstrap fails at generate-blocks
|
|
411
|
+
|
|
412
|
+
**Cause**: Missing or malformed `.deco/blocks/*.json` files.
|
|
413
|
+
**Fix**: Ensure `.deco/blocks/` was copied from source. Check JSON validity.
|
|
414
|
+
|
|
415
|
+
### package.json has wrong versions
|
|
416
|
+
|
|
417
|
+
**Cause**: npm registry fetch failed during scaffold.
|
|
418
|
+
**Fix**: The script falls back to `"latest"` — run `npm install` manually and check for version conflicts.
|
|
419
|
+
|
|
420
|
+
## Relationship to Manual Migration
|
|
421
|
+
|
|
422
|
+
This script handles **Phases 0-6** of the [migration playbook](../deco-to-tanstack-migration/SKILL.md):
|
|
423
|
+
- Phase 0 (Scaffold) → `phase-scaffold.ts`
|
|
424
|
+
- Phase 1 (Imports) → `transforms/imports.ts`
|
|
425
|
+
- Phase 2 (Signals) → `transforms/imports.ts` (bulk only — manual `useSignal` → `useState` still needed)
|
|
426
|
+
- Phase 3 (Deco Framework) → `transforms/fresh-apis.ts` + `transforms/deno-isms.ts`
|
|
427
|
+
- Phase 4 (Commerce) → `transforms/imports.ts`
|
|
428
|
+
- Phase 6 (Islands) → `phase-cleanup.ts` (deletes directory, repoints imports)
|
|
429
|
+
|
|
430
|
+
**Still manual after the script**:
|
|
431
|
+
- Phase 5 (Platform Hooks) — `useCart`, `useUser`, `useWishlist` implementation
|
|
432
|
+
- Phase 7-12 — Section registry tuning, route customization, matchers, async rendering, search
|
|
433
|
+
|
|
434
|
+
The script gets you from "raw Fresh site" to "builds with `npm run build` and has ~0 old imports". Human work starts at runtime debugging and feature wiring.
|