@kmudrick/io-ts-openapi
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "@kmudrick/io-ts-openapi", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"license": "MIT", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.js", | ||
"type": "commonjs", | ||
"files": [ | ||
"bin", | ||
"dist", | ||
"src" | ||
], | ||
"bin": { | ||
"io-ts-openapi": "./bin/index.ts" | ||
"io-ts-openapi": "./dist/index.js" | ||
}, | ||
"scripts": { | ||
"build": "rm -rf dist && tsc && chmod +x ./dist/index.js", | ||
"format": "npm run prettier -w .", | ||
"lint": "eslint .", | ||
"prepare": "npm run build" | ||
}, | ||
"devDependencies": { | ||
@@ -9,0 +23,0 @@ "@tsconfig/node16": "^1.0.2", |
@@ -1,38 +0,18 @@ | ||
import { parseFile } from "./parser"; | ||
import { JSONSchema } from "./json-schema"; | ||
import { isRight } from "fp-ts/lib/Either"; | ||
import { toDeclarations, getRuntime, getStatic } from "./type-codegen"; | ||
import fs from "fs/promises"; | ||
import path from "path"; | ||
#!/usr/bin/env node | ||
import yargs from "yargs/yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
import { runProgram } from "./program"; | ||
export async function runProgram( | ||
inputFile: string, | ||
outputFile: string | ||
): Promise<void> { | ||
const unparsedSchemas = await parseFile(inputFile); | ||
const parser = yargs(hideBin(process.argv)).options({ | ||
input: { type: "string", demandOption: true }, | ||
output: { type: "string", demandOption: true }, | ||
}); | ||
const parsed: Record<string, JSONSchema> = unparsedSchemas.reduce( | ||
(acc, entry) => { | ||
const { name, content } = entry; | ||
const decoded = JSONSchema.decode(content); | ||
if (isRight(decoded)) { | ||
const schema = decoded.right; | ||
return { ...acc, [name]: schema }; | ||
} else { | ||
console.error( | ||
`Could not decode ${name}: ${JSON.stringify(decoded.left)}` | ||
); | ||
return acc; | ||
} | ||
}, | ||
{} | ||
); | ||
const declarations = toDeclarations(parsed); | ||
const runtimeContents = getRuntime(declarations); | ||
const staticContents = getStatic(declarations); | ||
const contents = [staticContents, runtimeContents].join("\n"); | ||
await fs.mkdir(path.dirname(outputFile), { recursive: true }); | ||
await fs.writeFile(outputFile, contents, "utf8"); | ||
} | ||
(async () => { | ||
const { input, output } = await parser.argv; | ||
await runProgram(input, output); | ||
return output; | ||
})().then( | ||
(fileWritten) => console.log(`Successfully wrote ${fileWritten}`), | ||
(err) => console.error("Unsuccessful", err) | ||
); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33896
23
676
3
1