Skip to content

Commit 1a03c05

Browse files
committed
Add compiled version & lock file
1 parent 40899ea commit 1a03c05

File tree

7 files changed

+59
-6
lines changed

7 files changed

+59
-6
lines changed

bin/commands/from_spec.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Command } from "commander";
22
import { generateDefaultConfig } from "./FromSpec/generateDefaultConfig";
3+
import { getOpenApi } from "../index";
4+
import { readFileSync } from "fs";
35

46
const file_name = 'oas-config';
57
export const default_config_path = `./${file_name}.json`;
@@ -36,11 +38,28 @@ export const FromSpec = new Command()
3638
if (generate) {
3739
await generateDefaultConfig(path);
3840
} else {
39-
analyzeControllers();
41+
const api = getOpenApi();
42+
const options = getScanOptions(path);
43+
api.scan(options);
4044
}
4145
});
4246

4347

44-
function analyzeControllers() {
48+
function getScanOptions(config_path: string): ScanOptions {
49+
const file = readFileSync(config_path, {encoding: "utf8"});
50+
const parsed: StructuredOptions = JSON.parse(file);
4551

52+
return {
53+
folders: {
54+
base_folder: parsed.output,
55+
controller_folder: 'controllers',
56+
}
57+
};
58+
}
59+
60+
export interface ScanOptions {
61+
folders: {
62+
base_folder: string,
63+
controller_folder: string,
64+
}
4665
}

bin/commands/generation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Command } from "commander";
22
import { default_config_path, StructuredOptions } from "./from_spec";
33
import { existsSync, readFileSync } from "fs";
4-
import { resolve } from "path";
54
import { HttpClient } from "./FromSpec/generateDefaultConfig";
5+
import { getOpenApi } from "../index";
66

77
/**
88
* Copy from src/types/default.src
@@ -73,7 +73,7 @@ export const generation = new Command()
7373
throw new Error('DEFINE PLS');
7474
}
7575

76-
const OpenAPI = require(resolve(__dirname, '../../dist/index.js'));
76+
const OpenAPI = getOpenApi();
7777
OpenAPI.generate(generation_setting)
7878
.then(() => {
7979
process.exit(0);

bin/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
'use strict';
44

5-
import {program} from 'commander';
5+
import { program } from 'commander';
66
import { FromSpec } from "./commands/from_spec";
77
import { generation } from "./commands/generation";
8+
import { resolve } from "path";
9+
10+
interface AppInterface {
11+
generate: (options: any) => Promise<void>,
12+
scan: (options: any) => Promise<void>
13+
}
14+
15+
export const getOpenApi = (): AppInterface => require(resolve(__dirname, '../dist/index.js'));
816

917
program
1018
.name('OpenApi')

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { Client } from "./client/interfaces/Client";
1111
import { OpenApi as OpenApiV3 } from "./openApi/v3/interfaces/OpenApi";
1212
import { OpenApi as OpenApiV2 } from "./openApi/v2/interfaces/OpenApi";
1313
import { ExportOptions, ExportOptionsMight, GenerationOptions } from "./types/default";
14+
import { ScanOptions } from "./scan_files/types";
15+
import { scan_method } from "./scan_files/method";
1416

1517
export { HttpClient } from './HttpClient';
1618

@@ -54,6 +56,10 @@ export async function generate({
5456
}
5557
}
5658

59+
export function scan(options: ScanOptions) {
60+
scan_method(options);
61+
}
62+
5763
const fixOptions = (some: ExportOptionsMight): ExportOptions => {
5864
let a = {...some};
5965

src/scan_files/method.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ScanOptions } from "./types";
2+
import { resolve } from "path";
3+
import { readDirectory } from "../utils/fileSystem";
4+
5+
export async function scan_method (o: ScanOptions){
6+
const controller_path = resolve(o.folders.base_folder, o.folders.controller_folder);
7+
const results = await readDirectory(controller_path, {encoding: "utf8", withFileTypes: true});
8+
9+
results.forEach(entity => { /* Todo :: Use havas-parser here to to analyze controller files */});
10+
11+
}

src/scan_files/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
export interface ScanOptions {
3+
specification_place: string;
4+
folders: {
5+
base_folder: string,
6+
controller_folder: string,
7+
}
8+
}

src/utils/fileSystem.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { copyFile as __copyFile, exists as __exists, readFile as __readFile, writeFile as __writeFile } from 'fs';
1+
import { copyFile as __copyFile, exists as __exists, readFile as __readFile, writeFile as __writeFile, readdir } from 'fs';
22
import mkdirp from 'mkdirp';
33
import rimraf from 'rimraf';
44
import { promisify } from 'util';
55

66
// Wrapped file system calls
7+
export const readDirectory = promisify(readdir);
78
export const readFile = promisify(__readFile);
89
export const writeFile = promisify(__writeFile);
910
export const copyFile = promisify(__copyFile);

0 commit comments

Comments
 (0)