Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/1832.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@asyncapi/cli': minor
---

feat: add --compile flag support to generate fromTemplate command Issue#1829

- e7b086d: bump modelina-cli #1818
- f1b604c: fixed issue#1829


1 change: 1 addition & 0 deletions .modelina-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"current":"home","store":{"home":"test/fixtures/specification.yml"}}
34 changes: 34 additions & 0 deletions asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
asyncapi: '2.6.0'
info:
title: Streetlights API
version: '1.0.0'
description: |
The Smartylighting Streetlights API allows you to remotely manage streetlights.
You can turn them on/off, change their brightness and color.
servers:
production:
url: mqtt://smartylighting.com
protocol: mqtt
defaultContentType: application/json
channels:
light/measured:
description: The topic on which light measurements are sent.
subscribe:
summary: Receive information about environmental lighting conditions of a particular streetlight.
message:
name: lightMeasured
payload:
type: object
properties:
id:
type: integer
minimum: 0
description: Id of the streetlight.
lumens:
type: integer
minimum: 0
description: Light intensity measured in lumens.
sentAt:
type: string
format: date-time
description: Date and time when the message was sent.
36 changes: 24 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@asyncapi/converter": "^1.6.2",
"@asyncapi/diff": "^0.5.0",
"@asyncapi/generator": "^1.17.25",
"@asyncapi/modelina-cli": "^4.0.4",
"@asyncapi/modelina-cli": "^5.3.5",
"@asyncapi/openapi-schema-parser": "^3.0.24",
"@asyncapi/optimizer": "^1.0.4",
"@asyncapi/parser": "^3.3.0",
Expand Down
8 changes: 5 additions & 3 deletions src/commands/generate/fromTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default class Template extends Command {

async run() {
const { args, flags } = await this.parse(Template); // NOSONAR
const compile = flags['compile'];
const interactive = !flags['no-interactive'];
let asyncapi = args['asyncapi'] ?? '';
let template = args['template'] ?? '';
Expand Down Expand Up @@ -123,7 +124,7 @@ export default class Template extends Command {
}
}
if (flags['use-new-generator']) {
await this.generateUsingNewGenerator(asyncapi, template, output, options, genOption);
await this.generateUsingNewGenerator(asyncapi, template, output, options, genOption, compile);
} else {
await this.generate(asyncapi, template, output, options, genOption, interactive);
}
Expand Down Expand Up @@ -287,7 +288,8 @@ export default class Template extends Command {
s.stop(`${yellow('Check out your shiny new generated files at ') + magenta(output) + yellow('.')}\n`);
}

private async generateUsingNewGenerator(asyncapi: string | undefined, template: string, output: string, options: any, genOption: any) {
private async generateUsingNewGenerator(asyncapi: string | undefined, template: string, output: string, options: any, genOption: any, compile: boolean) {
console.log('⚙️ compile flag is:', compile);
let specification: Specification;
try {
specification = await load(asyncapi);
Expand All @@ -300,7 +302,7 @@ export default class Template extends Command {
{ exit: 1 },
);
}
const generator = new AsyncAPINewGenerator(template, output || path.resolve(os.tmpdir(), 'asyncapi-generator'), options);
const generator = new AsyncAPINewGenerator(template, output || path.resolve(os.tmpdir(), 'asyncapi-generator'), { ...options, compile });
this.log('Generation in progress. Keep calm and wait a bit');
try {
await generator.generateFromString(specification.text(), { ...genOption, path: asyncapi });
Expand Down
5 changes: 5 additions & 0 deletions src/core/flags/generate/fromTemplate.flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const fromTemplateFlags = () => {
default: false,
description: 'Force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir (defaults to false)'
}),
compile: Flags.boolean({
description: 'Compile the template before generating. Set to false to skip.',
default: true,
allowNo: true,
}),
watch: watchFlag(
'Watches the template directory and the AsyncAPI document, and re-generate the files when changes occur. Ignores the output directory.'
),
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/newtemplate/__transpiled/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.