Skip to content

Commit ceaf2eb

Browse files
committed
feat(generators): create new app :with-postgres-typeorm
1 parent c972902 commit ceaf2eb

File tree

19 files changed

+340
-2
lines changed

19 files changed

+340
-2
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ $ yo create-service:with-mongo
7777

7878
# or :with-postgres
7979
$ yo create-service:with-postgres
80+
81+
# or :with-postgres-typeorm
82+
$ yo create-service:with-postgres-typeorm
8083
```
8184

8285
This scaffolds out:
@@ -89,10 +92,10 @@ This scaffolds out:
8992
│ ├── config
9093
│ │ ├── index.ts
9194
│ │   ├── mongo.ts (:with-mongo)
92-
│ │   └── postgres.ts (:with-postgres)
95+
│ │   └── postgres.ts (:with-postgres or :with-postgres-typeorm)
9396
│ ├── db
9497
│ │   ├── mongo.ts (:with-mongo)
95-
│ │   └── postgres.ts (:with-postgres)
98+
│ │   └── postgres.ts (:with-postgres or :with-postgres-typeorm)
9699
│ ├── app.ts
97100
│ ├── index.ts
98101
├── .dockerignore
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const Generator = require('yeoman-generator');
2+
const chalk = require('chalk');
3+
const yosay = require('yosay');
4+
const changeCase = require('change-case');
5+
6+
const pkg = require('../../package.json');
7+
8+
module.exports = class extends Generator {
9+
async prompting() {
10+
this.log(yosay(`Welcome to the ${chalk.red(pkg.name)} generator!`));
11+
12+
const appName = changeCase.paramCase(this.appname);
13+
const organizationName = await (async () => {
14+
try {
15+
const username = await this.user.github.username();
16+
17+
return username;
18+
} catch (err) {
19+
return 'organization-name';
20+
}
21+
})();
22+
const gitName = this.user.git.name() || organizationName;
23+
const gitEmail =
24+
this.user.git.email() || `my-email@${organizationName}.com`;
25+
const prompts = [
26+
{
27+
type: 'input',
28+
name: 'elementName',
29+
message: 'Name of this service?',
30+
default: appName,
31+
},
32+
{
33+
type: 'input',
34+
name: 'elementDescription',
35+
message: 'Description?',
36+
default: 'My awesome service',
37+
},
38+
{
39+
type: 'input',
40+
name: 'elementOrganizationName',
41+
message: 'GitHub organization name?',
42+
default: organizationName,
43+
},
44+
{
45+
type: 'input',
46+
name: 'elementAuthor',
47+
message: 'Author?',
48+
default: `${gitName} <${gitEmail}>`,
49+
},
50+
{
51+
type: 'input',
52+
name: 'elementNodeVersion',
53+
message: 'Supported Node version?',
54+
default: 15,
55+
},
56+
];
57+
58+
const props = await this.prompt(prompts);
59+
60+
this.props = {
61+
...props,
62+
elementName: changeCase.paramCase(props.elementName),
63+
elementOrganizationName: changeCase.paramCase(
64+
props.elementOrganizationName,
65+
),
66+
};
67+
}
68+
69+
writing() {
70+
this.fs.copyTpl(
71+
[this.templatePath('**/*'), this.templatePath('**/.*')],
72+
this.destinationPath(),
73+
this.props,
74+
);
75+
76+
this.fs.copy(
77+
this.destinationPath('.env.example'),
78+
this.destinationPath('.env'),
79+
);
80+
}
81+
82+
install() {
83+
this.yarnInstall();
84+
}
85+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
node_modules
3+
Dockerfile
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
NODE_ENV=development
2+
3+
HOST=localhost
4+
PORT=9000
5+
6+
POSTGRES_HOST=localhost
7+
POSTGRES_PORT=5432
8+
POSTGRES_DB_NAME=<%= elementName %>
9+
POSTGRES_USER=
10+
POSTGRES_PASSWORD=
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@boringcodes/eslint-config-typescript');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"hooks": {
3+
"pre-commit": "lint-staged",
4+
"pre-push": "yarn build"
5+
}
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"*.{ts,js,json,md,yml}": "yarn format",
3+
"*.ts": "yarn lint"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= elementNodeVersion %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@boringcodes/prettier-config');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Base Image GitHub https://github.com/boringcodes/dev-runner
2+
# Default WORKDIR /app
3+
# Default CMD yarn dev
4+
5+
# builder stage
6+
FROM boringcodes/dev-runner:node-<%= elementNodeVersion %>-alpine as builder
7+
COPY . .
8+
RUN yarn && yarn build && yarn purge && yarn --production
9+
10+
# runner stage
11+
FROM boringcodes/dev-runner:node-<%= elementNodeVersion %>-alpine
12+
COPY --from=builder /app/build build
13+
COPY --from=builder /app/node_modules node_modules
14+
CMD node build/index.js

0 commit comments

Comments
 (0)