Skip to content

Commit 0fc7b9f

Browse files
all the operation function are not created.
1 parent aabac41 commit 0fc7b9f

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

asyncapi.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: 'Hello, Glee!'
4+
version: 0.1.0
5+
servers:
6+
websockets:
7+
host: 'localhost:3000'
8+
protocol: ws
9+
channels:
10+
check:
11+
address: check
12+
messages:
13+
atHello:
14+
$ref: '#/components/messages/hello'
15+
goodBye:
16+
$ref: '#/components/messages/hello'
17+
operations:
18+
atHello:
19+
action: receive
20+
channel:
21+
$ref: '#/channels/check'
22+
messages:
23+
- $ref: '#/components/messages/hello'
24+
goodBye:
25+
action: send
26+
channel:
27+
$ref: '#/channels/check'
28+
messages:
29+
- $ref: '#/components/messages/hello'
30+
components:
31+
messages:
32+
hello:
33+
payload:
34+
type: string

src/commands/new/glee.ts

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { promises as fPromises } from 'fs';
33
import Command from '../../base';
44
import { resolve, join } from 'path';
55
import fs from 'fs-extra';
6+
import { load, Specification } from '../../models/SpecificationFile';
7+
import {parse} from '../../parser'
8+
import { exec } from 'child_process';
69

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

20+
static args = [
21+
{
22+
name: 'file',
23+
description: 'spec path, URL or context-name',
24+
required: true,
25+
},
26+
];
1727
async run() {
18-
const { flags } = await this.parse(NewGlee); // NOSONAR
28+
const {args,flags } = await this.parse(NewGlee); // NOSONAR
1929

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

2233
const PROJECT_DIRECTORY = join(process.cwd(), projectName);
2334
const GLEE_TEMPLATES_DIRECTORY = resolve(__dirname, '../../../assets/create-glee-app/templates/default');
24-
35+
let operationList : Array<any> = []
36+
let response:any;
37+
let asyncApiFile:any;
2538
try {
2639
await fPromises.mkdir(PROJECT_DIRECTORY);
40+
const document = await load(args.file);
41+
response = await parse(this, document)
42+
const Jsondocument:any = JSON.stringify(response.document)
43+
asyncApiFile = response.document._meta.asyncapi.input;
44+
45+
// console.log({document},{response},{Jsondocument})
46+
console.log(response.document._meta.asyncapi.input,"<<<<<<<this is the response")
47+
// console.log(Object.keys(response.document._json.operations))
48+
operationList = Object.keys(response.document._json.operations);
49+
// console.log( JSON.stringify(response.document), {Jsondocument}, response.document._json.channels['/hello'].publish.operationId)
50+
// operation_id = response.document._json.channels['/hello'].publish.operationId
51+
// console.log({operation_id})
52+
2753
} catch (err: any) {
2854
switch (err.code) {
2955
case 'EEXIST':
@@ -40,14 +66,34 @@ export default class NewGlee extends Command {
4066
}
4167
}
4268

43-
try {
69+
70+
const createOperationFunction = async () => {
71+
for (const fileName of operationList) {
72+
await fPromises.writeFile(`${PROJECT_DIRECTORY}/functions/${fileName}.js`, "");
73+
await fPromises.copyFile(
74+
`${PROJECT_DIRECTORY}/functions/onHello.js`,
75+
`${PROJECT_DIRECTORY}/functions/${fileName}.js`
76+
);
77+
}
78+
};
79+
try {
4480
await fs.copy(GLEE_TEMPLATES_DIRECTORY, PROJECT_DIRECTORY);
4581
await fPromises.rename(`${PROJECT_DIRECTORY}/env`, `${PROJECT_DIRECTORY}/.env`);
4682
await fPromises.rename(`${PROJECT_DIRECTORY}/gitignore`, `${PROJECT_DIRECTORY}/.gitignore`);
4783
await fPromises.rename(`${PROJECT_DIRECTORY}/README-template.md`, `${PROJECT_DIRECTORY}/README.md`);
84+
85+
await createOperationFunction()
86+
await fPromises.unlink(`${PROJECT_DIRECTORY}/functions/onHello.js`);
87+
88+
await fPromises.writeFile(`${PROJECT_DIRECTORY}/asyncapi.yaml`,asyncApiFile);
89+
90+
4891
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.`);
4992
} catch (err) {
5093
this.error(`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`);
5194
}
5295
}
53-
}
96+
// const parseDocument = async () =>{
97+
98+
// }
99+
}

src/hooks/command_not_found/myhook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const closest = (target: string, possibilities: string[]): string =>
77
possibilities
88
.map((id) => ({distance: levenshtein.get(target, id, {useCollator: true}), id}))
99
.sort((a, b) => a.distance - b.distance)[0]?.id ?? '';
10-
10+
console.log("command not found hook is running")
1111
const hook: Hook.CommandNotFound = async function (opts) {
1212
if (opts.id === '--help') {
1313
const help = new Help(this.config);

0 commit comments

Comments
 (0)