Skip to content

Commit

Permalink
Lanching v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrahmanES1 committed Nov 11, 2023
1 parent e8327f1 commit 8b3f404
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-api-initializer",
"version": "0.0.3",
"version": "1.0.0",
"bin": {
"express-initializer": "dist/src/index.js"
},
Expand Down
35 changes: 18 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ const figlet = require("figlet");
import chalk from "chalk";
import cliSelect from "cli-select";
import createResource from "../util/createResource";
import packageJson from '../package.json'

const program = new Command();
console.log(chalk.cyanBright(figlet.textSync("Express Cli", {

console.log(chalk.cyanBright(figlet.textSync(packageJson.name, {
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
width: 150,
whitespaceBreak: true
})));

program
.version("1.0.0")
.description("An example CLI for managing a directory")
// .option("-l, --ls [value]", "List directory contents")
// .option("-m, --mkdir <value>", "Create a directory")
.option('-ts, --typescript', 'use TypeScript')
.version(packageJson.version)
.description("Express API Initializer is a tool designed to streamline the process of generating Express.js applications. ")
.option("-d, --debug", "output extra debugging")
.option('-ts, --typescript', 'use TypeScript')

type X = { id: number, value: string }
program.command('new')
Expand All @@ -32,8 +30,8 @@ program.command('new')
console.log("Select Type Of The App : ");
cliSelect({
values: ['RESTful API', 'Web App'],
selected: "->",
unselected: "-",
selected: "👉",
unselected: " ",
cleanup: false,
valueRenderer: (value, selected) => {
if (selected) {
Expand All @@ -45,12 +43,15 @@ program.command('new')
if (value.id === 0) {
await createApp(appName, options, () => { })
.then(() => {
console.log(chalk.blue(`cd ${appName}`));
console.log(chalk.blue(`npm install express express-async-handler`));
console.log(chalk.blue(`node index.js`));
console.log(chalk.blue.bold(`\n🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉`));
console.log(chalk.blue.bold(`\n cd ${appName}`));
console.log(chalk.blue.bold(` npm install express express-async-handler`));
console.log(chalk.blue.bold(` node index.js\n`));
}).catch((err) => {
console.log(console.log(chalk.red(err)));
})
}
else console.log(chalk.blue(`Web app Coming soon ..`));
else console.log(chalk.blue(`🚧 🚧 🚧 Web app Coming soon .. 🚧 🚧 🚧`));
})

});
Expand All @@ -59,9 +60,9 @@ program.command('new')


program.command('g')
.description('Generate new App Resource')
.addArgument(new commander.Argument('<fileType>', 'file type Controller Service').choices(['controller', 'model', 'middleware', "route", "resource", "view"]))
.argument('<fileName>', 'file name ex. users ')
.description("Generate new App Resource controller, model, middleware, route, resource")
.addArgument(new commander.Argument('<file-type>', 'file type Controller Service').choices(['controller', 'model', 'middleware', "route", "resource", "view"]))
.argument('<file-name>', 'file name ex. users ')
.action((fileType, fileName, options) => {
if (fileType == "resource") {
createResource(`${process.cwd()}`, fileName, options);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node16",
"outDir": "dist"
"outDir": "dist" ,
"resolveJsonModule": true
},
"include": ["src", "types.d.ts"]
}
5 changes: 3 additions & 2 deletions util/createApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export default async (appName: string, options: any, callback: Function) => {
await writeFile(`${appName}/src/middlewares/error.middleware${getFilesExtention(options)}`, errorMiddlewareTemplate())
callback()
} catch (error: any) {
console.log(chalk.red(error.message));
}
console.log(chalk.red("🚨 " + error.message));
return
}

}

Expand Down
18 changes: 12 additions & 6 deletions util/createFile.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import chalk from "chalk";
import { existsSync } from "fs";
import { writeFile } from "fs/promises";

export default async (appName: string, fileType: string, fileName: string, options: any, fileContent = "") => {
const getFilesExtention = (options: any) => options?.typescript ? ".ts" : ".js";

await writeFile(`${appName}/src/${fileType}s/${fileName}.${fileType}${getFilesExtention(options)}`, fileContent).then(() => {

console.log(chalk.green(`CREATE /src/${fileType}s/${fileName}.${fileType}${getFilesExtention(options)}`));

})

if(existsSync(`${appName}/src/${fileType}s`)){
await writeFile(`${appName}/src/${fileType}s/${fileName}.${fileType}${getFilesExtention(options)}`, fileContent).then(() => {
console.log(chalk.green(`🚀 CREATE /src/${fileType}s/${fileName}.${fileType}${getFilesExtention(options)}`));
})
}else
{
console.log(chalk.red(`🚨 FAILED /src/${fileType}s/${fileName}.${fileType}${getFilesExtention(options)}`));
console.log(chalk.red(`🚦 Initilize Project first`));
return
}

}
28 changes: 19 additions & 9 deletions util/createResource.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@

import createFile from './createFile'
import { routeTemplate, controllerTemplate } from '../templates/js'
import { existsSync } from 'fs'
import chalk from 'chalk'

export default async (appName: string, fileName: string, options: any) => {
await Promise.race(
[
createFile(appName, "controller", fileName, options, controllerTemplate(fileName)),
createFile(appName, "middleware", fileName, options),
createFile(appName, "model", fileName, options),
createFile(appName, "route", fileName, options, routeTemplate(fileName)),
// createFile(appName, "view", fileName, options),
]
)

if (existsSync(`${appName}/src`)) {
await Promise.race(
[
createFile(appName, "controller", fileName, options, controllerTemplate(fileName)),
createFile(appName, "middleware", fileName, options),
createFile(appName, "model", fileName, options),
createFile(appName, "route", fileName, options, routeTemplate(fileName)),
// createFile(appName, "view", fileName, options),
]
)
} else {
console.log(chalk.red(`🚨 FAILED Creating Resource`));
console.log(chalk.underline.cyan(`🚦 Initilize Project first`));
return
}

}


Expand Down

0 comments on commit 8b3f404

Please sign in to comment.