create-gasket-app 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
@@ -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,22 @@ 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
+ await loadPreset({ context });
114
115
 
115
116
  const presetGasket = makeGasket({
116
117
  plugins: context.presets
117
118
  });
118
119
 
119
- await presetPromptHooks(presetGasket, context);
120
- await presetConfigHooks(presetGasket, context);
120
+ await presetPromptHooks({ gasket: presetGasket, context });
121
+ await presetConfigHooks({ gasket: presetGasket, context });
121
122
  }
122
123
 
123
124
  const pluginGasket = makeGasket({
@@ -125,18 +126,18 @@ createCommand.action = async function run(appname, options, command) {
125
126
  plugins: context.presets.concat(context.presetConfig.plugins, defaultPlugins)
126
127
  });
127
128
 
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);
129
+ await promptHooks({ gasket: pluginGasket, context });
130
+ await mkDir({ context });
131
+ await setupPkg({ context });
132
+ await createHooks({ gasket: pluginGasket, context });
133
+ await writePkg({ context });
134
+ await generateFiles({ context });
135
+ await writeGasketConfig({ context });
136
+ await installModules({ context });
137
+ await linkModules({ context });
138
+ await postCreateHooks({ gasket: pluginGasket, context });
138
139
  if (context.tmpDir) await rm(context.tmpDir, { recursive: true });
139
- printReport(null, context);
140
+ printReport({ context });
140
141
  } catch (err) {
141
142
  console.error(chalk.red('Exiting with errors.'));
142
143
  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,11 +31,9 @@ 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> {
40
39
  /**
@@ -95,7 +94,7 @@ export interface ConfigBuilder<Config> {
95
94
  * import { readFileSync } from 'fs';
96
95
  * import fs from 'fs';
97
96
  */
98
- addImport(importName: string, importPath: string): ConfigBuilder;
97
+ addImport(importName: string, importPath: string): ConfigBuilder<Config>;
99
98
 
100
99
  /**
101
100
  * addExpression - add programmatic expression to the gasket file
@@ -110,7 +109,7 @@ export interface ConfigBuilder<Config> {
110
109
  * import fs from 'fs';
111
110
  * const file = fs.readFileSync('./file.txt');
112
111
  */
113
- addExpression(expression: string): ConfigBuilder;
112
+ addExpression(expression: string): ConfigBuilder<Config>;
114
113
 
115
114
  /**
116
115
  * injectValue - Inject a value into the gasket config object
@@ -127,21 +126,21 @@ export interface ConfigBuilder<Config> {
127
126
  * }
128
127
  * });
129
128
  */
130
- injectValue(configKey: string, injectedValue: any): void;
129
+ injectValue(configKey: string, injectedValue: string): void;
131
130
  }
132
131
 
133
132
  export interface PackageJsonBuilder extends ConfigBuilder<PackageJson> {
134
133
  /**
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
134
+ * Checks if a property exists on the package.json fields.
135
+ * @param key - Field to search
136
+ * @param value - Value to search for
137
+ * @returns True if the property exists and matches the value
139
138
  */
140
- has(key: keyof Dependencies, value: string): boolean;
139
+ has(key: keyof PackageJson, value: string): boolean;
141
140
  }
142
141
 
143
142
  export interface Files {
144
- add(...args: string[]): void
143
+ add(...args: string[]): void;
145
144
  }
146
145
 
147
146
  export interface CreateContext {
@@ -186,7 +185,7 @@ export interface CreateContext {
186
185
  generatedFiles: Set<string>;
187
186
 
188
187
  /** Default empty array, populated by load-preset with actual imports */
189
- presets: Array<any>;
188
+ presets: Array<Plugin>;
190
189
 
191
190
  /** Default to object w/empty plugins array to be populated by `presetConfig` hook */
192
191
  presetConfig: GasketConfigDefinition;
@@ -199,8 +198,8 @@ export interface CreateContext {
199
198
  /** Should a git repo be initialized and first commit */
200
199
  gitInit: boolean;
201
200
 
202
- /** Name of the plugin for unit tests */
203
- testPlugin: string;
201
+ /** Names of the plugins that add unit and integration tests */
202
+ testPlugins: Array<string>;
204
203
 
205
204
  /** Which package manager to use (Default: 'npm') */
206
205
  packageManager: string;
@@ -233,14 +232,23 @@ export interface CreateContext {
233
232
  files: Files;
234
233
  }
235
234
 
236
- declare module '@gasket/engine' {
235
+ export interface ActionWrapperParams {
236
+ gasket: GasketEngine;
237
+ context: CreateContext;
238
+ spinner?: any;
239
+ }
240
+
241
+ declare module '@gasket/core' {
237
242
  export interface HookExecTypes {
238
243
  presetPrompt(context: CreateContext): Promise<void>;
239
- presetConfig(context: CreateContext): Promise<void>;
244
+ presetConfig(context: CreateContext): Promise<CreateContext['presetConfig']>;
240
245
  prompt(
241
246
  context: CreateContext,
242
247
  utils: {
243
- prompt: (prompts: Array<Record<string, any>>) => Promise<Record<string, any>>,
248
+ prompt: (
249
+ prompts: Array<Record<string, any>>
250
+ ) => Promise<Record<string, any>>;
251
+ addPlugins: (plugins: Array<string>) => Promise<void>;
244
252
  }
245
253
  ): MaybeAsync<CreateContext>;
246
254
 
@@ -249,7 +257,8 @@ declare module '@gasket/engine' {
249
257
  postCreate(
250
258
  context: CreateContext,
251
259
  utils: {
252
- runScript: (script: string) => Promise<void>
253
- }): MaybeAsync<void>;
260
+ runScript: (script: string) => Promise<void>;
261
+ }
262
+ ): MaybeAsync<void>;
254
263
  }
255
264
  }
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();
@@ -10,7 +10,7 @@ const { dim } = chalk;
10
10
  import action from '../action-wrapper.js';
11
11
  import * as syncGlob from 'glob';
12
12
  const glob = promisify(syncGlob.default);
13
- // TODOfollowup - look at deps
13
+
14
14
  const flatten = (acc, values) => (acc || []).concat(values);
15
15
  const reSep = /[/\\]+/;
16
16
  const joinSep = pthArr => pthArr.join(path.sep);
@@ -164,7 +164,7 @@ async function performGenerate(context, descriptors) {
164
164
  * @param {Spinner} spinner - Spinner
165
165
  * @returns {Promise} promise
166
166
  */
167
- async function generateFiles(_, context, spinner) {
167
+ async function generateFiles({ context, spinner }) {
168
168
  const { files } = context;
169
169
 
170
170
  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,7 +88,7 @@ function cleanupFields(config) {
88
88
  * @param {CreateContext} context - Create context
89
89
  * @returns {Promise} promise
90
90
  */
91
- async function writeGasketConfig(gasket, context) {
91
+ async function writeGasketConfig({ context }) {
92
92
  const { dest, gasketConfig, generatedFiles } = context;
93
93
  const fileName = context.typescript ? 'gasket.ts' : 'gasket.js';
94
94
  const filePath = path.join(dest, fileName);
@@ -96,6 +96,7 @@ async function writeGasketConfig(gasket, context) {
96
96
  const assignments = gasketConfig.fields.injectionAssignments || null;
97
97
  const expressions = gasketConfig.fields.expressions || null;
98
98
  gasketConfig.fields.plugins = 'PLUGIN_REPLACE';
99
+ gasketConfig.fields.filename = 'FILENAME_REPLACE';
99
100
 
100
101
  let contents = '';
101
102
  contents += `import { makeGasket } from '@gasket/core';\n`;
@@ -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
+ const pluginImports = `[\n${writePluginImports(plugins)}\n\xa0\xa0]`;
109
110
  contents += `\nexport default makeGasket(${JSON5.stringify(gasketConfig.fields, null, 2)});\n`;
111
+ contents = contents.replace('\'FILENAME_REPLACE\'', 'import.meta.filename');
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);
@@ -4,7 +4,6 @@ import { default as semver } from 'semver';
4
4
  import { default as diagnostics } from 'diagnostics';
5
5
  const debug = diagnostics('gasket:cli:package');
6
6
 
7
- // TODOfollowup - evaluate methods for deletion
8
7
  /**
9
8
  * Simple object check without bringing in a large
10
9
  * utility library.
@@ -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';
@@ -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.5",
3
+ "version": "7.0.0-next.50",
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.5",
36
- "@gasket/engine": "^7.0.0-next.5",
37
- "@gasket/plugin-git": "^7.0.0-next.5",
38
- "@gasket/plugin-lifecycle": "^7.0.0-next.5",
39
- "@gasket/plugin-logger": "^7.0.0-next.5",
40
- "@gasket/plugin-metadata": "^7.0.0-next.5",
41
- "@gasket/plugin-start": "^7.0.0-next.5",
42
- "@gasket/resolve": "^7.0.0-next.5",
43
- "@gasket/utils": "^7.0.0-next.5",
36
+ "@gasket/core": "^7.0.0-next.50",
37
+ "@gasket/plugin-command": "^7.0.0-next.50",
38
+ "@gasket/plugin-docs": "^7.0.0-next.50",
39
+ "@gasket/plugin-docusaurus": "^7.0.0-next.50",
40
+ "@gasket/plugin-git": "^7.0.0-next.50",
41
+ "@gasket/plugin-logger": "^7.0.0-next.50",
42
+ "@gasket/plugin-metadata": "^7.0.0-next.50",
43
+ "@gasket/utils": "^7.0.0-next.50",
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": "b3b132ef284ac43616794283b969c23c45c0a90e"
86
+ "gitHead": "e7cfec6a118cf087c6532c23dc31170f4b15d182"
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
- }