Skip to content

Commit

Permalink
correctly formatted the glee file.
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushNautiyalDeveloper committed Jan 12, 2024
1 parent 5331813 commit 5126039
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions src/commands/new/glee.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { Flags } from "@oclif/core";
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";
import { Flags } from '@oclif/core';
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";
static description = 'Creates a new Glee project';

protected commandName = "glee";
protected commandName = 'glee';

static flags = {
help: Flags.help({ char: "h" }),
help: Flags.help({ char: 'h' }),
name: Flags.string({
char: "n",
description: "name of the project",
default: "project",
char: 'n',
description: 'name of the project',
default: 'project',
}),
template: Flags.string({
char: "t",
description: "name of the template",
default: "default",
char: 't',
description: 'name of the template',
default: 'default',
}),
file: Flags.string({
char: "f",
description: "path of the file",
char: 'f',
description: 'path of the file',
}),
};

Expand All @@ -39,15 +39,15 @@ export default class NewGlee extends Command {

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

const currentTemplateName =
"https://github.com/KhudaDad414/glee-generator-template";
'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 && templateName && templateName != 'default') {
this.error('You cannot use both --t and --f in the same command.');
}
if (file) {
try {
Expand All @@ -58,7 +58,7 @@ export default class NewGlee extends Command {
const remoteServers = [];
for (const server of servers) {
const isRemote = await CliUx.ux.confirm(
`Is "${server}" a remote server`,
`Is "${server}" a remote server`
);
remoteServers.push({ server, isRemote });
}
Expand All @@ -67,7 +67,7 @@ export default class NewGlee extends Command {
.filter(({ isRemote }) => isRemote)
.map(({ server }) => server);
const asyncapiObject = asyncapiInput.toJson();
asyncapiObject["x-remoteServers"] = selectedRemoteServers;
asyncapiObject['x-remoteServers'] = selectedRemoteServers;

delete asyncapiObject.filePath;
delete asyncapiObject.kind;
Expand All @@ -76,11 +76,11 @@ export default class NewGlee extends Command {
lineWidth: -1,
});

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

fs.writeFileSync(currentFileDirectory, updatedAsyncApiContent);

await this.config.runCommand("generate:fromTemplate", [
await this.config.runCommand('generate:fromTemplate', [
file,
currentTemplateName,
`--output=${projectName}`,
Expand All @@ -93,24 +93,24 @@ export default class NewGlee extends Command {
await fPromises.mkdir(PROJECT_DIRECTORY);
} catch (err: any) {
switch (err.code) {
case "EEXIST":
case 'EEXIST':
this.error(
`Unable to create the project. We tried to use "${projectName}" as the directory of your new project but it already exists (${PROJECT_DIRECTORY}). Please specify a different name for the new project. For example, run the following command instead:\n\n asyncapi new ${this.commandName} --name ${projectName}-1\n`,
`Unable to create the project. We tried to use "${projectName}" as the directory of your new project but it already exists (${PROJECT_DIRECTORY}). Please specify a different name for the new project. For example, run the following command instead:\n\n asyncapi new ${this.commandName} --name ${projectName}-1\n`
);
break;
case "EACCES":
case 'EACCES':
this.error(
`Unable to create the project. We tried to access the "${PROJECT_DIRECTORY}" directory but it was not possible due to file access permissions. Please check the write permissions of your current working directory ("${process.cwd()}").`,
`Unable to create the project. We tried to access the "${PROJECT_DIRECTORY}" directory but it was not possible due to file access permissions. Please check the write permissions of your current working directory ("${process.cwd()}").`
);
break;
case "EPERM":
case 'EPERM':
this.error(
`Unable to create the project. We tried to create the "${PROJECT_DIRECTORY}" directory but the operation requires elevated privileges. Please check the privileges for your current user.`,
`Unable to create the project. We tried to create the "${PROJECT_DIRECTORY}" directory but the operation requires elevated privileges. Please check the privileges for your current user.`
);
break;
default:
this.error(
`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`,
`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`
);
}
}
Expand All @@ -119,22 +119,22 @@ export default class NewGlee extends Command {
await fs.copy(GLEE_TEMPLATES_DIRECTORY, PROJECT_DIRECTORY);
await fPromises.rename(
`${PROJECT_DIRECTORY}/env`,
`${PROJECT_DIRECTORY}/.env`,
`${PROJECT_DIRECTORY}/.env`
);
await fPromises.rename(
`${PROJECT_DIRECTORY}/gitignore`,
`${PROJECT_DIRECTORY}/.gitignore`,
`${PROJECT_DIRECTORY}/.gitignore`
);
await fPromises.rename(
`${PROJECT_DIRECTORY}/README-template.md`,
`${PROJECT_DIRECTORY}/README.md`,
`${PROJECT_DIRECTORY}/README.md`
);
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.`,
`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}`,
`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`
);
}
}
Expand Down

0 comments on commit 5126039

Please sign in to comment.