Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dist/types #316

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading