Skip to content

Commit

Permalink
chore: add hygen and create a generator for core module
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman committed Jan 31, 2024
1 parent 2326785 commit 9cc42b7
Show file tree
Hide file tree
Showing 18 changed files with 517 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@types/jest": "^29.5.11",
"@types/node": "^20.10.6",
"eslint": "^8.56.0",
"hygen": "^6.2.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.0",
"prettier": "^3.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
to: src/internal/<%= moduleName %>/data/<%= h.capitalize(moduleName) %>DataSource.ts
---
export interface <%= h.capitalize(moduleName) %>DataSource {}


Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
to: src/internal/<%= moduleName %>/service/Default<%= h.capitalize(moduleName) %>Service.ts
---
import { injectable } from "inversify";
import { <%= h.capitalize(moduleName) %>Service } from "./<%= h.capitalize(moduleName) %>Service";

@injectable()
export class Default<%= h.capitalize(moduleName) %>Service implements <%= h.capitalize(moduleName) %>Service {
constructor() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
to: src/internal/<%= moduleName %>/service/Default<%= h.capitalize(moduleName) %>Service.test.ts
---
import { <%= h.capitalize(moduleName) %>Service } from "./<%= h.capitalize(moduleName) %>Service";
import { Default<%= h.capitalize(moduleName) %>Service } from "./Default<%= h.capitalize(moduleName) %>Service";

let service: <%= h.capitalize(moduleName) %>Service;
describe("<%= h.capitalize(moduleName) %>Service", () => {
beforeEach(() => {
service = new Default<%= h.capitalize(moduleName) %>Service();
});

it("should be defined", () => {
expect(service).toBeDefined();
});
});
15 changes: 15 additions & 0 deletions packages/core/_templates/core-module/with-prompt/di-module.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
to: src/internal/<%= moduleName %>/di/<%= moduleName %>Module.ts
---
import { ContainerModule } from "inversify";
import { Default<%= h.capitalize(moduleName) %>Service } from "../service/Default<%= h.capitalize(moduleName) %>Service";
import { types } from "./<%= moduleName %>Types";

type FactoryProps = {};

const <%= moduleName %>ModuleFactory = ({}: Partial<FactoryProps> = {}) =>
new ContainerModule((bind, _unbind, _isBound, _rebind, _unbindAsync, _onActivation, _onDeactivation) => {
bind(types.<%= h.capitalize(moduleName) %>Service).to(Default<%= h.capitalize(moduleName) %>Service);
});

export default <%= moduleName %>ModuleFactory;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
to: src/internal/<%= moduleName %>/di/<%= moduleName %>Module.test.ts
---
import { Container } from "inversify";
import <%= moduleName %>ModuleFactory from "./<%= moduleName %>Module";
import { types } from "./<%= moduleName %>Types";

describe("<%= moduleName %>ModuleFactory", () => {
describe("Default", () => {
let container: Container;
let mod: ReturnType<typeof <%= moduleName %>ModuleFactory>;
beforeEach(() => {
mod = <%= moduleName %>ModuleFactory();
container = new Container();
container.load(mod);
});

it("should return the config module", () => {
expect(mod).toBeDefined();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
to: src/internal/<%= moduleName %>/di/<%= moduleName %>Types.ts
---
export const types = {
<%= h.capitalize(moduleName) %>Service: Symbol.for("<%= h.capitalize(moduleName) %>Service"),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
to: src/internal/<%= moduleName %>/model/.gitkeep
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
to: src/internal/<%= moduleName %>/usecase/.gitkeep
---
10 changes: 10 additions & 0 deletions packages/core/_templates/core-module/with-prompt/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// see types of prompts:
// https://github.com/enquirer/enquirer/tree/master/examples
//
module.exports = [
{
type: "input",
name: "moduleName",
message: "What's the name of the module?",
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
to: src/internal/<%= moduleName %>/service/<%= h.capitalize(moduleName) %>Service.ts
---
export interface <%= h.capitalize(moduleName) %>Service {}
5 changes: 5 additions & 0 deletions packages/core/_templates/generator/help/index.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
message: |
hygen {bold generator new} --name [NAME] --action [ACTION]
hygen {bold generator with-prompt} --name [NAME] --action [ACTION]
---
18 changes: 18 additions & 0 deletions packages/core/_templates/generator/new/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
---
---
to: app/hello.js
---
const hello = ```
Hello!
This is your first hygen template.

Learn what it can do here:

https://github.com/jondot/hygen
```

console.log(hello)


18 changes: 18 additions & 0 deletions packages/core/_templates/generator/with-prompt/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
---
---
to: app/hello.js
---
const hello = ```
Hello!
This is your first prompt based hygen template.

Learn what it can do here:

https://github.com/jondot/hygen
```

console.log(hello)


14 changes: 14 additions & 0 deletions packages/core/_templates/generator/with-prompt/prompt.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/prompt.js
---

// see types of prompts:
// https://github.com/enquirer/enquirer/tree/master/examples
//
module.exports = [
{
type: 'input',
name: 'message',
message: "What's your message?"
}
]
4 changes: 4 additions & 0 deletions packages/core/_templates/init/repo/new-repo.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
setup: <%= name %>
force: true # this is because mostly, people init into existing folders is safe
---
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test": "jest src",
"test:watch": "pnpm test -- --watch",
"test:coverage": "pnpm test -- --coverage",
"module:init": "zx scripts/add-module.mjs"
"module:create": "pnpm hygen core-module with-prompt"
},
"dependencies": {
"inversify": "^6.0.2",
Expand Down
Loading

0 comments on commit 9cc42b7

Please sign in to comment.