Skip to content

Commit

Permalink
Added the -f flag support for the glee command.
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushNautiyalDeveloper committed Jan 12, 2024
1 parent 10d051e commit 9b906a0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
11 changes: 0 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,13 @@
"@asyncapi/bundler": "^0.4.0",
"@asyncapi/converter": "^1.4.7",
"@asyncapi/diff": "^0.4.1",
<<<<<<< HEAD
"@asyncapi/generator": "^1.15.3",
"@asyncapi/modelina": "^2.0.2",
"@asyncapi/openapi-schema-parser": "^3.0.5",
"@asyncapi/optimizer": "^0.2.4",
"@asyncapi/parser": "^3.0.1",
"@asyncapi/protobuf-schema-parser": "^3.0.4",
"@asyncapi/raml-dt-schema-parser": "^4.0.6",
=======
"@asyncapi/generator": "^1.16.0",
"@asyncapi/modelina": "^2.1.1",
"@asyncapi/openapi-schema-parser": "^3.0.10",
"@asyncapi/optimizer": "^0.2.7",
"@asyncapi/parser": "^3.0.2",
"@asyncapi/protobuf-schema-parser": "^3.0.6",
"@asyncapi/raml-dt-schema-parser": "^4.0.10",
>>>>>>> master
"@asyncapi/studio": "^0.17.3",
"@oclif/core": "^1.26.2",
"@oclif/errors": "^1.3.6",
Expand All @@ -40,7 +30,6 @@
"chokidar": "^3.5.2",
"fast-levenshtein": "^3.0.0",
"fs-extra": "^11.1.0",
"handlebars": "^4.7.8",
"indent-string": "^4.0.0",
"inquirer": "^8.2.0",
"js-yaml": "^4.1.0",
Expand Down
61 changes: 50 additions & 11 deletions src/commands/new/glee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { promises as fPromises } from "fs";
import Command from "../../base";
import { resolve, join } from "path";
import fs from "fs-extra";

import { load } from "../../models/SpecificationFile";
import { CliUx } from "@oclif/core";
import path from "path";
import yaml from "js-yaml";
export default class NewGlee extends Command {
static description = "Creates a new Glee project";

Expand All @@ -18,37 +21,73 @@ export default class NewGlee extends Command {
}),
template: Flags.string({
char: "t",
description: "template for the project",
description: "name of the template",
default: "default",
}),
file: Flags.string({
char: "f",
description: "path of the file",
default: "asyncapi.yaml",
}),
};

async run() {
const { flags } = await this.parse(NewGlee); // NOSONAR

const { name: projectName, template, file } = flags;
const { name: projectName, template: templateName, file } = flags;

const PROJECT_DIRECTORY = join(process.cwd(), projectName);

const GLEE_TEMPLATES_DIRECTORY = resolve(
__dirname,
"../../../assets/create-glee-app/templates/default",
"../../../assets/create-glee-app/templates/",
templateName,
);

console.log({ GLEE_TEMPLATES_DIRECTORY });
console.log({ file }, { template });
if (template) {
const currentTemplateName =
"https://github.com/KhudaDad414/glee-generator-template";

if (file && templateName && templateName != "default") {
this.error("You cannot use both --t and --f in the same command.");
}
if (file) {
const asyncapiInput = (await load(file)) || (await load());

const serversObject = asyncapiInput.toJson().servers;
const servers = Object.keys(serversObject);
const remoteServers = [];
for (const server of servers) {
const isRemote = await CliUx.ux.confirm(
`Is "${server}" a remote server`,
);
remoteServers.push({ server, isRemote });
}

const selectedRemoteServers = remoteServers
.filter(({ isRemote }) => isRemote)
.map(({ server }) => server);

try {
const asyncapiObject = asyncapiInput.toJson();
asyncapiObject["x-remoteServers"] = selectedRemoteServers;

delete asyncapiObject.filePath;
delete asyncapiObject.kind;

const updatedAsyncApiContent = yaml.dump(asyncapiObject, {
lineWidth: -1,
});

const currentFileDirectory = path.join(__dirname, "../../..", file);

fs.writeFileSync(currentFileDirectory, updatedAsyncApiContent);

await this.config.runCommand("generate:fromTemplate", [
file,
template,
`--output=${flags.name}`,
currentTemplateName,
`--output=${projectName}`,
]);
} catch (error) {
console.log(error);
console.log({ error });
}
} else {
try {
Expand Down

0 comments on commit 9b906a0

Please sign in to comment.