@gasket/preset-api 7.0.0-next.6 → 7.0.0-next.60

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,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
- gasket create <app-name> --presets @gasket/preset-api
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,6 @@
1
+ import gasket from './gasket.js';
2
+ {{#if apiApp }}
3
+ import './routes/index.js';
4
+ {{/if}}
5
+
6
+ gasket.actions.startServer();
package/lib/create.js CHANGED
@@ -1,23 +1,30 @@
1
+ import path from 'path';
1
2
  import { createRequire } from 'module';
2
3
  import { fileURLToPath } from 'url';
3
4
  const require = createRequire(import.meta.url);
4
- const { dependencies, devDependencies } = require('../package.json');
5
+ const { devDependencies } = require('../package.json');
5
6
 
7
+ /**
8
+ * createHook
9
+ * @param {Gasket} gasket - Gasket API
10
+ * @param {Create} context - Create context
11
+ */
6
12
  export default function create(gasket, context) {
7
13
  const { pkg, files } = context;
8
14
  const __dirname = fileURLToPath(import.meta.url);
9
- const generatorDir = `${__dirname}/../../generator`;
10
-
11
- pkg.add('dependencies', dependencies);
15
+ const generatorDir = path.join(__dirname, '..', '..', 'generator');
12
16
 
13
17
  if (!context.typescript) {
14
18
  files.add(`${generatorDir}/*`);
15
19
 
16
- pkg.add('devDependencies', devDependencies);
20
+ pkg.add('devDependencies', {
21
+ nodemon: devDependencies.nodemon
22
+ });
17
23
 
18
24
  pkg.add('scripts', {
19
25
  start: 'node server.js',
20
- local: 'GASKET_ENV=local nodemon server.js'
26
+ local: 'GASKET_ENV=local nodemon server.js',
27
+ preview: 'npm run build && npm run start'
21
28
  });
22
29
  }
23
30
  }
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-start';
8
- import '@gasket/plugin-swagger';
9
- import '@gasket/plugin-winston';
5
+ import '@gasket/plugin-winston';
package/lib/index.js CHANGED
@@ -3,10 +3,13 @@ import presetPrompt from './preset-prompt.js';
3
3
  import presetConfig from './preset-config.js';
4
4
  import create from './create.js';
5
5
  const require = createRequire(import.meta.url);
6
- const { name } = require('../package.json');
6
+ const { name, version, description } = require('../package.json');
7
7
 
8
+ // TODO: need to create types for "preset" plugins
8
9
  export default {
9
10
  name,
11
+ version,
12
+ description,
10
13
  hooks: {
11
14
  presetPrompt,
12
15
  presetConfig,
@@ -1,34 +1,44 @@
1
- import pluginExpress from '@gasket/plugin-express';
2
1
  import pluginHttps from '@gasket/plugin-https';
3
- import pluginDocs from '@gasket/plugin-docs';
4
- import pluginDocusaurus from '@gasket/plugin-docusaurus';
5
- import pluginResponseData from '@gasket/plugin-response-data';
6
2
  import pluginWinston from '@gasket/plugin-winston';
7
- import pluginSwagger from '@gasket/plugin-swagger';
8
3
  import pluginLint from '@gasket/plugin-lint';
9
4
 
5
+ /**
6
+ * presetConfig hook
7
+ * @param {Gasket} gasket - Gasket API
8
+ * @param {Create} context - Create context
9
+ * @returns {Promise<CreateContext.presetConfig>} config
10
+ */
10
11
  export default async function presetConfig(gasket, context) {
11
- let testPlugin, typescriptPlugin;
12
- if ('testPlugin' in context) {
13
- testPlugin = await import(context.testPlugin);
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
+ }));
14
29
  }
15
30
 
16
31
  if (context.typescript) {
17
- typescriptPlugin = await import('@gasket/plugin-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);
18
39
  }
19
40
 
20
41
  return {
21
- plugins: [
22
- pluginExpress,
23
- pluginHttps,
24
- pluginDocs,
25
- pluginDocusaurus,
26
- pluginResponseData,
27
- pluginWinston,
28
- pluginSwagger,
29
- pluginLint,
30
- typescriptPlugin ? typescriptPlugin.default || typescriptPlugin : null,
31
- testPlugin ? testPlugin.default || testPlugin : null
32
- ].filter(Boolean)
42
+ plugins: plugins.filter(Boolean)
33
43
  };
34
44
  }
@@ -1,16 +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
+ */
1
11
  export default async function presetPrompt(gasket, context, { prompt }) {
2
12
  context.apiApp = true;
3
13
 
4
- if (!('typescript' in context)) {
5
- const { typescript } = await prompt([
14
+ await typescriptPrompts.promptTypescript(context, prompt);
15
+ await swaggerPrompts.promptSwagger(context, prompt);
16
+
17
+ if (!('server' in context)) {
18
+ const { server } = await prompt([
6
19
  {
7
- name: 'typescript',
8
- message: 'Do you want to use TypeScript?',
9
- type: 'confirm',
10
- default: false
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
+ ]
11
27
  }
12
28
  ]);
13
29
 
14
- Object.assign(context, { typescript });
30
+ Object.assign(context, { server });
31
+
32
+ return context;
15
33
  }
16
34
  }
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@gasket/preset-api",
3
- "version": "7.0.0-next.6",
3
+ "version": "7.0.0-next.60",
4
4
  "description": "Create Express-based API with Gasket",
5
+ "type": "module",
5
6
  "main": "lib/index.js",
6
7
  "types": "lib/index.d.ts",
7
8
  "files": [
9
+ "generator",
8
10
  "lib"
9
11
  ],
10
- "type": "module",
11
12
  "scripts": {
12
13
  "lint": "eslint .",
13
14
  "lint:fix": "npm run lint -- --fix",
14
15
  "test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict --experimental-vm-modules' jest",
15
- "test:watch": "jest --watch",
16
+ "test:watch": "npm run test -- --watch",
16
17
  "test:coverage": "jest --coverage",
17
18
  "posttest": "npm run lint"
18
19
  },
@@ -29,24 +30,23 @@
29
30
  "url": "https://github.com/godaddy/gasket/issues"
30
31
  },
31
32
  "dependencies": {
32
- "@gasket/core": "^7.0.0-next.6",
33
- "@gasket/engine": "^7.0.0-next.6",
34
- "@gasket/plugin-docs": "^7.0.0-next.6",
35
- "@gasket/plugin-docusaurus": "^7.0.0-next.6",
36
- "@gasket/plugin-express": "^7.0.0-next.6",
37
- "@gasket/plugin-https": "^7.0.0-next.6",
38
- "@gasket/plugin-lint": "^7.0.0-next.6",
39
- "@gasket/plugin-response-data": "^7.0.0-next.6",
40
- "@gasket/plugin-swagger": "^7.0.0-next.6",
41
- "@gasket/plugin-winston": "^7.0.0-next.6",
42
- "@gasket/utils": "^7.0.0-next.6"
33
+ "@gasket/plugin-cypress": "7.0.0-next.60",
34
+ "@gasket/plugin-express": "7.0.0-next.60",
35
+ "@gasket/plugin-fastify": "7.0.0-next.60",
36
+ "@gasket/plugin-https": "7.0.0-next.60",
37
+ "@gasket/plugin-jest": "7.0.0-next.60",
38
+ "@gasket/plugin-lint": "7.0.0-next.60",
39
+ "@gasket/plugin-mocha": "7.0.0-next.60",
40
+ "@gasket/plugin-swagger": "7.0.0-next.60",
41
+ "@gasket/plugin-typescript": "7.0.0-next.60",
42
+ "@gasket/plugin-winston": "7.0.0-next.60"
43
43
  },
44
44
  "devDependencies": {
45
45
  "cross-env": "^7.0.3",
46
46
  "eslint": "^8.56.0",
47
- "eslint-config-godaddy": "^7.0.2",
48
- "eslint-plugin-jest": "^27.6.3",
49
- "eslint-plugin-unicorn": "^44.0.0",
47
+ "eslint-config-godaddy": "^7.1.1",
48
+ "eslint-plugin-jest": "^28.6.0",
49
+ "eslint-plugin-unicorn": "^55.0.0",
50
50
  "jest": "^29.7.0",
51
51
  "nodemon": "^3.1.0"
52
52
  },
@@ -63,10 +63,11 @@
63
63
  }
64
64
  },
65
65
  "eslintIgnore": [
66
- "test/fixtures"
66
+ "test/fixtures",
67
+ "generator"
67
68
  ],
68
69
  "jest": {
69
70
  "transform": {}
70
71
  },
71
- "gitHead": "805a1026959d8aa783ee32be8a8ff76c06badd2f"
72
+ "gitHead": "ea9feae6cd291d4361c06e09659e50dbec19bcea"
72
73
  }