|
1 | 1 | import * as NodeContext from "@effect/platform-node/NodeContext"; |
2 | 2 | import * as NodeRuntime from "@effect/platform-node/NodeRuntime"; |
| 3 | +import * as Command from "@effect/platform/Command"; |
| 4 | +import * as CommandExecutor from "@effect/platform/CommandExecutor"; |
3 | 5 | import * as FileSystem from "@effect/platform/FileSystem"; |
4 | 6 | import * as Effect from "effect/Effect"; |
5 | 7 |
|
| 8 | +const getCurrentBranch = Command.make("git", "branch", "--show-current"); |
| 9 | + |
6 | 10 | const program = Effect.gen(function*() { |
7 | 11 | const fs = yield* FileSystem.FileSystem; |
| 12 | + const ce = yield* CommandExecutor.CommandExecutor; |
| 13 | + const branch = yield* ce.string(getCurrentBranch); |
8 | 14 | const source = "README.md"; |
9 | 15 | const destination = "packages/plugins/eslint-plugin/README.md"; |
10 | | - |
11 | 16 | // Ensure the destination directory exists |
12 | 17 | yield* fs.makeDirectory("packages/plugins/eslint-plugin", { recursive: true }); |
13 | 18 |
|
14 | | - // Copy the README file |
15 | | - yield* fs.copyFile(source, destination); |
| 19 | + const readmeContent = yield* fs.readFileString(source, "utf8"); |
| 20 | + |
| 21 | + // Convert relative links to absolute links |
| 22 | + const updatedContent = readmeContent.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, text, url) => { |
| 23 | + if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("#")) { |
| 24 | + return match; // Leave absolute links unchanged |
| 25 | + } |
| 26 | + const absoluteUrl = `${`https://github.com/Rel1cx/eslint-react/tree/${branch.trim()}`}/${url.replace(/^\.\//, "")}`; |
| 27 | + return `[${text}](${absoluteUrl})`; |
| 28 | + }); |
16 | 29 |
|
17 | | - yield* Effect.log(`Copied ${source} to ${destination}`); |
| 30 | + yield* fs.writeFileString(destination, updatedContent); |
| 31 | + yield* Effect.log(`Updated ${destination} from ${source}`); |
18 | 32 | }); |
19 | 33 |
|
20 | 34 | program.pipe(Effect.provide(NodeContext.layer), NodeRuntime.runMain); |
0 commit comments