diff --git a/src/commands/new/glee.ts b/src/commands/new/glee.ts index 400160eb6c7..461c167b112 100644 --- a/src/commands/new/glee.ts +++ b/src/commands/new/glee.ts @@ -3,6 +3,8 @@ 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' export default class NewGlee extends Command { static description = 'Creates a new Glee project'; @@ -14,16 +16,31 @@ 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 operation_id = "" try { - await fPromises.mkdir(PROJECT_DIRECTORY); + // await fPromises.mkdir(PROJECT_DIRECTORY); + const document = await load(args.file); + const response:any = await parse(this, document) + const Jsondocument:any = JSON.stringify(response.document) + 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': @@ -45,9 +62,15 @@ export default class NewGlee extends Command { 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 fPromises.writeFile(`${PROJECT_DIRECTORY}/functions/${operation_id}.js`,""); + + await fPromises.copyFile(`${PROJECT_DIRECTORY}/functions/onHello.js` , `${PROJECT_DIRECTORY}/functions/${operation_id}.js`) 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 () =>{ + + // } }