create-gasket-app 7.3.0-canary.3 → 7.3.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.
Files changed (36) hide show
  1. package/README.md +55 -57
  2. package/lib/commands/create.js +21 -27
  3. package/lib/index.d.ts +306 -20
  4. package/lib/index.js +3 -0
  5. package/lib/internal.d.ts +178 -0
  6. package/lib/scaffold/actions/create-hooks.js +8 -10
  7. package/lib/scaffold/actions/generate-files.js +11 -22
  8. package/lib/scaffold/actions/global-prompts.js +26 -31
  9. package/lib/scaffold/actions/install-modules.js +3 -5
  10. package/lib/scaffold/actions/link-modules.js +3 -6
  11. package/lib/scaffold/actions/load-preset.js +10 -10
  12. package/lib/scaffold/actions/mkdir.js +5 -8
  13. package/lib/scaffold/actions/post-create-hooks.js +5 -8
  14. package/lib/scaffold/actions/preset-config-hooks.js +3 -4
  15. package/lib/scaffold/actions/preset-prompt-hooks.js +3 -4
  16. package/lib/scaffold/actions/print-report.js +10 -14
  17. package/lib/scaffold/actions/prompt-hooks.js +5 -14
  18. package/lib/scaffold/actions/setup-pkg.js +7 -8
  19. package/lib/scaffold/actions/write-gasket-config.js +15 -22
  20. package/lib/scaffold/actions/write-pkg.js +3 -5
  21. package/lib/scaffold/config-builder.js +111 -42
  22. package/lib/scaffold/create-context.js +9 -66
  23. package/lib/scaffold/dump-error-context.js +1 -4
  24. package/lib/scaffold/files.js +8 -5
  25. package/lib/scaffold/readme.js +51 -0
  26. package/lib/scaffold/utils.js +1 -9
  27. package/lib/scaffold/with-spinner.js +48 -0
  28. package/lib/utils/create-option.js +1 -2
  29. package/lib/utils/logo.js +10 -10
  30. package/lib/utils/process-args.js +5 -7
  31. package/lib/utils/process-command.js +2 -4
  32. package/lib/utils/process-options.js +6 -8
  33. package/package.json +59 -38
  34. package/lib/config/default-plugins.js +0 -15
  35. package/lib/scaffold/action-wrapper.js +0 -37
  36. package/lib/scaffold/actions/index.js +0 -33
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # create-gasket-app
2
2
 
3
- Starter Pack for creating Gasket apps.
3
+ Starter Pack for creating Gasket apps.
4
4
 
5
5
  ### Get Started Immediately
6
6
 
@@ -43,9 +43,6 @@ Options:
43
43
  -p, --presets [presets] Initial Gasket preset(s) to use.
44
44
  Can be set as short name with version (e.g. --presets nextjs@^1.0.0)
45
45
  Or other (multiple) custom presets (e.g. --presets my-gasket-preset@1.0.0.beta-1,nextjs@^1.0.0)
46
- --plugins [plugins] Additional plugin(s) to install. Can be set as
47
- multiple flags (e.g. --plugins jest --plugins zkconfig@^1.0.0)
48
- comma-separated values: --plugins=jest,zkconfig^1.0.0
49
46
  --package-manager [package-manager] Selects which package manager you would like to use during
50
47
  installation. (e.g. --package-manager yarn)
51
48
  -r, --require [require] Require module(s) before Gasket is initialized
@@ -84,7 +81,6 @@ Additional code style choices are prompted during the create command. Some
84
81
  predefined choices are provided from the [lint plugin], or you can specify your
85
82
  own config.
86
83
 
87
-
88
84
  ## Lifecycles
89
85
 
90
86
  Lifecycles for apps are enabled by plugins, however the CLI has some built-in
@@ -100,38 +96,36 @@ The `prompt` lifecycle is fired using [execWaterfall] and hooks should return a
100
96
  modified `context` object.
101
97
 
102
98
  ```js
103
- module.exports = {
104
- id: 'gasket-plugin-pizza',
105
- hooks: {
106
- async prompt(gasket, context, { prompt, addPlugins }) {
107
- const answers = await prompt([
108
- {
109
- name: 'pizzaSize',
110
- message: 'Choose a pizza size:',
111
- type: 'list',
112
- choices: ['small', 'medium', 'large']
113
- },
114
- {
115
- name: 'pizzaSauce',
116
- message: 'Choose a pizza sauce:',
117
- type: 'list',
118
- choices: ['red', 'white']
119
- },
120
- {
121
- name: 'wantSoda',
122
- message: 'Do you want a soda?',
123
- type: 'confirm'
124
- }
125
- ]);
126
-
127
- if (answers.wantSoda === true) {
128
- await addPlugins('gasket-plugin-soda@^2.0.0')
99
+ // gasket-plugin-pizza.js
100
+
101
+ const name = 'gasket-plugin-pizza';
102
+ const hooks = {
103
+ async prompt(gasket, context, { prompt }) {
104
+ const answers = await prompt([
105
+ {
106
+ name: 'pizzaSize',
107
+ message: 'Choose a pizza size:',
108
+ type: 'list',
109
+ choices: ['small', 'medium', 'large']
110
+ },
111
+ {
112
+ name: 'pizzaSauce',
113
+ message: 'Choose a pizza sauce:',
114
+ type: 'list',
115
+ choices: ['red', 'white']
116
+ },
117
+ {
118
+ name: 'wantSoda',
119
+ message: 'Do you want a soda?',
120
+ type: 'confirm'
129
121
  }
122
+ ]);
130
123
 
131
- return { ...context, ...answers };
132
- }
124
+ return { ...context, ...answers };
133
125
  }
134
126
  };
127
+
128
+ export default { name, hooks };
135
129
  ```
136
130
 
137
131
  The hook is passed the following parameters:
@@ -156,29 +150,31 @@ package.json or register files and templates to be generated.
156
150
  The `create` lifecycle is fired using [exec].
157
151
 
158
152
  ```js
159
- const path = require('path');
153
+ // gasket-plugin-pizza.js
160
154
 
161
- module.exports = {
162
- id: 'gasket-plugin-pizza',
163
- hooks: {
164
- async create(gasket, context) {
165
- const { pkg, files } = context; // utils from context
166
- const { pizzaSize, pizzaSauce } = context; // data provided by prompt
155
+ import path from 'path';
167
156
 
168
- files.add(
169
- path.join(__dirname, 'generator', 'ingredients', pizzaSauce)
170
- );
157
+ const name = 'gasket-plugin-pizza';
158
+ const hooks = {
159
+ async create(gasket, context) {
160
+ const { pkg, files } = context; // utils from context
161
+ const { pizzaSize, pizzaSauce } = context; // data provided by prompt
171
162
 
172
- pkg.add('devDependencies', {
173
- 'pizza-oven': '^1.0.0'
174
- });
163
+ files.add(
164
+ path.join(__dirname, 'generator', 'ingredients', pizzaSauce)
165
+ );
175
166
 
176
- pkg.add('scripts', {
177
- bake: `pizza-oven --size ${ pizzaSize }`
178
- });
179
- }
167
+ pkg.add('devDependencies', {
168
+ 'pizza-oven': '^1.0.0'
169
+ });
170
+
171
+ pkg.add('scripts', {
172
+ bake: `pizza-oven --size ${ pizzaSize }`
173
+ });
180
174
  }
181
175
  };
176
+
177
+ export default { name, hooks };
182
178
  ```
183
179
 
184
180
  The hook is passed the following parameters:
@@ -189,7 +185,7 @@ The hook is passed the following parameters:
189
185
  | `context` | The CreateContext with data from flags, prompts, etc |
190
186
  | `context.pkg` | Commonly used in create to add to package.json |
191
187
  | `context.file` | Commonly used to add files and templates for the app |
192
- | `context.gasketConfig` | Used to add config to the generated gasket.config.js |
188
+ | `context.gasketConfig` | Used to add config to the generated gasket.js |
193
189
  | `context.messages` | non-error/warning messages to report |
194
190
  | `context.warnings` | warnings messages to report |
195
191
  | `context.errors` | error messages to report but do not exit process |
@@ -206,9 +202,10 @@ generated. This is useful to use in conjunction with any scripts added in the
206
202
  The `postCreate` lifecycle is fired by [exec]:
207
203
 
208
204
  ```js
209
- module.exports = {
210
- id: 'totally-a-good-idea',
211
- hooks: {
205
+ // totally-a-good-idea.js
206
+
207
+ const name = 'totally-a-good-idea';
208
+ const hooks = {
212
209
  async create(gasket, context) {
213
210
  const { pkg } = context;
214
211
 
@@ -221,6 +218,8 @@ module.exports = {
221
218
  }
222
219
  }
223
220
  };
221
+
222
+ export default { name, hooks };
224
223
  ```
225
224
 
226
225
  The hook is passed the following parameters:
@@ -232,7 +231,6 @@ The hook is passed the following parameters:
232
231
  | `utils` | Functions that aid in post create hooks |
233
232
  | `utils.runScript` | run an `npm` script at the root of the generated `npm` package |
234
233
 
235
-
236
234
  ## License
237
235
 
238
236
  [MIT](./LICENSE.md)
@@ -245,7 +243,7 @@ The hook is passed the following parameters:
245
243
  [yarn env vars]:https://yarnpkg.com/en/docs/envvars#toc-npm-config
246
244
  [Jest plugin]:/packages/gasket-plugin-jest/README.md
247
245
  [Mocha plugin]:/packages/gasket-plugin-mocha/README.md
248
- [execWaterfall]:/packages/gasket-engine/README.md#execwaterfallevent-value-args
249
- [exec]:/packages/gasket-engine/README.md#execevent-args
246
+ [execWaterfall]:/packages/gasket-core/docs/gasket-engine.md#execwaterfallevent-value-args
247
+ [exec]:/packages/gasket-core/docs/gasket-engine.md#execevent-args
250
248
  [inquirer questions]:https://github.com/SBoudrias/Inquirer.js#question
251
249
  [lint plugin]:/packages/gasket-plugin-lint/README.md
@@ -4,30 +4,25 @@ import { makeCreateContext } from '../scaffold/create-context.js';
4
4
  import { dumpErrorContext } from '../scaffold/dump-error-context.js';
5
5
  import { rm } from 'fs/promises';
6
6
  import { makeGasket } from '@gasket/core';
7
- import { defaultPlugins } from '../config/default-plugins.js';
8
- import {
9
- createHooks,
10
- generateFiles,
11
- globalPrompts,
12
- installModules,
13
- linkModules,
14
- loadPreset,
15
- mkDir,
16
- postCreateHooks,
17
- printReport,
18
- presetPromptHooks,
19
- presetConfigHooks,
20
- promptHooks,
21
- setupPkg,
22
- writeGasketConfig,
23
- writePkg
24
- } from '../scaffold/actions/index.js';
7
+ import globalPrompts from '../scaffold/actions/global-prompts.js';
8
+ import loadPreset from '../scaffold/actions/load-preset.js';
9
+ import presetPromptHooks from '../scaffold/actions/preset-prompt-hooks.js';
10
+ import presetConfigHooks from '../scaffold/actions/preset-config-hooks.js';
11
+ import promptHooks from '../scaffold/actions/prompt-hooks.js';
12
+ import mkDir from '../scaffold/actions/mkdir.js';
13
+ import setupPkg from '../scaffold/actions/setup-pkg.js';
14
+ import createHooks from '../scaffold/actions/create-hooks.js';
15
+ import writePkg from '../scaffold/actions/write-pkg.js';
16
+ import generateFiles from '../scaffold/actions/generate-files.js';
17
+ import writeGasketConfig from '../scaffold/actions/write-gasket-config.js';
18
+ import installModules from '../scaffold/actions/install-modules.js';
19
+ import linkModules from '../scaffold/actions/link-modules.js';
20
+ import postCreateHooks from '../scaffold/actions/post-create-hooks.js';
21
+ import printReport from '../scaffold/actions/print-report.js';
25
22
 
26
23
  /**
27
24
  * Parses comma separated option input to array
28
- *
29
- * @param {String} input - option argument
30
- * @returns {String[]} results
25
+ * @type {import('../internal').commasToArray}
31
26
  */
32
27
  const commasToArray = input => input.split(',').map(name => name.trim());
33
28
 
@@ -53,7 +48,7 @@ const createCommand = {
53
48
  {
54
49
  name: 'package-manager',
55
50
  description: `Selects which package manager you would like to use during
56
- installation. (e.g. --package-manager yarn)`
51
+ installation. (e.g. --package-manager pnpm)`
57
52
  },
58
53
  {
59
54
  name: 'require',
@@ -97,12 +92,10 @@ const createCommand = {
97
92
 
98
93
  /**
99
94
  * createCommand action
100
- * @param {string} appname Required cmd arg - name of the app to create
101
- * @param {object} options cmd options
102
- * @param {Command} command - the command instance
103
- * @returns {Promise<void>} void
95
+ * @type {import('../index').createCommandAction}
104
96
  */
105
97
  createCommand.action = async function run(appname, options, command) {
98
+ // eslint-disable-next-line no-process-env
106
99
  process.env.GASKET_ENV = 'create';
107
100
  const context = makeCreateContext([appname], options);
108
101
  const { rawPresets, localPresets } = context;
@@ -123,7 +116,7 @@ createCommand.action = async function run(appname, options, command) {
123
116
 
124
117
  const pluginGasket = makeGasket({
125
118
  ...context.presetConfig,
126
- plugins: context.presets.concat(context.presetConfig.plugins, defaultPlugins)
119
+ plugins: context.presetConfig.plugins.concat(context.presets)
127
120
  });
128
121
 
129
122
  await promptHooks({ gasket: pluginGasket, context });
@@ -139,6 +132,7 @@ createCommand.action = async function run(appname, options, command) {
139
132
  if (context.tmpDir) await rm(context.tmpDir, { recursive: true });
140
133
  printReport({ context });
141
134
  } catch (err) {
135
+ // eslint-disable-next-line no-console
142
136
  console.error(chalk.red('Exiting with errors.'));
143
137
  dumpErrorContext(context, err);
144
138
  throw err;