@uscreen.de/create-fastify-app 0.7.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/package.json +3 -3
- package/skeleton/.eslintrc +3 -0
- package/skeleton/.taprc +6 -2
- package/skeleton/app/app.js +4 -6
- package/skeleton/app/config.js +5 -4
- package/skeleton/app/modules/common-esm.js +17 -0
- package/skeleton/app/plugins/noop.js +2 -4
- package/skeleton/app/schemas.js +3 -5
- package/skeleton/app/server.js +7 -7
- package/skeleton/app/services/noop.js +1 -3
- package/skeleton/package.json +18 -15
- package/skeleton/{pm2-dev.config.js → pm2-dev.config.cjs} +0 -0
- package/skeleton/{pm2.config.js → pm2.config.cjs} +1 -1
- package/skeleton/test/app/noop.test.js +2 -2
- package/skeleton/test/helper.js +7 -14
- package/skeleton/.eslintrc.js +0 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> cli to quickly bootstrap a new fastify-app
|
|
4
4
|
|
|
5
|
-
This package provides the cli skript to create a new `@uscreen.de/fastify-app` from scratch. No need to install any other
|
|
5
|
+
This package provides the cli skript to create a new `@uscreen.de/fastify-app` from scratch. No need to install any other prerequisites than node and yarn. Features include:
|
|
6
6
|
|
|
7
7
|
* initialize new __git__ repository
|
|
8
8
|
* initialize new __yarn__ package.json
|
|
@@ -49,7 +49,7 @@ new-app
|
|
|
49
49
|
|
|
50
50
|
More Details can be found in `@uscreen.de/fastify-app` [README](https://www.npmjs.com/package/@uscreen.de/fastify-app)
|
|
51
51
|
|
|
52
|
-
After creation has finished cd into the new apps directory and check it's README for options. In
|
|
52
|
+
After creation has finished cd into the new apps directory and check it's README for options. In general you should be able to start your new app in dev mode, like so:
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
55
|
$ cd ./new-app
|
|
@@ -68,6 +68,13 @@ $ make logs
|
|
|
68
68
|
|
|
69
69
|
## Changelog
|
|
70
70
|
|
|
71
|
+
### 1.0.0
|
|
72
|
+
|
|
73
|
+
#### Changed
|
|
74
|
+
|
|
75
|
+
- switch skeleton to __ESM only__
|
|
76
|
+
- upgrade skeleton to fastify@4.x
|
|
77
|
+
|
|
71
78
|
### v0.7.0
|
|
72
79
|
|
|
73
80
|
- added: graceful shutdown in skeleton
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uscreen.de/create-fastify-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "cli to create a new @uscreen.de/fastify-app",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"prepare": "husky install"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"commander": "^9.4.
|
|
18
|
+
"commander": "^9.4.1",
|
|
19
19
|
"fs-extra": "^10.0.1",
|
|
20
20
|
"read-pkg-up": "^9.1.0",
|
|
21
21
|
"write-pkg": "^5.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@uscreen.de/eslint-config-prettystandard-node": "^0.2.10",
|
|
25
|
-
"husky": ">=8.0.
|
|
25
|
+
"husky": ">=8.0.2",
|
|
26
26
|
"lint-staged": ">=13.0.3"
|
|
27
27
|
},
|
|
28
28
|
"lint-staged": {
|
package/skeleton/.taprc
CHANGED
package/skeleton/app/app.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import fastifyApp from '@uscreen.de/fastify-app'
|
|
2
|
+
import fp from 'fastify-plugin'
|
|
3
|
+
import schemas from './schemas.js'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
const fp = require('fastify-plugin')
|
|
5
|
-
const schemas = require('./schemas')
|
|
6
|
-
|
|
7
|
-
module.exports = fp((fastify, opts, next) => {
|
|
5
|
+
export default fp((fastify, opts, next) => {
|
|
8
6
|
/**
|
|
9
7
|
* add schemas
|
|
10
8
|
*/
|
package/skeleton/app/config.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import envSchema from 'env-schema'
|
|
3
|
+
import { dirname } from './modules/common-esm.js'
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const envSchema = require('env-schema')
|
|
5
|
+
const __dirname = dirname(import.meta.url)
|
|
5
6
|
|
|
6
7
|
const schema = {
|
|
7
8
|
type: 'object',
|
|
@@ -34,4 +35,4 @@ config.health = {
|
|
|
34
35
|
exposeStatusRoute: `${config.prefix}/health`
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
export default config
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { readFileSync } from 'fs'
|
|
2
|
+
import desm, { dirname, filename, join } from 'desm'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* like const { name } = require('./package.json')
|
|
6
|
+
*/
|
|
7
|
+
const json = (metaUrl, file) => JSON.parse(readFileSync(join(metaUrl, file)))
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* like if (!module.parent)
|
|
11
|
+
*/
|
|
12
|
+
const isMain = (metaUrl) =>
|
|
13
|
+
filename(metaUrl) === process.argv[1] ||
|
|
14
|
+
filename(metaUrl) === process.env.pm_exec_path
|
|
15
|
+
|
|
16
|
+
export { dirname, filename, join, json, isMain }
|
|
17
|
+
export default desm
|
package/skeleton/app/schemas.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const fp = require('fastify-plugin')
|
|
4
|
-
const S = require('fluent-json-schema')
|
|
1
|
+
import fp from 'fastify-plugin'
|
|
2
|
+
import S from 'fluent-json-schema'
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Usage of the Globaly Shared Schema feature
|
|
8
6
|
*/
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
export default fp((fastify, opts, next) => {
|
|
11
9
|
const addSchema = (schema) => {
|
|
12
10
|
fastify.addSchema(schema)
|
|
13
11
|
return schema
|
package/skeleton/app/server.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import fastify from 'fastify'
|
|
2
|
+
import hyperid from 'hyperid'
|
|
3
|
+
import config from './config.js'
|
|
4
|
+
import app from './app.js'
|
|
5
|
+
import { json } from './modules/common-esm.js'
|
|
2
6
|
|
|
3
|
-
const
|
|
4
|
-
const hyperid = require('hyperid')
|
|
5
|
-
const { name, version } = require('../package.json')
|
|
6
|
-
const config = require('./config')
|
|
7
|
-
const app = require('./app')
|
|
7
|
+
const { name, version } = json(import.meta.url, '../package.json')
|
|
8
8
|
|
|
9
9
|
const instance = hyperid({ urlSafe: true })
|
|
10
10
|
|
|
@@ -47,4 +47,4 @@ process.on('SIGINT', async () => {
|
|
|
47
47
|
/**
|
|
48
48
|
* start http server
|
|
49
49
|
*/
|
|
50
|
-
server.listen(config.httpPort, config.httpBind)
|
|
50
|
+
server.listen({ port: config.httpPort, host: config.httpBind })
|
package/skeleton/package.json
CHANGED
|
@@ -2,33 +2,36 @@
|
|
|
2
2
|
"name": "new-fastify-app",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"main": "app/server.js",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"dependencies": {
|
|
6
|
-
"@uscreen.de/fastify-app": "^0.
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"fastify
|
|
10
|
-
"
|
|
7
|
+
"@uscreen.de/fastify-app": "^1.0.0-0",
|
|
8
|
+
"desm": "^1.3.0",
|
|
9
|
+
"env-schema": "^5.1.1",
|
|
10
|
+
"fastify": "^4.10.2",
|
|
11
|
+
"fastify-plugin": "^4.3.0",
|
|
12
|
+
"fluent-json-schema": "^4.0.0",
|
|
11
13
|
"hyperid": "^3.0.1"
|
|
12
14
|
},
|
|
13
15
|
"devDependencies": {
|
|
14
16
|
"@uscreen.de/eslint-config-prettystandard-node": "^0.2.8",
|
|
17
|
+
"c8": "^7.12.0",
|
|
15
18
|
"lint-staged": "^13.0.3",
|
|
16
|
-
"pino-pretty": "^9.1.
|
|
17
|
-
"pm2": "^5.2.
|
|
19
|
+
"pino-pretty": "^9.1.1",
|
|
20
|
+
"pm2": "^5.2.2",
|
|
18
21
|
"prettier": "^2.7.1",
|
|
19
|
-
"tap": "^16.3.
|
|
22
|
+
"tap": "^16.3.2",
|
|
20
23
|
"yorkie": "^2.0.0"
|
|
21
24
|
},
|
|
22
25
|
"scripts": {
|
|
23
|
-
"start": "pm2 start pm2-dev.config.
|
|
24
|
-
"stop": "pm2 delete pm2-dev.config.
|
|
26
|
+
"start": "pm2 start pm2-dev.config.cjs",
|
|
27
|
+
"stop": "pm2 delete pm2-dev.config.cjs",
|
|
25
28
|
"logs": "pm2 logs new-fastify-app --raw | pino-pretty -t",
|
|
26
29
|
"lint": "eslint '**/*.js' --fix",
|
|
27
|
-
"test": "tap
|
|
28
|
-
"test:cov": "
|
|
29
|
-
"test:ci": "
|
|
30
|
-
"deploy": "pm2 deploy pm2.config.
|
|
31
|
-
"postdeploy": "pm2 reload pm2.config.
|
|
30
|
+
"test": "c8 tap",
|
|
31
|
+
"test:cov": "c8 --reporter=html --reporter=text tap",
|
|
32
|
+
"test:ci": "c8 --reporter=text-summary tap",
|
|
33
|
+
"deploy": "pm2 deploy pm2.config.cjs",
|
|
34
|
+
"postdeploy": "pm2 reload pm2.config.cjs"
|
|
32
35
|
},
|
|
33
36
|
"gitHooks": {
|
|
34
37
|
"pre-commit": "lint-staged"
|
|
File without changes
|
|
@@ -23,7 +23,7 @@ module.exports = {
|
|
|
23
23
|
'post-setup':
|
|
24
24
|
'cp ./.env.example ../shared/.env; ln -s ../shared/.env ./.env',
|
|
25
25
|
'post-deploy':
|
|
26
|
-
'yarn install --production; ~/node_modules/.bin/pm2 reload pm2.config.
|
|
26
|
+
'yarn install --production; ~/node_modules/.bin/pm2 reload pm2.config.cjs'
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
package/skeleton/test/helper.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
// This file contains code that we reuse
|
|
4
2
|
// between our tests.
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import Fastify from 'fastify'
|
|
5
|
+
import fp from 'fastify-plugin'
|
|
8
6
|
|
|
9
|
-
// setup to
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
// setup to import YOUR app
|
|
8
|
+
import App from '../app/app.js'
|
|
9
|
+
import Config from '../app/config.js'
|
|
12
10
|
|
|
13
11
|
// overwrite some config option(s) on tests
|
|
14
12
|
Config.hemeralogLevel = 'fatal'
|
|
15
13
|
Config.hemeraNS = `test-${process.env.TAP_CHILD_ID}`
|
|
16
14
|
|
|
17
15
|
// automatically build and tear down our instance
|
|
18
|
-
const build = async (t, featureSwitches = {}, ConfigOverwrite = {}) => {
|
|
16
|
+
export const build = async (t, featureSwitches = {}, ConfigOverwrite = {}) => {
|
|
19
17
|
return new Promise((resolve, reject) => {
|
|
20
18
|
const app = Fastify()
|
|
21
19
|
|
|
@@ -32,9 +30,4 @@ const build = async (t, featureSwitches = {}, ConfigOverwrite = {}) => {
|
|
|
32
30
|
})
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
36
|
-
|
|
37
|
-
module.exports = {
|
|
38
|
-
build,
|
|
39
|
-
wait
|
|
40
|
-
}
|
|
33
|
+
export const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
package/skeleton/.eslintrc.js
DELETED