Skip to content

Commit ef698d6

Browse files
committed
chore: updating amf and adding generate function
Signed-off-by: Pawel Psztyc <jarrodek@gmail.com>
1 parent 3ffc00c commit ef698d6

6 files changed

Lines changed: 654 additions & 568 deletions

File tree

index.d.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import { ApiGenerationOptions, ApiConfiguration } from './types';
22

3-
declare function process(init: string|Map<string, ApiConfiguration|string|string[]>, opts?: ApiGenerationOptions): Promise<void>;
3+
/**
4+
* @param init If string then this is a location of the file that holds processing configuration. Otherwise it is already prepared configuration.
5+
* @param opts Processing options.
6+
*/
7+
declare function mainFn(init: string|Map<string, ApiConfiguration|string|string[]>, opts?: ApiGenerationOptions): Promise<void>;
48

5-
export = process;
9+
declare namespace mainFn {
10+
/**
11+
* Runs the default function and exists the process when failed.
12+
* @param {Map<string, ApiConfiguration>} init The list of files to parse with their configuration.
13+
* @param {ApiGenerationOptions=} opts Optional parsing options.
14+
*/
15+
function generate(init: Map<string, ApiConfiguration>, opts?: ApiGenerationOptions): Promise<void>;
16+
}
17+
18+
export = mainFn;

index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
/* eslint-disable import/no-commonjs */
23
const amf = require('amf-client-js');
34
const fs = require('fs-extra');
@@ -160,7 +161,7 @@ function prepareFile(file) {
160161
* @param {ApiGenerationOptions=} opts Processing options.
161162
* @return {Promise<void>}
162163
*/
163-
module.exports = async function(init, opts={}) {
164+
async function main(init, opts={}) {
164165
if (typeof init === 'string') {
165166
const { files: cnfFiles, opts: cnfOpts } = prepareFile(init);
166167
init = cnfFiles;
@@ -170,4 +171,23 @@ module.exports = async function(init, opts={}) {
170171
for (const [file, type] of init) {
171172
await parseFile(file, type, opts);
172173
}
173-
};
174+
}
175+
176+
/**
177+
* Runs the default function and exists the process when failed.
178+
* @param {Map<string, ApiConfiguration>} init The list of files to parse with their configuration.
179+
* @param {ApiGenerationOptions=} opts Optional parsing options.
180+
*/
181+
async function generate(init, opts) {
182+
try {
183+
console.log(`Generating graph models for ${init.size} api(s).`);
184+
await main(init, opts);
185+
console.log('Models created');
186+
} catch (cause) {
187+
console.error(cause);
188+
throw new Error('Unable to process APIs.');
189+
}
190+
}
191+
192+
const myModule = module.exports = main;
193+
myModule.generate = generate;

0 commit comments

Comments
 (0)