Skip to content

Commit 9c601e1

Browse files
committed
server: add github workflows and pre-commit hooks
1 parent 7f564f6 commit 9c601e1

File tree

16 files changed

+135
-52
lines changed

16 files changed

+135
-52
lines changed

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"tabWidth": 2,
44
"semi": true,
55
"singleQuote": true,
6-
"quoteProps": "as-needed",
6+
"quoteProps": "preserve",
77
"trailingComma": "none",
88
"bracketSpacing": true,
99
"arrowParens": "always",

lib/server.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ const information = {
77
projectUrl: 'Url for project repository',
88
authorName: 'Author name',
99
authorEmail: 'Author email',
10-
keywords: 'Key words devided by comma'
10+
keywords: 'Key words devided by comma',
11+
preCommit: 'Add pre-commit hooks?(Need git repository before install packages.)(y/n)',
12+
ciAction: 'Add github ci workflow?(Enter pull_request target branch or nothing for cancel)'
1113
};
1214

15+
const preCommit = `"pre-commit": "^1.2.2"
16+
},
17+
18+
"pre-commit": [
19+
"prettier",
20+
"lint",
21+
"test"
22+
]`;
23+
1324
const files = {
1425
'package.json': [
1526
'projectName',
@@ -20,11 +31,20 @@ const files = {
2031
{
2132
name: 'keywords',
2233
convert: (value) => `${value.split(',').join('",\n\t\t"')}`
34+
},
35+
{
36+
name: 'preCommit',
37+
convert: (value) => {
38+
if(value === 'y' || value === 'yes' ) {
39+
return preCommit;
40+
} else {
41+
return `}`
42+
}
43+
}
2344
}
2445
],
2546
'README.md': ['projectName', 'projectDescription'],
2647
'nodemon.json': [],
27-
LICENSE: [],
2848
'docker-compose.yml': [],
2949
'.prettierrc.json': [],
3050
'.prettierignore': [],
@@ -34,11 +54,18 @@ const files = {
3454
'.editorconfig': [],
3555
'src/index.js': [],
3656
'src/modules/index.js': [],
37-
'db/structure.sql': []
57+
'db/structure.sql': [],
58+
'test/unit/.gitkeep': [],
59+
'test/integration/.gitkeep': []
3860
};
3961

4062
const createServer = async (directory) => {
4163
const values = await askInformation(information);
64+
65+
if (values['ciAction']) {
66+
files['.github/workflows/ci.yml'] = ['ciAction'];
67+
}
68+
4269
createFiles(path.resolve(directory, values.projectName), path.resolve(__dirname, 'server'), files, values);
4370
};
4471

lib/server/.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
node_modules
22
db
3-
pgdata
3+
test
44
.editorconfig
55
.prettierignore
66
.eslintrc

lib/server/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
}
129129
],
130130
"arrow-parens": ["error", "always"],
131-
"arrow-body-style": ["error", "as-needed"],
131+
"arrow-body-style": ["off"],
132132
"arrow-spacing": ["error"],
133133
"no-useless-rename": ["error"],
134134
"no-var": ["error"],

lib/server/.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- edited
7+
- reopened
8+
- closed
9+
- synchronize
10+
- converted_to_draft
11+
- ready_for_review
12+
- locked
13+
- unlocked
14+
- review_requested
15+
- review_request
16+
branches: [$ciAction$]
17+
workflow_dispatch:
18+
jobs:
19+
test-and-lint:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
- name: Use Node.js 16
24+
uses: actions/setup-node@v1
25+
with:
26+
node-version: '16'
27+
- name: Install dependencies
28+
run: npm i
29+
- name: Linter
30+
run: npm run lint
31+
- name: Unit tests
32+
run: npm run test
33+
- name: Start database container
34+
run: npm run docker
35+
- name: Install forever for starting server
36+
run: npm install -g forever
37+
- name: Start server
38+
run: PGHOST=localhost PGUSER=test_user PGDATABASE=test_db PGPASSWORD=test_password PGPORT=5432 forever start ./src/index.js
39+
- name: Integration tests
40+
run: npm run integration
41+
- name: Stop server
42+
run: forever stopall

lib/server/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
node_modules
2-
pgdata

lib/server/.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
.github
12
node_modules
23
db
3-
pgdata
44
.editorconfig
55
.eslintignore
66
.eslintrc

lib/server/.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"tabWidth": 2,
44
"semi": true,
55
"singleQuote": true,
6-
"quoteProps": "as-needed",
6+
"quoteProps": "preserve",
77
"trailingComma": "none",
88
"bracketSpacing": true,
99
"arrowParens": "always",

lib/server/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/server/db/structure.sql

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,29 @@ CREATE OR REPLACE FUNCTION CURRENT_SYSTEM_TIME() RETURNS timestamp without time
1010
SELECT CURRENT_TIMESTAMP AT TIME ZONE ( SELECT "timezone" FROM "SystemSettings" );
1111
$$;
1212

13+
CREATE TABLE "Role"(
14+
"name" text NOT NULL
15+
);
16+
17+
ALTER TABLE "Role" ADD CONSTRAINT "pkRole" PRIMARY KEY ( "name" );
18+
INSERT INTO "Role"(name) VALUES ('user');
19+
1320
CREATE TABLE "SystemUser"(
14-
"username" varchar( 128 ) NOT NULL,
15-
"password" varchar( 255 ) NOT NULL,
16-
"role" varchar( 32 ) NOT NULL,
17-
"createdTime" timestamp(2) DEFAULT CURRENT_SYSTEM_TIME()
21+
"username" char( 11 ) NOT NULL,
22+
"password" text NOT NULL,
23+
"role" text NOT NULL,
24+
"createdTime" timestamp(3) DEFAULT CURRENT_SYSTEM_TIME()
1825
);
26+
1927
ALTER TABLE "SystemUser" ADD CONSTRAINT "pkSystemUser" PRIMARY KEY ( "username" );
28+
ALTER TABLE "SystemUser" ADD CONSTRAINT "fkSystemUserRoleName" FOREIGN KEY ( "role" ) REFERENCES "Role"( "name" ) ON DELETE CASCADE;
2029

2130
CREATE TABLE "Session"(
22-
"username" varchar( 128 ) NOT NULL,
23-
"token" varchar( 64 ) NOT NULL,
24-
"createdTime" timestamp(2) DEFAULT CURRENT_SYSTEM_TIME()
31+
"username" char( 11 ) NOT NULL,
32+
"token" uuid NOT NULL,
33+
"createdTime" timestamp(3) DEFAULT CURRENT_SYSTEM_TIME()
2534
);
35+
2636
ALTER TABLE "Session" ADD CONSTRAINT "pkSession" PRIMARY KEY ( "token" );
2737
ALTER TABLE "Session" ADD CONSTRAINT "fkSessionUserUsername" FOREIGN KEY ( "username" ) REFERENCES "SystemUser"( "username" ) ON DELETE CASCADE;
2838

0 commit comments

Comments
 (0)