Skip to content

Commit a0335e4

Browse files
authored
Merge pull request #44 from HSLdevcom/feature/66224-integrate-prettier
feat(66224): integrate prettier autoformatter
2 parents 76fd13d + 05cb76a commit a0335e4

File tree

10 files changed

+341
-34
lines changed

10 files changed

+341
-34
lines changed

.github/workflows/ci-cd.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: "CI/CD: Continuous integration and continuous deployment"
3+
on: [pull_request]
4+
permissions:
5+
contents: read
6+
7+
jobs:
8+
build-check:
9+
name: 'Build & check format'
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Install Node
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: "lts/*"
19+
cache: "npm"
20+
21+
- name: Install NPM dependencies
22+
run: yarn install --frozen-lockfile
23+
24+
- name: Check code formatting
25+
run: yarn run format:check

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
.env
2+
.env
3+
.idea/

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
build
4+
coverage

.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"printWidth": 95,
5+
"arrowParens": "always",
6+
"bracketSpacing": true,
7+
"trailingComma": "es5",
8+
"tabWidth": 2
9+
}

PgNumericToFloatPlugin.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@
1111
* arbitrary precision numbers such as NUMERIC because loss of precision can
1212
* occur.
1313
*/
14-
module.exports = function PgNumericToFloatPlugin(
15-
builder
16-
) {
17-
builder.hook("build", build => {
14+
module.exports = function PgNumericToFloatPlugin(builder) {
15+
builder.hook('build', (build) => {
1816
// Register a type handler for NUMERIC / DECIMAL (oid = 1700), always
1917
// returning the GraphQLFloat type
20-
build.pgRegisterGqlTypeByTypeId(
21-
"1700",
22-
() => build.graphql.GraphQLFloat
23-
);
24-
return build;
25-
});
26-
};
18+
build.pgRegisterGqlTypeByTypeId('1700', () => build.graphql.GraphQLFloat)
19+
return build
20+
})
21+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Prerequisites
44

55
Start a postgis docker container:
6+
67
```
78
docker run --name jore-postgis -e POSTGRES_PASSWORD=mysecretpassword -d mdillon/postgis
89
```
@@ -12,13 +13,15 @@ Import data using [jore-graphql-import](https://github.com/HSLdevcom/jore-graphq
1213
### Install
1314

1415
Build the container:
16+
1517
```
1618
docker build -t hsldevcom/jore-graphql .
1719
```
1820

1921
### Run
2022

2123
Start the server:
24+
2225
```
2326
docker run --link jore-postgis -e "PG_CONNECTION_STRING=postgres://postgres:mysecretpassword@jore-postgis:5432/postgres" -d -p 0.0.0.0:5000:5000 hsldevcom/jore-graphql
2427
```

constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ module.exports = {
33
DB_JORE_SCHEMA: process.env.DB_JORE_SCHEMA || 'jore',
44
SERVICE_PATH_PREFIX: (process.env.SERVICE_PATH_PREFIX || '').replace(/\/$/, ''), // Remove trailing slash if accidentally given.
55
PORT: process.env.PORT || 5000,
6-
};
6+
}

index.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1-
const http = require('http');
2-
const { postgraphile } = require('postgraphile');
3-
const numericPlugin = require('./PgNumericToFloatPlugin');
4-
const { PG_CONNECTION_STRING, DB_JORE_SCHEMA, SERVICE_PATH_PREFIX, PORT } = require('./constants');
1+
const http = require('http')
2+
const { postgraphile } = require('postgraphile')
3+
const numericPlugin = require('./PgNumericToFloatPlugin')
4+
const {
5+
PG_CONNECTION_STRING,
6+
DB_JORE_SCHEMA,
7+
SERVICE_PATH_PREFIX,
8+
PORT,
9+
} = require('./constants')
510

6-
if (!PG_CONNECTION_STRING) throw new Error("Missing required env PG_CONNECTION_STRING")
11+
if (!PG_CONNECTION_STRING) throw new Error('Missing required env PG_CONNECTION_STRING')
712

8-
http.createServer(postgraphile(PG_CONNECTION_STRING, DB_JORE_SCHEMA, {
9-
disableDefaultMutations: true,
10-
dynamicJson: true,
11-
enableCors: true,
12-
externalUrlBase: SERVICE_PATH_PREFIX,
13-
graphiql: true,
14-
host: '0.0.0.0',
15-
retryOnInitFail: true,
16-
timeout: 36000000,
17-
disableQueryLog: true,
18-
appendPlugins: [ numericPlugin ]
19-
})).listen(PORT, () => {
20-
console.log('JORE GraphQL listening on port ' + PORT)
21-
});
13+
http
14+
.createServer(
15+
postgraphile(PG_CONNECTION_STRING, DB_JORE_SCHEMA, {
16+
disableDefaultMutations: true,
17+
dynamicJson: true,
18+
enableCors: true,
19+
externalUrlBase: SERVICE_PATH_PREFIX,
20+
graphiql: true,
21+
host: '0.0.0.0',
22+
retryOnInitFail: true,
23+
timeout: 36000000,
24+
disableQueryLog: true,
25+
appendPlugins: [numericPlugin],
26+
})
27+
)
28+
.listen(PORT, () => {
29+
console.log('JORE GraphQL listening on port ' + PORT)
30+
})

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,28 @@
66
"license": "MIT",
77
"scripts": {
88
"start": "node -r dotenv/config index.js",
9-
"start:production": "node index.js"
9+
"start:production": "node index.js",
10+
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,json,css,md}\"",
11+
"format:check": "prettier --check \"**/*.{ts,tsx,js,jsx,json,css,md}\""
1012
},
1113
"dependencies": {
1214
"postgraphile": "^4.14.1"
1315
},
1416
"devDependencies": {
15-
"dotenv": "^17.2.1"
17+
"dotenv": "^17.2.1",
18+
"husky": "^9.1.7",
19+
"lint-staged": "^16.2.3",
20+
"prettier": "^3.6.2"
21+
},
22+
"lint-staged": {
23+
"*.{ts,js}": [
24+
"prettier --write",
25+
"git add"
26+
]
27+
},
28+
"husky": {
29+
"hooks": {
30+
"pre-commit": "lint-staged"
31+
}
1632
}
1733
}

0 commit comments

Comments
 (0)