@nu-art/schema-to-types 0.202.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const getConfigArg: () => string | undefined;
package/main.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConfigArg = void 0;
4
+ const schema_to_types_1 = require("./schema-to-types");
5
+ const getConfigArg = () => {
6
+ const configArgPrefix = '--config=';
7
+ const configArg = process.argv.find(arg => arg.startsWith(configArgPrefix));
8
+ if (!configArg) {
9
+ return;
10
+ }
11
+ return configArg.substring(configArgPrefix.length);
12
+ };
13
+ exports.getConfigArg = getConfigArg;
14
+ const main = async () => {
15
+ const configPath = (0, exports.getConfigArg)();
16
+ if (!configPath) {
17
+ console.log("Usage: ts-node generate-types.ts --config=<config-file-path>");
18
+ process.exit(1);
19
+ }
20
+ await (0, schema_to_types_1.processConfig)(configPath).catch(console.error);
21
+ };
22
+ main();
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@nu-art/schema-to-types",
3
+ "version": "0.202.84",
4
+ "description": "schema-to-types - Express & Typescript based backend framework",
5
+ "keywords": [
6
+ "TacB0sS",
7
+ "infra",
8
+ "nu-art",
9
+ "thunderstorm",
10
+ "typescript",
11
+ "schema-to-types"
12
+ ],
13
+ "homepage": "https://github.com/nu-art-js/thunderstorm",
14
+ "bugs": {
15
+ "url": "https://github.com/nu-art-js/thunderstorm/issues"
16
+ },
17
+ "publishConfig": {
18
+ "directory": "dist",
19
+ "linkDirectory": true
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+ssh://git@github.com:nu-art-js/thunderstorm.git"
24
+ },
25
+ "license": "Apache-2.0",
26
+ "author": "TacB0sS",
27
+ "main": "index.js",
28
+ "types": "index.d.ts",
29
+ "files": [
30
+ "**/*"
31
+ ],
32
+ "scripts": {
33
+ "build": "tsc"
34
+ },
35
+ "dependencies": {
36
+ "json-schema-to-typescript": "^13.1.1"
37
+ }
38
+ }
@@ -0,0 +1 @@
1
+ export declare const processConfig: (configPath: string) => Promise<void>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processConfig = void 0;
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const json_schema_to_typescript_1 = require("json-schema-to-typescript");
7
+ const generateTypeScriptType = async (inputPath, outputPath) => {
8
+ const options = {
9
+ $refOptions: {
10
+ resolve: {
11
+ // Resolves local file references
12
+ file: {
13
+ read(file) {
14
+ const filePath = path.resolve(path.dirname(inputPath), file.url);
15
+ return fs.promises.readFile(filePath, 'utf8');
16
+ }
17
+ }
18
+ }
19
+ }
20
+ };
21
+ const ts = await (0, json_schema_to_typescript_1.compileFromFile)(inputPath, options);
22
+ const outputDir = path.dirname(outputPath);
23
+ if (!fs.existsSync(outputDir)) {
24
+ fs.mkdirSync(outputDir, { recursive: true });
25
+ }
26
+ fs.writeFileSync(outputPath, ts);
27
+ };
28
+ const processConfig = async (configPath) => {
29
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
30
+ for (const schemaConfig of config)
31
+ await generateTypeScriptType(schemaConfig.input, schemaConfig.output);
32
+ };
33
+ exports.processConfig = processConfig;