@@ -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
@@ -13,21 +15,24 @@ const program = Effect.gen(function*() {
1315 const branch = yield * ce . string ( getCurrentBranch ) ;
1416 const source = "README.md" ;
1517 const destination = "packages/plugins/eslint-plugin/README.md" ;
16- // Ensure the destination directory exists
17- yield * fs . makeDirectory ( "packages/plugins/eslint-plugin" , { recursive : true } ) ;
18-
18+ const buildToolVersion = match ( JSON . parse ( yield * fs . readFileString ( "package.json" , "utf8" ) ) )
19+ . with ( { devDependencies : { tsdown : P . select ( P . string ) } } , Str . replace ( "^" , "" ) )
20+ . otherwise ( ( ) => "latest" ) ;
1921 const readmeContent = yield * fs . readFileString ( source , "utf8" ) ;
20-
22+ // dprint-ignore
23+ const readmeContentNew = readmeContent . replaceAll ( / h t t p s : \/ \/ i m g \. s h i e l d s \. i o \/ b a d g e \/ b u i l t _ w i t h - t s d o w n @ .* - 0 0 0 0 0 0 / g, `https://img.shields.io/badge/built_with-tsdown@${ buildToolVersion . replaceAll ( "-" , "--" ) } -000000` ) ;
2124 // Convert relative links to absolute links
22- const updatedContent = readmeContent . replace ( / \[ ( [ ^ \] ] + ) \] \( ( [ ^ ) ] + ) \) / g, ( match , text , url ) => {
25+ const readmeContentAbs = readmeContentNew . replace ( / \[ ( [ ^ \] ] + ) \] \( ( [ ^ ) ] + ) \) / g, ( match , text , url ) => {
2326 if ( url . startsWith ( "http://" ) || url . startsWith ( "https://" ) || url . startsWith ( "#" ) ) {
2427 return match ; // Leave absolute links unchanged
2528 }
2629 const absoluteUrl = `${ `https://github.com/Rel1cx/eslint-react/tree/${ branch . trim ( ) } ` } /${ url . replace ( / ^ \. \/ / , "" ) } ` ;
2730 return `[${ text } ](${ absoluteUrl } )` ;
2831 } ) ;
29-
30- yield * fs . writeFileString ( destination , updatedContent ) ;
32+ // Ensure the destination directory exists
33+ yield * fs . makeDirectory ( "packages/plugins/eslint-plugin" , { recursive : true } ) ;
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