@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 CHANGED
@@ -1 +1 @@
1
- [{"/Users/martin/repos/uscreen/npm/create-fastify-app/bin/cli.js":"1"},{"size":4769,"mtime":1669380908819,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","suppressedMessages":"6","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1s60doj","/Users/martin/repos/uscreen/npm/create-fastify-app/bin/cli.js",[],[]]
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 = 'module'
102
-
103
- pack.packageJson.scripts = Object.assign(pack.packageJson.scripts || {}, {
104
- start: 'pm2 start pm2-dev.config.cjs',
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uscreen.de/create-fastify-app",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "cli to create a new @uscreen.de/fastify-app",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -3,4 +3,5 @@ node_modules
3
3
  /.nyc_output
4
4
  /coverage
5
5
  .DS_Store
6
- yarn-error.log
6
+ yarn-error.log
7
+ /.eslintcache
package/skeleton/Makefile CHANGED
@@ -1,12 +1,6 @@
1
1
  start:
2
2
  yarn
3
- yarn start
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
@@ -6,11 +6,7 @@
6
6
  ## Usage
7
7
 
8
8
  * `make start`: start app on local dev
9
- * `make logs`: watch logs
10
- * `make stop`: stop app
11
9
  * `make test`: test app
12
- * `make deploy`: deploy app to stage
13
- * `make live.deploy`: deploy app to live
14
10
 
15
11
  ## Configure
16
12
 
@@ -1,8 +1,7 @@
1
- import path from 'path'
2
1
  import envSchema from 'env-schema'
3
- import { dirname } from './modules/common-esm.js'
2
+ import CommonESM from '@uscreen.de/common-esm'
4
3
 
5
- const __dirname = dirname(import.meta.url)
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`,
@@ -1,29 +1,9 @@
1
1
  import fastify from 'fastify'
2
- import hyperid from 'hyperid'
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 { name, version } = json(import.meta.url, '../package.json')
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('server ready, routes are set:\n' + server.printRoutes())
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
- process.on('SIGINT', async () => {
42
- server.log.info(`server shutting down.`)
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
@@ -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
- "hyperid": "^3.0.1"
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
- "lint-staged": "^13.0.3",
19
- "pino-pretty": "^9.1.1",
20
- "pm2": "^5.2.2",
21
- "prettier": "^2.7.1",
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
- "start": "pm2 start pm2-dev.config.cjs",
27
- "stop": "pm2 delete pm2-dev.config.cjs",
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": "c8 --reporter=text-summary tap",
33
- "deploy": "pm2 deploy pm2.config.cjs",
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
- "*.{js}": [
41
- "eslint --fix"
42
- ]
33
+ "*.js": "eslint --cache --fix"
43
34
  }
44
35
  }
@@ -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, featureSwitches = {}, ConfigOverwrite = {}) => {
17
- return new Promise((resolve, reject) => {
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
@@ -1,16 +0,0 @@
1
- const { name, main } = require('./package.json')
2
-
3
- module.exports = {
4
- apps: [
5
- {
6
- name,
7
- script: main,
8
- merge_logs: true,
9
- watch: ['app'],
10
- ignore_watch: ['.git', 'app/*.pid'],
11
- env: {
12
- NODE_ENV: 'development'
13
- }
14
- }
15
- ]
16
- }
@@ -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
- }