@@ -4,6 +4,8 @@ import * as Command from "@effect/platform/Command";
44import * as CommandExecutor from "@effect/platform/CommandExecutor" ;
55import * as FileSystem from "@effect/platform/FileSystem" ;
66import * as Effect from "effect/Effect" ;
7+ import * as Str from "effect/String" ;
8+ import { P , match } from "ts-pattern" ;
79
810const getCurrentBranch = Command . make ( "git" , "branch" , "--show-current" ) ;
911
@@ -15,19 +17,22 @@ const program = Effect.gen(function*() {
1517 const destination = "packages/plugins/eslint-plugin/README.md" ;
1618 // Ensure the destination directory exists
1719 yield * fs . makeDirectory ( "packages/plugins/eslint-plugin" , { recursive : true } ) ;
18-
20+ const buildToolVersion = match ( JSON . parse ( yield * fs . readFileString ( "package.json" , "utf8" ) ) )
21+ . with ( { devDependencies : { tsdown : P . select ( P . string ) } } , Str . replace ( "^" , "" ) )
22+ . otherwise ( ( ) => "latest" ) ;
1923 const readmeContent = yield * fs . readFileString ( source , "utf8" ) ;
20-
24+ // dprint-ignore
25+ const readmeContentNew = readmeContent . replace ( / b u i l t _ w i t h - t s d o w n @ .* ?\) / g, `built_with-tsdown@${ buildToolVersion } )` ) ;
2126 // Convert relative links to absolute links
22- const updatedContent = readmeContent . replace ( / \[ ( [ ^ \] ] + ) \] \( ( [ ^ ) ] + ) \) / g, ( match , text , url ) => {
27+ const readmeContentAbs = readmeContentNew . replace ( / \[ ( [ ^ \] ] + ) \] \( ( [ ^ ) ] + ) \) / g, ( match , text , url ) => {
2328 if ( url . startsWith ( "http://" ) || url . startsWith ( "https://" ) || url . startsWith ( "#" ) ) {
2429 return match ; // Leave absolute links unchanged
2530 }
2631 const absoluteUrl = `${ `https://github.com/Rel1cx/eslint-react/tree/${ branch . trim ( ) } ` } /${ url . replace ( / ^ \. \/ / , "" ) } ` ;
2732 return `[${ text } ](${ absoluteUrl } )` ;
2833 } ) ;
29-
30- yield * fs . writeFileString ( destination , updatedContent ) ;
34+ yield * fs . writeFileString ( source , readmeContentNew ) ;
35+ yield * fs . writeFileString ( destination , readmeContentAbs ) ;
3136 yield * Effect . log ( `Updated ${ destination } from ${ source } ` ) ;
3237} ) ;
3338
0 commit comments