Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev committed Mar 6, 2024
1 parent 5826266 commit bad798b
Showing 1 changed file with 91 additions and 85 deletions.
176 changes: 91 additions & 85 deletions apps/registry/builder/index-old.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit bad798b

Please sign in to comment.