GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — t3code/scripts/update-release-package-versions.ts at main · AndryHTC/t3code Expand file tree/ Copy pathupdate-release-package-versions.tsMore file actions 180 lines (166 loc) · 5.54 KB / Copy pathupdate-release-package-versions.tsFile metadata and controls180 lines (166 loc) · 5.54 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 #!/usr/bin/env node import * as NodeRuntime from "@effect/platform-node/NodeRuntime"; import * as NodeServices from "@effect/platform-node/NodeServices"; import * as Config from "effect/Config"; import * as Console from "effect/Console"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; import { Argument, Command, Flag } from "effect/cli"; import { fromJsonStringPretty } from "@t3tools/shared/schemaJson"; export class ReleasePackageManifestError extends Schema.TaggedError<ReleasePackageManifestError>()( "ReleasePackageManifestError", { operation: Schema.Literals(["read", "decode", "encode", "write"]), filePath: Schema.String, cause: Schema.Defect(), }, ) { override get message(): string { return `Failed to ${this.operation} release package manifest '${this.filePath}'.`; } } export class ReleaseGitHubOutputConfigurationError extends Schema.TaggedError<ReleaseGitHubOutputConfigurationError>()( "ReleaseGitHubOutputConfigurationError", { cause: Schema.Defect() }, ) { override get message(): string { return "Failed to resolve GITHUB_OUTPUT for release package version output."; } } export class ReleaseGitHubOutputWriteError extends Schema.TaggedError<ReleaseGitHubOutputWriteError>()( "ReleaseGitHubOutputWriteError", { filePath: Schema.String, cause: Schema.Defect(), }, ) { override get message(): string { return `Failed to append release package version output to '${this.filePath}'.`; } } export const releasePackageFiles = [ "apps/server/package.json", "apps/desktop/package.json", "apps/web/package.json", "packages/contracts/package.json", ] as const; interface UpdateReleasePackageVersionsOptions { readonly rootDir?: string | undefined; } const PackageJsonSchema = Schema.Record(Schema.String, Schema.Unknown); const PackageJsonPrettyJson = fromJsonStringPretty(PackageJsonSchema); const decodePackageJson = Schema.decodeUnknownEffect(PackageJsonPrettyJson); const encodePackageJson = Schema.encodeEffect(PackageJsonPrettyJson); export const updateReleasePackageVersions = Effect.fn("updateReleasePackageVersions")(function* ( version: string, options: UpdateReleasePackageVersionsOptions = {}, ) { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const rootDir = path.resolve(options.rootDir ?? process.cwd()); let changed = false; for (const relativePath of releasePackageFiles) { const filePath = path.join(rootDir, relativePath); const packageJsonText = yield* fs.readFileString(filePath).pipe( Effect.mapError( (cause) => new ReleasePackageManifestError({ operation: "read", filePath, cause, }), ), ); const packageJson = yield* decodePackageJson(packageJsonText).pipe( Effect.mapError( (cause) => new ReleasePackageManifestError({ operation: "decode", filePath, cause, }), ), ); if (packageJson.version === version) { continue; } const packageJsonString = yield* encodePackageJson({ ...packageJson, version }).pipe( Effect.mapError( (cause) => new ReleasePackageManifestError({ operation: "encode", filePath, cause, }), ), ); yield* fs.writeFileString(filePath, `${packageJsonString}\n`).pipe( Effect.mapError( (cause) => new ReleasePackageManifestError({ operation: "write", filePath, cause, }), ), ); changed = true; } return { changed }; }); const writeGithubOutput = Effect.fn("writeGithubOutput")(function* (changed: boolean) { const fs = yield* FileSystem.FileSystem; const githubOutputPath = yield* Config.NonEmptyString("GITHUB_OUTPUT").pipe( Effect.mapError( (cause) => new ReleaseGitHubOutputConfigurationError({ cause, }), ), ); yield* fs.writeFileString(githubOutputPath, `changed=${changed}\n`, { flag: "a" }).pipe( Effect.mapError( (cause) => new ReleaseGitHubOutputWriteError({ filePath: githubOutputPath, cause, }), ), ); }); export const updateReleasePackageVersionsCommand = Command.make( "update-release-package-versions", { version: Argument.String("version").pipe( Argument.withDescription("Release version to write into each releasable package.json."), ), root: Flag.String("root").pipe( Flag.withDescription("Workspace root used to resolve the release package manifests."), Flag.optional, ), githubOutput: Flag.Boolean("github-output").pipe( Flag.withDescription("Append changed=<boolean> to GITHUB_OUTPUT."), Flag.withDefault(false), ), }, ({ version, root, githubOutput }) => updateReleasePackageVersions(version, { rootDir: Option.getOrUndefined(root), }).pipe( Effect.tap(({ changed }) => changed ? Effect.void : Console.log("All package.json versions already match release version."), ), Effect.tap(({ changed }) => (githubOutput ? writeGithubOutput(changed) : Effect.void)), ), ).pipe(Command.withDescription("Update release package versions across the workspace.")); if (import.meta.main) { Command.run(updateReleasePackageVersionsCommand, { version: "0.0.0" }).pipe( Effect.provide(NodeServices.layer), NodeRuntime.runMain, ); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |