-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add generate controller and generate middleware feture
- Loading branch information
1 parent
05ddaa3
commit 1890fa2
Showing
24 changed files
with
196 additions
and
57 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { writeContent } = require("../../util/gen/mdine"); | ||
async function generateController(name) { | ||
let FileName = name.split("/").pop(); | ||
let controllerContent = fs | ||
.readFileSync( | ||
path.join(__dirname, "../../templates/controllers/controller.js") | ||
) | ||
.toString(); | ||
controllerContent = controllerContent.replaceAll( | ||
"thisisplaceholder", | ||
FileName + "Controller" | ||
); | ||
writeContent(name, controllerContent, "controllers"); | ||
} | ||
module.exports = { | ||
generateController, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { generateController } = require("./controller"); | ||
const { generatemiddleware } = require("./middleware"); | ||
|
||
let ActionsToTake = { | ||
"c":generateController, | ||
"mi":generatemiddleware | ||
} | ||
async function genInit(type,fileName){ | ||
if(ActionsToTake[type]!= undefined){ | ||
ActionsToTake[type](fileName) | ||
}else{ | ||
return console.log(`type "${type}" is not valide`); | ||
} | ||
} | ||
|
||
|
||
module.exports = { | ||
genInit | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { writeContent } = require("../../util/gen/mdine"); | ||
async function generatemiddleware(name) { | ||
let FileName = name.split("/").pop(); | ||
let middlewareContent = fs | ||
.readFileSync( | ||
path.join(__dirname, "../../templates/middlewares/middleware.js") | ||
) | ||
.toString(); | ||
middlewareContent = middlewareContent.replaceAll( | ||
"thisisplaceholder", | ||
FileName + "Middleware" | ||
); | ||
writeContent(name, middlewareContent, "middlewares"); | ||
} | ||
module.exports = { | ||
generatemiddleware, | ||
}; |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
async function MVCInit(prompt){ | ||
const questions = { | ||
type:"list", | ||
name:"viewChose", | ||
message:"chose view engine :", | ||
choices:["ejs","pug","hbs"] | ||
} | ||
let viewEngine = await prompt(questions).viewChose | ||
const { changeDependency } = require("../../util/changeDependency"); | ||
const { unzip } = require("../../util/decompress"); | ||
const {templateEngines} = require("./packges.json"); | ||
async function MVCInit(prompt) { | ||
console.log("mvc"); | ||
await unzip("MVC"); | ||
const questions = { | ||
type: "list", | ||
name: "viewChose", | ||
message: "chose view engine :", | ||
choices: ["ejs", "pug"], | ||
}; | ||
let viewEngine = await prompt(questions); | ||
viewEngine = viewEngine.viewChose; | ||
console.log(); | ||
let tm = {} | ||
tm[`${viewEngine}`] = templateEngines[`${viewEngine}`] | ||
console.log(tm); | ||
changeDependency(tm); | ||
// console.clear(); | ||
console.log("test"); | ||
} | ||
module.exports = { | ||
MVCInit | ||
MVCInit, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"pakgesDetails": { | ||
"express-session": "^1.17.3", | ||
"body-parser": "^1.20.1", | ||
"cookie-parser": "^1.4.6", | ||
"multer": "^1.4.5-lts.1", | ||
"morgan": "^1.10.0" | ||
}, | ||
"devPakgesDetails":{ | ||
"nodemon:": "^2.0.20" | ||
}, | ||
"templateEngines":{ | ||
"ejs":"^3.1.8", | ||
"pug":"^3.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
#!/usr/bin/env node | ||
const { Command } = require("commander"); | ||
const { genInit } = require("./commands/gen/gen"); | ||
const { newGen } = require("./commands/new/new"); | ||
|
||
const program = new Command(); | ||
|
||
program | ||
.name("string-util") | ||
.description("CLI to some JavaScript string utilities") | ||
.version("0.0.1"); | ||
.name("exp-cli") | ||
.description("CLI tool to make your express project more fun") | ||
.version("0.0.7"); | ||
|
||
program | ||
.command("new") | ||
.description("generate new express application") | ||
.argument("<string>", "project name") | ||
.action(async (str) => { | ||
newGen(str) | ||
newGen(str); | ||
}); | ||
|
||
program | ||
.command("gen") | ||
.description("generate new express application") | ||
.argument("<string>", "project name") | ||
.action(async (str) => { | ||
await unzip(); | ||
changePjName(str); | ||
.argument("<type>", "project name") | ||
.argument("<filename>", "name of generated file") | ||
.action(async (type, filename) => { | ||
await genInit(type, filename); | ||
}); | ||
|
||
program.parse(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function thisisplaceholder(req, res) { | ||
res.send("this is thisisplaceholder"); | ||
} | ||
export default thisisplaceholder; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function thisisplaceholder(req, res, next) { | ||
res.send("this is thisisplaceholder"); | ||
next(); | ||
} | ||
export default thisisplaceholder; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
let jsTypeorm = ` | ||
var EntitySchema = require("typeorm").EntitySchema | ||
module.exports = new EntitySchema({ | ||
name: "thisiplaceHolder", | ||
tableName: "thisiplaceHolder", | ||
columns: { | ||
id: { | ||
primary: true, | ||
type: "int", | ||
generated: true, | ||
}, | ||
}, | ||
}) | ||
` | ||
|
||
let tsTypeorm = ` | ||
import { Entity, PrimaryGeneratedColumn } from "typeorm" | ||
@Entity() | ||
export class thisiplaceHolder { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
} | ||
` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
function writeContent (name,content,place) { | ||
let theArray = name.split("/") | ||
let FileName = theArray.pop() | ||
let DirectoryName = theArray.join("/") | ||
let FilePth = path.join(process.cwd(),place,DirectoryName,FileName+".controller.js") | ||
if (!fs.existsSync(path.join(process.cwd(),place,DirectoryName))){ | ||
fs.mkdirSync(path.join(process.cwd(),place,DirectoryName), { recursive: true }); | ||
} | ||
fs.writeFileSync(FilePth,content,{ | ||
flag:"a" | ||
}) | ||
console.log("create !"); | ||
} | ||
|
||
module.exports = { | ||
writeContent | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
function setViewEngine(name){ | ||
let data = fs.readFileSync(path.join(process.cwd(),"main.js")) | ||
console.log(data); | ||
} | ||
module.exports = { | ||
setViewEngine | ||
}; |