@uscreen.de/create-fastify-app 1.1.3 → 2.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/.eslintcache +1 -1
- package/.github/workflows/main.yml +12 -6
- package/.gitignore +1 -2
- package/.yarnrc +2 -0
- package/README.md +29 -20
- package/bin/cli.js +9 -43
- package/package.json +12 -19
- package/skeleton/.gitignore +0 -1
- package/skeleton/README.md +7 -7
- package/skeleton/app/config.js +2 -2
- package/skeleton/app/server.js +9 -5
- package/skeleton/app/services/noop.js +1 -1
- package/skeleton/package.json +15 -25
- package/skeleton/test/app/noop.test.js +27 -22
- package/skeleton/test/helper.js +7 -3
- package/test/cli.test.js +25 -52
- package/test/setup.js +1 -1
- package/.husky/.gitignore +0 -1
- package/.husky/_/.gitignore +0 -1
- package/.husky/pre-commit +0 -4
- package/skeleton/.editorconfig +0 -13
- package/skeleton/.envrc +0 -4
- package/skeleton/.eslintrc +0 -3
- package/skeleton/.gitlab-ci.yml.example +0 -25
- package/skeleton/.nvmrc +0 -1
- package/skeleton/.taprc +0 -7
- package/skeleton/Makefile +0 -11
package/.eslintcache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"/Users/martin/repos/uscreen/npm/create-fastify-app/bin/cli.js":"1"
|
|
1
|
+
[{"/Users/martin/repos/uscreen/npm/create-fastify-app/bin/cli.js":"1"},{"size":3451,"mtime":1744123221597,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","suppressedMessages":"6","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1cjo6f4","/Users/martin/repos/uscreen/npm/create-fastify-app/bin/cli.js",[],[]]
|
|
@@ -14,22 +14,28 @@ jobs:
|
|
|
14
14
|
runs-on: ubuntu-latest
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
node-version: [18, 20]
|
|
17
|
+
node-version: [18, 20, 22]
|
|
18
18
|
steps:
|
|
19
19
|
- name: Checkout code
|
|
20
|
-
uses: actions/checkout@
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Install pnpm
|
|
23
|
+
uses: pnpm/action-setup@v4
|
|
24
|
+
with:
|
|
25
|
+
version: 9
|
|
26
|
+
run_install: false
|
|
21
27
|
|
|
22
28
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
23
|
-
uses: actions/setup-node@
|
|
29
|
+
uses: actions/setup-node@v4
|
|
24
30
|
with:
|
|
25
31
|
node-version: ${{ matrix.node-version }}
|
|
26
|
-
cache: "
|
|
32
|
+
cache: "pnpm"
|
|
27
33
|
|
|
28
34
|
- name: Install packages
|
|
29
|
-
run:
|
|
35
|
+
run: pnpm install
|
|
30
36
|
|
|
31
37
|
- name: Run tests
|
|
32
|
-
run:
|
|
38
|
+
run: pnpm run test:ci
|
|
33
39
|
|
|
34
40
|
- name: Coveralls
|
|
35
41
|
uses: coverallsapp/github-action@master
|
package/.gitignore
CHANGED
package/.yarnrc
ADDED
package/README.md
CHANGED
|
@@ -7,30 +7,29 @@
|
|
|
7
7
|
|
|
8
8
|
> cli to quickly bootstrap a new fastify-app
|
|
9
9
|
|
|
10
|
-
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
|
|
10
|
+
This package provides the cli skript to create a new `@uscreen.de/fastify-app` from scratch inside of a monorepo. No need to install any other prerequisites than node and pnpm. Features include:
|
|
11
11
|
|
|
12
|
-
* initialize new
|
|
13
|
-
* initialize new __yarn__ package.json
|
|
14
|
-
* install all __dependencies__ and __devDependencies__
|
|
15
|
-
* add __skripts__ and __hooks__ to package.json
|
|
12
|
+
* initialize new package.json
|
|
16
13
|
* setup __application skeleton__
|
|
17
|
-
* setup __dotfiles__
|
|
14
|
+
* setup __dotfiles__
|
|
18
15
|
* setup __.env__ for starting
|
|
19
16
|
|
|
20
17
|
## Usage
|
|
21
18
|
|
|
22
|
-
Use `
|
|
19
|
+
Use `pnpm create` to create a new fastify-app, like so:
|
|
23
20
|
|
|
24
21
|
```bash
|
|
25
|
-
$
|
|
22
|
+
$ pnpm create @uscreen.de/fastify-app new-app
|
|
26
23
|
```
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
Inside that directory, it will generate the initial project structure
|
|
25
|
+
It will create a directory called `new-app` inside the current folder.
|
|
26
|
+
Inside that directory, it will generate the initial project structure:
|
|
30
27
|
|
|
31
28
|
```bash
|
|
32
29
|
new-app
|
|
33
|
-
├──
|
|
30
|
+
├── .env
|
|
31
|
+
├── .env.example
|
|
32
|
+
├── .gitignore
|
|
34
33
|
├── README.md
|
|
35
34
|
├── app
|
|
36
35
|
│ ├── app.js
|
|
@@ -42,15 +41,13 @@ new-app
|
|
|
42
41
|
│ └── services
|
|
43
42
|
│ └── noop.js
|
|
44
43
|
├── package.json
|
|
45
|
-
|
|
46
|
-
├──
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
│ └── noop.test.js
|
|
50
|
-
└── yarn.lock
|
|
44
|
+
└── test
|
|
45
|
+
├── app
|
|
46
|
+
│ └── noop.test.js
|
|
47
|
+
└── helper.js
|
|
51
48
|
```
|
|
52
49
|
|
|
53
|
-
`
|
|
50
|
+
`pnpm create` will update itself and checkout the latest version of the boilerplate packed with lot's of best-practice settings and prepared for local dev.
|
|
54
51
|
|
|
55
52
|
More Details can be found in `@uscreen.de/fastify-app` [README](https://www.npmjs.com/package/@uscreen.de/fastify-app)
|
|
56
53
|
|
|
@@ -58,8 +55,8 @@ After creation has finished cd into the new apps directory and check it's README
|
|
|
58
55
|
|
|
59
56
|
```bash
|
|
60
57
|
$ cd ./new-app
|
|
61
|
-
$
|
|
62
|
-
$
|
|
58
|
+
$ pnpm install
|
|
59
|
+
$ pnpm dev
|
|
63
60
|
```
|
|
64
61
|
|
|
65
62
|
---
|
|
@@ -73,6 +70,18 @@ $ make logs
|
|
|
73
70
|
|
|
74
71
|
## Changelog
|
|
75
72
|
|
|
73
|
+
### 2.0.0
|
|
74
|
+
|
|
75
|
+
#### Changed
|
|
76
|
+
|
|
77
|
+
- changed skeleton & creation process so it's suitable for use in a monorepo
|
|
78
|
+
- upgraded skeleton to fastify@5
|
|
79
|
+
- use pnpm instead of yarn
|
|
80
|
+
|
|
81
|
+
#### Removed
|
|
82
|
+
|
|
83
|
+
- `-y` option (it is default now)
|
|
84
|
+
|
|
76
85
|
### 1.1.2
|
|
77
86
|
|
|
78
87
|
#### Changed
|
package/bin/cli.js
CHANGED
|
@@ -20,57 +20,26 @@ let root
|
|
|
20
20
|
let skeleton
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* ensure path of new app
|
|
24
24
|
*/
|
|
25
|
-
const
|
|
26
|
-
new Promise((resolve, reject) => {
|
|
27
|
-
const git = spawn('git', ['init', path])
|
|
28
|
-
git.stdout.on('data', (data) => process.stdout.write(data))
|
|
29
|
-
git.stderr.on('data', (data) => process.stderr.write(data))
|
|
30
|
-
git.on('close', (code) => {
|
|
31
|
-
if (code === 0) return resolve(code)
|
|
32
|
-
/* c8 ignore next */
|
|
33
|
-
reject(code)
|
|
34
|
-
})
|
|
35
|
-
})
|
|
25
|
+
const ensurePath = (path) => fs.ensureDir(path)
|
|
36
26
|
|
|
37
27
|
/**
|
|
38
|
-
* init new
|
|
28
|
+
* init new pnpm project
|
|
39
29
|
*/
|
|
40
|
-
const
|
|
30
|
+
const initializePnpm = (path) =>
|
|
41
31
|
new Promise((resolve, reject) => {
|
|
42
|
-
const
|
|
43
|
-
if (yes) params.push('-y')
|
|
44
|
-
|
|
45
|
-
const yarn = spawn('yarn', params, {
|
|
32
|
+
const pnpm = spawn('pnpm', ['init'], {
|
|
46
33
|
cwd: path,
|
|
47
34
|
stdio: [0, 1, 2]
|
|
48
35
|
})
|
|
49
|
-
|
|
36
|
+
pnpm.on('close', (code) => {
|
|
50
37
|
if (code === 0) return resolve(code)
|
|
51
38
|
/* c8 ignore next */
|
|
52
39
|
reject(code)
|
|
53
40
|
})
|
|
54
41
|
})
|
|
55
42
|
|
|
56
|
-
/**
|
|
57
|
-
* install packages
|
|
58
|
-
*/
|
|
59
|
-
const installPackages = (appPath) => {
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
61
|
-
const yarn = spawn('yarn', ['install'], {
|
|
62
|
-
cwd: appPath
|
|
63
|
-
})
|
|
64
|
-
yarn.stdout.on('data', (data) => process.stdout.write(data))
|
|
65
|
-
yarn.stderr.on('data', (data) => process.stderr.write(data))
|
|
66
|
-
yarn.on('close', (code) => {
|
|
67
|
-
if (code === 0) return resolve(code)
|
|
68
|
-
/* c8 ignore next */
|
|
69
|
-
reject(code)
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
43
|
/**
|
|
75
44
|
* configure package.json to use linting, testing, stuff
|
|
76
45
|
*/
|
|
@@ -83,7 +52,6 @@ const addPackageConfig = (path, skelPath) => {
|
|
|
83
52
|
pack.packageJson.main = skelPack.packageJson.main
|
|
84
53
|
pack.packageJson.type = skelPack.packageJson.type
|
|
85
54
|
pack.packageJson.scripts = skelPack.packageJson.scripts
|
|
86
|
-
pack.packageJson['lint-staged'] = skelPack.packageJson['lint-staged']
|
|
87
55
|
|
|
88
56
|
pack.packageJson.dependencies = skelPack.packageJson.dependencies
|
|
89
57
|
pack.packageJson.devDependencies = skelPack.packageJson.devDependencies
|
|
@@ -117,8 +85,7 @@ const copyEnv = (appPath, skelPath) => {
|
|
|
117
85
|
program
|
|
118
86
|
.version(version)
|
|
119
87
|
.arguments('<name>')
|
|
120
|
-
.
|
|
121
|
-
.action(async (name, opt) => {
|
|
88
|
+
.action(async (name) => {
|
|
122
89
|
/**
|
|
123
90
|
* the root directory of new project
|
|
124
91
|
*/
|
|
@@ -132,10 +99,9 @@ program
|
|
|
132
99
|
/**
|
|
133
100
|
* setup new app
|
|
134
101
|
*/
|
|
135
|
-
await
|
|
136
|
-
await
|
|
102
|
+
await ensurePath(root)
|
|
103
|
+
await initializePnpm(root)
|
|
137
104
|
await addPackageConfig(root, skeleton)
|
|
138
|
-
await installPackages(root)
|
|
139
105
|
await copySkeleton(root, skeleton)
|
|
140
106
|
await copyEnv(root, skeleton)
|
|
141
107
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uscreen.de/create-fastify-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "cli to create a new @uscreen.de/fastify-app",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,28 +14,21 @@
|
|
|
14
14
|
"bin": {
|
|
15
15
|
"create-fastify-app": "./bin/cli.js"
|
|
16
16
|
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"test": "c8 tap",
|
|
19
|
-
"test:cov": "c8 --reporter=html --reporter=text tap",
|
|
20
|
-
"test:ci": "c8 --reporter=lcovonly tap",
|
|
21
|
-
"lint": "eslint --fix",
|
|
22
|
-
"prepare": "husky install"
|
|
23
|
-
},
|
|
24
17
|
"dependencies": {
|
|
25
18
|
"commander": "^11.0.0",
|
|
26
19
|
"fs-extra": "^11.1.0",
|
|
27
|
-
"read-pkg-up": "^
|
|
28
|
-
"write-pkg": "^
|
|
20
|
+
"read-pkg-up": "^11.0.0",
|
|
21
|
+
"write-pkg": "^7.0.0"
|
|
29
22
|
},
|
|
30
23
|
"devDependencies": {
|
|
31
|
-
"@uscreen.de/eslint-config-prettystandard-node": "^0.2.
|
|
32
|
-
"c8": "^
|
|
33
|
-
"
|
|
34
|
-
"lint-staged": ">=13.0.3",
|
|
35
|
-
"strip-ansi": "^7.0.1",
|
|
36
|
-
"tap": "^16.3.4"
|
|
24
|
+
"@uscreen.de/eslint-config-prettystandard-node": "^0.2.12",
|
|
25
|
+
"c8": "^10.1.2",
|
|
26
|
+
"strip-ansi": "^7.0.1"
|
|
37
27
|
},
|
|
38
|
-
"
|
|
39
|
-
"
|
|
28
|
+
"scripts": {
|
|
29
|
+
"lint": "eslint --fix",
|
|
30
|
+
"test": "node --test --test-reporter spec ./test",
|
|
31
|
+
"test:cov": "c8 --reporter=html --reporter=text node --test ./test",
|
|
32
|
+
"test:ci": "find ./test -name '*.test.js' | xargs c8 --reporter=lcov --reporter=text -- node --test"
|
|
40
33
|
}
|
|
41
|
-
}
|
|
34
|
+
}
|
package/skeleton/.gitignore
CHANGED
package/skeleton/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# ${app-name}
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> **TODO:**
|
|
4
4
|
> add a name & short description of this apps purpose
|
|
5
5
|
|
|
6
6
|
## Usage
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
- `make start`: start app on local dev
|
|
9
|
+
- `make test`: test app
|
|
10
10
|
|
|
11
11
|
## Configure
|
|
12
12
|
|
|
13
|
-
Configuration is read by dotenv from `app/.env` file and validated _[optional modified]_ by `app/config.js`. Please add extra defaults if needed to `config.js`. Default values should
|
|
13
|
+
Configuration is read by dotenv from `app/.env` file and validated _[optional modified]_ by `app/config.js`. Please add extra defaults if needed to `config.js`. Default values should **always** refer to local dev setups.
|
|
14
14
|
|
|
15
|
-
>
|
|
16
|
-
> the `.env` file should
|
|
15
|
+
> **Note:**
|
|
16
|
+
> the `.env` file should **never** get pushed to repository. So adding secrets and credentials to `.env` can be considered a secure option bound to specific environments.
|
|
17
17
|
|
|
18
18
|
## Api
|
|
19
19
|
|
|
@@ -29,7 +29,7 @@ After starting your server you will find swagger documenation at [http://127.0.0
|
|
|
29
29
|
|
|
30
30
|
### v0.0.0
|
|
31
31
|
|
|
32
|
-
- initially bootstrapped by `
|
|
32
|
+
- initially bootstrapped by `pnpm create @uscreen.de/fastify-app`
|
|
33
33
|
|
|
34
34
|
---
|
|
35
35
|
|
package/skeleton/app/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import envSchema from 'env-schema'
|
|
2
1
|
import CommonESM from '@uscreen.de/common-esm'
|
|
2
|
+
import envSchema from 'env-schema'
|
|
3
3
|
|
|
4
4
|
const { join } = new CommonESM(import.meta.url)
|
|
5
5
|
|
|
@@ -15,7 +15,7 @@ const schema = {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const config = envSchema({
|
|
18
|
-
schema
|
|
18
|
+
schema,
|
|
19
19
|
dotenv: true
|
|
20
20
|
})
|
|
21
21
|
|
package/skeleton/app/server.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import process from 'node:process'
|
|
2
2
|
import { options } from '@uscreen.de/fastify-app'
|
|
3
|
-
import
|
|
3
|
+
import fastify from 'fastify'
|
|
4
4
|
import app from './app.js'
|
|
5
5
|
|
|
6
|
+
import config from './config.js'
|
|
7
|
+
|
|
6
8
|
const server = fastify(options(config))
|
|
7
9
|
|
|
8
10
|
server.register(app, config)
|
|
@@ -11,10 +13,12 @@ server.register(app, config)
|
|
|
11
13
|
* post-treatment
|
|
12
14
|
*/
|
|
13
15
|
server.ready((err) => {
|
|
14
|
-
if (err)
|
|
16
|
+
if (err) {
|
|
17
|
+
throw err
|
|
18
|
+
}
|
|
15
19
|
server.log.debug(
|
|
16
|
-
|
|
17
|
-
server.printRoutes({ commonPrefix: false })
|
|
20
|
+
`server ready, routes are set:\n${
|
|
21
|
+
server.printRoutes({ commonPrefix: false })}`
|
|
18
22
|
)
|
|
19
23
|
})
|
|
20
24
|
|
package/skeleton/package.json
CHANGED
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "new-fastify-app",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"version": "0.0.0",
|
|
4
5
|
"main": "app/server.js",
|
|
5
|
-
"
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "nodemon",
|
|
8
|
+
"test": "node --test --test-reporter spec",
|
|
9
|
+
"test:cov": "c8 --reporter=html --reporter=text node --test",
|
|
10
|
+
"test:ci": "node --test"
|
|
11
|
+
},
|
|
6
12
|
"dependencies": {
|
|
13
|
+
"@fastify/one-line-logger": "^2.0.0",
|
|
7
14
|
"@uscreen.de/common-esm": "^1.0.0",
|
|
8
|
-
"@uscreen.de/fastify-app": "^
|
|
9
|
-
"env-schema": "^
|
|
10
|
-
"fastify": "^
|
|
11
|
-
"fastify-plugin": "^
|
|
12
|
-
"fluent-json-schema": "^
|
|
13
|
-
"pino-pretty": "^9.1.1"
|
|
15
|
+
"@uscreen.de/fastify-app": "^3.0.0",
|
|
16
|
+
"env-schema": "^6.0.0",
|
|
17
|
+
"fastify": "^5.0.0",
|
|
18
|
+
"fastify-plugin": "^5.0.0",
|
|
19
|
+
"fluent-json-schema": "^5.0.0"
|
|
14
20
|
},
|
|
15
21
|
"devDependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"husky": ">=6",
|
|
19
|
-
"lint-staged": ">=10",
|
|
20
|
-
"nodemon": "^2.0.20",
|
|
21
|
-
"prettier": "^2.8.0",
|
|
22
|
-
"tap": "^16.3.2"
|
|
23
|
-
},
|
|
24
|
-
"scripts": {
|
|
25
|
-
"dev": "nodemon",
|
|
26
|
-
"lint": "eslint --fix",
|
|
27
|
-
"test": "c8 tap",
|
|
28
|
-
"test:cov": "c8 --reporter=html --reporter=text tap",
|
|
29
|
-
"test:ci": "tap",
|
|
30
|
-
"prepare": "husky install"
|
|
31
|
-
},
|
|
32
|
-
"lint-staged": {
|
|
33
|
-
"*.js": "eslint --cache --fix"
|
|
22
|
+
"c8": "^10.0.0",
|
|
23
|
+
"nodemon": "^3.0.0"
|
|
34
24
|
}
|
|
35
25
|
}
|
|
@@ -1,45 +1,50 @@
|
|
|
1
|
-
import
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import test from 'node:test'
|
|
2
3
|
import { build } from '../helper.js'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
test('Test Setup', (t, done) => {
|
|
6
|
+
assert.equal(true, true, 'Tests and assertions should work')
|
|
7
|
+
done()
|
|
7
8
|
})
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const { prefix } =
|
|
10
|
+
test('Healthcheck', async (t) => {
|
|
11
|
+
const app = await build(t)
|
|
12
|
+
const { prefix } = app.config
|
|
12
13
|
|
|
13
|
-
t.test('a valid GET Request', (t) => {
|
|
14
|
-
|
|
14
|
+
t.test('a valid GET Request', (t, done) => {
|
|
15
|
+
app.inject(
|
|
15
16
|
{
|
|
16
17
|
method: 'GET',
|
|
17
18
|
url: `${prefix}/health`
|
|
18
19
|
},
|
|
19
20
|
(e, response) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
assert.ok(!e)
|
|
22
|
+
assert.equal(response.statusCode, 200, 'response ok')
|
|
23
|
+
assert.deepEqual(
|
|
24
|
+
JSON.parse(response.body),
|
|
25
|
+
{ status: 'ok' },
|
|
26
|
+
'payload ok'
|
|
27
|
+
)
|
|
28
|
+
done()
|
|
24
29
|
}
|
|
25
30
|
)
|
|
26
31
|
})
|
|
27
32
|
})
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const { prefix } =
|
|
34
|
+
test('Noop Service', async (t) => {
|
|
35
|
+
const app = await build(t)
|
|
36
|
+
const { prefix } = app.config
|
|
32
37
|
|
|
33
|
-
t.test('a valid GET Request', (t) => {
|
|
34
|
-
|
|
38
|
+
t.test('a valid GET Request', (t, done) => {
|
|
39
|
+
app.inject(
|
|
35
40
|
{
|
|
36
41
|
method: 'GET',
|
|
37
42
|
url: `${prefix}/noop`
|
|
38
43
|
},
|
|
39
44
|
(e, response) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
assert.ok(!e)
|
|
46
|
+
assert.equal(response.statusCode, 200, 'response ok')
|
|
47
|
+
assert.deepEqual(
|
|
43
48
|
JSON.parse(response.body),
|
|
44
49
|
{
|
|
45
50
|
noop: 'Hello world',
|
|
@@ -47,7 +52,7 @@ tap.test('Noop Service', async (t) => {
|
|
|
47
52
|
},
|
|
48
53
|
'payload ok'
|
|
49
54
|
)
|
|
50
|
-
|
|
55
|
+
done()
|
|
51
56
|
}
|
|
52
57
|
)
|
|
53
58
|
})
|
package/skeleton/test/helper.js
CHANGED
|
@@ -17,13 +17,17 @@ export const build = async (t, ConfigOverwrite = {}) => {
|
|
|
17
17
|
app.register(fp(App), { ...Config, ...ConfigOverwrite })
|
|
18
18
|
|
|
19
19
|
// tear down our app after we are done
|
|
20
|
-
t.
|
|
20
|
+
t.after(async () => {
|
|
21
|
+
await app.close()
|
|
22
|
+
})
|
|
21
23
|
|
|
22
24
|
app.ready((err) => {
|
|
23
|
-
if (err)
|
|
25
|
+
if (err) {
|
|
26
|
+
throw err
|
|
27
|
+
}
|
|
24
28
|
resolve(app)
|
|
25
29
|
})
|
|
26
30
|
})
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
export const wait =
|
|
33
|
+
export const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
|
package/test/cli.test.js
CHANGED
|
@@ -1,109 +1,82 @@
|
|
|
1
|
-
import
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
import fs from 'fs-extra'
|
|
3
4
|
import path from 'path'
|
|
4
5
|
import { createRequire } from 'module'
|
|
5
6
|
import stripAnsi from 'strip-ansi'
|
|
6
|
-
import { before,
|
|
7
|
+
import { before, after, cli, cwd } from './setup.js'
|
|
7
8
|
|
|
8
9
|
const require = createRequire(import.meta.url)
|
|
9
10
|
const { version } = require('../package.json')
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
test.before(before)
|
|
13
|
+
test.after(after)
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
test('`$ cli` should print error message', async (t) => {
|
|
15
16
|
const result = await cli([])
|
|
16
|
-
|
|
17
|
+
assert.equal(
|
|
17
18
|
true,
|
|
18
19
|
result.stderr.startsWith("error: missing required argument 'name'"),
|
|
19
20
|
'Should print error message'
|
|
20
21
|
)
|
|
21
|
-
|
|
22
|
-
t.end()
|
|
23
22
|
})
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
test('`$ cli -V` should show correct version', async (t) => {
|
|
26
25
|
const result = await cli(['--version'])
|
|
27
|
-
|
|
28
|
-
true,
|
|
29
|
-
result.stdout.startsWith(version),
|
|
30
|
-
'Should show correct version'
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
t.end()
|
|
26
|
+
assert.equal(true, result.stdout.startsWith(version))
|
|
34
27
|
})
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
const result = await cli(['new-app'
|
|
38
|
-
|
|
29
|
+
test('`$ cli new-app` should succeed', async (t) => {
|
|
30
|
+
const result = await cli(['new-app'])
|
|
39
31
|
/**
|
|
40
32
|
* check output
|
|
41
33
|
*/
|
|
42
|
-
|
|
34
|
+
assert.equal(0, result.code, 'Should succeed')
|
|
35
|
+
|
|
36
|
+
await t.test('Check output', (t, done) => {
|
|
37
|
+
const appPath = path.resolve(cwd, 'new-app')
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
const expectedOut = [
|
|
46
|
-
`Initialized empty Git repository in ${path.resolve(
|
|
47
|
-
cwd,
|
|
48
|
-
'new-app',
|
|
49
|
-
'.git'
|
|
50
|
-
)}`,
|
|
51
|
-
'success Saved package.json',
|
|
52
|
-
'[1/4] Resolving packages...',
|
|
53
|
-
'[2/4] Fetching packages...',
|
|
54
|
-
'[3/4] Linking dependencies...',
|
|
55
|
-
'[4/4] Building fresh packages...',
|
|
56
|
-
'success Saved lockfile.',
|
|
57
|
-
'husky - Git hooks installed'
|
|
58
|
-
]
|
|
39
|
+
const expectedOut = [`Wrote to ${appPath}/package.json`]
|
|
59
40
|
|
|
60
41
|
const stdout = stripAnsi(result.stdout)
|
|
61
42
|
|
|
62
43
|
for (const e of expectedOut) {
|
|
63
|
-
|
|
44
|
+
assert.equal(true, stdout.includes(e), `"${e.substring(0, 36)}"`)
|
|
64
45
|
}
|
|
65
46
|
|
|
66
|
-
|
|
47
|
+
done()
|
|
67
48
|
})
|
|
68
49
|
|
|
69
50
|
/**
|
|
70
51
|
* check files
|
|
71
52
|
*/
|
|
72
|
-
t.test('Check files', (t) => {
|
|
53
|
+
await t.test('Check files', (t, done) => {
|
|
73
54
|
const appPath = path.resolve(cwd, 'new-app')
|
|
74
55
|
|
|
75
|
-
|
|
76
|
-
true,
|
|
56
|
+
assert.ok(
|
|
77
57
|
fs.existsSync(path.resolve(appPath, 'package.json')),
|
|
78
58
|
'package.json was created'
|
|
79
59
|
)
|
|
80
|
-
|
|
81
|
-
true,
|
|
60
|
+
assert.ok(
|
|
82
61
|
fs.existsSync(path.resolve(appPath, 'README.md')),
|
|
83
62
|
'skeleton was copied'
|
|
84
63
|
)
|
|
85
|
-
|
|
86
|
-
true,
|
|
87
|
-
fs.existsSync(path.resolve(appPath, 'yarn.lock')),
|
|
88
|
-
'Packages were installed'
|
|
89
|
-
)
|
|
64
|
+
assert.ok(fs.existsSync(path.resolve(appPath, '.env')), 'Env was copied')
|
|
90
65
|
|
|
91
66
|
const pack = JSON.parse(
|
|
92
67
|
fs.readFileSync(path.resolve(appPath, 'package.json'), {
|
|
93
68
|
encoding: 'utf-8'
|
|
94
69
|
})
|
|
95
70
|
)
|
|
96
|
-
|
|
97
|
-
true,
|
|
71
|
+
assert.ok(
|
|
98
72
|
pack.name !== 'new-fastify-app',
|
|
99
73
|
'package.json was not just copied from skeleton'
|
|
100
74
|
)
|
|
101
|
-
|
|
102
|
-
true,
|
|
75
|
+
assert.ok(
|
|
103
76
|
pack.main === 'app/server.js',
|
|
104
77
|
'package.json was correctly enriched with data'
|
|
105
78
|
)
|
|
106
79
|
|
|
107
|
-
|
|
80
|
+
done()
|
|
108
81
|
})
|
|
109
82
|
})
|
package/test/setup.js
CHANGED
package/.husky/.gitignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
_
|
package/.husky/_/.gitignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
*
|
package/.husky/pre-commit
DELETED
package/skeleton/.editorconfig
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
charset = utf-8
|
|
5
|
-
indent_style = space
|
|
6
|
-
indent_size = 2
|
|
7
|
-
end_of_line = lf
|
|
8
|
-
insert_final_newline = true
|
|
9
|
-
trim_trailing_whitespace = true
|
|
10
|
-
|
|
11
|
-
[{Makefile,**.mk}]
|
|
12
|
-
# Use tabs for indentation (Makefiles require tabs)
|
|
13
|
-
indent_style = tab
|
package/skeleton/.envrc
DELETED
package/skeleton/.eslintrc
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# image: node:lts-alpine
|
|
2
|
-
|
|
3
|
-
# cache:
|
|
4
|
-
# paths:
|
|
5
|
-
# - node_modules/
|
|
6
|
-
# - .yarn
|
|
7
|
-
|
|
8
|
-
# stages:
|
|
9
|
-
# - test
|
|
10
|
-
# - audit
|
|
11
|
-
|
|
12
|
-
# test:
|
|
13
|
-
# stage: test
|
|
14
|
-
# script:
|
|
15
|
-
# - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
|
|
16
|
-
# - yarn install --pure-lockfile --cache-folder .yarn
|
|
17
|
-
# - yarn test:ci
|
|
18
|
-
# coverage: '/^Statements\s*:\s*([^%]+)/'
|
|
19
|
-
|
|
20
|
-
# audit:
|
|
21
|
-
# stage: audit
|
|
22
|
-
# only:
|
|
23
|
-
# - schedules
|
|
24
|
-
# script:
|
|
25
|
-
# - yarn audit
|
package/skeleton/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
20
|
package/skeleton/.taprc
DELETED