Skip to content

Commit

Permalink
Merge pull request #316 from Exabyte-io/fix/types
Browse files Browse the repository at this point in the history
fix: dist/types
  • Loading branch information
k0stik committed Apr 9, 2024
2 parents f940b16 + 39a2199 commit 92e2896
Show file tree
Hide file tree
Showing 9 changed files with 32,991 additions and 37,321 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
@@ -1,6 +1,6 @@
{
"extends": ["@exabyte-io/eslint-config"],
"ignorePatterns": ["dist/js/**/*.js", "dist/js/**/*.ts"],
"ignorePatterns": ["dist/js/**/*.js", "dist/js/**/*.ts", "src/js/types.ts"],
"settings": {
"import/resolver": {
"node": {
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -61,3 +61,5 @@ schema.js

# Static assets, if any
site

src/js/types.ts
2 changes: 1 addition & 1 deletion compile_ts.ts
@@ -1,3 +1,3 @@
import compileTS from "./src/js/scripts/compileTs";

compileTS("./dist/js/schema", `./dist/js/types.ts`);
compileTS("./dist/js/schema", `./src/js/types.ts`);
32 changes: 21 additions & 11 deletions dist/js/scripts/compileTs.js
@@ -1,7 +1,9 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const json_schema_to_typescript_1 = require("json-schema-to-typescript");
Expand Down Expand Up @@ -47,7 +49,11 @@ const filesystem_1 = require("../utils/filesystem");
function cleanSchema(schema) {
let firstRun = true;
return (0, schemaUtils_1.mapObjectDeep)(schema, (object) => {
if (typeof object === "object" && (object === null || object === void 0 ? void 0 : object.title) && !firstRun) {
if (
typeof object === "object" &&
(object === null || object === void 0 ? void 0 : object.title) &&
!firstRun
) {
firstRun = false;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { title, $schema, ...restObject } = object;
Expand All @@ -59,20 +65,24 @@ function cleanSchema(schema) {
async function compileTS(schemaPath, savePath) {
try {
await fs_1.default.promises.unlink(savePath);
}
catch (err) {
} catch (err) {
console.log("File with types not exists");
}
await (0, filesystem_1.walkDir)(schemaPath, async (filePath) => {
const data = await fs_1.default.promises.readFile(filePath, "utf8");
const schema = cleanSchema(JSON.parse(data));
console.log(`Compiling Typescript: ${filePath}`);
// @ts-ignore
const compiledSchema = await (0, json_schema_to_typescript_1.compile)(schema, schema.title || "", {
unreachableDefinitions: true,
additionalProperties: false,
bannerComment: `/** Schema ${filePath} */`,
});
const compiledSchema = await (0, json_schema_to_typescript_1.compile)(
schema,
schema.title || "",
{
unreachableDefinitions: true,
additionalProperties: false,
enableConstEnums: false,
bannerComment: `/** Schema ${filePath} */`,
},
);
await fs_1.default.promises.appendFile(savePath, `${compiledSchema} \n`, { flag: "a+" });
});
}
Expand Down

0 comments on commit 92e2896

Please sign in to comment.