@@ -38,7 +38,9 @@
|
||||
"clean:modules": "rm -rf node_modules"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@effect/platform-bun": "^0.87.1",
|
||||
"@effect/platform-node": "^0.104.1",
|
||||
"openapi-to-effect": "^0.9.3",
|
||||
"tsx": "^4.21.0",
|
||||
"undici": "^7.19.0"
|
||||
},
|
||||
|
||||
60
packages/effect-docker/scripts/codegen.ts
Normal file
60
packages/effect-docker/scripts/codegen.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { FetchHttpClient, FileSystem, HttpClient, Path } from "@effect/platform"
|
||||
import { BunContext, BunRuntime } from "@effect/platform-bun"
|
||||
import { YAML } from "bun"
|
||||
import { Effect, pipe } from "effect"
|
||||
import { run } from "openapi-to-effect"
|
||||
|
||||
|
||||
const versions = ["v1.53"]
|
||||
const outputDirPath = "../src/gen"
|
||||
|
||||
const downloadDockerOpenApiSpec = Effect.fn("downloadDockerOpenApiSpec")(function*(version: string) {
|
||||
const client = yield* HttpClient.HttpClient
|
||||
const fs = yield* FileSystem.FileSystem
|
||||
const outputFilePath = yield* fs.makeTempFileScoped()
|
||||
|
||||
const response = yield* client.get(`https://docs.docker.com/reference/api/engine/version/${ version }.yaml`)
|
||||
const json = pipe(yield* response.text, YAML.parse, JSON.stringify)
|
||||
yield* fs.writeFileString(outputFilePath, json)
|
||||
|
||||
return outputFilePath
|
||||
})
|
||||
|
||||
const generate = Effect.fn("generate")(function*(
|
||||
version: string,
|
||||
specFilePath: string,
|
||||
tempOutputDirPath: string,
|
||||
) {
|
||||
const path = yield* Path.Path
|
||||
const fs = yield* FileSystem.FileSystem
|
||||
|
||||
const outputDirPath = path.join(tempOutputDirPath, version)
|
||||
yield* fs.makeDirectory(outputDirPath)
|
||||
run(["gen", specFilePath, outputDirPath])
|
||||
})
|
||||
|
||||
Effect.gen(function*() {
|
||||
const path = yield* Path.Path
|
||||
const fs = yield* FileSystem.FileSystem
|
||||
const tempOutputDirPath = yield* fs.makeTempDirectoryScoped()
|
||||
|
||||
yield* Effect.all(
|
||||
versions.map(version => Effect.andThen(
|
||||
downloadDockerOpenApiSpec(version),
|
||||
specFilePath => generate(version, specFilePath, tempOutputDirPath),
|
||||
))
|
||||
)
|
||||
|
||||
const outputDirFiles = yield* fs.readDirectory(outputDirPath)
|
||||
yield* Effect.all(outputDirFiles.map(p => fs.remove(p, { recursive: true })))
|
||||
|
||||
const tempOutputDirFiles = yield* fs.readDirectory(tempOutputDirPath)
|
||||
yield* Effect.all(tempOutputDirFiles.map(p => fs.rename(p, path.join(outputDirPath, path.basename(p)))))
|
||||
}).pipe(
|
||||
Effect.provide([
|
||||
FetchHttpClient.layer,
|
||||
BunContext.layer,
|
||||
]),
|
||||
Effect.scoped,
|
||||
BunRuntime.runMain,
|
||||
)
|
||||
3
packages/effect-docker/src/Client.ts
Normal file
3
packages/effect-docker/src/Client.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export interface Client {
|
||||
|
||||
}
|
||||
@@ -34,5 +34,5 @@
|
||||
]
|
||||
},
|
||||
|
||||
"include": ["./src"]
|
||||
"include": ["./src", "./scripts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user