@uscreen.de/create-fastify-app 1.0.2 → 1.1.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/.eslintcache +1 -1
- package/README.md +17 -0
- package/bin/cli.js +4 -19
- package/package.json +1 -1
- package/skeleton/.gitignore +2 -1
- package/skeleton/Makefile +1 -19
- package/skeleton/README.md +0 -4
- package/skeleton/app/config.js +3 -7
- package/skeleton/app/server.js +13 -26
- package/skeleton/package.json +12 -21
- package/skeleton/test/helper.js +2 -6
- package/skeleton/app/modules/common-esm.js +0 -17
- package/skeleton/pm2-dev.config.cjs +0 -16
- package/skeleton/pm2.config.cjs +0 -29
package/.eslintcache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"/Users/
|
|
1
|
+
[{"/Users/marcus/Sites/npm-uscreen/repos/create-fastify-app/bin/cli.js":"1"},{"size":4235,"mtime":1669742140487,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","suppressedMessages":"6","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"8tgkqw","/Users/marcus/Sites/npm-uscreen/repos/create-fastify-app/bin/cli.js",[],[]]
|
package/README.md
CHANGED
|
@@ -68,6 +68,23 @@ $ make logs
|
|
|
68
68
|
|
|
69
69
|
## Changelog
|
|
70
70
|
|
|
71
|
+
### 1.1.0
|
|
72
|
+
|
|
73
|
+
#### Changed
|
|
74
|
+
|
|
75
|
+
- migrated yorkie to husky
|
|
76
|
+
- cleanup app.js and server.js
|
|
77
|
+
|
|
78
|
+
#### Added
|
|
79
|
+
|
|
80
|
+
- uses @uscreen.de/common-esm for esm migration
|
|
81
|
+
- uses @uscreen.de/fastify-app options for app creation
|
|
82
|
+
- uses nodemon for dev mode
|
|
83
|
+
|
|
84
|
+
#### Removed
|
|
85
|
+
|
|
86
|
+
- dropped pm2 package and config
|
|
87
|
+
|
|
71
88
|
### 1.0.0
|
|
72
89
|
|
|
73
90
|
#### Changed
|
package/bin/cli.js
CHANGED
|
@@ -98,25 +98,10 @@ const addPackageConfig = (path, skelPath) => {
|
|
|
98
98
|
delete pack.packageJson.readme
|
|
99
99
|
|
|
100
100
|
pack.packageJson.main = skelPack.packageJson.main
|
|
101
|
-
pack.packageJson.type =
|
|
102
|
-
|
|
103
|
-
pack.packageJson
|
|
104
|
-
|
|
105
|
-
stop: 'pm2 delete pm2-dev.config.cjs',
|
|
106
|
-
logs: `pm2 logs ${pack.packageJson.name} --raw | pino-pretty -t`,
|
|
107
|
-
lint: "eslint '**/*.js' --fix",
|
|
108
|
-
test: 'tap test/**/*.test.js',
|
|
109
|
-
'test:cov': 'tap --coverage-report=html test/**/*.test.js',
|
|
110
|
-
'test:ci': 'tap --coverage-report=text-summary test/**/*.test.js',
|
|
111
|
-
deploy: 'pm2 deploy pm2.config.cjs',
|
|
112
|
-
postdeploy: 'pm2 reload pm2.config.cjs'
|
|
113
|
-
})
|
|
114
|
-
pack.packageJson.gitHooks = {
|
|
115
|
-
'pre-commit': 'lint-staged'
|
|
116
|
-
}
|
|
117
|
-
pack.packageJson['lint-staged'] = {
|
|
118
|
-
'*.{js}': ['eslint --fix', 'git add']
|
|
119
|
-
}
|
|
101
|
+
pack.packageJson.type = skelPack.packageJson.type
|
|
102
|
+
pack.packageJson.scripts = skelPack.packageJson.scripts
|
|
103
|
+
pack.packageJson['lint-staged'] = skelPack.packageJson['lint-staged']
|
|
104
|
+
|
|
120
105
|
return writePackage(pack.path, pack.packageJson)
|
|
121
106
|
}
|
|
122
107
|
|
package/package.json
CHANGED
package/skeleton/.gitignore
CHANGED
package/skeleton/Makefile
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
start:
|
|
2
2
|
yarn
|
|
3
|
-
yarn
|
|
4
|
-
|
|
5
|
-
stop:
|
|
6
|
-
yarn stop
|
|
7
|
-
|
|
8
|
-
logs:
|
|
9
|
-
yarn logs
|
|
3
|
+
yarn dev
|
|
10
4
|
|
|
11
5
|
test:
|
|
12
6
|
yarn test
|
|
@@ -14,16 +8,4 @@ test:
|
|
|
14
8
|
test.coverage:
|
|
15
9
|
yarn test:cov
|
|
16
10
|
|
|
17
|
-
deploy:
|
|
18
|
-
yarn deploy stage
|
|
19
|
-
|
|
20
|
-
deploy.setup:
|
|
21
|
-
yarn deploy stage setup
|
|
22
|
-
|
|
23
|
-
live.deploy:
|
|
24
|
-
yarn deploy live
|
|
25
|
-
|
|
26
|
-
live.deploy.setup:
|
|
27
|
-
yarn deploy live setup
|
|
28
|
-
|
|
29
11
|
.PHONY: test
|
package/skeleton/README.md
CHANGED
package/skeleton/app/config.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
1
|
import envSchema from 'env-schema'
|
|
3
|
-
import
|
|
2
|
+
import CommonESM from '@uscreen.de/common-esm'
|
|
4
3
|
|
|
5
|
-
const
|
|
4
|
+
const { join } = new CommonESM(import.meta.url)
|
|
6
5
|
|
|
7
6
|
const schema = {
|
|
8
7
|
type: 'object',
|
|
@@ -20,10 +19,7 @@ const config = envSchema({
|
|
|
20
19
|
dotenv: true
|
|
21
20
|
})
|
|
22
21
|
|
|
23
|
-
config.autoloads = [
|
|
24
|
-
path.join(__dirname, 'plugins'),
|
|
25
|
-
path.join(__dirname, 'services')
|
|
26
|
-
]
|
|
22
|
+
config.autoloads = [join('plugins'), join('services')]
|
|
27
23
|
|
|
28
24
|
config.swagger = {
|
|
29
25
|
routePrefix: `${config.prefix}/docs`,
|
package/skeleton/app/server.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
import fastify from 'fastify'
|
|
2
|
-
import
|
|
2
|
+
import { options } from '@uscreen.de/fastify-app'
|
|
3
3
|
import config from './config.js'
|
|
4
4
|
import app from './app.js'
|
|
5
|
-
import { json } from './modules/common-esm.js'
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const instance = hyperid({ urlSafe: true })
|
|
10
|
-
|
|
11
|
-
const server = fastify({
|
|
12
|
-
genReqId() {
|
|
13
|
-
return instance()
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
logger: config.logEnabled
|
|
17
|
-
? {
|
|
18
|
-
level: config.logLevel,
|
|
19
|
-
name: `${name} (v${version}) ${process.env.NODE_APP_INSTANCE}`,
|
|
20
|
-
redact: {
|
|
21
|
-
paths: ['pattern'], // limit hemeras verbosity
|
|
22
|
-
remove: true
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
: false
|
|
26
|
-
})
|
|
6
|
+
const server = fastify(options(config))
|
|
27
7
|
|
|
28
8
|
server.register(app, config)
|
|
29
9
|
|
|
@@ -32,17 +12,24 @@ server.register(app, config)
|
|
|
32
12
|
*/
|
|
33
13
|
server.ready((err) => {
|
|
34
14
|
if (err) throw err
|
|
35
|
-
server.log.debug(
|
|
15
|
+
server.log.debug(
|
|
16
|
+
'server ready, routes are set:\n' +
|
|
17
|
+
server.printRoutes({ commonPrefix: false })
|
|
18
|
+
)
|
|
36
19
|
})
|
|
37
20
|
|
|
38
21
|
/**
|
|
39
22
|
* graceful shutdown (closing handles, etc.)
|
|
40
23
|
*/
|
|
41
|
-
|
|
42
|
-
server.log.info(
|
|
24
|
+
const shutdown = async () => {
|
|
25
|
+
server.log.info(
|
|
26
|
+
`application shutting down. (${server.app.name} ${server.app.version})`
|
|
27
|
+
)
|
|
43
28
|
await server.close()
|
|
44
29
|
process.exit()
|
|
45
|
-
}
|
|
30
|
+
}
|
|
31
|
+
process.on('SIGINT', shutdown)
|
|
32
|
+
process.on('SIGTERM', shutdown)
|
|
46
33
|
|
|
47
34
|
/**
|
|
48
35
|
* start http server
|
package/skeleton/package.json
CHANGED
|
@@ -4,41 +4,32 @@
|
|
|
4
4
|
"main": "app/server.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
+
"@uscreen.de/common-esm": "^1.0.0",
|
|
7
8
|
"@uscreen.de/fastify-app": "^1.0.0-0",
|
|
8
|
-
"desm": "^1.3.0",
|
|
9
9
|
"env-schema": "^5.1.1",
|
|
10
10
|
"fastify": "^4.10.2",
|
|
11
11
|
"fastify-plugin": "^4.3.0",
|
|
12
12
|
"fluent-json-schema": "^4.0.0",
|
|
13
|
-
"
|
|
13
|
+
"pino-pretty": "^9.1.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@uscreen.de/eslint-config-prettystandard-node": "^0.2.8",
|
|
17
17
|
"c8": "^7.12.0",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"prettier": "^2.
|
|
22
|
-
"tap": "^16.3.2"
|
|
23
|
-
"yorkie": "^2.0.0"
|
|
18
|
+
"husky": ">=6",
|
|
19
|
+
"lint-staged": ">=10",
|
|
20
|
+
"nodemon": "^2.0.20",
|
|
21
|
+
"prettier": "^2.8.0",
|
|
22
|
+
"tap": "^16.3.2"
|
|
24
23
|
},
|
|
25
24
|
"scripts": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"logs": "pm2 logs new-fastify-app --raw | pino-pretty -t",
|
|
29
|
-
"lint": "eslint '**/*.js' --fix",
|
|
25
|
+
"dev": "nodemon",
|
|
26
|
+
"lint": "eslint --fix",
|
|
30
27
|
"test": "c8 tap",
|
|
31
28
|
"test:cov": "c8 --reporter=html --reporter=text tap",
|
|
32
|
-
"test:ci": "
|
|
33
|
-
"
|
|
34
|
-
"postdeploy": "pm2 reload pm2.config.cjs"
|
|
35
|
-
},
|
|
36
|
-
"gitHooks": {
|
|
37
|
-
"pre-commit": "lint-staged"
|
|
29
|
+
"test:ci": "tap",
|
|
30
|
+
"prepare": "husky install"
|
|
38
31
|
},
|
|
39
32
|
"lint-staged": {
|
|
40
|
-
"*.
|
|
41
|
-
"eslint --fix"
|
|
42
|
-
]
|
|
33
|
+
"*.js": "eslint --cache --fix"
|
|
43
34
|
}
|
|
44
35
|
}
|
package/skeleton/test/helper.js
CHANGED
|
@@ -8,13 +8,9 @@ import fp from 'fastify-plugin'
|
|
|
8
8
|
import App from '../app/app.js'
|
|
9
9
|
import Config from '../app/config.js'
|
|
10
10
|
|
|
11
|
-
// overwrite some config option(s) on tests
|
|
12
|
-
Config.hemeralogLevel = 'fatal'
|
|
13
|
-
Config.hemeraNS = `test-${process.env.TAP_CHILD_ID}`
|
|
14
|
-
|
|
15
11
|
// automatically build and tear down our instance
|
|
16
|
-
export const build = async (t,
|
|
17
|
-
return new Promise((resolve
|
|
12
|
+
export const build = async (t, ConfigOverwrite = {}) => {
|
|
13
|
+
return new Promise((resolve) => {
|
|
18
14
|
const app = Fastify()
|
|
19
15
|
|
|
20
16
|
// setup to register YOUR app
|
|
@@ -1,17 +0,0 @@
|
|
|
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/pm2.config.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const { name, main, repository } = require('./package.json')
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
apps: [
|
|
5
|
-
{
|
|
6
|
-
name,
|
|
7
|
-
script: main,
|
|
8
|
-
merge_logs: true,
|
|
9
|
-
ignore_watch: ['.git', 'app/*.pid'],
|
|
10
|
-
env: {
|
|
11
|
-
NODE_ENV: 'production'
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
],
|
|
15
|
-
deploy: {
|
|
16
|
-
stage: {
|
|
17
|
-
user: 'user',
|
|
18
|
-
host: 'server-stage.example.com',
|
|
19
|
-
ref: 'origin/master',
|
|
20
|
-
repo: repository.url || repository,
|
|
21
|
-
path: `/home/user/${name}`,
|
|
22
|
-
'pre-setup': 'yarn add pm2 pino-pretty;',
|
|
23
|
-
'post-setup':
|
|
24
|
-
'cp ./.env.example ../shared/.env; ln -s ../shared/.env ./.env',
|
|
25
|
-
'post-deploy':
|
|
26
|
-
'yarn install --production; ~/node_modules/.bin/pm2 reload pm2.config.cjs'
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|