|
1 | | -import { Effect, pipe, ReadonlyRecord } from "effect" |
| 1 | +import { Console, Effect, identity } from "effect" |
2 | 2 | import * as path from "node:path" |
3 | 3 | import * as FileSystem from "./FileSystem" |
4 | 4 |
|
5 | | -const excludeEffectPackages = (deps: Record<string, string>): Record<string, string> => { |
6 | | - return ReadonlyRecord.filter(deps, (_, k) => !k.startsWith("@effect")) |
7 | | -} |
| 5 | +const moveJson = (from: string, to: string, modify: (json: any) => any) => |
| 6 | + Console.log(`moving ${from} to ${to}`).pipe( |
| 7 | + Effect.flatMap(() => FileSystem.readJsonFile(from)), |
| 8 | + Effect.map(modify), |
| 9 | + Effect.flatMap((json) => FileSystem.writeFile(to, JSON.stringify(json, null, 2))) |
| 10 | + ) |
8 | 11 |
|
9 | | -const read = pipe( |
10 | | - FileSystem.readJsonFile("package.json"), |
11 | | - Effect.map((json: any) => ({ |
12 | | - name: json.name, |
13 | | - version: json.version, |
14 | | - description: json.description, |
15 | | - main: "index.js", |
16 | | - bin: "index.js", |
17 | | - engines: json.engines, |
18 | | - dependencies: excludeEffectPackages(json.dependencies), |
19 | | - peerDependencies: excludeEffectPackages(json.peerDependencies), |
20 | | - repository: json.repository, |
21 | | - author: json.author, |
22 | | - license: json.license, |
23 | | - bugs: json.bugs, |
24 | | - homepage: json.homepage, |
25 | | - tags: json.tags, |
26 | | - keywords: json.keywords |
27 | | - })) |
28 | | -) |
29 | | - |
30 | | -const pathTo = path.join("dist", "package.json") |
| 12 | +const packageJson = moveJson("package.json", path.join("dist", "package.json"), (json: any) => ({ |
| 13 | + name: json.name, |
| 14 | + version: json.version, |
| 15 | + description: json.description, |
| 16 | + main: "index.js", |
| 17 | + bin: "index.js", |
| 18 | + engines: json.engines, |
| 19 | + dependencies: json.dependencies, |
| 20 | + peerDependencies: json.peerDependencies, |
| 21 | + repository: json.repository, |
| 22 | + author: json.author, |
| 23 | + license: json.license, |
| 24 | + bugs: json.bugs, |
| 25 | + homepage: json.homepage, |
| 26 | + tags: json.tags, |
| 27 | + keywords: json.keywords |
| 28 | +})) |
31 | 29 |
|
32 | | -const write = (pkg: object) => FileSystem.writeFile(pathTo, JSON.stringify(pkg, null, 2)) |
33 | | - |
34 | | -const program = pipe( |
35 | | - Effect.sync(() => console.log(`copying package.json to ${pathTo}...`)), |
36 | | - Effect.flatMap(() => read), |
37 | | - Effect.flatMap(write) |
| 30 | +const dtslintJson = moveJson( |
| 31 | + path.join("src", "dtslint.json"), |
| 32 | + path.join("dist", "dtslint.json"), |
| 33 | + identity |
38 | 34 | ) |
39 | 35 |
|
| 36 | +const program = packageJson.pipe(Effect.flatMap(() => dtslintJson)) |
| 37 | + |
40 | 38 | Effect.runPromise(program) |
0 commit comments