From bad798bb52ed2ac4aeef3d5ba42dd5b441909910 Mon Sep 17 00:00:00 2001 From: Sasha Mysak Date: Wed, 6 Mar 2024 22:22:45 +0100 Subject: [PATCH] try --- apps/registry/builder/index-old.ts | 176 +++++++++++++++-------------- 1 file changed, 91 insertions(+), 85 deletions(-) diff --git a/apps/registry/builder/index-old.ts b/apps/registry/builder/index-old.ts index e7d3a6819..4e7aa5009 100644 --- a/apps/registry/builder/index-old.ts +++ b/apps/registry/builder/index-old.ts @@ -16,93 +16,93 @@ import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { promisify } from "node:util"; import { deflate } from "node:zlib"; -import * as S from "@effect/schema/Schema"; +// import * as S from "@effect/schema/Schema"; import glob from "fast-glob"; import * as tar from "tar"; const promisifiedDeflate = promisify(deflate); -const argumentsSchema = S.array( - S.union( - S.struct({ - name: S.string, - kind: S.literal("string"), - default: S.optional(S.string), - description: S.optional(S.string).withDefault(() => ""), - required: S.optional(S.boolean).withDefault(() => false), - }), - S.struct({ - name: S.string, - kind: S.literal("number"), - default: S.optional(S.number), - description: S.optional(S.string).withDefault(() => ""), - required: S.optional(S.boolean).withDefault(() => false), - }), - S.struct({ - name: S.string, - kind: S.literal("boolean"), - default: S.optional(S.boolean), - description: S.optional(S.string).withDefault(() => ""), - required: S.optional(S.boolean).withDefault(() => false), - }), - ), -); - -const optionalArgumentsSchema = S.optional(argumentsSchema).withDefault( - () => [], -); - -export const PIRANHA_LANGUAGES = [ - "java", - "kt", - "go", - "py", - "swift", - "ts", - "tsx", - "scala", -] as const; - -const piranhaLanguageSchema = S.union( - ...PIRANHA_LANGUAGES.map((language) => S.literal(language)), -); - -const codemodConfigSchema = S.union( - S.struct({ - schemaVersion: S.literal("1.0.0"), - engine: S.literal("piranha"), - language: piranhaLanguageSchema, - arguments: optionalArgumentsSchema, - owner: S.optional(S.string), - }), - S.struct({ - schemaVersion: S.literal("1.0.0"), - engine: S.literal("jscodeshift"), - arguments: optionalArgumentsSchema, - owner: S.optional(S.string), - }), - S.struct({ - schemaVersion: S.literal("1.0.0"), - engine: S.literal("ts-morph"), - arguments: optionalArgumentsSchema, - owner: S.optional(S.string), - }), - S.struct({ - schemaVersion: S.literal("1.0.0"), - engine: S.literal("filemod"), - arguments: optionalArgumentsSchema, - owner: S.optional(S.string), - }), - S.struct({ - schemaVersion: S.literal("1.0.0"), - engine: S.literal("recipe"), - names: S.array(S.string), - arguments: optionalArgumentsSchema, - owner: S.optional(S.string), - }), -); - -const parseCodemodConfigSchema = S.parseSync(codemodConfigSchema); +// const argumentsSchema = S.array( +// S.union( +// S.struct({ +// name: S.string, +// kind: S.literal("string"), +// default: S.optional(S.string), +// description: S.optional(S.string).withDefault(() => ""), +// required: S.optional(S.boolean).withDefault(() => false), +// }), +// S.struct({ +// name: S.string, +// kind: S.literal("number"), +// default: S.optional(S.number), +// description: S.optional(S.string).withDefault(() => ""), +// required: S.optional(S.boolean).withDefault(() => false), +// }), +// S.struct({ +// name: S.string, +// kind: S.literal("boolean"), +// default: S.optional(S.boolean), +// description: S.optional(S.string).withDefault(() => ""), +// required: S.optional(S.boolean).withDefault(() => false), +// }), +// ), +// ); + +// const optionalArgumentsSchema = S.optional(argumentsSchema).withDefault( +// () => [], +// ); + +// export const PIRANHA_LANGUAGES = [ +// "java", +// "kt", +// "go", +// "py", +// "swift", +// "ts", +// "tsx", +// "scala", +// ] as const; + +// const piranhaLanguageSchema = S.union( +// ...PIRANHA_LANGUAGES.map((language) => S.literal(language)), +// ); + +// const codemodConfigSchema = S.union( +// S.struct({ +// schemaVersion: S.literal("1.0.0"), +// engine: S.literal("piranha"), +// language: piranhaLanguageSchema, +// arguments: optionalArgumentsSchema, +// owner: S.optional(S.string), +// }), +// S.struct({ +// schemaVersion: S.literal("1.0.0"), +// engine: S.literal("jscodeshift"), +// arguments: optionalArgumentsSchema, +// owner: S.optional(S.string), +// }), +// S.struct({ +// schemaVersion: S.literal("1.0.0"), +// engine: S.literal("ts-morph"), +// arguments: optionalArgumentsSchema, +// owner: S.optional(S.string), +// }), +// S.struct({ +// schemaVersion: S.literal("1.0.0"), +// engine: S.literal("filemod"), +// arguments: optionalArgumentsSchema, +// owner: S.optional(S.string), +// }), +// S.struct({ +// schemaVersion: S.literal("1.0.0"), +// engine: S.literal("recipe"), +// names: S.array(S.string), +// arguments: optionalArgumentsSchema, +// owner: S.optional(S.string), +// }), +// ); + +// const parseCodemodConfigSchema = S.parseSync(codemodConfigSchema); const removeDirectoryContents = async (directoryPath: string) => { const paths = await readdir(directoryPath); @@ -169,9 +169,15 @@ const build = async () => { const data = await readFile(configPath, { encoding: "utf8" }); - const config = parseCodemodConfigSchema(JSON.parse(data), { - onExcessProperty: "ignore", - }); + const keys = ["schemaVersion", "engine", "language", "arguments", "owner"]; + + const config = JSON.parse(data); + + for (const key of Object.getOwnPropertyNames(config)) { + if (!keys.includes(key)) { + delete config[key]; + } + } { const configWithName = {