@goast/core 0.0.3 → 0.0.5
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/cjs/index.js +1 -0
- package/cjs/lib/codegen/generator.js +8 -1
- package/cjs/lib/collect/helpers.js +6 -0
- package/cjs/lib/utils/file-system.utils.js +40 -0
- package/esm/index.js +1 -0
- package/esm/lib/codegen/generator.js +8 -1
- package/esm/lib/collect/helpers.js +6 -0
- package/esm/lib/utils/file-system.utils.js +36 -0
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/lib/codegen/generator.d.ts +2 -0
- package/types/lib/collect/helpers.d.ts +2 -2
- package/types/lib/utils/file-system.utils.d.ts +8 -0
package/cjs/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const fs_extra_1 = require("fs-extra");
|
|
|
7
7
|
const config_1 = require("./config");
|
|
8
8
|
const parser_1 = require("../parse/parser");
|
|
9
9
|
const action_provider_1 = require("../utils/action-provider");
|
|
10
|
+
const file_system_utils_1 = require("../utils/file-system.utils");
|
|
10
11
|
class _OpenApiGenerator {
|
|
11
12
|
constructor(config, providers, parser) {
|
|
12
13
|
this._providers = providers;
|
|
@@ -56,6 +57,12 @@ class _OpenApiGenerator {
|
|
|
56
57
|
return yield this.generate(data);
|
|
57
58
|
});
|
|
58
59
|
}
|
|
60
|
+
parseAndGenerateFromDir(dir, options) {
|
|
61
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const filter = (file) => { var _a, _b; return (file.endsWith('.yml') || file.endsWith('.yaml') || file.endsWith('.json')) && ((_b = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, file)) !== null && _b !== void 0 ? _b : true); };
|
|
63
|
+
return this.parseAndGenerate(...(yield (0, file_system_utils_1.getFiles)(dir, Object.assign(Object.assign({}, options), { filter }))));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
59
66
|
}
|
|
60
67
|
class OpenApiGenerator extends _OpenApiGenerator {
|
|
61
68
|
constructor(config) {
|
|
@@ -93,7 +100,7 @@ class OpenApiGenerationProviderBase {
|
|
|
93
100
|
return this.onGenerate(ctx);
|
|
94
101
|
}
|
|
95
102
|
getProviderContext(context, config, defaultConfig) {
|
|
96
|
-
const c = Object.assign(Object.assign(Object.assign({},
|
|
103
|
+
const c = Object.assign(Object.assign(Object.assign({}, context.config), defaultConfig), config);
|
|
97
104
|
return Object.assign(context, {
|
|
98
105
|
config: c,
|
|
99
106
|
});
|
|
@@ -9,10 +9,14 @@ function collect(data, obj, func) {
|
|
|
9
9
|
for (const o of obj) {
|
|
10
10
|
if (!o)
|
|
11
11
|
continue;
|
|
12
|
+
if (o['x-ignore'])
|
|
13
|
+
continue;
|
|
12
14
|
func(data, o);
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
else {
|
|
18
|
+
if (obj['x-ignore'])
|
|
19
|
+
return;
|
|
16
20
|
func(data, obj);
|
|
17
21
|
}
|
|
18
22
|
}
|
|
@@ -26,6 +30,8 @@ function collectRecord(data, obj, func) {
|
|
|
26
30
|
const value = obj[key];
|
|
27
31
|
if (!value)
|
|
28
32
|
continue;
|
|
33
|
+
if (value['x-ignore'])
|
|
34
|
+
continue;
|
|
29
35
|
func(data, value, key);
|
|
30
36
|
}
|
|
31
37
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFiles = exports.defaultDirectoryScanOptions = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const fs_extra_1 = require("fs-extra");
|
|
7
|
+
exports.defaultDirectoryScanOptions = {
|
|
8
|
+
recursive: false,
|
|
9
|
+
maxDepth: 5,
|
|
10
|
+
};
|
|
11
|
+
function getFiles(dir, options) {
|
|
12
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const opts = Object.assign(Object.assign({}, exports.defaultDirectoryScanOptions), options);
|
|
14
|
+
const files = [];
|
|
15
|
+
yield getFilesImpl(dir, opts, files, 0);
|
|
16
|
+
return files;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.getFiles = getFiles;
|
|
20
|
+
function getFilesImpl(dir, options, files, currentDepth) {
|
|
21
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const dirFiles = yield (0, fs_extra_1.readdir)(dir);
|
|
23
|
+
for (const file of dirFiles) {
|
|
24
|
+
const filePath = (0, path_1.resolve)(dir, file);
|
|
25
|
+
const stat = yield (0, fs_extra_1.lstat)(filePath);
|
|
26
|
+
if (stat.isDirectory()) {
|
|
27
|
+
if (options.recursive) {
|
|
28
|
+
if (options.maxDepth && options.maxDepth > currentDepth) {
|
|
29
|
+
getFilesImpl(filePath, options, files, currentDepth + 1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (!options.filter || options.filter(file)) {
|
|
35
|
+
files.push(filePath);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { emptyDir, ensureDir } from 'fs-extra';
|
|
|
4
4
|
import { defaultOpenApiGeneratorConfig } from './config';
|
|
5
5
|
import { OpenApiParser } from '../parse/parser';
|
|
6
6
|
import { ActionProvider } from '../utils/action-provider';
|
|
7
|
+
import { getFiles } from '../utils/file-system.utils';
|
|
7
8
|
class _OpenApiGenerator {
|
|
8
9
|
constructor(config, providers, parser) {
|
|
9
10
|
this._providers = providers;
|
|
@@ -53,6 +54,12 @@ class _OpenApiGenerator {
|
|
|
53
54
|
return yield this.generate(data);
|
|
54
55
|
});
|
|
55
56
|
}
|
|
57
|
+
parseAndGenerateFromDir(dir, options) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const filter = (file) => { var _a, _b; return (file.endsWith('.yml') || file.endsWith('.yaml') || file.endsWith('.json')) && ((_b = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, file)) !== null && _b !== void 0 ? _b : true); };
|
|
60
|
+
return this.parseAndGenerate(...(yield getFiles(dir, Object.assign(Object.assign({}, options), { filter }))));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
56
63
|
}
|
|
57
64
|
export class OpenApiGenerator extends _OpenApiGenerator {
|
|
58
65
|
constructor(config) {
|
|
@@ -89,7 +96,7 @@ export class OpenApiGenerationProviderBase {
|
|
|
89
96
|
return this.onGenerate(ctx);
|
|
90
97
|
}
|
|
91
98
|
getProviderContext(context, config, defaultConfig) {
|
|
92
|
-
const c = Object.assign(Object.assign(Object.assign({},
|
|
99
|
+
const c = Object.assign(Object.assign(Object.assign({}, context.config), defaultConfig), config);
|
|
93
100
|
return Object.assign(context, {
|
|
94
101
|
config: c,
|
|
95
102
|
});
|
|
@@ -6,10 +6,14 @@ export function collect(data, obj, func) {
|
|
|
6
6
|
for (const o of obj) {
|
|
7
7
|
if (!o)
|
|
8
8
|
continue;
|
|
9
|
+
if (o['x-ignore'])
|
|
10
|
+
continue;
|
|
9
11
|
func(data, o);
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
else {
|
|
15
|
+
if (obj['x-ignore'])
|
|
16
|
+
return;
|
|
13
17
|
func(data, obj);
|
|
14
18
|
}
|
|
15
19
|
}
|
|
@@ -22,6 +26,8 @@ export function collectRecord(data, obj, func) {
|
|
|
22
26
|
const value = obj[key];
|
|
23
27
|
if (!value)
|
|
24
28
|
continue;
|
|
29
|
+
if (value['x-ignore'])
|
|
30
|
+
continue;
|
|
25
31
|
func(data, value, key);
|
|
26
32
|
}
|
|
27
33
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { lstat, readdir } from 'fs-extra';
|
|
4
|
+
export const defaultDirectoryScanOptions = {
|
|
5
|
+
recursive: false,
|
|
6
|
+
maxDepth: 5,
|
|
7
|
+
};
|
|
8
|
+
export function getFiles(dir, options) {
|
|
9
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
const opts = Object.assign(Object.assign({}, defaultDirectoryScanOptions), options);
|
|
11
|
+
const files = [];
|
|
12
|
+
yield getFilesImpl(dir, opts, files, 0);
|
|
13
|
+
return files;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function getFilesImpl(dir, options, files, currentDepth) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const dirFiles = yield readdir(dir);
|
|
19
|
+
for (const file of dirFiles) {
|
|
20
|
+
const filePath = resolve(dir, file);
|
|
21
|
+
const stat = yield lstat(filePath);
|
|
22
|
+
if (stat.isDirectory()) {
|
|
23
|
+
if (options.recursive) {
|
|
24
|
+
if (options.maxDepth && options.maxDepth > currentDepth) {
|
|
25
|
+
getFilesImpl(filePath, options, files, currentDepth + 1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (!options.filter || options.filter(file)) {
|
|
31
|
+
files.push(filePath);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { AnyConfig, OpenApiGenerationProvider, OpenApiGenerationProviderContext,
|
|
|
3
3
|
import { OpenApiParser } from '../parse/parser';
|
|
4
4
|
import { ApiData } from '../transform';
|
|
5
5
|
import { ActionProvider } from '../utils/action-provider';
|
|
6
|
+
import { DirectoryScanOptions } from '../utils/file-system.utils';
|
|
6
7
|
import { EmptyConstructor, Merge } from '../utils/type.utils';
|
|
7
8
|
type OpenApiGenerationProviders = {
|
|
8
9
|
provider: ActionProvider<OpenApiGenerationProviderFn>;
|
|
@@ -22,6 +23,7 @@ declare class _OpenApiGenerator<TOutput extends OpenApiGeneratorInput> {
|
|
|
22
23
|
useValue<PInput extends TOutput, POutput extends OpenApiGeneratorOutput, PConfig extends AnyConfig>(value: OpenApiGenerationProvider<VInput<PInput, TOutput>, POutput, PConfig>, config?: Partial<PConfig>): _OpenApiGenerator<Merge<[TOutput, POutput]>>;
|
|
23
24
|
generate<T extends ApiData>(data: T): Promise<TOutput>;
|
|
24
25
|
parseAndGenerate(...fileNames: (string | string[])[]): Promise<TOutput>;
|
|
26
|
+
parseAndGenerateFromDir(dir: string, options?: Partial<DirectoryScanOptions>): Promise<TOutput>;
|
|
25
27
|
}
|
|
26
28
|
export declare class OpenApiGenerator extends _OpenApiGenerator<{}> {
|
|
27
29
|
constructor(config?: Partial<OpenApiGeneratorConfig>);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { OpenApiCollectorData } from './types';
|
|
2
|
-
export declare function collect<T
|
|
3
|
-
export declare function collectRecord<T
|
|
2
|
+
export declare function collect<T extends Record<`x-${string}`, unknown>>(data: OpenApiCollectorData, obj: T | T[] | undefined, func: (data: OpenApiCollectorData, obj: NonNullable<T>) => void): void;
|
|
3
|
+
export declare function collectRecord<T extends Record<`x-${string}`, unknown>>(data: OpenApiCollectorData, obj: Record<string, T> | undefined, func: (data: OpenApiCollectorData, obj: NonNullable<T>, key: string) => void): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Nullable } from './type.utils';
|
|
2
|
+
export type DirectoryScanOptions = {
|
|
3
|
+
recursive: boolean;
|
|
4
|
+
maxDepth: Nullable<number>;
|
|
5
|
+
filter?: (file: string) => boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const defaultDirectoryScanOptions: DirectoryScanOptions;
|
|
8
|
+
export declare function getFiles(dir: string, options?: Partial<DirectoryScanOptions>): Promise<string[]>;
|