@gasket/plugin-fastify 7.5.3 → 8.0.0-next.2
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 +12 -0
- package/lib/adapters/adapter-factory.js +46 -0
- package/lib/adapters/base-adapter.js +30 -0
- package/lib/adapters/fastify-v4-adapter.js +55 -0
- package/lib/adapters/fastify-v5-adapter.js +67 -0
- package/lib/adapters/index.js +4 -0
- package/lib/create-servers.js +9 -18
- package/lib/index.js +0 -2
- package/lib/utils.js +15 -27
- package/package.json +9 -17
- package/cjs/actions.cjs +0 -21
- package/cjs/create-servers.cjs +0 -41
- package/cjs/create.cjs +0 -72
- package/cjs/index.cjs +0 -84
- package/cjs/package.json +0 -1
- package/cjs/utils.cjs +0 -66
- package/generator/app/plugins/README.md +0 -11
- package/generator/app/plugins/routes-plugin.js +0 -30
- package/generator/app/plugins/routes-plugin.ts +0 -29
- package/generator/jest/jest.config.js +0 -21
- package/generator/jest/test/index.test.js +0 -20
- package/generator/jest/test/index.test.ts +0 -26
- package/generator/mocha/test/index.test.js +0 -23
- package/generator/mocha/test/index.test.ts +0 -23
- package/generator/vitest/test/index.test.js +0 -21
- package/generator/vitest/test/index.test.ts +0 -21
- package/lib/create.js +0 -61
package/README.md
CHANGED
|
@@ -24,6 +24,18 @@ export default makeGasket({
|
|
|
24
24
|
});
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
## Fastify Version Support
|
|
28
|
+
|
|
29
|
+
This plugin supports both Fastify v4 and v5 through an internal adapter pattern. The appropriate version-specific adapter is automatically selected based on your installed Fastify version.
|
|
30
|
+
|
|
31
|
+
### Fastify v4
|
|
32
|
+
- **Installation**: `npm install fastify@^4`
|
|
33
|
+
|
|
34
|
+
### Fastify v5
|
|
35
|
+
- **Installation**: `npm install fastify@^5`
|
|
36
|
+
|
|
37
|
+
The plugin automatically detects your Fastify version and applies the correct configuration. No manual configuration is required.
|
|
38
|
+
|
|
27
39
|
## Configuration
|
|
28
40
|
|
|
29
41
|
All the configurations for the plugin are added under `fastify` in the config:
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { FastifyV4Adapter } from './fastify-v4-adapter.js';
|
|
3
|
+
import { FastifyV5Adapter } from './fastify-v5-adapter.js';
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Detect the installed Fastify version.
|
|
9
|
+
* Reads the version from fastify/package.json in node_modules.
|
|
10
|
+
* This works reliably with npm, pnpm, yarn, and bun.
|
|
11
|
+
* @returns {string} - Version string (e.g., '5.2.1')
|
|
12
|
+
*/
|
|
13
|
+
export function detectFastifyVersion() {
|
|
14
|
+
try {
|
|
15
|
+
const fastifyModule = require('fastify/package.json');
|
|
16
|
+
return fastifyModule.version;
|
|
17
|
+
} catch (err) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
'Could not detect Fastify version. Ensure fastify is installed.\n' +
|
|
20
|
+
`Error: ${err.message}`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create the appropriate Fastify adapter based on the installed Fastify version.
|
|
27
|
+
* Automatically detects the version from fastify/package.json.
|
|
28
|
+
* @returns {import('./base-adapter.js').FastifyAdapter} - Adapter instance
|
|
29
|
+
*/
|
|
30
|
+
export function createFastifyAdapter() {
|
|
31
|
+
const version = detectFastifyVersion();
|
|
32
|
+
const majorVersion = parseInt(version.split('.')[0], 10);
|
|
33
|
+
|
|
34
|
+
switch (majorVersion) {
|
|
35
|
+
case 4:
|
|
36
|
+
return new FastifyV4Adapter();
|
|
37
|
+
case 5:
|
|
38
|
+
return new FastifyV5Adapter();
|
|
39
|
+
default:
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Unsupported Fastify version: ${version}\n` +
|
|
42
|
+
'Gasket supports Fastify v4 and v5. Please upgrade or downgrade Fastify, ' +
|
|
43
|
+
'or open an issue at https://github.com/godaddy/gasket'
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base abstract class for Fastify version adapters.
|
|
3
|
+
* Provides a common interface for creating and configuring Fastify instances
|
|
4
|
+
* across different major versions.
|
|
5
|
+
* @abstract
|
|
6
|
+
*/
|
|
7
|
+
export class FastifyAdapter {
|
|
8
|
+
constructor() {
|
|
9
|
+
if (new.target === FastifyAdapter) {
|
|
10
|
+
throw new Error('FastifyAdapter is an abstract class and cannot be instantiated directly');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create a Fastify instance with version-specific configuration.
|
|
16
|
+
* Subclasses must implement this method to handle version-specific options.
|
|
17
|
+
* @abstract
|
|
18
|
+
* @param {object} config - Fastify configuration options
|
|
19
|
+
* @param {boolean} [config.trustProxy] - Trust proxy headers
|
|
20
|
+
* @param {object} [config.https] - HTTPS configuration
|
|
21
|
+
* @param {boolean} [config.http2] - Enable HTTP/2
|
|
22
|
+
* @param {boolean} [config.disableRequestLogging] - Disable request logging
|
|
23
|
+
* @param {object} logger - Gasket logger instance
|
|
24
|
+
* @returns {ReturnType<typeof import('fastify').default>} - Configured Fastify instance
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line no-unused-vars
|
|
27
|
+
createInstance(config, logger) {
|
|
28
|
+
throw new Error('createInstance() must be implemented by subclass');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import fastify from 'fastify';
|
|
2
|
+
import { FastifyAdapter } from './base-adapter.js';
|
|
3
|
+
|
|
4
|
+
const fallbackMap = {
|
|
5
|
+
fatal: 'error',
|
|
6
|
+
trace: 'debug'
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Adapter for Fastify v4.x
|
|
11
|
+
*
|
|
12
|
+
* Key differences from v5:
|
|
13
|
+
* - Uses 'logger' option (not 'loggerInstance')
|
|
14
|
+
* - No 'useSemicolonDelimiter' option
|
|
15
|
+
* - Supports Node.js v14+
|
|
16
|
+
*/
|
|
17
|
+
export class FastifyV4Adapter extends FastifyAdapter {
|
|
18
|
+
/**
|
|
19
|
+
* Align Gasket logger with Fastify v4 requirements.
|
|
20
|
+
* Ensures 'fatal' and 'trace' log levels exist.
|
|
21
|
+
* @param {object} logger - Gasket logger instance
|
|
22
|
+
* @returns {object} - Fastify-compatible logger
|
|
23
|
+
*/
|
|
24
|
+
alignLogger(logger) {
|
|
25
|
+
const fastifyLogger = logger;
|
|
26
|
+
['fatal', 'trace'].forEach(level => {
|
|
27
|
+
if (!logger[level]) {
|
|
28
|
+
fastifyLogger[level] = logger[fallbackMap[level]];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return fastifyLogger;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create a Fastify v4 instance.
|
|
36
|
+
* @param {object} config - Fastify configuration
|
|
37
|
+
* @param {object} logger - Gasket logger
|
|
38
|
+
* @returns {ReturnType<typeof import('fastify').default>} - Configured Fastify v4 instance
|
|
39
|
+
*/
|
|
40
|
+
createInstance(config, logger) {
|
|
41
|
+
const { trustProxy = false, disableRequestLogging = true, https, http2, ...restConfig } = config;
|
|
42
|
+
|
|
43
|
+
const fastifyLogger = this.alignLogger(logger);
|
|
44
|
+
|
|
45
|
+
// Fastify v4 uses 'logger' option
|
|
46
|
+
return fastify({
|
|
47
|
+
logger: fastifyLogger,
|
|
48
|
+
trustProxy,
|
|
49
|
+
disableRequestLogging,
|
|
50
|
+
https,
|
|
51
|
+
http2,
|
|
52
|
+
...restConfig
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fastify from 'fastify';
|
|
2
|
+
import { FastifyAdapter } from './base-adapter.js';
|
|
3
|
+
|
|
4
|
+
const fallbackMap = {
|
|
5
|
+
fatal: 'error',
|
|
6
|
+
trace: 'debug'
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Adapter for Fastify v5.x
|
|
11
|
+
*
|
|
12
|
+
* Key differences from v4:
|
|
13
|
+
* - Uses 'loggerInstance' option (not 'logger')
|
|
14
|
+
* - Adds 'useSemicolonDelimiter' option (defaults to true)
|
|
15
|
+
* - Requires Node.js v20+
|
|
16
|
+
* - Stricter JSON Schema validation
|
|
17
|
+
*/
|
|
18
|
+
export class FastifyV5Adapter extends FastifyAdapter {
|
|
19
|
+
/**
|
|
20
|
+
* Align Gasket logger with Fastify v5 requirements.
|
|
21
|
+
* Ensures 'fatal' and 'trace' log levels exist.
|
|
22
|
+
* @param {object} logger - Gasket logger instance
|
|
23
|
+
* @returns {object} - Fastify-compatible logger
|
|
24
|
+
*/
|
|
25
|
+
alignLogger(logger) {
|
|
26
|
+
const fastifyLogger = logger;
|
|
27
|
+
['fatal', 'trace'].forEach(level => {
|
|
28
|
+
if (!logger[level]) {
|
|
29
|
+
fastifyLogger[level] = logger[fallbackMap[level]];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return fastifyLogger;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a Fastify v5 instance.
|
|
37
|
+
* @param {object} config - Fastify configuration
|
|
38
|
+
* @param {object} logger - Gasket logger
|
|
39
|
+
* @returns {ReturnType<typeof import('fastify').default>} - Configured Fastify v5 instance
|
|
40
|
+
*/
|
|
41
|
+
createInstance(config, logger) {
|
|
42
|
+
const {
|
|
43
|
+
trustProxy = false,
|
|
44
|
+
disableRequestLogging = true,
|
|
45
|
+
https,
|
|
46
|
+
http2,
|
|
47
|
+
useSemicolonDelimiter = true,
|
|
48
|
+
...restConfig
|
|
49
|
+
} = config;
|
|
50
|
+
|
|
51
|
+
const fastifyLogger = this.alignLogger(logger);
|
|
52
|
+
|
|
53
|
+
// Fastify v5 uses 'loggerInstance' instead of 'logger'
|
|
54
|
+
// Router options are nested under 'routerOptions' to avoid deprecation warnings
|
|
55
|
+
return fastify({
|
|
56
|
+
loggerInstance: fastifyLogger,
|
|
57
|
+
trustProxy,
|
|
58
|
+
disableRequestLogging,
|
|
59
|
+
https,
|
|
60
|
+
http2,
|
|
61
|
+
routerOptions: {
|
|
62
|
+
useSemicolonDelimiter
|
|
63
|
+
},
|
|
64
|
+
...restConfig
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
package/lib/create-servers.js
CHANGED
|
@@ -5,32 +5,23 @@ import { getAppInstance } from './utils.js';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Create the Fastify instance and setup the lifecycle hooks.
|
|
8
|
-
* Fastify is compatible with express middleware
|
|
8
|
+
* Fastify is compatible with express middleware out of the box, so we can
|
|
9
|
+
* use the same middleware lifecycles.
|
|
9
10
|
* @type {import('@gasket/core').HookHandler<'createServers'>}
|
|
10
11
|
*/
|
|
11
12
|
export default async function createServers(gasket, serverOpts) {
|
|
12
|
-
|
|
13
|
+
/** Cast to Fastify + Express hybrid because Gasket adds `.use()` via @fastify/express plugin */
|
|
14
|
+
const app = /** @type {import('fastify').FastifyInstance & { use: Function }} */ (getAppInstance(gasket));
|
|
13
15
|
|
|
14
16
|
// allow consuming apps to directly append options to their server
|
|
15
17
|
await gasket.exec('fastify', app);
|
|
16
18
|
|
|
17
19
|
const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
'errorMiddleware requires @fastify/express to be installed and registered. ' +
|
|
24
|
-
'Install @fastify/express and ensure @gasket/plugin-middleware is configured.'
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
postRenderingStacks.forEach((stack) => {
|
|
28
|
-
/** @type {import('connect').NextHandleFunction} */
|
|
29
|
-
const middleware = stack;
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
app.use(middleware);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
20
|
+
postRenderingStacks.forEach((stack) => {
|
|
21
|
+
/** @type {import('connect').NextHandleFunction} */
|
|
22
|
+
const middleware = stack;
|
|
23
|
+
app.use(middleware);
|
|
24
|
+
});
|
|
34
25
|
|
|
35
26
|
return {
|
|
36
27
|
...serverOpts,
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="@gasket/core" />
|
|
2
2
|
/// <reference types="@gasket/plugin-metadata" />
|
|
3
3
|
|
|
4
|
-
import create from './create.js';
|
|
5
4
|
import createServers from './create-servers.js';
|
|
6
5
|
import actions from './actions.js';
|
|
7
6
|
import packageJson from '../package.json' with { type: 'json' };
|
|
@@ -14,7 +13,6 @@ const plugin = {
|
|
|
14
13
|
description,
|
|
15
14
|
actions,
|
|
16
15
|
hooks: {
|
|
17
|
-
create,
|
|
18
16
|
createServers,
|
|
19
17
|
metadata(gasket, meta) {
|
|
20
18
|
return {
|
package/lib/utils.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const fallbackMap = {
|
|
6
|
-
fatal: 'error',
|
|
7
|
-
trace: 'debug'
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A helper function to ensure that all the required log levels
|
|
12
|
-
* for a Fastify server are present.
|
|
13
|
-
* @type {import('@gasket/plugin-fastify').alignLogger}
|
|
14
|
-
*/
|
|
15
|
-
function alignLogger(logger) {
|
|
16
|
-
const fastifyLogger = logger;
|
|
17
|
-
['fatal', 'trace'].map(level => {
|
|
18
|
-
if (!logger[level]) {
|
|
19
|
-
fastifyLogger[level] = logger[fallbackMap[level]];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return fastifyLogger;
|
|
24
|
-
}
|
|
3
|
+
import { createFastifyAdapter } from './adapters/index.js';
|
|
25
4
|
|
|
26
5
|
let instance = null;
|
|
6
|
+
let adapter = null;
|
|
27
7
|
|
|
28
8
|
/**
|
|
29
9
|
* Get the Fastify instance.
|
|
@@ -33,21 +13,29 @@ let instance = null;
|
|
|
33
13
|
export function getAppInstance(gasket) {
|
|
34
14
|
if (!instance) {
|
|
35
15
|
const { fastify: fastifyConfig = {}, http2, https } = gasket.config;
|
|
36
|
-
const { trustProxy = false, disableRequestLogging = true } = fastifyConfig;
|
|
37
|
-
const fastifyLogger = alignLogger(gasket.logger);
|
|
38
16
|
|
|
39
|
-
|
|
17
|
+
// Create the appropriate adapter for the installed Fastify version
|
|
18
|
+
adapter = createFastifyAdapter();
|
|
19
|
+
|
|
20
|
+
// Use the adapter to create the Fastify instance
|
|
21
|
+
instance = adapter.createInstance(
|
|
22
|
+
{
|
|
23
|
+
...fastifyConfig,
|
|
24
|
+
https,
|
|
25
|
+
http2
|
|
26
|
+
},
|
|
27
|
+
gasket.logger
|
|
28
|
+
);
|
|
40
29
|
}
|
|
41
30
|
|
|
42
31
|
return instance;
|
|
43
32
|
}
|
|
44
33
|
|
|
45
|
-
export { alignLogger };
|
|
46
|
-
|
|
47
34
|
/**
|
|
48
35
|
* Clear the Fastify app instance (for testing only)
|
|
49
36
|
* @returns {void}
|
|
50
37
|
*/
|
|
51
38
|
export function testClearAppInstance() {
|
|
52
39
|
instance = null;
|
|
40
|
+
adapter = null;
|
|
53
41
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-fastify",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-next.2",
|
|
4
4
|
"description": "Adds fastify support to your application",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./lib/index.js",
|
|
7
6
|
"types": "./lib/index.d.ts",
|
|
8
7
|
"files": [
|
|
9
|
-
"cjs",
|
|
10
8
|
"generator",
|
|
11
9
|
"lib",
|
|
12
10
|
"EXAMPLES.md"
|
|
@@ -14,8 +12,7 @@
|
|
|
14
12
|
"exports": {
|
|
15
13
|
".": {
|
|
16
14
|
"types": "./lib/index.d.ts",
|
|
17
|
-
"import": "./lib/index.js"
|
|
18
|
-
"require": "./cjs/index.cjs"
|
|
15
|
+
"import": "./lib/index.js"
|
|
19
16
|
},
|
|
20
17
|
"./package.json": "./package.json"
|
|
21
18
|
},
|
|
@@ -32,25 +29,20 @@
|
|
|
32
29
|
"license": "MIT",
|
|
33
30
|
"bugs": "https://github.com/godaddy/gasket/issues",
|
|
34
31
|
"homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-fastify",
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"fastify": "^4.29.1"
|
|
37
|
-
},
|
|
38
32
|
"devDependencies": {
|
|
39
33
|
"@types/connect": "^3.4.38",
|
|
40
|
-
"fastify": "^
|
|
34
|
+
"fastify": "^5.0.0",
|
|
41
35
|
"vitest": "^3.2.0",
|
|
42
|
-
"@gasket/
|
|
43
|
-
"@gasket/
|
|
44
|
-
"@gasket/plugin-
|
|
45
|
-
"@gasket/plugin-
|
|
46
|
-
"
|
|
47
|
-
"create-gasket-app": "^7.4.19"
|
|
36
|
+
"@gasket/core": "^8.0.0-next.1",
|
|
37
|
+
"@gasket/plugin-https": "^8.0.0-next.1",
|
|
38
|
+
"@gasket/plugin-logger": "^8.0.0-next.1",
|
|
39
|
+
"@gasket/plugin-metadata": "^8.0.0-next.1",
|
|
40
|
+
"create-gasket-app": "^8.0.0-next.1"
|
|
48
41
|
},
|
|
49
42
|
"peerDependencies": {
|
|
50
|
-
"fastify": "^4.29.1"
|
|
43
|
+
"fastify": "^4.29.1 || ^5.0.0"
|
|
51
44
|
},
|
|
52
45
|
"scripts": {
|
|
53
|
-
"build": "gasket-cjs ./lib",
|
|
54
46
|
"lint": "eslint .",
|
|
55
47
|
"lint:fix": "pnpm run lint --fix",
|
|
56
48
|
"posttest": "pnpm run lint && pnpm run typecheck",
|
package/cjs/actions.cjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", {
|
|
2
|
-
value: true
|
|
3
|
-
});
|
|
4
|
-
Object.defineProperty(exports, "default", {
|
|
5
|
-
enumerable: true,
|
|
6
|
-
get: function() {
|
|
7
|
-
return _default;
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
const _utils = require("./utils.cjs");
|
|
11
|
-
const actions = {
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated
|
|
14
|
-
* @param {import('@gasket/core').Gasket} gasket - Gasket instance
|
|
15
|
-
* @returns {import('fastify').FastifyInstance} - Fastify instance
|
|
16
|
-
*/ getFastifyApp (gasket) {
|
|
17
|
-
gasket.logger.warn(`DEPRECATED \`getFastifyApp\` action will not be support in future major release.`);
|
|
18
|
-
return (0, _utils.getAppInstance)(gasket);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const _default = actions;
|
package/cjs/create-servers.cjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/// <reference types="@gasket/plugin-https" />
|
|
2
|
-
/// <reference types="@gasket/plugin-logger" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, /**
|
|
7
|
-
* Create the Fastify instance and setup the lifecycle hooks.
|
|
8
|
-
* Fastify is compatible with express middleware when @fastify/express is installed.
|
|
9
|
-
* @type {import('@gasket/core').HookHandler<'createServers'>}
|
|
10
|
-
*/ "default", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function() {
|
|
13
|
-
return createServers;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
const _utils = require("./utils.cjs");
|
|
17
|
-
async function createServers(gasket, serverOpts) {
|
|
18
|
-
const app = (0, _utils.getAppInstance)(gasket);
|
|
19
|
-
// allow consuming apps to directly append options to their server
|
|
20
|
-
await gasket.exec('fastify', app);
|
|
21
|
-
const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
|
|
22
|
-
if (postRenderingStacks.length > 0) {
|
|
23
|
-
// app.use() is added by @fastify/express when registered via @gasket/plugin-middleware
|
|
24
|
-
// @ts-expect-error
|
|
25
|
-
if (typeof app.use !== 'function') {
|
|
26
|
-
throw new Error('errorMiddleware requires @fastify/express to be installed and registered. ' + 'Install @fastify/express and ensure @gasket/plugin-middleware is configured.');
|
|
27
|
-
}
|
|
28
|
-
postRenderingStacks.forEach((stack)=>{
|
|
29
|
-
/** @type {import('connect').NextHandleFunction} */ const middleware = stack;
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
app.use(middleware);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
...serverOpts,
|
|
36
|
-
handler: async function handler(...args) {
|
|
37
|
-
await app.ready();
|
|
38
|
-
app.server.emit('request', ...args);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
package/cjs/create.cjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/// <reference types="@gasket/core" />
|
|
2
|
-
/// <reference types="create-gasket-app" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, /**
|
|
7
|
-
* Add files & extend package.json for new apps.
|
|
8
|
-
* @type {import('@gasket/core').HookHandler<'create'>}
|
|
9
|
-
*/ "default", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function() {
|
|
12
|
-
return create;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
const _url = require("url");
|
|
16
|
-
const _path = require("path");
|
|
17
|
-
const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
|
|
18
|
-
function _interop_require_default(obj) {
|
|
19
|
-
return obj && obj.__esModule ? obj : {
|
|
20
|
-
default: obj
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
const fileName = (0, _url.fileURLToPath)(require("url").pathToFileURL(__filename).toString());
|
|
24
|
-
const dirName = (0, _path.dirname)(fileName);
|
|
25
|
-
const { name, version, devDependencies } = _packagejson.default;
|
|
26
|
-
const createTestFiles = ({ files, generatorDir, testPlugins, globIgnore })=>{
|
|
27
|
-
if (!testPlugins || testPlugins.length === 0) return;
|
|
28
|
-
const unit = [
|
|
29
|
-
'jest',
|
|
30
|
-
'mocha',
|
|
31
|
-
'vitest'
|
|
32
|
-
];
|
|
33
|
-
const integration = [
|
|
34
|
-
'cypress'
|
|
35
|
-
];
|
|
36
|
-
const frameworks = [
|
|
37
|
-
...unit,
|
|
38
|
-
...integration
|
|
39
|
-
];
|
|
40
|
-
const frameworksRegex = new RegExp(frameworks.join('|'));
|
|
41
|
-
testPlugins.forEach((testPlugin)=>{
|
|
42
|
-
const match = frameworksRegex.exec(testPlugin);
|
|
43
|
-
if (match) {
|
|
44
|
-
const matchedFramework = match[0];
|
|
45
|
-
if (unit.includes(matchedFramework)) {
|
|
46
|
-
files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/${globIgnore}`);
|
|
47
|
-
} else {
|
|
48
|
-
files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/*`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
async function create(gasket, context) {
|
|
54
|
-
const { files, typescript, apiApp, addApiRoutes = true, testPlugins, pkg, gasketConfig } = context;
|
|
55
|
-
const generatorDir = `${dirName}/../generator`;
|
|
56
|
-
gasketConfig.addPlugin('pluginFastify', name);
|
|
57
|
-
pkg.add('dependencies', {
|
|
58
|
-
[name]: `^${version}`,
|
|
59
|
-
fastify: devDependencies.fastify
|
|
60
|
-
});
|
|
61
|
-
if (apiApp && addApiRoutes) {
|
|
62
|
-
const globIgnore = typescript ? '!(*.js)' : '!(*.ts)';
|
|
63
|
-
files.add(`${generatorDir}/app/**/${globIgnore}`);
|
|
64
|
-
gasketConfig.addPlugin('pluginRoutes', './plugins/routes-plugin.js');
|
|
65
|
-
createTestFiles({
|
|
66
|
-
files,
|
|
67
|
-
generatorDir,
|
|
68
|
-
testPlugins,
|
|
69
|
-
globIgnore
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
package/cjs/index.cjs
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/// <reference types="@gasket/core" />
|
|
2
|
-
/// <reference types="@gasket/plugin-metadata" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "default", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function() {
|
|
9
|
-
return _default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
const _create = /*#__PURE__*/ _interop_require_default(require("./create.cjs"));
|
|
13
|
-
const _createservers = /*#__PURE__*/ _interop_require_default(require("./create-servers.cjs"));
|
|
14
|
-
const _actions = /*#__PURE__*/ _interop_require_default(require("./actions.cjs"));
|
|
15
|
-
const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
|
|
16
|
-
function _interop_require_default(obj) {
|
|
17
|
-
return obj && obj.__esModule ? obj : {
|
|
18
|
-
default: obj
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const { name, version, description } = _packagejson.default;
|
|
22
|
-
/** @type {import('@gasket/core').Plugin} */ const plugin = {
|
|
23
|
-
name,
|
|
24
|
-
version,
|
|
25
|
-
description,
|
|
26
|
-
actions: _actions.default,
|
|
27
|
-
hooks: {
|
|
28
|
-
create: _create.default,
|
|
29
|
-
createServers: _createservers.default,
|
|
30
|
-
metadata (gasket, meta) {
|
|
31
|
-
return {
|
|
32
|
-
...meta,
|
|
33
|
-
actions: [
|
|
34
|
-
{
|
|
35
|
-
name: 'getFastifyApp',
|
|
36
|
-
description: 'Get the Fastify app instance',
|
|
37
|
-
link: 'README.md#getFastifyApp',
|
|
38
|
-
deprecated: true
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
lifecycles: [
|
|
42
|
-
{
|
|
43
|
-
name: 'fastify',
|
|
44
|
-
method: 'exec',
|
|
45
|
-
description: 'Modify the Fastify instance to for adding endpoints',
|
|
46
|
-
link: 'README.md#express',
|
|
47
|
-
parent: 'createServers',
|
|
48
|
-
after: 'middleware'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: 'errorMiddleware',
|
|
52
|
-
method: 'exec',
|
|
53
|
-
description: 'Add Express style middleware for handling errors with Fastify',
|
|
54
|
-
link: 'README.md#errorMiddleware',
|
|
55
|
-
parent: 'createServers',
|
|
56
|
-
after: 'express'
|
|
57
|
-
}
|
|
58
|
-
],
|
|
59
|
-
configurations: [
|
|
60
|
-
{
|
|
61
|
-
name: 'fastify',
|
|
62
|
-
link: 'README.md#configuration',
|
|
63
|
-
description: 'Fastify configuration object',
|
|
64
|
-
type: 'object'
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: 'fastify.compression',
|
|
68
|
-
link: 'README.md#configuration',
|
|
69
|
-
description: 'Automatic compression',
|
|
70
|
-
type: 'boolean',
|
|
71
|
-
default: true
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: 'fastify.excludedRoutesRegex',
|
|
75
|
-
link: 'README.md#configuration',
|
|
76
|
-
description: 'Routes to be excluded based on a regex',
|
|
77
|
-
type: 'RegExp'
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const _default = plugin;
|
package/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
package/cjs/utils.cjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
alignLogger: function() {
|
|
13
|
-
return alignLogger;
|
|
14
|
-
},
|
|
15
|
-
getAppInstance: function() {
|
|
16
|
-
return getAppInstance;
|
|
17
|
-
},
|
|
18
|
-
testClearAppInstance: function() {
|
|
19
|
-
return testClearAppInstance;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _fastify = /*#__PURE__*/ _interop_require_default(require("fastify"));
|
|
23
|
-
function _interop_require_default(obj) {
|
|
24
|
-
return obj && obj.__esModule ? obj : {
|
|
25
|
-
default: obj
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
const fallbackMap = {
|
|
29
|
-
fatal: 'error',
|
|
30
|
-
trace: 'debug'
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* A helper function to ensure that all the required log levels
|
|
34
|
-
* for a Fastify server are present.
|
|
35
|
-
* @type {import('@gasket/plugin-fastify').alignLogger}
|
|
36
|
-
*/ function alignLogger(logger) {
|
|
37
|
-
const fastifyLogger = logger;
|
|
38
|
-
[
|
|
39
|
-
'fatal',
|
|
40
|
-
'trace'
|
|
41
|
-
].map((level)=>{
|
|
42
|
-
if (!logger[level]) {
|
|
43
|
-
fastifyLogger[level] = logger[fallbackMap[level]];
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
return fastifyLogger;
|
|
47
|
-
}
|
|
48
|
-
let instance = null;
|
|
49
|
-
function getAppInstance(gasket) {
|
|
50
|
-
if (!instance) {
|
|
51
|
-
const { fastify: fastifyConfig = {}, http2, https } = gasket.config;
|
|
52
|
-
const { trustProxy = false, disableRequestLogging = true } = fastifyConfig;
|
|
53
|
-
const fastifyLogger = alignLogger(gasket.logger);
|
|
54
|
-
instance = (0, _fastify.default)({
|
|
55
|
-
logger: fastifyLogger,
|
|
56
|
-
trustProxy,
|
|
57
|
-
https,
|
|
58
|
-
http2,
|
|
59
|
-
disableRequestLogging
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return instance;
|
|
63
|
-
}
|
|
64
|
-
function testClearAppInstance() {
|
|
65
|
-
instance = null;
|
|
66
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const defaultHandler = async (req, res) => {
|
|
2
|
-
if (res.statusCode === 200) {
|
|
3
|
-
res.send({ message: 'Welcome to your default route...' });
|
|
4
|
-
}
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
name: 'routes-plugin',
|
|
9
|
-
hooks: {
|
|
10
|
-
fastify(gasket, app) {
|
|
11
|
-
{{#if useSwagger }}
|
|
12
|
-
/**
|
|
13
|
-
* @swagger
|
|
14
|
-
*
|
|
15
|
-
* /default:
|
|
16
|
-
* get:
|
|
17
|
-
* summary: "Get default route"
|
|
18
|
-
* produces:
|
|
19
|
-
* - "application/json"
|
|
20
|
-
* responses:
|
|
21
|
-
* "200":
|
|
22
|
-
* description: "Returns welcome message."
|
|
23
|
-
* content:
|
|
24
|
-
* application/json
|
|
25
|
-
*/
|
|
26
|
-
{{/if }}
|
|
27
|
-
app.get('/default', defaultHandler);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export const defaultHandler = async (req, res) => {
|
|
2
|
-
if (res.statusCode === 200) {
|
|
3
|
-
res.send({ message: 'Welcome to your default route...' });
|
|
4
|
-
}
|
|
5
|
-
};
|
|
6
|
-
export default {
|
|
7
|
-
name: 'routes-plugin',
|
|
8
|
-
hooks: {
|
|
9
|
-
fastify(gasket, app) {
|
|
10
|
-
{{#if useSwagger }}
|
|
11
|
-
/**
|
|
12
|
-
* @swagger
|
|
13
|
-
*
|
|
14
|
-
* /default:
|
|
15
|
-
* get:
|
|
16
|
-
* summary: "Get default route"
|
|
17
|
-
* produces:
|
|
18
|
-
* - "application/json"
|
|
19
|
-
* responses:
|
|
20
|
-
* "200":
|
|
21
|
-
* description: "Returns welcome message."
|
|
22
|
-
* content:
|
|
23
|
-
* application/json
|
|
24
|
-
*/
|
|
25
|
-
{{/if }}
|
|
26
|
-
app.get('/default', defaultHandler);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{{#if typescript}}
|
|
2
|
-
const config = {
|
|
3
|
-
preset: 'ts-jest/presets/default-esm',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
injectGlobals: true,
|
|
6
|
-
moduleDirectories: ['node_modules', '<rootDir>'],
|
|
7
|
-
moduleNameMapper: {
|
|
8
|
-
'^(\\.{1,2}/.*)\\.js$': '$1'
|
|
9
|
-
},
|
|
10
|
-
transform: {
|
|
11
|
-
'^.+.ts$': ['ts-jest', { useESM: true }]
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default config;
|
|
16
|
-
{{else}}
|
|
17
|
-
export default {
|
|
18
|
-
testEnvironment: 'node',
|
|
19
|
-
injectGlobals: true
|
|
20
|
-
};
|
|
21
|
-
{{/if}}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals';
|
|
2
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
3
|
-
|
|
4
|
-
describe('Routes', () => {
|
|
5
|
-
let mockRequest, mockResponse;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
mockRequest = {};
|
|
8
|
-
mockResponse = {
|
|
9
|
-
statusCode: 200,
|
|
10
|
-
send: jest.fn()
|
|
11
|
-
};
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('defaultHandler should use expeced message', async () => {
|
|
15
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
16
|
-
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
17
|
-
message: 'Welcome to your default route...'
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
jest,
|
|
3
|
-
describe,
|
|
4
|
-
beforeEach,
|
|
5
|
-
it,
|
|
6
|
-
expect
|
|
7
|
-
} from '@jest/globals';
|
|
8
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
9
|
-
|
|
10
|
-
describe('Routes', () => {
|
|
11
|
-
let mockRequest, mockResponse;
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
mockRequest = {};
|
|
14
|
-
mockResponse = {
|
|
15
|
-
statusCode: 200,
|
|
16
|
-
send: jest.fn()
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('defaultHandler should use expeced message', async () => {
|
|
21
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
22
|
-
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
23
|
-
message: 'Welcome to your default route...'
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import sinon from 'sinon';
|
|
3
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
4
|
-
|
|
5
|
-
describe('Routes', () => {
|
|
6
|
-
let mockRequest, mockResponse, sendSpy;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
mockRequest = {};
|
|
10
|
-
sendSpy = sinon.spy();
|
|
11
|
-
mockResponse = {
|
|
12
|
-
statusCode: 200,
|
|
13
|
-
send: sendSpy
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('defaultHandler should use expected message', async () => {
|
|
18
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
19
|
-
expect(sendSpy.calledWith({
|
|
20
|
-
message: 'Welcome to your default route...'
|
|
21
|
-
})).to.be.true;
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import sinon from 'sinon';
|
|
3
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
4
|
-
|
|
5
|
-
describe('Routes', () => {
|
|
6
|
-
let mockRequest, mockResponse, sendSpy;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
mockRequest = {};
|
|
10
|
-
sendSpy = sinon.spy();
|
|
11
|
-
mockResponse = {
|
|
12
|
-
statusCode: 200,
|
|
13
|
-
send: sendSpy
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('defaultHandler should use expected message', async () => {
|
|
18
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
19
|
-
expect(sendSpy.calledWith({
|
|
20
|
-
message: 'Welcome to your default route...'
|
|
21
|
-
})).to.be.true;
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { vi, expect } from 'vitest';
|
|
2
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
3
|
-
|
|
4
|
-
describe('Routes', () => {
|
|
5
|
-
let mockRequest, mockResponse;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
mockRequest = {};
|
|
9
|
-
mockResponse = {
|
|
10
|
-
statusCode: 200,
|
|
11
|
-
send: vi.fn()
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('defaultHeader should use expected message', async () => {
|
|
16
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
17
|
-
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
18
|
-
message: 'Welcome to your default route...'
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
3
|
-
|
|
4
|
-
describe('Routes', () => {
|
|
5
|
-
let mockRequest, mockResponse;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
mockRequest = {};
|
|
9
|
-
mockResponse = {
|
|
10
|
-
statusCode: 200,
|
|
11
|
-
send: vi.fn()
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('defaultHeader should use expected message', async () => {
|
|
16
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
17
|
-
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
18
|
-
message: 'Welcome to your default route...'
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
package/lib/create.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/// <reference types="@gasket/core" />
|
|
2
|
-
/// <reference types="create-gasket-app" />
|
|
3
|
-
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import { dirname } from 'path';
|
|
6
|
-
import packageJson from '../package.json' with { type: 'json' };
|
|
7
|
-
const fileName = fileURLToPath(import.meta.url);
|
|
8
|
-
const dirName = dirname(fileName);
|
|
9
|
-
const { name, version, devDependencies } = packageJson;
|
|
10
|
-
|
|
11
|
-
const createTestFiles = ({ files, generatorDir, testPlugins, globIgnore }) => {
|
|
12
|
-
if (!testPlugins || testPlugins.length === 0) return;
|
|
13
|
-
const unit = ['jest', 'mocha', 'vitest'];
|
|
14
|
-
const integration = ['cypress'];
|
|
15
|
-
const frameworks = [...unit, ...integration];
|
|
16
|
-
const frameworksRegex = new RegExp(frameworks.join('|'));
|
|
17
|
-
|
|
18
|
-
testPlugins.forEach((testPlugin) => {
|
|
19
|
-
const match = frameworksRegex.exec(testPlugin);
|
|
20
|
-
if (match) {
|
|
21
|
-
const matchedFramework = match[0];
|
|
22
|
-
if (unit.includes(matchedFramework)) {
|
|
23
|
-
files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/${globIgnore}`);
|
|
24
|
-
} else {
|
|
25
|
-
files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/*`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Add files & extend package.json for new apps.
|
|
33
|
-
* @type {import('@gasket/core').HookHandler<'create'>}
|
|
34
|
-
*/
|
|
35
|
-
export default async function create(gasket, context) {
|
|
36
|
-
const {
|
|
37
|
-
files,
|
|
38
|
-
typescript,
|
|
39
|
-
apiApp,
|
|
40
|
-
addApiRoutes = true,
|
|
41
|
-
testPlugins,
|
|
42
|
-
pkg,
|
|
43
|
-
gasketConfig
|
|
44
|
-
} = context;
|
|
45
|
-
const generatorDir = `${dirName}/../generator`;
|
|
46
|
-
|
|
47
|
-
gasketConfig.addPlugin('pluginFastify', name);
|
|
48
|
-
|
|
49
|
-
pkg.add('dependencies', {
|
|
50
|
-
[name]: `^${version}`,
|
|
51
|
-
fastify: devDependencies.fastify
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (apiApp && addApiRoutes) {
|
|
55
|
-
const globIgnore = typescript ? '!(*.js)' : '!(*.ts)';
|
|
56
|
-
files.add(`${generatorDir}/app/**/${globIgnore}`);
|
|
57
|
-
gasketConfig.addPlugin('pluginRoutes', './plugins/routes-plugin.js');
|
|
58
|
-
|
|
59
|
-
createTestFiles({ files, generatorDir, testPlugins, globIgnore });
|
|
60
|
-
}
|
|
61
|
-
}
|