diff --git a/src/apps/cli/commands/bundle.ts b/src/apps/cli/commands/bundle.ts index 47f3a909..362715df 100644 --- a/src/apps/cli/commands/bundle.ts +++ b/src/apps/cli/commands/bundle.ts @@ -26,13 +26,17 @@ export default class Bundle extends Command { async run() { const { argv, flags } = await this.parse(Bundle); + //Guard: building requires at least one AsyncApi file path. + if (!argv.length) { + this.error('At least one AsyncAPI file path is required!'); + } const output = flags.output; const outputFormat = path.extname(argv[0] as string); - const AsyncAPIFiles = argv as string[]; + const AsyncApiFiles = argv as string[]; - this.metricsMetadata.files = AsyncAPIFiles.length; + this.metricsMetadata.files = AsyncApiFiles.length; - const document = await bundle(AsyncAPIFiles, { + const document = await bundle(AsyncApiFiles, { base: flags.base, baseDir: flags.baseDir, xOrigin: flags.xOrigin, @@ -49,6 +53,7 @@ export default class Bundle extends Command { } else { const format = path.extname(output); + //Ensuring only one output format is written and fail fast on unsupported extension. if (format === '.yml' || format === '.yaml') { await writeFile( path.resolve(process.cwd(), output), @@ -57,9 +62,7 @@ export default class Bundle extends Command { encoding: 'utf-8', }, ); - } - - if (format === '.json') { + } else if (format === '.json') { await writeFile( path.resolve(process.cwd(), output), document.string() || '', @@ -67,6 +70,8 @@ export default class Bundle extends Command { encoding: 'utf-8', }, ); + } else { + this.error('Output file must be .json, .yaml or .yml'); } this.log(`Check out your shiny new bundled files at ${output}`); } diff --git a/test/docs/test-output/README.md b/test/docs/test-output/README.md new file mode 100644 index 00000000..4c85f7d7 --- /dev/null +++ b/test/docs/test-output/README.md @@ -0,0 +1,72 @@ +# AsyncAPI Sample App + +## Overview + +This is a sample app. + +- **Version:** 1.0.1 +- **Server URL:** mqtt://api.streetlights.smartylighting.com:{port} + + +## Usage + +```javascript +const AsyncAPISampleApp = require('./client'); +const wsClient = new AsyncAPISampleApp(); + +async function main() { + try { + await wsClient.connect(); + // use wsClient to send/receive messages + await wsClient.close(); + } catch (error) { + console.error('Failed to connect:', error); + } +} + +main(); +``` + + +## API + +### `connect()` +Establishes a WebSocket connection. + +### `registerMessageHandler(handlerFunction)` +Registers a callback for incoming messages. + +### `registerErrorHandler(handlerFunction)` +Registers a callback for connection errors. + +### `close()` +Closes the WebSocket connection. + + +### Available Operations + +#### `receiveLightMeasured(payload)` + + + + +#### `receiveTurnOn(payload)` + + + + +#### `smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.subscribe(payload)` + + + + +#### `turnOnOff(payload)` + + + + +#### `dimLight(payload)` + + + +