Skip to content

Commit

Permalink
Merge pull request #867 from samchon/features/reflect
Browse files Browse the repository at this point in the history
Add `reflect.metadata()` function.
  • Loading branch information
samchon committed Nov 12, 2023
2 parents bb769d0 + 0631cc5 commit 81d2298
Show file tree
Hide file tree
Showing 1,394 changed files with 235,249 additions and 4,671 deletions.
94 changes: 0 additions & 94 deletions build/internal/TestApplicationGenerator.ts

This file was deleted.

96 changes: 96 additions & 0 deletions build/internal/TestJsonApplicationGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import cp from "child_process";
import fs from "fs";

import { TestStructure } from "./TestStructure";

export namespace TestJsonApplicationGenerator {
export async function generate(
structures: TestStructure<any>[],
): Promise<void> {
const location: string = `${__dirname}/../../test/features/json.application`;
if (fs.existsSync(location)) cp.execSync("npx rimraf " + location);
await fs.promises.mkdir(location);

await application(structures, "ajv");
await application(structures, "swagger");
}

async function application(
structures: TestStructure<any>[],
purpose: "ajv" | "swagger",
): Promise<void> {
const path: string = `${__dirname}/../../test/features/json.application/${purpose}`;
await fs.promises.mkdir(path);

for (const s of structures) {
if (s.JSONABLE === false) continue;

const content: string[] = [
`import typia from "../../../../src";`,
`import { ${s.name} } from "../../../structures/${s.name}";`,
`import { _test_json_application } from "../../../internal/_test_json_application";`,
"",
`export const test_json_application_${purpose}_${s.name} = `,
` _test_json_application("${purpose}")("${s.name}")(`,
` typia.json.application<[${s.name}], "${purpose}">(),`,
` );`,
];
await fs.promises.writeFile(
`${__dirname}/../../test/features/json.application/${purpose}/test_json_application_${purpose}_${s.name}.ts`,
content.join("\n"),
"utf8",
);
}
}

export async function schemas(): Promise<void> {
const location: string = `${__dirname}/../../test/schemas/json`;
await mkdir(location);

await iterate("ajv");
await iterate("swagger");
}

function getSchema(content: string): object {
const first: number = content.indexOf("schemas: [");
const last: number = content.lastIndexOf("}");

return new Function(
"return {" + content.substring(first, last) + "}",
)();
}

async function iterate(type: "ajv" | "swagger") {
const path: string = `${__dirname}/../../test/features/json.application/${type}`;
const schemaPath: string = `${__dirname}/../../test/schemas/json/${type}`;
await mkdir(schemaPath);

for (const file of await fs.promises.readdir(path)) {
if (file.substring(file.length - 3) !== ".ts") continue;

const name: string = file.substring(
`test_json_application_${type}_`.length,
file.length - 3,
);
const location: string =
__dirname +
`/../../bin/test/features/json.application/${type}/${file.slice(
0,
-3,
)}.js`;
const schema: object = getSchema(
await fs.promises.readFile(location, "utf8"),
);
await fs.promises.writeFile(
`${schemaPath}/${name}.json`,
JSON.stringify(schema, null, 2),
"utf8",
);
}
}

async function mkdir(path: string): Promise<void> {
if (fs.existsSync(path)) cp.execSync(`npx rimraf ${path}`);
await fs.promises.mkdir(path);
}
}
98 changes: 0 additions & 98 deletions build/internal/TestMessageGenerator.ts

This file was deleted.

98 changes: 98 additions & 0 deletions build/internal/TestProtobufMessageGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import cp from "child_process";
import fs from "fs";

import { TestStructure } from "./TestStructure";

export namespace TestProtobufMessageGenerator {
export async function generate(
structures: TestStructure<any>[],
): Promise<void> {
const path: string = `${__dirname}/../../test/features/protobuf.message`;
await mkdir(path);

for (const s of structures) {
if (s.BINARABLE === false) continue;

const content: string[] = [
`import typia from "../../../src";`,
`import { ${s.name} } from "../../structures/${s.name}";`,
`import { _test_protobuf_message } from "../../internal/_test_protobuf_message";`,
"",
`export const test_protobuf_message_${s.name} = _test_protobuf_message(`,
` "${s.name}",`,
`)(typia.protobuf.message<${s.name}>());`,
];
await fs.promises.writeFile(
`${__dirname}/../../test/features/protobuf.message/test_protobuf_message_${s.name}.ts`,
content.join("\n"),
"utf8",
);
}
}

export async function schemas(): Promise<void> {
const path: string = `${__dirname}/../../test/features/protobuf.message`;
const protobuf: string = `${path}/../../schemas/protobuf`;
await mkdir(protobuf);

const schemaList: string[] = [];
for (const file of await fs.promises.readdir(path)) {
if (file.substring(file.length - 3) !== ".ts") continue;

const name: string = file.substring(
"test_protobuf_message_".length,
file.length - 3,
);
schemaList.push(name);

await fs.promises.writeFile(
`${protobuf}/${name}.proto`,
await read(file),
"utf8",
);
}

// const current: string = process.cwd();
// process.chdir(protobuf);
// {
// const root: string = `../../..`;
// await fs.promises.copyFile(
// `${root}/assets/protoc.exe`,
// "protoc.exe",
// );
// await fs.promises.mkdir("references");

// for (const schema of schemaList)
// try {
// const command: string = [
// "protoc",
// `--plugin=${root}/node_modules/.bin/protoc-gen-ts_proto.cmd`,
// `--ts_proto_out=./references`,
// `./${schema}.proto`,
// ].join(" ");
// cp.execSync(command);
// } catch {
// console.log("failed", schema);
// }
// }
// process.chdir(current);
}

async function read(file: string): Promise<string> {
const content: string = await fs.promises.readFile(
`${__dirname}/../../bin/test/features/protobuf.message/${file.slice(
0,
-3,
)}.js`,
"utf8",
);
const first: number = content.indexOf(`"syntax = `);
const last: number = content.lastIndexOf(`}"`);
return JSON.parse(content.substring(first, last + 2));
}

async function mkdir(path: string): Promise<void> {
if (fs.existsSync(path)) cp.execSync(`npx rimraf ${path}`);
await fs.promises.mkdir(path);
}
}
Loading

0 comments on commit 81d2298

Please sign in to comment.