Skip to content

Commit

Permalink
fix: dist/types enums
Browse files Browse the repository at this point in the history
  • Loading branch information
k0stik committed Apr 9, 2024
1 parent 22e5a36 commit 5f84138
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 47 deletions.
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
40 changes: 4 additions & 36 deletions dist/js/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,7 @@ export interface NISTJARVISDbEntrySchema {
* @minItems 3
* @maxItems 3
*/
lattice_mat?: [
[
number,
number,
number
],
[
number,
number,
number
],
[
number,
number,
number
]
];
lattice_mat?: [[number, number, number], [number, number, number], [number, number, number]];
/**
* Atomic coordinates for each atom in the unit cell
*
Expand Down Expand Up @@ -1621,23 +1605,7 @@ export interface DimensionalGridSchema {
* @minItems 3
* @maxItems 3
*/
export type DimensionalTensorSchema = [
[
number,
number,
number
],
[
number,
number,
number
],
[
number,
number,
number
]
];
export type DimensionalTensorSchema = [[number, number, number], [number, number, number], [number, number, number]];
/** Schema dist/js/schema/core/abstract/3d_vector_basis.json */
export interface DimensionalVectorBasis {
/**
Expand Down Expand Up @@ -23683,14 +23651,14 @@ export interface IframeMessageSchema {
/**
* The type of the message to distinguish the direction of the message.
*/
export declare const enum Type {
export declare enum Type {
fromIframeToHost = "from-iframe-to-host",
fromHostToIframe = "from-host-to-iframe"
}
/**
* The action to be performed upon receiving the message.
*/
export declare const enum Action {
export declare enum Action {
setData = "set-data",
getData = "get-data",
info = "info"
Expand Down
1 change: 1 addition & 0 deletions src/js/scripts/compileTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default async function compileTS(schemaPath: string, savePath: string) {
const compiledSchema = await compile(schema, schema.title || "", {
unreachableDefinitions: true,
additionalProperties: false,
enableConstEnums: false,
bannerComment: `/** Schema ${filePath} */`,
});

Expand Down

0 comments on commit 5f84138

Please sign in to comment.