@gasket/preset-api 7.0.0-next.5 → 7.0.0-next.50

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,7 @@ 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)
17
+ - [@gasket/plugin-data](/packages/gasket-plugin-data/README.md)
26
18
  - [@gasket/plugin-swagger](/packages/gasket-plugin-swagger/README.md)
27
19
  - [@gasket/plugin-docs](/packages/gasket-plugin-docs/README.md)
28
20
  - [@gasket/plugin-docusaurus](/packages/gasket-plugin-docusaurus/README.md)
@@ -0,0 +1,2 @@
1
+ import gasket from './gasket.js';
2
+ gasket.actions.startServer();
package/lib/create.js ADDED
@@ -0,0 +1,29 @@
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
+ /**
8
+ * createHook
9
+ * @param {Gasket} gasket - Gasket API
10
+ * @param {Create} context - Create context
11
+ */
12
+ export default function create(gasket, context) {
13
+ const { pkg, files } = context;
14
+ const __dirname = fileURLToPath(import.meta.url);
15
+ const generatorDir = path.join(__dirname, '..', '..', 'generator');
16
+
17
+ if (!context.typescript) {
18
+ files.add(`${generatorDir}/*`);
19
+
20
+ pkg.add('devDependencies', {
21
+ nodemon: devDependencies.nodemon
22
+ });
23
+
24
+ pkg.add('scripts', {
25
+ start: 'node server.js',
26
+ local: 'GASKET_ENV=local nodemon server.js'
27
+ });
28
+ }
29
+ }
package/lib/index.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- import '@gasket/plugin-response-data';
2
- import '@gasket/plugin-docs';
3
- import '@gasket/plugin-docusaurus';
1
+ import '@gasket/plugin-data';
4
2
  import '@gasket/plugin-express';
3
+ import '@gasket/plugin-fastify';
5
4
  import '@gasket/plugin-https';
6
5
  import '@gasket/plugin-lint';
7
- import '@gasket/plugin-start';
8
6
  import '@gasket/plugin-swagger';
9
- import '@gasket/plugin-winston';
7
+ import '@gasket/plugin-winston';
package/lib/index.js CHANGED
@@ -1,77 +1,18 @@
1
- import pluginExpress from '@gasket/plugin-express';
2
- 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
- import pluginWinston from '@gasket/plugin-winston';
7
- import pluginSwagger from '@gasket/plugin-swagger';
8
- import pluginLint from '@gasket/plugin-lint';
9
1
  import { createRequire } from 'module';
10
- import { fileURLToPath } from 'url';
2
+ import presetPrompt from './preset-prompt.js';
3
+ import presetConfig from './preset-config.js';
4
+ import create from './create.js';
11
5
  const require = createRequire(import.meta.url);
12
- const { name, dependencies, devDependencies } = require('../package.json');
6
+ const { name, version, description } = require('../package.json');
13
7
 
8
+ // TODO: need to create types for "preset" plugins
14
9
  export default {
15
10
  name,
11
+ version,
12
+ description,
16
13
  hooks: {
17
- async presetPrompt(gasket, context, { prompt }) {
18
- context.apiApp = true;
19
- // TODOfollowup - TS prompt could possibly be global
20
- if (!('typescript' in context)) {
21
- const { typescript } = await prompt([
22
- {
23
- name: 'typescript',
24
- message: 'Do you want to use TypeScript?',
25
- type: 'confirm',
26
- default: false
27
- }
28
- ]);
29
-
30
- Object.assign(context, { typescript });
31
- }
32
- },
33
- async presetConfig(gasket, context) {
34
- let testPlugin, typescriptPlugin;
35
- if ('testPlugin' in context) {
36
- testPlugin = await import(context.testPlugin);
37
- }
38
-
39
- if (context.typescript) {
40
- typescriptPlugin = await import('@gasket/plugin-typescript');
41
- }
42
-
43
- return {
44
- plugins: [
45
- pluginExpress,
46
- pluginHttps,
47
- pluginDocs,
48
- pluginDocusaurus,
49
- pluginResponseData,
50
- pluginWinston,
51
- pluginSwagger,
52
- pluginLint,
53
- typescriptPlugin ? typescriptPlugin.default || typescriptPlugin : null,
54
- testPlugin ? testPlugin.default || testPlugin : null
55
- ].filter(Boolean)
56
- }
57
- },
58
- create(gasket, context) {
59
- const { pkg, files } = context;
60
- const __dirname = fileURLToPath(import.meta.url);
61
- const generatorDir = `${__dirname}/../../generator`;
62
-
63
- pkg.add('dependencies', dependencies);
64
-
65
- if (!context.typescript) {
66
- files.add(`${generatorDir}/*`);
67
-
68
- pkg.add('devDependencies', devDependencies);
69
-
70
- pkg.add('scripts', {
71
- start: 'node server.js',
72
- local: 'GASKET_ENV=local nodemon server.js',
73
- });
74
- }
75
- }
14
+ presetPrompt,
15
+ presetConfig,
16
+ create
76
17
  }
77
18
  };
@@ -0,0 +1,43 @@
1
+ import pluginHttps from '@gasket/plugin-https';
2
+ import pluginData from '@gasket/plugin-data';
3
+ import pluginWinston from '@gasket/plugin-winston';
4
+ import pluginSwagger from '@gasket/plugin-swagger';
5
+ import pluginLint from '@gasket/plugin-lint';
6
+
7
+ /**
8
+ * presetConfig hook
9
+ * @param {Gasket} gasket - Gasket API
10
+ * @param {Create} context - Create context
11
+ * @returns {Promise<CreateContext.presetConfig>} config
12
+ */
13
+ export default async function presetConfig(gasket, context) {
14
+ let typescriptPlugin;
15
+ const testPlugins = [];
16
+ const frameworkPlugin = context.server === 'express'
17
+ ? await import('@gasket/plugin-express')
18
+ : await import('@gasket/plugin-fastify');
19
+
20
+ if ('testPlugins' in context && context.testPlugins.length > 0) {
21
+ await Promise.all(context.testPlugins.map(async (testPlugin) => {
22
+ const plugin = await import(testPlugin);
23
+ testPlugins.push(plugin ? plugin.default || plugin : null);
24
+ }));
25
+ }
26
+
27
+ if (context.typescript) {
28
+ typescriptPlugin = await import('@gasket/plugin-typescript');
29
+ }
30
+
31
+ return {
32
+ plugins: [
33
+ pluginHttps,
34
+ pluginData,
35
+ pluginWinston,
36
+ pluginSwagger,
37
+ pluginLint,
38
+ frameworkPlugin.default || frameworkPlugin,
39
+ typescriptPlugin ? typescriptPlugin.default || typescriptPlugin : null,
40
+ ...testPlugins
41
+ ].filter(Boolean)
42
+ };
43
+ }
@@ -0,0 +1,32 @@
1
+ import typescriptPrompts from '@gasket/plugin-typescript/prompts';
2
+
3
+ /**
4
+ * presetPrompt hook
5
+ * @param {Gasket} gasket - Gasket API
6
+ * @param {Create} context - Create context
7
+ * @param {Object} utils - Prompt utils
8
+ * @param {Function} utils.prompt - Inquirer prompt
9
+ */
10
+ export default async function presetPrompt(gasket, context, { prompt }) {
11
+ context.apiApp = true;
12
+
13
+ await typescriptPrompts.promptTypescript(context, prompt);
14
+
15
+ if (!('server' in context)) {
16
+ const { server } = await prompt([
17
+ {
18
+ name: 'server',
19
+ message: 'Which server framework would you like to use?',
20
+ type: 'list',
21
+ choices: [
22
+ { name: 'Express', value: 'express' },
23
+ { name: 'Fastify', value: 'fastify' }
24
+ ]
25
+ }
26
+ ]);
27
+
28
+ Object.assign(context, { server });
29
+
30
+ return context;
31
+ }
32
+ }
package/package.json CHANGED
@@ -1,13 +1,22 @@
1
1
  {
2
2
  "name": "@gasket/preset-api",
3
- "version": "7.0.0-next.5",
3
+ "version": "7.0.0-next.50",
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",
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
+ },
11
20
  "repository": {
12
21
  "type": "git",
13
22
  "url": "git+ssh://git@github.com/godaddy/gasket.git"
@@ -21,20 +30,44 @@
21
30
  "url": "https://github.com/godaddy/gasket/issues"
22
31
  },
23
32
  "dependencies": {
24
- "@gasket/core": "^7.0.0-next.5",
25
- "@gasket/engine": "^7.0.0-next.5",
26
- "@gasket/plugin-docs": "^7.0.0-next.5",
27
- "@gasket/plugin-docusaurus": "^7.0.0-next.5",
28
- "@gasket/plugin-express": "^7.0.0-next.5",
29
- "@gasket/plugin-https": "^7.0.0-next.5",
30
- "@gasket/plugin-lint": "^7.0.0-next.5",
31
- "@gasket/plugin-response-data": "^7.0.0-next.5",
32
- "@gasket/plugin-swagger": "^7.0.0-next.5",
33
- "@gasket/plugin-winston": "^7.0.0-next.5",
34
- "@gasket/utils": "^7.0.0-next.5"
33
+ "@gasket/plugin-cypress": "^7.0.0-next.50",
34
+ "@gasket/plugin-data": "^7.0.0-next.50",
35
+ "@gasket/plugin-express": "^7.0.0-next.50",
36
+ "@gasket/plugin-fastify": "^7.0.0-next.50",
37
+ "@gasket/plugin-https": "^7.0.0-next.50",
38
+ "@gasket/plugin-jest": "^7.0.0-next.50",
39
+ "@gasket/plugin-lint": "^7.0.0-next.50",
40
+ "@gasket/plugin-mocha": "^7.0.0-next.50",
41
+ "@gasket/plugin-swagger": "^7.0.0-next.50",
42
+ "@gasket/plugin-typescript": "^7.0.0-next.50",
43
+ "@gasket/plugin-winston": "^7.0.0-next.50"
35
44
  },
36
45
  "devDependencies": {
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",
37
52
  "nodemon": "^3.1.0"
38
53
  },
39
- "gitHead": "b3b132ef284ac43616794283b969c23c45c0a90e"
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
+ ],
69
+ "jest": {
70
+ "transform": {}
71
+ },
72
+ "gitHead": "e7cfec6a118cf087c6532c23dc31170f4b15d182"
40
73
  }