(dir: string)
| 106 | } |
| 107 | |
| 108 | export async function updateProject(dir: string) { |
| 109 | // Detect if the project is already on Fresh 2 by checking imports |
| 110 | const isFresh2 = await detectFresh2(dir); |
| 111 | |
| 112 | if (isFresh2) { |
| 113 | // deno-lint-ignore no-console |
| 114 | console.log(colors.blue(`🔄 Updating Fresh to ${FRESH_VERSION}...`)); |
| 115 | } else { |
| 116 | // deno-lint-ignore no-console |
| 117 | console.log(colors.blue("🚀 Starting Fresh 1 to Fresh 2 migration...")); |
| 118 | // deno-lint-ignore no-console |
| 119 | console.log( |
| 120 | colors.italic( |
| 121 | "Note: Breaking changes may require additional manual updates.", |
| 122 | ), |
| 123 | ); |
| 124 | // deno-lint-ignore no-console |
| 125 | console.log(); |
| 126 | } |
| 127 | |
| 128 | // deno-lint-ignore no-console |
| 129 | console.log(colors.yellow("📝 Updating configuration files...")); |
| 130 | |
| 131 | // Update config |
| 132 | await updateDenoJson(dir, (config) => { |
| 133 | if (config.imports !== null && typeof config.imports !== "object") { |
| 134 | config.imports = {}; |
| 135 | } |
| 136 | |
| 137 | config.imports["fresh"] = `jsr:@fresh/core@^${FRESH_VERSION}`; |
| 138 | config.imports["preact"] = `npm:preact@^${PREACT_VERSION}`; |
| 139 | config.imports["@preact/signals"] = |
| 140 | `npm:@preact/signals@^${PREACT_SIGNALS_VERSION}`; |
| 141 | delete config.imports["$fresh/"]; |
| 142 | delete config.imports["@preact/signals-core"]; |
| 143 | delete config.imports["preact-render-to-string"]; |
| 144 | |
| 145 | // We should always use a lockfile going forwards |
| 146 | if ("lock" in config) { |
| 147 | delete config.lock; |
| 148 | } |
| 149 | |
| 150 | // Update Fresh 1.x tasks |
| 151 | const tasks = config.tasks; |
| 152 | if (tasks !== undefined) { |
| 153 | if (tasks.manifest === "deno task cli manifest $(pwd)") { |
| 154 | delete tasks.manifest; |
| 155 | } |
| 156 | |
| 157 | if ( |
| 158 | tasks.cli === |
| 159 | "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -" || |
| 160 | tasks.cli === |
| 161 | "echo \"import '$fresh/src/dev/cli.ts'\" | deno run --unstable -A -" |
| 162 | ) { |
| 163 | delete tasks.cli; |
| 164 | } |
| 165 |
no test coverage detected