@gasket/preset-api 7.0.3-cli.0 → 7.0.4
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 +1 -10
- package/generator/README.md +43 -0
- package/generator/server.js +6 -0
- package/lib/create.js +27 -0
- package/lib/index.d.ts +2 -6
- package/lib/index.js +16 -4
- package/lib/preset-config.js +44 -0
- package/lib/preset-prompt.js +34 -0
- package/package.json +50 -12
package/README.md
CHANGED
|
@@ -2,18 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Framework for building API's using Gasket.
|
|
4
4
|
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
This preset requires v5 of the `@gasket/cli`:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm i -g @gasket/cli@^5.0.0
|
|
11
|
-
```
|
|
12
|
-
|
|
13
5
|
## Installation
|
|
14
6
|
|
|
15
7
|
```bash
|
|
16
|
-
|
|
8
|
+
npx create-gasket-app <app-name> --presets @gasket/preset-api
|
|
17
9
|
```
|
|
18
10
|
|
|
19
11
|
## Docs
|
|
@@ -22,7 +14,6 @@ To see complete the list of plugins configured in your app, and what commands, l
|
|
|
22
14
|
|
|
23
15
|
## Plugins
|
|
24
16
|
|
|
25
|
-
- [@gasket/plugin-response-data](/packages/gasket-plugin-response-data/README.md)
|
|
26
17
|
- [@gasket/plugin-swagger](/packages/gasket-plugin-swagger/README.md)
|
|
27
18
|
- [@gasket/plugin-docs](/packages/gasket-plugin-docs/README.md)
|
|
28
19
|
- [@gasket/plugin-docusaurus](/packages/gasket-plugin-docusaurus/README.md)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# {{{appName}}}
|
|
2
|
+
|
|
3
|
+
{{{appDescription}}}
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This API is built with {{{server}}}.js framework and [Gasket](https://gasket.dev/). This application utilizes [EcmaScript Modules] and requires Node.js v20 or higher.
|
|
8
|
+
|
|
9
|
+
## Getting Started
|
|
10
|
+
|
|
11
|
+
### Development
|
|
12
|
+
|
|
13
|
+
To start the API locally, run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd {{{appName}}}
|
|
17
|
+
{{{installCmd}}}
|
|
18
|
+
{{{localCmd}}}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Debugging
|
|
22
|
+
|
|
23
|
+
To start the API locally with debugging enabled, run:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
DEBUG=* {{{localCmd}}}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Extended filtering of the debug output can be achieved by adding to the `DEBUG` environment variable:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
DEBUG=gasket:* {{{localCmd}}} // gasket operations only
|
|
33
|
+
DEBUG={{{server}}}:* {{{localCmd}}} // {{{server}}} operations only
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
{{#each readme.markdown}}
|
|
37
|
+
{{{markdownCompile this}}}
|
|
38
|
+
{{/each}}
|
|
39
|
+
<!-- LINKS -->
|
|
40
|
+
[EcmaScript Modules]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
41
|
+
{{#each readme.links}}
|
|
42
|
+
{{{this}}}
|
|
43
|
+
{{/each}}
|
package/lib/create.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
const { devDependencies } = require('../package.json');
|
|
6
|
+
|
|
7
|
+
/** @type {import('@gasket/core').HookHandler<'create'>} */
|
|
8
|
+
export default function create(gasket, context) {
|
|
9
|
+
const { pkg, files } = context;
|
|
10
|
+
const __dirname = fileURLToPath(import.meta.url);
|
|
11
|
+
const generatorDir = path.join(__dirname, '..', '..', 'generator');
|
|
12
|
+
files.add(`${generatorDir}/*.md`);
|
|
13
|
+
|
|
14
|
+
if (!context.typescript) {
|
|
15
|
+
files.add(`${generatorDir}/*.js`);
|
|
16
|
+
|
|
17
|
+
pkg.add('devDependencies', {
|
|
18
|
+
nodemon: devDependencies.nodemon
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
pkg.add('scripts', {
|
|
22
|
+
start: 'node server.js',
|
|
23
|
+
local: 'nodemon server.js',
|
|
24
|
+
preview: 'npm run start'
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import '@gasket/plugin-response-data';
|
|
2
|
-
import '@gasket/plugin-docs';
|
|
3
|
-
import '@gasket/plugin-docusaurus';
|
|
4
1
|
import '@gasket/plugin-express';
|
|
2
|
+
import '@gasket/plugin-fastify';
|
|
5
3
|
import '@gasket/plugin-https';
|
|
6
4
|
import '@gasket/plugin-lint';
|
|
7
|
-
import '@gasket/plugin-
|
|
8
|
-
import '@gasket/plugin-swagger';
|
|
9
|
-
import '@gasket/plugin-winston';
|
|
5
|
+
import '@gasket/plugin-winston';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import presetPrompt from './preset-prompt.js';
|
|
3
|
+
import presetConfig from './preset-config.js';
|
|
4
|
+
import create from './create.js';
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const { name, version, description } = require('../package.json');
|
|
7
|
+
|
|
8
|
+
/** @type {import('@gasket/core').Preset} */
|
|
9
|
+
export default {
|
|
10
|
+
name,
|
|
11
|
+
version,
|
|
12
|
+
description,
|
|
13
|
+
hooks: {
|
|
14
|
+
presetPrompt,
|
|
15
|
+
presetConfig,
|
|
16
|
+
create
|
|
5
17
|
}
|
|
6
18
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import pluginHttps from '@gasket/plugin-https';
|
|
2
|
+
import pluginWinston from '@gasket/plugin-winston';
|
|
3
|
+
import pluginLint from '@gasket/plugin-lint';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* presetConfig hook
|
|
7
|
+
* @param {Gasket} gasket - Gasket API
|
|
8
|
+
* @param {Create} context - Create context
|
|
9
|
+
* @returns {Promise<CreateContext.presetConfig>} config
|
|
10
|
+
*/
|
|
11
|
+
export default async function presetConfig(gasket, context) {
|
|
12
|
+
const plugins = [
|
|
13
|
+
pluginHttps,
|
|
14
|
+
pluginWinston,
|
|
15
|
+
pluginLint
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const frameworkPlugin = context.server === 'express'
|
|
19
|
+
? await import('@gasket/plugin-express')
|
|
20
|
+
: await import('@gasket/plugin-fastify');
|
|
21
|
+
|
|
22
|
+
plugins.push(frameworkPlugin.default || frameworkPlugin);
|
|
23
|
+
|
|
24
|
+
if ('testPlugins' in context && context.testPlugins.length > 0) {
|
|
25
|
+
await Promise.all(context.testPlugins.map(async (testPlugin) => {
|
|
26
|
+
const plugin = await import(testPlugin);
|
|
27
|
+
plugins.push(plugin ? plugin.default || plugin : null);
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (context.typescript) {
|
|
32
|
+
const typescriptPlugin = await import('@gasket/plugin-typescript');
|
|
33
|
+
plugins.push(typescriptPlugin.default || typescriptPlugin);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (context.useSwagger) {
|
|
37
|
+
const swaggerPlugin = await import('@gasket/plugin-swagger');
|
|
38
|
+
plugins.push(swaggerPlugin.default || swaggerPlugin);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
plugins: plugins.filter(Boolean)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import typescriptPrompts from '@gasket/plugin-typescript/prompts';
|
|
2
|
+
import swaggerPrompts from '@gasket/plugin-swagger/prompts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* presetPrompt hook
|
|
6
|
+
* @param {Gasket} gasket - Gasket API
|
|
7
|
+
* @param {Create} context - Create context
|
|
8
|
+
* @param {Object} utils - Prompt utils
|
|
9
|
+
* @param {Function} utils.prompt - Inquirer prompt
|
|
10
|
+
*/
|
|
11
|
+
export default async function presetPrompt(gasket, context, { prompt }) {
|
|
12
|
+
context.apiApp = true;
|
|
13
|
+
|
|
14
|
+
await typescriptPrompts.promptTypescript(context, prompt);
|
|
15
|
+
await swaggerPrompts.promptSwagger(context, prompt);
|
|
16
|
+
|
|
17
|
+
if (!('server' in context)) {
|
|
18
|
+
const { server } = await prompt([
|
|
19
|
+
{
|
|
20
|
+
name: 'server',
|
|
21
|
+
message: 'Which server framework would you like to use?',
|
|
22
|
+
type: 'list',
|
|
23
|
+
choices: [
|
|
24
|
+
{ name: 'Express', value: 'express' },
|
|
25
|
+
{ name: 'Fastify', value: 'fastify' }
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
Object.assign(context, { server });
|
|
31
|
+
|
|
32
|
+
return context;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/preset-api",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.4",
|
|
4
4
|
"description": "Create Express-based API with Gasket",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
6
7
|
"types": "lib/index.d.ts",
|
|
7
8
|
"files": [
|
|
9
|
+
"generator",
|
|
8
10
|
"lib"
|
|
9
11
|
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"lint:fix": "npm run lint -- --fix",
|
|
15
|
+
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict --experimental-vm-modules' jest",
|
|
16
|
+
"test:watch": "npm run test -- --watch",
|
|
17
|
+
"test:coverage": "jest --coverage",
|
|
18
|
+
"posttest": "npm run lint"
|
|
19
|
+
},
|
|
10
20
|
"repository": {
|
|
11
21
|
"type": "git",
|
|
12
22
|
"url": "git+ssh://git@github.com/godaddy/gasket.git"
|
|
@@ -19,18 +29,46 @@
|
|
|
19
29
|
"bugs": {
|
|
20
30
|
"url": "https://github.com/godaddy/gasket/issues"
|
|
21
31
|
},
|
|
32
|
+
"homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-preset-api",
|
|
22
33
|
"dependencies": {
|
|
23
|
-
"@gasket/plugin-
|
|
24
|
-
"@gasket/plugin-
|
|
25
|
-
"@gasket/plugin-
|
|
26
|
-
"@gasket/plugin-https": "^7.0.
|
|
27
|
-
"@gasket/plugin-
|
|
28
|
-
"@gasket/plugin-
|
|
29
|
-
"@gasket/plugin-
|
|
30
|
-
"@gasket/plugin-
|
|
34
|
+
"@gasket/plugin-cypress": "^7.0.3",
|
|
35
|
+
"@gasket/plugin-express": "^7.0.4",
|
|
36
|
+
"@gasket/plugin-fastify": "^7.0.4",
|
|
37
|
+
"@gasket/plugin-https": "^7.0.4",
|
|
38
|
+
"@gasket/plugin-jest": "^7.0.1",
|
|
39
|
+
"@gasket/plugin-lint": "^7.0.3",
|
|
40
|
+
"@gasket/plugin-mocha": "^7.0.4",
|
|
41
|
+
"@gasket/plugin-swagger": "^7.0.1",
|
|
42
|
+
"@gasket/plugin-typescript": "^7.0.1",
|
|
43
|
+
"@gasket/plugin-winston": "^7.0.4"
|
|
31
44
|
},
|
|
32
45
|
"devDependencies": {
|
|
33
|
-
"
|
|
46
|
+
"cross-env": "^7.0.3",
|
|
47
|
+
"eslint": "^8.56.0",
|
|
48
|
+
"eslint-config-godaddy": "^7.1.1",
|
|
49
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
50
|
+
"eslint-plugin-unicorn": "^55.0.0",
|
|
51
|
+
"jest": "^29.7.0",
|
|
52
|
+
"nodemon": "^3.1.0"
|
|
53
|
+
},
|
|
54
|
+
"eslintConfig": {
|
|
55
|
+
"extends": [
|
|
56
|
+
"godaddy",
|
|
57
|
+
"plugin:jest/recommended"
|
|
58
|
+
],
|
|
59
|
+
"plugins": [
|
|
60
|
+
"unicorn"
|
|
61
|
+
],
|
|
62
|
+
"rules": {
|
|
63
|
+
"unicorn/filename-case": "error"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"eslintIgnore": [
|
|
67
|
+
"test/fixtures",
|
|
68
|
+
"generator"
|
|
69
|
+
],
|
|
70
|
+
"jest": {
|
|
71
|
+
"transform": {}
|
|
34
72
|
},
|
|
35
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "af49c0e42e7947e000faa771777b815b90aaffa3"
|
|
36
74
|
}
|