-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #867 from samchon/features/reflect
Add `reflect.metadata()` function.
- Loading branch information
Showing
1,394 changed files
with
235,249 additions
and
4,671 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.