Skip to content

Commit 08ed491

Browse files
committed
feat(generators): create new app with-postgres
1 parent 9896214 commit 08ed491

File tree

18 files changed

+348
-0
lines changed

18 files changed

+348
-0
lines changed

generators/with-postgres/index.js

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
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "<%= elementName %>",
3+
"version": "0.0.0",
4+
"description": "<%= elementDescription %>",
5+
"homepage": "https://github.com/<%= elementOrganizationName %>/<%= elementName %>",
6+
"bugs": "https://github.com/<%= elementOrganizationName %>/<%= elementName %>/issues",
7+
"license": "MIT",
8+
"author": "<%- elementAuthor %>",
9+
"repository": "https://github.com/<%= elementOrganizationName %>/<%= elementName %>.git",
10+
"engines": {
11+
"node": ">=<%= elementNodeVersion %>"
12+
},
13+
"scripts": {
14+
"dev": "backpack dev",
15+
"prebuild": "yarn clean",
16+
"build": "backpack build",
17+
"start": "cross-env NODE_ENV=production node build/index.js",
18+
"purge": "rimraf node_modules",
19+
"clean": "rimraf build",
20+
"format": "prettier --write --ignore-path .gitignore .",
21+
"format:check": "prettier --check --ignore-path .gitignore .",
22+
"lint": "eslint --quiet --ignore-path .gitignore --ext .ts .",
23+
"release": "standard-version",
24+
"release:major": "yarn release --release-as major",
25+
"release:minor": "yarn release --release-as minor",
26+
"release:patch": "yarn release --release-as patch"
27+
},
28+
"dependencies": {
29+
"@boringcodes/utils": "*",
30+
"body-parser": "*",
31+
"cross-env": "*",
32+
"express": "*",
33+
"http-status-codes": "*",
34+
"morgan": "*",
35+
"pg": "*",
36+
"sequelize": "*",
37+
"source-map-support": "*",
38+
"yup": "*"
39+
},
40+
"devDependencies": {
41+
"@boringcodes/backpack": "*",
42+
"@boringcodes/eslint-config-typescript": "*",
43+
"@boringcodes/prettier-config": "*",
44+
"@types/express": "*",
45+
"@types/morgan": "*",
46+
"@types/yup": "*",
47+
"@typescript-eslint/eslint-plugin": "*",
48+
"@typescript-eslint/parser": "*",
49+
"eslint": "*",
50+
"eslint-config-prettier": "*",
51+
"eslint-config-standard-with-typescript": "*",
52+
"eslint-plugin-import": "*",
53+
"eslint-plugin-node": "*",
54+
"eslint-plugin-promise": "*",
55+
"eslint-plugin-standard": "*",
56+
"husky": "*",
57+
"lint-staged": "*",
58+
"prettier": "*",
59+
"rimraf": "*",
60+
"standard-version": "*",
61+
"typescript": "*"
62+
}
63+
}

0 commit comments

Comments
 (0)