1+ /* eslint-disable no-console */
12/* eslint-disable import/no-commonjs */
23const amf = require ( 'amf-client-js' ) ;
34const 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