| 1 | import * as Effect from "effect/Effect" |
| 2 | import * as FileSystem from "effect/FileSystem" |
| 3 | import * as Path from "effect/Path" |
| 4 | |
| 5 | export const writeFixturePackage = Effect.fnUntraced(function*( |
| 6 | repoRoot: string, |
| 7 | files: Readonly<Record<string, string>>, |
| 8 | exports: Readonly<Record<string, unknown>> = { |
| 9 | ".": "./index.js", |
| 10 | "./*": "./*.js", |
| 11 | "./internal/*": null |
| 12 | } |
| 13 | ) { |
| 14 | const fs = yield* FileSystem.FileSystem |
| 15 | const path = yield* Path.Path |
| 16 | const root = path.join(repoRoot, "packages", "sample", "dist") |
| 17 | yield* fs.makeDirectory(root, { recursive: true }) |
| 18 | yield* fs.writeFileString( |
| 19 | path.join(root, "package.json"), |
| 20 | `${ |
| 21 | JSON.stringify( |
| 22 | { |
| 23 | name: "@fixture/sample", |
| 24 | version: "1.0.0", |
| 25 | exports |
| 26 | }, |
| 27 | null, |
| 28 | 2 |
| 29 | ) |
| 30 | }\n` |
| 31 | ) |
| 32 | for (const [name, source] of Object.entries(files)) { |
| 33 | const location = path.join(root, name) |
| 34 | yield* fs.makeDirectory(path.dirname(location), { recursive: true }) |
| 35 | yield* fs.writeFileString(location, source) |
| 36 | } |
| 37 | }) |