@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 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 prerequisits than node and yarn. Features include:
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 General you should be able to start your new app in dev mode, like so:
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.7.1",
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.0",
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.1",
25
+ "husky": ">=8.0.2",
26
26
  "lint-staged": ">=13.0.3"
27
27
  },
28
28
  "lint-staged": {
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "@uscreen.de/eslint-config-prettystandard-node"
3
+ }
package/skeleton/.taprc CHANGED
@@ -1,3 +1,7 @@
1
1
  {
2
- "reporter": "spec"
3
- }
2
+ "timeout": 10,
3
+ "reporter": "spec",
4
+ "check-coverage": false,
5
+ "no-coverage": true,
6
+ "test-regex": "\\w+\\.test\\.js$"
7
+ }
@@ -1,10 +1,8 @@
1
- 'use strict'
1
+ import fastifyApp from '@uscreen.de/fastify-app'
2
+ import fp from 'fastify-plugin'
3
+ import schemas from './schemas.js'
2
4
 
3
- const fastifyApp = require('@uscreen.de/fastify-app')
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
  */
@@ -1,7 +1,8 @@
1
- 'use strict'
1
+ import path from 'path'
2
+ import envSchema from 'env-schema'
3
+ import { dirname } from './modules/common-esm.js'
2
4
 
3
- const path = require('path')
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
- module.exports = config
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
@@ -1,8 +1,6 @@
1
- 'use strict'
1
+ import fp from 'fastify-plugin'
2
2
 
3
- const fp = require('fastify-plugin')
4
-
5
- module.exports = fp(
3
+ export default fp(
6
4
  (fastify, opts, next) => {
7
5
  fastify.decorate('noop', () => {
8
6
  return 'Hello Universe'
@@ -1,13 +1,11 @@
1
- 'use strict'
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
- module.exports = fp((fastify, opts, next) => {
8
+ export default fp((fastify, opts, next) => {
11
9
  const addSchema = (schema) => {
12
10
  fastify.addSchema(schema)
13
11
  return schema
@@ -1,10 +1,10 @@
1
- 'use strict'
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 fastify = require('fastify')
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 })
@@ -1,6 +1,4 @@
1
- 'use strict'
2
-
3
- module.exports = (fastify, opts, next) => {
1
+ export default (fastify, opts, next) => {
4
2
  fastify.get(
5
3
  '/noop',
6
4
  {
@@ -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.8.9",
7
- "env-schema": "^5.0.0",
8
- "fastify": "^3.29.1",
9
- "fastify-plugin": "^3.0.1",
10
- "fluent-json-schema": "^3.1.0",
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.0",
17
- "pm2": "^5.2.0",
19
+ "pino-pretty": "^9.1.1",
20
+ "pm2": "^5.2.2",
18
21
  "prettier": "^2.7.1",
19
- "tap": "^16.3.0",
22
+ "tap": "^16.3.2",
20
23
  "yorkie": "^2.0.0"
21
24
  },
22
25
  "scripts": {
23
- "start": "pm2 start pm2-dev.config.js",
24
- "stop": "pm2 delete pm2-dev.config.js",
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 test/**/*.test.js",
28
- "test:cov": "tap --coverage-report=html test/**/*.test.js",
29
- "test:ci": "tap --coverage-report=text-summary test/**/*.test.js",
30
- "deploy": "pm2 deploy pm2.config.js",
31
- "postdeploy": "pm2 reload pm2.config.js"
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"
@@ -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.js'
26
+ 'yarn install --production; ~/node_modules/.bin/pm2 reload pm2.config.cjs'
27
27
  }
28
28
  }
29
29
  }
@@ -1,5 +1,5 @@
1
- const tap = require('tap')
2
- const { build } = require('../helper')
1
+ import tap from 'tap'
2
+ import { build } from '../helper.js'
3
3
 
4
4
  tap.test('Test Setup', (t) => {
5
5
  t.equal(true, true, 'Tests and assertions should work')
@@ -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
- const Fastify = require('fastify')
7
- const fp = require('fastify-plugin')
4
+ import Fastify from 'fastify'
5
+ import fp from 'fastify-plugin'
8
6
 
9
- // setup to require YOUR app
10
- const App = require('../app/app')
11
- const Config = require('../app/config')
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))
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- extends: ['@uscreen.de/eslint-config-prettystandard-node']
3
- }