create-gasket-app 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
@@ -100,38 +100,36 @@ The `prompt` lifecycle is fired using [execWaterfall] and hooks should return a
100
100
  modified `context` object.
101
101
 
102
102
  ```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')
103
+ // gasket-plugin-pizza.js
104
+
105
+ const name = 'gasket-plugin-pizza';
106
+ const hooks = {
107
+ async prompt(gasket, context, { prompt }) {
108
+ const answers = await prompt([
109
+ {
110
+ name: 'pizzaSize',
111
+ message: 'Choose a pizza size:',
112
+ type: 'list',
113
+ choices: ['small', 'medium', 'large']
114
+ },
115
+ {
116
+ name: 'pizzaSauce',
117
+ message: 'Choose a pizza sauce:',
118
+ type: 'list',
119
+ choices: ['red', 'white']
120
+ },
121
+ {
122
+ name: 'wantSoda',
123
+ message: 'Do you want a soda?',
124
+ type: 'confirm'
129
125
  }
126
+ ]);
130
127
 
131
- return { ...context, ...answers };
132
- }
128
+ return { ...context, ...answers };
133
129
  }
134
130
  };
131
+
132
+ export default { name, hooks };
135
133
  ```
136
134
 
137
135
  The hook is passed the following parameters:
@@ -156,29 +154,31 @@ package.json or register files and templates to be generated.
156
154
  The `create` lifecycle is fired using [exec].
157
155
 
158
156
  ```js
159
- const path = require('path');
157
+ // gasket-plugin-pizza.js
160
158
 
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
159
+ import path from 'path';
167
160
 
168
- files.add(
169
- path.join(__dirname, 'generator', 'ingredients', pizzaSauce)
170
- );
161
+ const name = 'gasket-plugin-pizza';
162
+ const hooks = {
163
+ async create(gasket, context) {
164
+ const { pkg, files } = context; // utils from context
165
+ const { pizzaSize, pizzaSauce } = context; // data provided by prompt
171
166
 
172
- pkg.add('devDependencies', {
173
- 'pizza-oven': '^1.0.0'
174
- });
167
+ files.add(
168
+ path.join(__dirname, 'generator', 'ingredients', pizzaSauce)
169
+ );
175
170
 
176
- pkg.add('scripts', {
177
- bake: `pizza-oven --size ${ pizzaSize }`
178
- });
179
- }
171
+ pkg.add('devDependencies', {
172
+ 'pizza-oven': '^1.0.0'
173
+ });
174
+
175
+ pkg.add('scripts', {
176
+ bake: `pizza-oven --size ${ pizzaSize }`
177
+ });
180
178
  }
181
179
  };
180
+
181
+ export default { name, hooks };
182
182
  ```
183
183
 
184
184
  The hook is passed the following parameters:
@@ -206,9 +206,10 @@ generated. This is useful to use in conjunction with any scripts added in the
206
206
  The `postCreate` lifecycle is fired by [exec]:
207
207
 
208
208
  ```js
209
- module.exports = {
210
- id: 'totally-a-good-idea',
211
- hooks: {
209
+ // totally-a-good-idea.js
210
+
211
+ const name = 'totally-a-good-idea';
212
+ const hooks = {
212
213
  async create(gasket, context) {
213
214
  const { pkg } = context;
214
215
 
@@ -221,6 +222,8 @@ module.exports = {
221
222
  }
222
223
  }
223
224
  };
225
+
226
+ export default { name, hooks };
224
227
  ```
225
228
 
226
229
  The hook is passed the following parameters:
@@ -103,21 +103,23 @@ const createCommand = {
103
103
  * @returns {Promise<void>} void
104
104
  */
105
105
  createCommand.action = async function run(appname, options, command) {
106
+ process.env.GASKET_ENV = 'create';
106
107
  const context = makeCreateContext([appname], options);
107
108
  const { rawPresets, localPresets } = context;
108
109
 
109
110
  try {
110
- await globalPrompts(null, context);
111
+ await globalPrompts({ context });
111
112
 
112
113
  if (rawPresets.length || localPresets.length) {
113
- await loadPreset(null, context);
114
+
115
+ await loadPreset({ context });
114
116
 
115
117
  const presetGasket = makeGasket({
116
118
  plugins: context.presets
117
119
  });
118
120
 
119
- await presetPromptHooks(presetGasket, context);
120
- await presetConfigHooks(presetGasket, context);
121
+ await presetPromptHooks({ gasket: presetGasket, context });
122
+ await presetConfigHooks({ gasket: presetGasket, context });
121
123
  }
122
124
 
123
125
  const pluginGasket = makeGasket({
@@ -125,18 +127,18 @@ createCommand.action = async function run(appname, options, command) {
125
127
  plugins: context.presets.concat(context.presetConfig.plugins, defaultPlugins)
126
128
  });
127
129
 
128
- await promptHooks(pluginGasket, context);
129
- await mkDir(null, context);
130
- await setupPkg(null, context);
131
- await createHooks(pluginGasket, context);
132
- await writePkg(null, context);
133
- await generateFiles(null, context);
134
- await writeGasketConfig(null, context);
135
- await installModules(null, context);
136
- await linkModules(null, context);
137
- await postCreateHooks(pluginGasket, context);
130
+ await promptHooks({ gasket: pluginGasket, context });
131
+ await mkDir({ context });
132
+ await setupPkg({ context });
133
+ await createHooks({ gasket: pluginGasket, context });
134
+ await writePkg({ context });
135
+ await generateFiles({ context });
136
+ await writeGasketConfig({ context });
137
+ await installModules({ context });
138
+ await linkModules({ context });
139
+ await postCreateHooks({ gasket: pluginGasket, context });
138
140
  if (context.tmpDir) await rm(context.tmpDir, { recursive: true });
139
- printReport(null, context);
141
+ printReport({ context });
140
142
  } catch (err) {
141
143
  console.error(chalk.red('Exiting with errors.'));
142
144
  dumpErrorContext(context, err);
@@ -1,7 +1,15 @@
1
1
  import pluginGit from '@gasket/plugin-git';
2
2
  import pluginLogger from '@gasket/plugin-logger';
3
+ import pluginMetadata from '@gasket/plugin-metadata';
4
+ import pluginCommand from '@gasket/plugin-command';
5
+ import pluginDocs from '@gasket/plugin-docs';
6
+ import pluginDocusaurus from '@gasket/plugin-docusaurus';
3
7
 
4
8
  export const defaultPlugins = [
5
9
  pluginLogger,
6
- pluginGit
10
+ pluginGit,
11
+ pluginMetadata,
12
+ pluginCommand,
13
+ pluginDocs,
14
+ pluginDocusaurus
7
15
  ];
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { GasketConfigDefinition, MaybeAsync } from '@gasket/engine';
1
+ import type { GasketConfigDefinition, MaybeAsync, Plugin, GasketEngine } from '@gasket/core';
2
2
  import type { PackageManager } from '@gasket/utils';
3
3
 
4
4
  export interface Dependencies {
@@ -9,17 +9,18 @@ export interface Dependencies {
9
9
 
10
10
  export interface PackageJson extends Dependencies {
11
11
  name: string;
12
- version: string;
12
+ version?: string;
13
13
  description?: string;
14
14
  license?: string;
15
15
  repository?:
16
16
  | string
17
17
  | {
18
- type: 'git';
19
- url: string;
20
- };
18
+ type: 'git';
19
+ url: string;
20
+ };
21
21
  scripts?: Record<string, string>;
22
22
  optionalDependencies?: Record<string, string>;
23
+ homepage?: string;
23
24
  }
24
25
 
25
26
  export interface ModuleInfo {
@@ -30,13 +31,16 @@ export interface ModuleInfo {
30
31
  version?: string;
31
32
  }
32
33
 
33
- export interface PresetInfo extends ModuleInfo {
34
- }
34
+ export interface PresetInfo extends ModuleInfo {}
35
35
 
36
- export interface PluginInfo extends ModuleInfo {
37
- }
36
+ export interface PluginInfo extends ModuleInfo {}
38
37
 
39
38
  export interface ConfigBuilder<Config> {
39
+ /**
40
+ * fields object
41
+ */
42
+ fields: { [key: string]: any };
43
+
40
44
  /**
41
45
  * Adds all `[key, value]` pairs in the `fields` provided.
42
46
  * @param fields - Object to merge. Can be a function that accepts the current fields and object to merge.
@@ -95,7 +99,7 @@ export interface ConfigBuilder<Config> {
95
99
  * import { readFileSync } from 'fs';
96
100
  * import fs from 'fs';
97
101
  */
98
- addImport(importName: string, importPath: string): ConfigBuilder;
102
+ addImport(importName: string, importPath: string): ConfigBuilder<Config>;
99
103
 
100
104
  /**
101
105
  * addExpression - add programmatic expression to the gasket file
@@ -110,7 +114,7 @@ export interface ConfigBuilder<Config> {
110
114
  * import fs from 'fs';
111
115
  * const file = fs.readFileSync('./file.txt');
112
116
  */
113
- addExpression(expression: string): ConfigBuilder;
117
+ addExpression(expression: string): ConfigBuilder<Config>;
114
118
 
115
119
  /**
116
120
  * injectValue - Inject a value into the gasket config object
@@ -127,21 +131,21 @@ export interface ConfigBuilder<Config> {
127
131
  * }
128
132
  * });
129
133
  */
130
- injectValue(configKey: string, injectedValue: any): void;
134
+ injectValue(configKey: string, injectedValue: string): void;
131
135
  }
132
136
 
133
137
  export interface PackageJsonBuilder extends ConfigBuilder<PackageJson> {
134
138
  /**
135
- * Checks if a dependency has been already added
136
- * @param key - Dependency bucket
137
- * @param value - Dependency to search
138
- * @returns True if the dependency exists on the bucket
139
+ * Checks if a property exists on the package.json fields.
140
+ * @param key - Field to search
141
+ * @param value - Value to search for
142
+ * @returns True if the property exists and matches the value
139
143
  */
140
- has(key: keyof Dependencies, value: string): boolean;
144
+ has(key: keyof PackageJson, value: string): boolean;
141
145
  }
142
146
 
143
147
  export interface Files {
144
- add(...args: string[]): void
148
+ add(...args: string[]): void;
145
149
  }
146
150
 
147
151
  export interface CreateContext {
@@ -186,7 +190,7 @@ export interface CreateContext {
186
190
  generatedFiles: Set<string>;
187
191
 
188
192
  /** Default empty array, populated by load-preset with actual imports */
189
- presets: Array<any>;
193
+ presets: Array<Plugin>;
190
194
 
191
195
  /** Default to object w/empty plugins array to be populated by `presetConfig` hook */
192
196
  presetConfig: GasketConfigDefinition;
@@ -199,8 +203,8 @@ export interface CreateContext {
199
203
  /** Should a git repo be initialized and first commit */
200
204
  gitInit: boolean;
201
205
 
202
- /** Name of the plugin for unit tests */
203
- testPlugin: string;
206
+ /** Names of the plugins that add unit and integration tests */
207
+ testPlugins: Array<string>;
204
208
 
205
209
  /** Which package manager to use (Default: 'npm') */
206
210
  packageManager: string;
@@ -233,14 +237,23 @@ export interface CreateContext {
233
237
  files: Files;
234
238
  }
235
239
 
236
- declare module '@gasket/engine' {
240
+ export interface ActionWrapperParams {
241
+ gasket: GasketEngine;
242
+ context: CreateContext;
243
+ spinner?: any;
244
+ }
245
+
246
+ declare module '@gasket/core' {
237
247
  export interface HookExecTypes {
238
248
  presetPrompt(context: CreateContext): Promise<void>;
239
- presetConfig(context: CreateContext): Promise<void>;
249
+ presetConfig(context: CreateContext): Promise<CreateContext['presetConfig']>;
240
250
  prompt(
241
251
  context: CreateContext,
242
252
  utils: {
243
- prompt: (prompts: Array<Record<string, any>>) => Promise<Record<string, any>>,
253
+ prompt: (
254
+ prompts: Array<Record<string, any>>
255
+ ) => Promise<Record<string, any>>;
256
+ addPlugins: (plugins: Array<string>) => Promise<void>;
244
257
  }
245
258
  ): MaybeAsync<CreateContext>;
246
259
 
@@ -249,7 +262,8 @@ declare module '@gasket/engine' {
249
262
  postCreate(
250
263
  context: CreateContext,
251
264
  utils: {
252
- runScript: (script: string) => Promise<void>
253
- }): MaybeAsync<void>;
265
+ runScript: (script: string) => Promise<void>;
266
+ }
267
+ ): MaybeAsync<void>;
254
268
  }
255
269
  }
package/lib/index.js CHANGED
@@ -2,7 +2,8 @@
2
2
  import { Command } from 'commander';
3
3
  import { createRequire } from 'module';
4
4
  import { createCommand } from './commands/create.js';
5
- import { processCommand, logo, warnIfOutdated } from './utils/index.js';
5
+ import { processCommand, logo } from './utils/index.js';
6
+ import { warnIfOutdated } from '@gasket/utils';
6
7
 
7
8
  const require = createRequire(import.meta.url);
8
9
  const pkg = require('../package.json');
@@ -14,14 +14,16 @@ export default function withSpinner(label, fn, { startSpinner = true } = {}) {
14
14
  /**
15
15
  * Decorated function
16
16
  *
17
- * @param {CreateContext} context - Create context
17
+ * @param {ActionWrapperParams} params - ActionWrapperParams
18
+ * @param {GasketEngine} params.gasket - Gasket config
19
+ * @param {CreateContext} params.context - Create context
18
20
  * @returns {Promise} promise
19
21
  */
20
- async function wrapper(gasket = {}, context) {
22
+ async function wrapper({ gasket = {}, context }) {
21
23
  const spinner = ora(label);
22
24
  if (startSpinner) spinner.start();
23
25
  try {
24
- await fn(gasket, context, spinner);
26
+ await fn({ gasket, context, spinner });
25
27
  if (spinner.isSpinning) spinner.succeed();
26
28
  } catch (err) {
27
29
  spinner.fail();
@@ -6,10 +6,11 @@ import { Files } from '../files.js';
6
6
  * Executes the `create` hook for all registered plugins.
7
7
  * Adds `files` to context for plugins to add their files and templates.
8
8
  *
9
+ * @param {GasketEngine} gasket - Gasket API
9
10
  * @param {CreateContext} context - Create context
10
11
  * @returns {Promise} promise
11
12
  */
12
- async function createHooks(gasket, context) {
13
+ async function createHooks({ gasket, context }) {
13
14
  const { plugins = [], warnings } = context;
14
15
 
15
16
  const files = new Files();
@@ -109,6 +109,7 @@ async function performGenerate(context, descriptors) {
109
109
  handlebars.registerHelper('jspretty', (data) => {
110
110
  return JSON.stringify(data).replace(/"/g, '\'');
111
111
  });
112
+ handlebars.registerHelper('eq', (a, b) => a === b)
112
113
 
113
114
  debug('descriptors', JSON.stringify(descriptors, null, 2));
114
115
 
@@ -164,7 +165,7 @@ async function performGenerate(context, descriptors) {
164
165
  * @param {Spinner} spinner - Spinner
165
166
  * @returns {Promise} promise
166
167
  */
167
- async function generateFiles(_, context, spinner) {
168
+ async function generateFiles({ context, spinner }) {
168
169
  const { files } = context;
169
170
 
170
171
  if (!files.globSets.length) {
@@ -61,42 +61,54 @@ async function choosePackageManager(context, prompt) {
61
61
  }
62
62
 
63
63
  /**
64
- * Choose your unit test suite
64
+ * Choose your unit test suite and integration test suite
65
65
  *
66
66
  * @param {CreateContext} context - Create context
67
67
  * @param {function} prompt - function to prompt user
68
68
  * @returns {Promise} promise
69
69
  */
70
- async function chooseTestPlugin(context, prompt) {
71
- const knownTestPlugins = { mocha: '@gasket/plugin-mocha', jest: '@gasket/plugin-jest', cypress: '@gasket/plugin-cypress' };
72
-
73
- if (!('testPlugin' in context)) {
74
- let testPlugin;
70
+ async function chooseTestPlugins(context, prompt) {
71
+ const knownTestPlugins = {
72
+ unit: { mocha: '@gasket/plugin-mocha', jest: '@gasket/plugin-jest' },
73
+ integration: { cypress: '@gasket/plugin-cypress' }
74
+ };
75
75
 
76
- if ('testSuite' in context) {
77
- testPlugin = knownTestPlugins[context.testSuite];
76
+ const testTypes = ['unit', 'integration'];
77
+ const testPlugins = [];
78
+
79
+ if (!('testPlugins' in context)) {
80
+ for (const type of testTypes) {
81
+ if (type + 'TestSuite' in context) {
82
+ const testSuite = knownTestPlugins[type][context[type + 'TestSuite']];
83
+ if (testSuite) testPlugins.push(testSuite);
84
+ } else {
85
+ const plugin = await promptForTestPlugin(
86
+ prompt,
87
+ `Choose your ${type} test suite`,
88
+ Object.entries(knownTestPlugins[type]).map(([name, value]) => ({ name, value }))
89
+ );
90
+
91
+ if (plugin) testPlugins.push(plugin);
92
+ }
78
93
  }
79
94
 
80
- if (!testPlugin) {
81
- ({ testPlugin } = await prompt([
82
- {
83
- name: 'testPlugin',
84
- message: 'Choose your unit test suite',
85
- type: 'list',
86
- choices: [
87
- { name: 'none (not recommended)', value: 'none' },
88
- { name: 'mocha + nyc + sinon + chai', value: '@gasket/plugin-mocha' },
89
- { name: 'jest', value: '@gasket/plugin-jest' },
90
- { name: 'cypress', value: '@gasket/plugin-cypress' }
91
- ]
92
- }
93
- ]));
95
+ if (testPlugins.length > 0) {
96
+ Object.assign(context, { testPlugins });
94
97
  }
98
+ }
99
+ }
95
100
 
96
- if (testPlugin && testPlugin !== 'none') {
97
- Object.assign(context, { testPlugin });
101
+ async function promptForTestPlugin(prompt, message, choices) {
102
+ const { testPlugin } = await prompt([
103
+ {
104
+ name: 'testPlugin',
105
+ message,
106
+ type: 'list',
107
+ choices: [{ name: 'none', value: 'none' }, ...choices]
98
108
  }
99
- }
109
+ ]);
110
+
111
+ return testPlugin !== 'none' ? testPlugin : null;
100
112
  }
101
113
 
102
114
  /**
@@ -126,7 +138,7 @@ async function allowExtantOverwriting(context, prompt) {
126
138
  export const questions = [
127
139
  chooseAppDescription,
128
140
  choosePackageManager,
129
- chooseTestPlugin,
141
+ chooseTestPlugins,
130
142
  allowExtantOverwriting
131
143
  ];
132
144
 
@@ -136,7 +148,7 @@ export const questions = [
136
148
  * @param {CreateContext} context - Create context
137
149
  * @returns {Promise} promise
138
150
  */
139
- async function globalPrompts(_, context) {
151
+ async function globalPrompts({ context }) {
140
152
  const prompt = context.prompts ? inquirer.prompt : () => ({});
141
153
  for (var fn of questions) {
142
154
  await fn(context, prompt);
@@ -6,7 +6,7 @@ import action from '../action-wrapper.js';
6
6
  * @param {CreateContext} context - Create context
7
7
  * @returns {Promise} promise
8
8
  */
9
- async function installModules(_, context) {
9
+ async function installModules({ context }) {
10
10
  const { pkgManager } = context;
11
11
 
12
12
  await pkgManager.install();
@@ -7,7 +7,7 @@ import action from '../action-wrapper.js';
7
7
  * @param {Spinner} spinner - Spinner
8
8
  * @returns {Promise} promise
9
9
  */
10
- async function linkModules(_, context, spinner) {
10
+ async function linkModules({ context, spinner }) {
11
11
  const { pkgLinks, pkgManager } = context;
12
12
 
13
13
  if (pkgLinks && pkgLinks.length) {
@@ -5,37 +5,53 @@ import { default as gasketUtils } from '@gasket/utils';
5
5
  import { mkdtemp } from 'fs/promises';
6
6
  import { createRequire } from 'module';
7
7
  const require = createRequire(import.meta.url);
8
+ const hasVersionOrTag = /@([\^~]?\d+\.\d+\.\d+(?:-[\d\w.-]+)?|[\^~]?\d+\.\d+\.\d+|[a-zA-Z]+)$/;
8
9
 
9
10
  /**
10
11
  * loadPresets - Load presets to temp directory
11
- * @param {null} _ - no input
12
12
  * @param {CreateContext} context - Create context
13
13
  */
14
- async function loadPresets(_, context) {
14
+ async function loadPresets({ context }) {
15
15
  const tmpDir = await mkdtemp(path.join(os.tmpdir(), `gasket-create-${context.appName}`));
16
16
  context.tmpDir = tmpDir;
17
17
 
18
+ const modPath = path.join(tmpDir, 'node_modules');
18
19
  const pkgManager = new gasketUtils.PackageManager({
19
20
  packageManager: context.packageManager,
20
21
  dest: tmpDir
21
22
  });
22
- const pkgVerb = pkgManager.isYarn ? 'add' : 'install';
23
+ const pkgVerb = pkgManager.manager === 'yarn' ? 'add' : 'install';
23
24
 
24
25
  const remotePresets = context.rawPresets.map(async preset => {
25
- const parts = /@(\^[0-9]\.|[0-9]).+/.test(preset) && preset.split('@').filter(Boolean);
26
+ const parts = hasVersionOrTag.test(preset) && preset.split('@').filter(Boolean);
26
27
  const name = parts ? `@${parts[0]}` : preset;
27
28
  const version = parts ? `@${parts[1]}` : '@latest';
28
- await pkgManager.exec(pkgVerb, [`${name}${version}`]);
29
- // eslint-disable-next-line
30
- const mod = await import(name);
31
- return mod.default || mod;
29
+
30
+ try {
31
+ // Install the preset
32
+ await pkgManager.exec(pkgVerb, [`${name}${version}`]);
33
+ // Get the package file
34
+ const pkgFile = require(path.join(modPath, name, 'package.json'));
35
+ // Import the preset via the package file attrs, name and main
36
+ // We can't specify the cwd for the import, so we need to use the full path
37
+ // expects type:module & "main": "lib/fullpath.js"
38
+ const mod = await import(`${modPath}/${name}/${pkgFile.main}`);
39
+ return mod.default || mod;
40
+ } catch (err) {
41
+ throw new Error(`Failed to install preset ${name}${version}: ${err.message}`);
42
+ }
32
43
  });
33
44
 
34
45
  const localPresets = context.localPresets.map(async localPresetPath => {
35
- await pkgManager.exec(pkgVerb, [localPresetPath]);
36
- const pkgFile = require(path.join(localPresetPath, 'package.json'));
37
- const mod = await import(pkgFile.name);
38
- return mod.default || mod;
46
+
47
+ try {
48
+ await pkgManager.exec(pkgVerb, [localPresetPath]);
49
+ const pkgFile = require(path.join(localPresetPath, 'package.json'));
50
+ const mod = await import(`${modPath}/${pkgFile.name}/${pkgFile.main}`);
51
+ return mod.default || mod;
52
+ } catch (err) {
53
+ throw new Error(`Failed to install local preset ${localPresetPath}`);
54
+ }
39
55
  });
40
56
 
41
57
  context.presets = await Promise.all([...remotePresets, ...localPresets]);
@@ -10,7 +10,7 @@ import action from '../action-wrapper.js';
10
10
  * @param {Spinner} spinner - Spinner
11
11
  * @returns {Promise} promise
12
12
  */
13
- async function mkDir(_, context, spinner) {
13
+ async function mkDir({ context, spinner }) {
14
14
  const { dest, relDest, extant, destOverride } = context;
15
15
 
16
16
  // At this point, either the directory does not exist, or the user has
@@ -4,10 +4,11 @@ import { runShellCommand } from '@gasket/utils';
4
4
  /**
5
5
  * Executes the `postCreate` hook for all registered plugins.
6
6
  *
7
+ * @param {GasketEngine} gasket - Gasket API
7
8
  * @param {CreateContext} context - Create context
8
9
  * @returns {Promise} promise
9
10
  */
10
- async function postCreateHooks(gasket, context) {
11
+ async function postCreateHooks({ gasket, context }) {
11
12
  const { dest } = context;
12
13
 
13
14
  /**
@@ -5,7 +5,7 @@ import action from '../action-wrapper.js';
5
5
  * @param {Gasket} gasket - Preset gasket instance
6
6
  * @param {CreateContext} context - Create context
7
7
  */
8
- async function presetConfigHooks(gasket, context) {
8
+ async function presetConfigHooks({ gasket, context }) {
9
9
  const config = await gasket.execWaterfall('presetConfig', context);
10
10
  Object.assign(context.presetConfig, config);
11
11
  }
@@ -6,7 +6,7 @@ import action from '../action-wrapper.js';
6
6
  * @param {Gasket} gasket - Preset gasket instance
7
7
  * @param {CreateContext} context - Create context
8
8
  */
9
- async function presetPromptHooks(gasket, context) {
9
+ async function presetPromptHooks({ gasket, context }) {
10
10
  const prompt = context.prompts ? inquirer.createPromptModule() : () => ({});
11
11
 
12
12
  const nextContext = await gasket.execWaterfall('presetPrompt', context, { prompt });
@@ -63,7 +63,7 @@ function buildReport(context) {
63
63
 
64
64
  * @param {CreateContext} context - Create context
65
65
  */
66
- async function printReport(_, context) {
66
+ async function printReport({ context }) {
67
67
  const report = buildReport(context);
68
68
  const { warnings, errors } = context;
69
69
 
@@ -27,10 +27,11 @@ async function execPluginPrompts(gasket, context) {
27
27
  * Executes the `prompt` hook for all registered plugins.
28
28
  * Adds `prompt` util function for prompting features.
29
29
  *
30
+ * @param {GasketEngine} gasket - Gasket API
30
31
  * @param {CreateContext} context - Create context
31
32
  * @returns {Promise} promise
32
33
  */
33
- async function promptHooks(gasket, context) {
34
+ async function promptHooks({ gasket, context }) {
34
35
  //
35
36
  // Because `execPluginPrompts` is recursively, we need to start it
36
37
  // with the processPlugins and presets from our initial context
@@ -1,6 +1,9 @@
1
1
  import action from '../action-wrapper.js';
2
2
  import { ConfigBuilder } from '../config-builder.js';
3
3
  import { default as gasketUtils } from '@gasket/utils';
4
+ import { createRequire } from 'module';
5
+ const require = createRequire(import.meta.url);
6
+ const { dependencies } = require('../../../package.json');
4
7
 
5
8
  /**
6
9
  * Initializes the ConfigBuilder builder and adds to context.
@@ -8,16 +11,22 @@ import { default as gasketUtils } from '@gasket/utils';
8
11
  * @param {CreateContext} context - Create context
9
12
  * @returns {Promise} promise
10
13
  */
11
- async function setupPkg(gasket, context) {
14
+ async function setupPkg({ context }) {
12
15
  const { appName, appDescription, warnings } = context;
13
16
 
14
17
  const pkg = ConfigBuilder.createPackageJson({
15
18
  name: appName,
16
19
  version: '0.0.0',
17
20
  description: appDescription,
18
- type: context.typescript ? 'commonjs' : 'module'
21
+ type: 'module'
19
22
  }, { warnings });
20
23
 
24
+ // Add critical dependencies
25
+ pkg.add('dependencies', {
26
+ '@gasket/core': dependencies['@gasket/core'],
27
+ '@gasket/utils': dependencies['@gasket/utils']
28
+ });
29
+
21
30
  const pkgManager = new gasketUtils.PackageManager(context);
22
31
  Object.assign(context, { pkg, pkgManager });
23
32
  }
@@ -88,9 +88,9 @@ function cleanupFields(config) {
88
88
  * @param {CreateContext} context - Create context
89
89
  * @returns {Promise} promise
90
90
  */
91
- async function writeGasketConfig(gasket, context) {
92
- const { dest, gasketConfig, generatedFiles } = context;
93
- const fileName = context.typescript ? 'gasket.ts' : 'gasket.js';
91
+ async function writeGasketConfig({ context }) {
92
+ const { dest, gasketConfig, generatedFiles, typescript } = context;
93
+ const fileName = typescript ? 'gasket.ts' : 'gasket.js';
94
94
  const filePath = path.join(dest, fileName);
95
95
  const plugins = gasketConfig.fields.plugins;
96
96
  const assignments = gasketConfig.fields.injectionAssignments || null;
@@ -98,6 +98,7 @@ async function writeGasketConfig(gasket, context) {
98
98
  gasketConfig.fields.plugins = 'PLUGIN_REPLACE';
99
99
 
100
100
  let contents = '';
101
+ if (typescript) contents += `import type { GasketConfigDefinition } from '@gasket/core';\n`;
101
102
  contents += `import { makeGasket } from '@gasket/core';\n`;
102
103
  contents += writeImports(gasketConfig.fields.pluginImports);
103
104
  contents += writeImports(gasketConfig.fields.imports);
@@ -105,8 +106,9 @@ async function writeGasketConfig(gasket, context) {
105
106
  createInjectionAssignments(gasketConfig.fields, assignments);
106
107
  cleanupFields(gasketConfig);
107
108
 
108
- const pluginImports = `[\n${writePluginImports(plugins)}\n\t]`;
109
- contents += `\nexport default makeGasket(${JSON5.stringify(gasketConfig.fields, null, 2)});\n`;
109
+ const pluginImports = `[\n${writePluginImports(plugins)}\n ]`;
110
+ const typeCoercion = typescript ? ' as GasketConfigDefinition' : '';
111
+ contents += `\nexport default makeGasket(${JSON5.stringify(gasketConfig.fields, null, 2)}${typeCoercion});\n`;
110
112
  contents = contents.replace('\'PLUGIN_REPLACE\'', pluginImports);
111
113
  contents = replaceInjectionAssignments(contents, assignments);
112
114
 
@@ -6,10 +6,9 @@ import action from '../action-wrapper.js';
6
6
  * Writes the contents of `pkg` to the app's package.json.
7
7
  *
8
8
  * @param {CreateContext} context - Create context
9
- * @param {Boolean} update - Is an update step
10
9
  * @returns {Promise} promise
11
10
  */
12
- async function writePkg(gasket, context) {
11
+ async function writePkg({ context }) {
13
12
  const { dest, pkg, generatedFiles } = context;
14
13
  const fileName = 'package.json';
15
14
  const filePath = path.join(dest, fileName);
@@ -18,5 +17,3 @@ async function writePkg(gasket, context) {
18
17
  }
19
18
 
20
19
  export default action('Write package.json', writePkg);
21
-
22
- export const writePkgUpdate = action('Update package.json', writePkg);
@@ -376,9 +376,12 @@ export class ConfigBuilder {
376
376
  return;
377
377
  }
378
378
 
379
+ // If a prerelease version, strip the range prefix
380
+ const version = ver.includes('-') ? ver.replace(/^[\^~]/, '') : ver;
381
+
379
382
  const blameId = `${key}.${dep}`;
380
383
  if (!prev) {
381
- existing[dep] = ver;
384
+ existing[dep] = version;
382
385
  setBlame(blameId);
383
386
  return;
384
387
  }
@@ -386,7 +389,7 @@ export class ConfigBuilder {
386
389
  const blamed = this.blame.get(blameId);
387
390
  const forced = this.force.has(blameId);
388
391
 
389
- if (prev === ver) {
392
+ if (prev === version) {
390
393
  if (forced) return;
391
394
  if (force) {
392
395
  setBlame(blameId);
@@ -398,21 +401,21 @@ export class ConfigBuilder {
398
401
 
399
402
  const prevName = blamed.join(', ');
400
403
  if (!forced) {
401
- const newer = force ? ver : this.tryGetNewerRange(prev, ver);
402
- const overridden = newer === ver;
404
+ const newer = force ? version : this.tryGetNewerRange(prev, version);
405
+ const overridden = newer === version;
403
406
  if (overridden) {
404
- existing[dep] = ver;
407
+ existing[dep] = version;
405
408
  setBlame(blameId);
406
409
  }
407
410
  }
408
411
 
409
- if (!semver.validRange(prev) || !semver.validRange(ver) || !semver.intersects(prev, ver)) {
412
+ if (!semver.validRange(prev) || !semver.validRange(version) || !semver.intersects(prev, version)) {
410
413
  let forceMsg = force ? '(forced)' : '';
411
414
  forceMsg = forced && force ? '(cannot be forced)' : forceMsg;
412
415
  this.warn(`
413
416
  Conflicting versions for ${dep} in "${key}":
414
417
  - ${prev} provided by ${prevName} ${forced && '(forced)' || ''}
415
- - ${ver} provided by ${name} ${forceMsg}
418
+ - ${version} provided by ${name} ${forceMsg}
416
419
  Using ${existing[dep]}, but this may cause unexpected behavior.
417
420
  `);
418
421
  }
@@ -83,7 +83,7 @@ function flatten(acc, values) {
83
83
  *
84
84
  * @property {String} appDescription - Description of app
85
85
  * @property {Boolean} gitInit - Should a git repo be initialized and first commit
86
- * @property {String} testPlugin - Name of the plugin for unit tests
86
+ * @property {String} testPlugins - Array of testing plugins
87
87
  * @property {String} packageManager - Which package manager to use (Default: 'npm')
88
88
  * @property {String} installCmd - Derived install command (Default: 'npm install')
89
89
  * @property {String} localCmd - Derived local run command (Default: 'npx gasket local')
@@ -3,4 +3,3 @@ export { processArgs } from './process-args.js';
3
3
  export { processOptions } from './process-options.js';
4
4
  export { createOption } from './create-option.js';
5
5
  export { logo } from './logo.js';
6
- export { warnIfOutdated } from './warn-if-outdated.js';
package/lib/utils/logo.js CHANGED
@@ -1,12 +1,12 @@
1
1
  export const logo = `
2
- ▄▄▄▄████▀▀█▄
3
- ▄███▀▀▀▀▀▀▀█▄▄██
4
- ▄██▀ ▄▄▄▄▄ ▀██▌ ▄▄▄
5
- ▄██▀ ███▀▀▀▀█ ██ ██ ██
6
- █▀▀█ ██▌ ▐█▌ ▄▀▀▀█▄ ▄█▀▀▀▄ ██ ▐██▀ ▄█▀▀█▄ ▀██▀▀
7
- █▄▄█ ██▌ ▀▀██ ▐█▌ ▄▄▄▄██ ▀▀█▄▄▄ █████ ██▄▄██ ██
8
- ▀██▄ ███▄▄▄▄██ ██ ▀▄▄▄▀█▄ ▀▄▄▄█▀ ▄██▄ ██▄ ▀█▄▄▄▄ ▀█▄▄
9
- ▀██▄ ▀▀▀ ▀▀ ▄██▌
10
- ▀███▄▄▄▄▄▄▄█▀▀██
11
- ▀▀▀▀████▄▄█▀
2
+ ▄▄▄▄████▀▀█▄
3
+ ▄████▀▀▀▀▀▀█▄▄██
4
+ ███▀ ▄▄▄▄▄ ▀██▌ ▄▄▄
5
+ ▄███ ███▀▀▀▀██ ██ ██ ██
6
+ █▀▀█ ██▌ ▐█▌ ▄▀▀▀█▄ ▄█▀▀▀▄ ██ ▐██▀ ▄█▀▀█▄ ▀██▀▀
7
+ █▄▄█ ██▌ ▀▀██ ▐█▌ ▄▄▄▄██ ▀▀█▄▄▄ █████ ██▄▄██ ██
8
+ ▀███ ███▄▄▄▄██ ██ ▀▄▄▄▀█▄ ▀▄▄▄█▀ ▄██▄ ██▄ ▀█▄▄▄▄ ▀█▄▄
9
+ ███▄ ▀▀▀ ▀▀ ▄██▌
10
+ ▀████▄▄▄▄▄▄█▀▀██
11
+ ▀▀▀▀████▄▄█▀
12
12
  `;
@@ -1,5 +1,7 @@
1
1
  import { Command } from 'commander';
2
- import { processArgs, processOptions, createOption } from './index.js';
2
+ import { processArgs } from './process-args.js';
3
+ import { processOptions } from './process-options.js';
4
+ import { createOption } from './create-option.js';
3
5
  const program = new Command();
4
6
 
5
7
  /**
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "create-gasket-app",
3
- "version": "7.0.0-next.6",
3
+ "version": "7.0.0-next.60",
4
4
  "description": "starter pack for creating a gasket app",
5
- "main": "lib",
5
+ "type": "module",
6
6
  "bin": {
7
7
  "create-gasket-app": "./lib/index.js"
8
8
  },
9
+ "main": "lib/index.js",
10
+ "types": "lib/index.d.ts",
9
11
  "files": [
10
12
  "lib"
11
13
  ],
12
- "type": "module",
13
14
  "scripts": {
14
15
  "lint": "eslint .",
15
16
  "lint:fix": "npm run lint -- --fix",
16
17
  "test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict --experimental-vm-modules' jest",
17
- "test:watch": "jest --watch",
18
+ "test:watch": "npm run test -- --watch",
18
19
  "test:coverage": "jest --coverage",
19
20
  "posttest": "npm run lint"
20
21
  },
@@ -32,17 +33,17 @@
32
33
  },
33
34
  "homepage": "https://github.com/godaddy/gasket/tree/main/packages/create-gasket-app",
34
35
  "dependencies": {
35
- "@gasket/core": "^7.0.0-next.6",
36
- "@gasket/engine": "^7.0.0-next.6",
37
- "@gasket/plugin-git": "^7.0.0-next.6",
38
- "@gasket/plugin-lifecycle": "^7.0.0-next.6",
39
- "@gasket/plugin-logger": "^7.0.0-next.6",
40
- "@gasket/plugin-metadata": "^7.0.0-next.6",
41
- "@gasket/plugin-start": "^7.0.0-next.6",
42
- "@gasket/resolve": "^7.0.0-next.6",
43
- "@gasket/utils": "^7.0.0-next.6",
36
+ "@gasket/core": "7.0.0-next.60",
37
+ "@gasket/plugin-command": "7.0.0-next.60",
38
+ "@gasket/plugin-docs": "7.0.0-next.60",
39
+ "@gasket/plugin-docusaurus": "7.0.0-next.60",
40
+ "@gasket/plugin-git": "7.0.0-next.60",
41
+ "@gasket/plugin-logger": "7.0.0-next.60",
42
+ "@gasket/plugin-metadata": "7.0.0-next.60",
43
+ "@gasket/utils": "7.0.0-next.60",
44
44
  "commander": "^12.0.0",
45
45
  "deepmerge": "^4.3.1",
46
+ "glob": "^8.1.0",
46
47
  "handlebars": "^4.7.8",
47
48
  "inquirer": "6.5.2",
48
49
  "json5": "^2.2.3",
@@ -58,10 +59,10 @@
58
59
  "diagnostics": "^2.0.2",
59
60
  "dotenv": "^16.4.5",
60
61
  "eslint": "^8.56.0",
61
- "eslint-config-godaddy": "^7.0.2",
62
- "eslint-plugin-jest": "^27.6.3",
62
+ "eslint-config-godaddy": "^7.1.1",
63
+ "eslint-plugin-jest": "^28.6.0",
63
64
  "eslint-plugin-json": "^3.1.0",
64
- "eslint-plugin-unicorn": "^44.0.0",
65
+ "eslint-plugin-unicorn": "^55.0.0",
65
66
  "jest": "^29.7.0"
66
67
  },
67
68
  "eslintConfig": {
@@ -82,5 +83,5 @@
82
83
  "jest": {
83
84
  "transform": {}
84
85
  },
85
- "gitHead": "805a1026959d8aa783ee32be8a8ff76c06badd2f"
86
+ "gitHead": "ea9feae6cd291d4361c06e09659e50dbec19bcea"
86
87
  }
@@ -1,32 +0,0 @@
1
- import { default as diagnostics } from 'diagnostics';
2
- const debug = diagnostics('gasket:cli:config:utils');
3
-
4
- /**
5
- * Returns specified env option if set or appropriate fallback
6
- *
7
- * @param {Object} options - CLI Option
8
- * @param {string} commandId - Name of the command
9
- * @param {function} warn - Warning logger
10
- * @returns {string} environment
11
- */
12
- export function getEnvironment(options, commandId, warn) {
13
- if (options.env) {
14
- debug('Environment was passed through command line options', options.env);
15
- return options.env;
16
- }
17
-
18
- // special snowflake case to match up `local` env with command unless set
19
- if (commandId === 'local') {
20
- debug('Environment defaulting to `local` due to `local` command');
21
- return 'local';
22
- }
23
-
24
- const { NODE_ENV } = process.env;
25
- if (NODE_ENV) {
26
- warn(`No env specified, falling back to NODE_ENV: "${ NODE_ENV }".`);
27
- return NODE_ENV;
28
- }
29
-
30
- warn('No env specified, falling back to "development".');
31
- return 'development';
32
- }
package/lib/main.js DELETED
@@ -1,20 +0,0 @@
1
- import { fork } from 'child_process';
2
- import { createRequire } from 'module';
3
- const require = createRequire(import.meta.url);
4
-
5
- /**
6
- * Executes the @gasket/cli passing through the create command and any arguments.
7
- *
8
- * @param {string[]} args - create command arguments
9
- * @returns {ChildProcess} process
10
- */
11
- export default function main(...args) {
12
- // import.meta.resolve is not available in Jest without babel transform
13
- const gasketBin = require.resolve('@gasket/cli/bin/run');
14
-
15
- return fork(
16
- gasketBin,
17
- ['create', ...args],
18
- { stdio: 'inherit', stdin: 'inherit', stderr: 'inherit' }
19
- );
20
- }
@@ -1,78 +0,0 @@
1
- import { default as gasketUtils } from '@gasket/utils';
2
- import semver from 'semver';
3
- import chalk from 'chalk';
4
- import { readFile, writeFile } from 'fs/promises';
5
- import path from 'path';
6
- import { fileURLToPath } from 'url';
7
- const __dirname = fileURLToPath(import.meta.url);
8
-
9
- const cachePath = path.join(__dirname, '..', '..', '..', '.cache'); // Place at root of gasket-cli
10
- const LATEST_VERSION = 'latestVersion';
11
- const LATEST_VERSION_UPDATE_TIME = 'latestVersionUpdateTime';
12
-
13
- /**
14
- * Checks if the latest version update time is older than seven days
15
- * @param {number} currentTime - current time in milliseconds
16
- * @param {number} latestVersionUpdateTime - latest version update time in milliseconds
17
- * @returns {boolean} - true if latestVersionUpdateTime is older than seven days
18
- */
19
- function isOlderThanSevenDays(currentTime, latestVersionUpdateTime) {
20
- const sevenDaysInMillis = 7 * 24 * 60 * 60 * 1000; // Seven days in milliseconds
21
- const timeDifference = Math.abs(currentTime - latestVersionUpdateTime);
22
- return timeDifference > sevenDaysInMillis;
23
- }
24
-
25
- /**
26
- * Fetches the latest version of a package from npm
27
- * @param {string} pkgName - package name
28
- * @param {number} currentTime - current time in milliseconds
29
- * @param {object} cache - cache object
30
- * @returns {string} - latest version of the package
31
- */
32
- async function getLatestVersion(pkgName, currentTime, cache) {
33
- if (
34
- !cache[LATEST_VERSION_UPDATE_TIME] ||
35
- !cache[LATEST_VERSION] ||
36
- isOlderThanSevenDays(currentTime, cache[LATEST_VERSION_UPDATE_TIME])
37
- ) {
38
- try {
39
- const cmdResult = await gasketUtils.runShellCommand('npm', ['view', pkgName, 'version'], {});
40
- if (cmdResult?.stdout) {
41
- const latestVersion = cmdResult.stdout.trim();
42
- cache[LATEST_VERSION_UPDATE_TIME] = currentTime;
43
- cache[LATEST_VERSION] = latestVersion;
44
- await writeFile(cachePath, JSON.stringify(cache));
45
- return latestVersion;
46
- }
47
- } catch (error) {
48
- console.error('Error fetching latest version:', error);
49
- }
50
- } else {
51
- return cache[LATEST_VERSION];
52
- }
53
- }
54
-
55
- /**
56
- * Warns if the package is outdated
57
- * @param {string} pkgName - package name
58
- * @param {string} currentVersion - current version of the package
59
- */
60
- export async function warnIfOutdated(pkgName, currentVersion) {
61
- const currentTime = new Date().getTime();
62
- let cache = {};
63
-
64
- try {
65
- const file = await readFile(cachePath, 'utf8');
66
- cache = JSON.parse(file);
67
- } catch (error) {
68
- // console.error('Error reading cache file:', error);
69
- }
70
-
71
- const latestVersion = await getLatestVersion(pkgName, currentTime, cache);
72
-
73
- if (typeof latestVersion === 'string' && semver.gt(latestVersion, currentVersion)) {
74
- console.warn(
75
- ` ${chalk.yellow('›')} Warning: ${pkgName} update available from ${chalk.green(latestVersion)} to ${chalk.green(currentVersion)}`
76
- );
77
- }
78
- }