Skip to content

Commit

Permalink
all the operation function are not created.
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushNautiyalDeveloper committed Nov 18, 2023
1 parent aabac41 commit 0fc7b9f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 5 deletions.
34 changes: 34 additions & 0 deletions asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
asyncapi: 3.0.0
info:
title: 'Hello, Glee!'
version: 0.1.0
servers:
websockets:
host: 'localhost:3000'
protocol: ws
channels:
check:
address: check
messages:
atHello:
$ref: '#/components/messages/hello'
goodBye:
$ref: '#/components/messages/hello'
operations:
atHello:
action: receive
channel:
$ref: '#/channels/check'
messages:
- $ref: '#/components/messages/hello'
goodBye:
action: send
channel:
$ref: '#/channels/check'
messages:
- $ref: '#/components/messages/hello'
components:
messages:
hello:
payload:
type: string
54 changes: 50 additions & 4 deletions src/commands/new/glee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { promises as fPromises } from 'fs';
import Command from '../../base';
import { resolve, join } from 'path';
import fs from 'fs-extra';
import { load, Specification } from '../../models/SpecificationFile';
import {parse} from '../../parser'
import { exec } from 'child_process';

export default class NewGlee extends Command {
static description = 'Creates a new Glee project';
Expand All @@ -14,16 +17,39 @@ export default class NewGlee extends Command {
name: Flags.string({ char: 'n', description: 'name of the project', default: 'project' }),
};

static args = [
{
name: 'file',
description: 'spec path, URL or context-name',
required: true,
},
];
async run() {
const { flags } = await this.parse(NewGlee); // NOSONAR
const {args,flags } = await this.parse(NewGlee); // NOSONAR

const projectName = flags.name;
// console.log(flags.name , {flags} , {args})

const PROJECT_DIRECTORY = join(process.cwd(), projectName);
const GLEE_TEMPLATES_DIRECTORY = resolve(__dirname, '../../../assets/create-glee-app/templates/default');

let operationList : Array<any> = []
let response:any;
let asyncApiFile:any;
try {
await fPromises.mkdir(PROJECT_DIRECTORY);
const document = await load(args.file);
response = await parse(this, document)
const Jsondocument:any = JSON.stringify(response.document)
asyncApiFile = response.document._meta.asyncapi.input;

// console.log({document},{response},{Jsondocument})
console.log(response.document._meta.asyncapi.input,"<<<<<<<this is the response")
// console.log(Object.keys(response.document._json.operations))
operationList = Object.keys(response.document._json.operations);
// console.log( JSON.stringify(response.document), {Jsondocument}, response.document._json.channels['/hello'].publish.operationId)
// operation_id = response.document._json.channels['/hello'].publish.operationId
// console.log({operation_id})

} catch (err: any) {
switch (err.code) {
case 'EEXIST':
Expand All @@ -40,14 +66,34 @@ export default class NewGlee extends Command {
}
}

try {

const createOperationFunction = async () => {
for (const fileName of operationList) {
await fPromises.writeFile(`${PROJECT_DIRECTORY}/functions/${fileName}.js`, "");
await fPromises.copyFile(
`${PROJECT_DIRECTORY}/functions/onHello.js`,
`${PROJECT_DIRECTORY}/functions/${fileName}.js`
);
}
};
try {
await fs.copy(GLEE_TEMPLATES_DIRECTORY, PROJECT_DIRECTORY);
await fPromises.rename(`${PROJECT_DIRECTORY}/env`, `${PROJECT_DIRECTORY}/.env`);
await fPromises.rename(`${PROJECT_DIRECTORY}/gitignore`, `${PROJECT_DIRECTORY}/.gitignore`);
await fPromises.rename(`${PROJECT_DIRECTORY}/README-template.md`, `${PROJECT_DIRECTORY}/README.md`);

await createOperationFunction()
await fPromises.unlink(`${PROJECT_DIRECTORY}/functions/onHello.js`);

await fPromises.writeFile(`${PROJECT_DIRECTORY}/asyncapi.yaml`,asyncApiFile);


this.log(`Your project "${projectName}" has been created successfully!\n\nNext steps:\n\n cd ${projectName}\n npm install\n npm run dev\n\nAlso, you can already open the project in your favorite editor and start tweaking it.`);
} catch (err) {
this.error(`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`);
}
}
}
// const parseDocument = async () =>{

// }
}
2 changes: 1 addition & 1 deletion src/hooks/command_not_found/myhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const closest = (target: string, possibilities: string[]): string =>
possibilities
.map((id) => ({distance: levenshtein.get(target, id, {useCollator: true}), id}))
.sort((a, b) => a.distance - b.distance)[0]?.id ?? '';

console.log("command not found hook is running")
const hook: Hook.CommandNotFound = async function (opts) {
if (opts.id === '--help') {
const help = new Help(this.config);
Expand Down

0 comments on commit 0fc7b9f

Please sign in to comment.