-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat) Add support for generating modules #73
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,103 @@ | ||
export default function ( | ||
/** @type {import('plop').NodePlopAPI} */ | ||
plop | ||
) { | ||
plop.setGenerator("basics", { | ||
description: "this is a skeleton plopfile", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "name", | ||
message: "Name your resource: ", | ||
}, | ||
], | ||
actions: [ | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/types.ts", | ||
templateFile: "templates/types.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/{{snakeCase name}}-service.ts", | ||
templateFile: "templates/service.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/{{snakeCase name}}-service-manager.ts", | ||
templateFile: "templates/service-manager.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/rest-api/{{snakeCase name}}-controller.ts", | ||
templateFile: "templates/controller.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/rest-api/{{snakeCase name}}-rest-api-server.ts", | ||
templateFile: "templates/rest-api-server.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/rest-api/{{snakeCase name}}-router.ts", | ||
templateFile: "templates/router.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/internal/{{snakeCase name}}-writer.ts", | ||
templateFile: "templates/writer.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/internal/{{snakeCase name}}-reader.ts", | ||
templateFile: "templates/reader.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/internal/{{snakeCase name}}-utils.ts", | ||
templateFile: "templates/utils.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/internal/store/{{snakeCase name}}-db.ts", | ||
templateFile: "templates/db.template.hbs", | ||
}, | ||
{ | ||
type: "add", | ||
path: "src/apps/backend/modules/{{snakeCase name}}/internal/store/{{snakeCase name}}-repository.ts", | ||
templateFile: "templates/repository.template.hbs", | ||
}, | ||
], | ||
}); | ||
|
||
plop.setHelper("titleCase", (str) => { | ||
return str.replace(/\w\S*/g, function (txt) { | ||
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); | ||
}); | ||
}); | ||
|
||
plop.setHelper("snakeCase", (str) => { | ||
return str | ||
.replace(/\W+/g, " ") | ||
.split(/ |\B(?=[A-Z])/) | ||
.map((word) => word.toLowerCase()) | ||
.join("-"); | ||
}); | ||
|
||
plop.setHelper("titleCase", (str) => { | ||
return str | ||
.replace(/\W+/g, " ") | ||
.split(/ |\B(?=[A-Z])/) | ||
.map((txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()) | ||
.join(""); | ||
}); | ||
|
||
plop.setHelper("camleCase", (str) => { | ||
const string = str | ||
.replace(/\W+/g, " ") | ||
.split(/ |\B(?=[A-Z])/) | ||
.map((txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()) | ||
.join(""); | ||
return string.charAt(0).toLowerCase() + string.substr(1) | ||
}); | ||
} |
2 changes: 2 additions & 0 deletions
2
src/apps/backend/modules/organization-account/internal/organization-account-reader.ts
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,2 @@ | ||
export default class OrganizationAccountReader { | ||
} |
2 changes: 2 additions & 0 deletions
2
src/apps/backend/modules/organization-account/internal/organization-account-utils.ts
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,2 @@ | ||
export default class OrganizationAccountUtil { | ||
} |
2 changes: 2 additions & 0 deletions
2
src/apps/backend/modules/organization-account/internal/organization-account-writer.ts
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,2 @@ | ||
export default class OrganizationAccountWriter { | ||
} |
16 changes: 16 additions & 0 deletions
16
src/apps/backend/modules/organization-account/internal/store/organization-account-db.ts
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 @@ | ||
import { Schema, Types } from 'mongoose'; | ||
|
||
export interface OrganizationAccountDB { | ||
_id: Types.ObjectId; | ||
} | ||
|
||
export const organizationAccountDbSchema: Schema = new Schema<OrganizationAccountDB>( | ||
{ | ||
}, | ||
{ | ||
timestamps: { | ||
createdAt: 'createdAt', | ||
updatedAt: 'updatedAt', | ||
}, | ||
}, | ||
); |
30 changes: 30 additions & 0 deletions
30
...ps/backend/modules/organization-account/internal/store/organization-account-repository.ts
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 @@ | ||
import mongoose, { CallbackError, Connection } from 'mongoose'; | ||
|
||
import ConfigService from '../../../config/config-service'; | ||
|
||
import { OrganizationAccountDB, organizationAccountDbSchema } from './organization-account-db'; | ||
|
||
export default class OrganizationAccountRepository { | ||
public static organizationAccountDB: mongoose.Model<OrganizationAccountDB>; | ||
|
||
static async createDBConnection(): Promise<Connection> { | ||
return new Promise((resolve, reject) => { | ||
const mongoURI = ConfigService.getStringValue('mongoDb.uri'); | ||
mongoose.createConnection( | ||
mongoURI, | ||
{}, | ||
(error: CallbackError, result: Connection): void => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
OrganizationAccountRepository.organizationAccountDB = result.model( | ||
'OrganizationAccount', | ||
organizationAccountDbSchema, | ||
) as unknown as mongoose.Model<OrganizationAccountDB>; | ||
resolve(result); | ||
} | ||
}, | ||
); | ||
}); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/apps/backend/modules/organization-account/organization-account-service-manager.ts
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 @@ | ||
import { Application } from 'express'; | ||
|
||
import OrganizationAccountRESTApiServer from './rest-api/organization-account-rest-api-server'; | ||
|
||
export default class OrganizationAccountServiceManager { | ||
public static async createRestAPIServer(): Promise<Application> { | ||
return OrganizationAccountRESTApiServer.create(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/apps/backend/modules/organization-account/organization-account-service.ts
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,2 @@ | ||
export default class OrganizationAccountService { | ||
} |
17 changes: 17 additions & 0 deletions
17
src/apps/backend/modules/organization-account/rest-api/organization-account-controller.ts
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,17 @@ | ||
import { | ||
NextFunction, Request, Response, | ||
} from 'express'; | ||
|
||
export default class OrganizationAccountController { | ||
public static createOrganizationAccount( | ||
_req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
): void { | ||
try { | ||
res.status(201).send({}); | ||
} catch (e) { | ||
next(e); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...pps/backend/modules/organization-account/rest-api/organization-account-rest-api-server.ts
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,23 @@ | ||
import bodyParser from 'body-parser'; | ||
import express, { Application } from 'express'; | ||
|
||
import ErrorHandler from '../../error/error-handler'; | ||
import OrganizationAccountRepository from '../internal/store/organization-account-repository'; | ||
|
||
import OrganizationAccountRouter from './organization-account-router'; | ||
|
||
export default class OrganizationAccountRESTApiServer { | ||
public static async create(): Promise<Application> { | ||
await OrganizationAccountRepository.createDBConnection(); | ||
|
||
const app = express(); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(bodyParser.json()); | ||
|
||
app.use('/organization account', OrganizationAccountRouter.getRoutes()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be asked as a question too - like what rest base url you want for the module? If user presses Enter you can fall back to default one. Also we are missing a hyphen |
||
|
||
app.use(ErrorHandler.AppErrorHandler); | ||
|
||
return Promise.resolve(app); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/apps/backend/modules/organization-account/rest-api/organization-account-router.ts
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,14 @@ | ||
/* eslint-disable @typescript-eslint/no-misused-promises */ | ||
import { Router } from 'express'; | ||
|
||
import OrganizationAccountController from './organization-account-controller'; | ||
|
||
export default class OrganizationAccountRouter { | ||
public static getRoutes(): Router { | ||
const router = Router(); | ||
|
||
router.post('/', OrganizationAccountController.createOrganizationAccount); | ||
|
||
return router; | ||
} | ||
} |
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,3 @@ | ||
export default class OrganizationAccount { | ||
id: string; | ||
} |
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,17 @@ | ||
import { | ||
NextFunction, Request, Response, | ||
} from 'express'; | ||
|
||
export default class {{titleCase name}}Controller { | ||
public static create{{titleCase name}}( | ||
_req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
): void { | ||
try { | ||
res.status(201).send({}); | ||
} catch (e) { | ||
next(e); | ||
} | ||
} | ||
} |
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 @@ | ||
import { Schema, Types } from 'mongoose'; | ||
|
||
export interface {{titleCase name}}DB { | ||
_id: Types.ObjectId; | ||
} | ||
|
||
export const {{camleCase name}}DbSchema: Schema = new Schema<{{titleCase name}}DB>( | ||
{ | ||
}, | ||
{ | ||
timestamps: { | ||
createdAt: 'createdAt', | ||
updatedAt: 'updatedAt', | ||
}, | ||
}, | ||
); |
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,2 @@ | ||
export default class {{titleCase name}}Reader { | ||
} |
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 @@ | ||
import mongoose, { CallbackError, Connection } from 'mongoose'; | ||
|
||
import ConfigService from '../../../config/config-service'; | ||
|
||
import { {{titleCase name}}DB, {{camleCase name}}DbSchema } from './{{snakeCase name}}-db'; | ||
|
||
export default class {{titleCase name}}Repository { | ||
public static {{camleCase name}}DB: mongoose.Model<{{titleCase name}}DB>; | ||
|
||
static async createDBConnection(): Promise<Connection> { | ||
return new Promise((resolve, reject) => { | ||
const mongoURI = ConfigService.getStringValue('mongoDb.uri'); | ||
mongoose.createConnection( | ||
mongoURI, | ||
{}, | ||
(error: CallbackError, result: Connection): void => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
{{titleCase name}}Repository.{{camleCase name}}DB = result.model( | ||
'{{titleCase name}}', | ||
{{camleCase name}}DbSchema, | ||
) as unknown as mongoose.Model<{{titleCase name}}DB>; | ||
resolve(result); | ||
} | ||
}, | ||
); | ||
}); | ||
} | ||
} |
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,23 @@ | ||
import bodyParser from 'body-parser'; | ||
import express, { Application } from 'express'; | ||
|
||
import ErrorHandler from '../../error/error-handler'; | ||
import {{titleCase name}}Repository from '../internal/store/{{snakeCase name}}-repository'; | ||
|
||
import {{titleCase name}}Router from './{{snakeCase name}}-router'; | ||
|
||
export default class {{titleCase name}}RESTApiServer { | ||
public static async create(): Promise<Application> { | ||
await {{titleCase name}}Repository.createDBConnection(); | ||
|
||
const app = express(); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(bodyParser.json()); | ||
|
||
app.use('/{{name}}', {{titleCase name}}Router.getRoutes()); | ||
|
||
app.use(ErrorHandler.AppErrorHandler); | ||
|
||
return Promise.resolve(app); | ||
} | ||
} |
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,14 @@ | ||
/* eslint-disable @typescript-eslint/no-misused-promises */ | ||
import { Router } from 'express'; | ||
|
||
import {{titleCase name}}Controller from './{{snakeCase name}}-controller'; | ||
|
||
export default class {{titleCase name}}Router { | ||
public static getRoutes(): Router { | ||
const router = Router(); | ||
|
||
router.post('/', {{titleCase name}}Controller.create{{titleCase name}}); | ||
|
||
return router; | ||
} | ||
} |
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 @@ | ||
import { Application } from 'express'; | ||
|
||
import {{titleCase name}}RESTApiServer from './rest-api/{{snakeCase name}}-rest-api-server'; | ||
|
||
export default class {{titleCase name}}ServiceManager { | ||
public static async createRestAPIServer(): Promise<Application> { | ||
return {{titleCase name}}RESTApiServer.create(); | ||
} | ||
} |
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,2 @@ | ||
export default class {{titleCase name}}Service { | ||
} |
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,3 @@ | ||
export default class {{titleCase name}} { | ||
id: string; | ||
} |
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,2 @@ | ||
export default class {{titleCase name}}Util { | ||
} |
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,2 @@ | ||
export default class {{titleCase name}}Writer { | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we use module instead of resource?