@@ -86,10 +86,44 @@ const compat = new Set([
8686 "UnknownPageProps" ,
8787] ) ;
8888
89+ async function detectFresh2 ( dir : string ) : Promise < boolean > {
90+ for ( const filename of [ "deno.json" , "deno.jsonc" ] ) {
91+ try {
92+ const content = await Deno . readTextFile ( path . join ( dir , filename ) ) ;
93+ const config = JSONC . parse ( content ) as DenoJson ;
94+ const imports = config . imports ;
95+ if ( imports ) {
96+ // Fresh 2 uses "fresh" or "@fresh/core" as the import specifier
97+ if ( imports [ "fresh" ] ?. includes ( "@fresh/core" ) ) {
98+ return true ;
99+ }
100+ }
101+ } catch {
102+ // File doesn't exist, try next
103+ }
104+ }
105+ return false ;
106+ }
107+
89108export async function updateProject ( dir : string ) {
90- // add initial log
91- // deno-lint-ignore no-console
92- console . log ( colors . blue ( "π Starting Fresh 1 to Fresh 2 migration..." ) ) ;
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+ }
93127
94128 // deno-lint-ignore no-console
95129 console . log ( colors . yellow ( "π Updating configuration files..." ) ) ;
@@ -194,7 +228,13 @@ export async function updateProject(dir: string) {
194228
195229 if ( filesToProcess . length === 0 ) {
196230 // deno-lint-ignore no-console
197- console . log ( colors . green ( "π Migration completed successfully!" ) ) ;
231+ console . log (
232+ colors . green (
233+ isFresh2
234+ ? "π Update completed successfully!"
235+ : "π Migration completed successfully!" ,
236+ ) ,
237+ ) ;
198238 return ;
199239 }
200240
@@ -238,9 +278,10 @@ export async function updateProject(dir: string) {
238278 // Clear the progress line and add a newline
239279 await bar . stop ( ) ;
240280
241- // add migration summary
242281 // deno-lint-ignore no-console
243- console . log ( "\n" + colors . bold ( "π Migration Summary:" ) ) ;
282+ console . log (
283+ "\n" + colors . bold ( isFresh2 ? "π Update Summary:" : "π Migration Summary:" ) ,
284+ ) ;
244285 // deno-lint-ignore no-console
245286 console . log ( ` Total files processed: ${ filesToProcess . length } ` ) ;
246287 // deno-lint-ignore no-console
@@ -267,7 +308,14 @@ export async function updateProject(dir: string) {
267308 }
268309
269310 // deno-lint-ignore no-console
270- console . log ( "\n" + colors . green ( "π Migration completed successfully!" ) ) ;
311+ console . log (
312+ "\n" +
313+ colors . green (
314+ isFresh2
315+ ? "π Update completed successfully!"
316+ : "π Migration completed successfully!" ,
317+ ) ,
318+ ) ;
271319}
272320
273321async function updateFile ( sourceFile : tsmorph . SourceFile ) : Promise < boolean > {
0 commit comments