create-gasket-app 7.0.0-next.3 → 7.0.0-next.5

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/lib/commands/create.js +42 -328
  2. package/lib/config/default-plugins.js +2 -2
  3. package/lib/config/utils.js +0 -27
  4. package/lib/index.d.ts +74 -24
  5. package/lib/index.js +1 -1
  6. package/lib/main.js +5 -4
  7. package/lib/scaffold/action-wrapper.js +1 -1
  8. package/lib/scaffold/actions/create-hooks.js +3 -5
  9. package/lib/scaffold/actions/generate-files.js +2 -2
  10. package/lib/scaffold/actions/global-prompts.js +6 -20
  11. package/lib/scaffold/actions/index.js +5 -12
  12. package/lib/scaffold/actions/install-modules.js +1 -4
  13. package/lib/scaffold/actions/link-modules.js +1 -3
  14. package/lib/scaffold/actions/load-preset.js +32 -71
  15. package/lib/scaffold/actions/mkdir.js +1 -1
  16. package/lib/scaffold/actions/post-create-hooks.js +2 -5
  17. package/lib/scaffold/actions/preset-config-hooks.js +13 -0
  18. package/lib/scaffold/actions/preset-prompt-hooks.js +5 -2
  19. package/lib/scaffold/actions/print-report.js +1 -1
  20. package/lib/scaffold/actions/prompt-hooks.js +5 -52
  21. package/lib/scaffold/actions/setup-pkg.js +3 -23
  22. package/lib/scaffold/actions/write-gasket-config.js +97 -12
  23. package/lib/scaffold/actions/write-pkg.js +1 -1
  24. package/lib/scaffold/config-builder.js +89 -12
  25. package/lib/scaffold/create-context.js +19 -27
  26. package/lib/scaffold/dump-error-context.js +3 -3
  27. package/lib/scaffold/files.js +1 -1
  28. package/lib/scaffold/utils.js +2 -87
  29. package/lib/utils/index.js +1 -1
  30. package/lib/utils/warn-if-outdated.js +4 -2
  31. package/package.json +15 -11
  32. package/lib/scaffold/actions/apply-preset-config.js +0 -29
  33. package/lib/scaffold/actions/cli-version.js +0 -88
  34. package/lib/scaffold/actions/load-pkg-for-debug.js +0 -24
  35. package/lib/scaffold/create-engine.js +0 -21
  36. package/lib/scaffold/fetcher.js +0 -194
@@ -1,34 +1,27 @@
1
- /* eslint-disable max-statements */
2
- import ora from 'ora';
1
+ /* eslint-disable max-statements, no-unused-vars */
3
2
  import chalk from 'chalk';
4
3
  import { makeCreateContext } from '../scaffold/create-context.js';
5
4
  import { dumpErrorContext } from '../scaffold/dump-error-context.js';
5
+ import { rm } from 'fs/promises';
6
+ import { makeGasket } from '@gasket/core';
7
+ import { defaultPlugins } from '../config/default-plugins.js';
6
8
  import {
7
- applyPresetConfig,
8
- cliVersion,
9
9
  createHooks,
10
10
  generateFiles,
11
11
  globalPrompts,
12
12
  installModules,
13
13
  linkModules,
14
- loadPkgForDebug,
15
14
  loadPreset,
16
15
  mkDir,
17
16
  postCreateHooks,
18
17
  printReport,
19
18
  presetPromptHooks,
19
+ presetConfigHooks,
20
20
  promptHooks,
21
21
  setupPkg,
22
22
  writeGasketConfig,
23
23
  writePkg
24
24
  } from '../scaffold/actions/index.js';
25
- import path from 'path';
26
- import os from 'os';
27
- import { mkdtemp, rm } from 'fs/promises';
28
- import { default as gasketUtils } from '@gasket/utils';
29
- import { makeGasket } from '@gasket/core';
30
- import { createRequire } from 'module';
31
- const require = createRequire(import.meta.url);
32
25
 
33
26
  /**
34
27
  * Parses comma separated option input to array
@@ -57,13 +50,6 @@ const createCommand = {
57
50
  Or other (multiple) custom presets (e.g. --presets my-gasket-preset@1.0.0.beta-1,nextjs@^1.0.0)`,
58
51
  parse: commasToArray
59
52
  },
60
- {
61
- name: 'plugins',
62
- description: `Additional plugin(s) to install. Can be set as
63
- multiple flags (e.g. --plugins jest --plugins zkconfig@^1.0.0)
64
- comma-separated values: --plugins=jest,zkconfig^1.0.0`,
65
- parse: commasToArray
66
- },
67
53
  {
68
54
  name: 'package-manager',
69
55
  description: `Selects which package manager you would like to use during
@@ -75,18 +61,6 @@ const createCommand = {
75
61
  description: 'Require module(s) before Gasket is initialized',
76
62
  parse: commasToArray
77
63
  },
78
- {
79
- name: 'no-bootstrap',
80
- description: '(INTERNAL) If provided, skip the bootstrap phase',
81
- type: 'boolean',
82
- hidden: true
83
- },
84
- {
85
- name: 'no-generate',
86
- description: '(INTERNAL) If provided, skip the generate phase',
87
- type: 'boolean',
88
- hidden: true
89
- },
90
64
  {
91
65
  name: 'npm-link',
92
66
  description: `(INTERNAL) Local packages to be linked. Can be set as
@@ -113,207 +87,14 @@ const createCommand = {
113
87
  conflicts: ['config']
114
88
  },
115
89
  {
116
- name: 'prompts',
90
+ name: 'no-prompts',
117
91
  description: '(INTERNAL) Disable to skip the prompts',
118
- default: true,
119
92
  type: 'boolean',
120
93
  hidden: true
121
94
  }
122
95
  ]
123
96
  };
124
97
 
125
- async function wait(ms = 50) {
126
- return new Promise(resolve => {
127
- console.log('waiting...')
128
- setTimeout(resolve, ms);
129
- });
130
- }
131
-
132
- function evaluatePreset(preset) {
133
- const parts = preset.split('@').filter(Boolean);
134
- if (parts.length > 1) {
135
- return {
136
- name: `@${parts[0]}`,
137
- version: parts[1]
138
- };
139
- } else if (parts.length === 1) {
140
- return {
141
- name: `@${parts[0]}`,
142
- version: null
143
- };
144
- }
145
-
146
- return preset;
147
- }
148
-
149
- createCommand.action = async function run(appname, options, command) {
150
- // temp
151
- process.env.GASKET_DEBUG_NPM = 'true';
152
- // temp
153
- const context = makeCreateContext([appname], options);
154
- const {
155
- presets = [],
156
- presetPath = [],
157
- } = options;
158
-
159
- const tmpDir = await mkdtemp(path.join(os.tmpdir(), `gasket-create-${context.appName}`));
160
- const modPath = path.join(tmpDir, 'node_modules');
161
- console.log(tmpDir);
162
- await globalPrompts(context);
163
-
164
- const pkgManager = new gasketUtils.PackageManager({ packageManager: context.packageManager, dest: tmpDir });
165
- const pkgVerb = pkgManager.isYarn ? 'add' : 'install';
166
-
167
- const remotePresets = await Promise.all(presets.map(async preset => {
168
- await pkgManager.exec(pkgVerb, [preset]);
169
- const pkgFile = require(path.join(modPath, preset, 'package.json'));
170
- const presetMod = await import(pkgFile.name, { from: modPath });
171
-
172
- const dependencies = Object.entries(pkgFile.dependencies || {})
173
- .filter(([name]) => name.startsWith('@gasket'))
174
- .map(([name, version]) => ({ name, version }));
175
-
176
- const plugins = await Promise.all(dependencies.map(async ({ name }) => {
177
- const mod = await import(name, { from: modPath });
178
- return mod.default || mod;
179
- }));
180
-
181
- return {
182
- pkgFile,
183
- dependencies,
184
- plugins: [
185
- presetMod.default || presetMod,
186
- ...plugins
187
- ]
188
- }
189
- }));
190
-
191
- const localPresets = await Promise.all(presetPath.map(async localPreset => {
192
- await pkgManager.exec(pkgVerb, [localPreset]);
193
- const pkgFile = require(path.join(localPreset, 'package.json'));
194
- const presetMod = await import(pkgFile.name, { from: modPath });
195
-
196
- const dependencies = Object.entries(pkgFile.dependencies || {})
197
- .filter(([name]) => name.startsWith('@gasket'))
198
- .map(([name, version]) => ({ name, version }));
199
-
200
- const plugins = await Promise.all(dependencies.map(async ({ name }) => {
201
- const mod = await import(name, { from: modPath });
202
- return mod.default || mod;
203
- }));
204
-
205
- return {
206
- module: presetMod.default || presetMod,
207
- pkgFile,
208
- dependencies,
209
- plugins
210
- };
211
- }));
212
-
213
-
214
- const configuredPresets = await Promise.all([
215
- ...remotePresets,
216
- ...localPresets
217
- ]);
218
-
219
- const presetPlugins = configuredPresets.reduce((acc, p) => {
220
- return [
221
- ...acc,
222
- p.module
223
- ];
224
- }, []);
225
-
226
- const presetGasket = makeGasket({
227
- plugins: presetPlugins
228
- });
229
-
230
- console.log(presetGasket);
231
-
232
- await presetPromptHooks(presetGasket, context);
233
- console.log(context);
234
- const presetConfig = await presetGasket.execWaterfall('presetConfig', context);
235
-
236
- console.log(configuredPresets)
237
- console.log(configuredPresets[0].dependencies)
238
- console.log(configuredPresets[0].plugins)
239
- console.log(presetConfig);
240
-
241
- // Check preset plugins vs the plugins from the presetConfig
242
-
243
-
244
-
245
- // await globalPrompts(context);
246
- // presetPrompt
247
- // presetConfig
248
-
249
- // const gasketPlugins = makeGasket({
250
- // // plugins
251
- // })
252
-
253
- // promptHooks
254
-
255
-
256
- // applyPresetConfig(context);
257
- // await globalPrompts(context);
258
- // await mkDir(context);
259
- // await setupPkg(context);
260
- // await writePkg(context);
261
- // await installModules(context);
262
- // await linkModules(context);
263
- // await promptHooks(gasketPlugins, context);
264
- // await createHooks(context);
265
- // await generateFiles(context);
266
- // await writeGasketConfig(context);
267
- // await writePkg.update(context);
268
- // await installModules.update(context);
269
- // await linkModules.update(context); // relink any that were messed up by re-install
270
- // await postCreateHooks(context);
271
-
272
-
273
- // download preset to os temp dir
274
- // import preset to CGA
275
- // makeGasket with preset
276
- // exec presetPrompt
277
- // exec presetConfig
278
- // makeGasket with presetConfig
279
- // exec prompt
280
- // exec create
281
-
282
- // console.log('Deleting tmp dir...')
283
- // await rm(tmpDir, { recursive: true });
284
- }
285
-
286
- /**
287
- * bootstrap - Bootstrap the application
288
- * @param {CreateContext} context - Create context
289
- */
290
- // async function bootstrapHandler(context) {
291
- // await loadPreset(context);
292
- // cliVersion(context);
293
- // applyPresetConfig(context);
294
- // await globalPrompts(context);
295
- // await mkDir(context);
296
- // await setupPkg(context);
297
- // await writePkg(context);
298
- // await installModules(context);
299
- // await linkModules(context);
300
- // }
301
-
302
- /**
303
- * generate - Generate the application
304
- * @param {CreateContext} context - Create context
305
- */
306
- // async function generateHandler(context) {
307
- // await promptHooks(context);
308
- // await createHooks(context);
309
- // await generateFiles(context);
310
- // await writeGasketConfig(context);
311
- // await writePkg.update(context);
312
- // await installModules.update(context);
313
- // await linkModules.update(context); // relink any that were messed up by re-install
314
- // await postCreateHooks(context);
315
- // }
316
-
317
98
  /**
318
99
  * createCommand action
319
100
  * @param {string} appname Required cmd arg - name of the app to create
@@ -321,113 +102,46 @@ createCommand.action = async function run(appname, options, command) {
321
102
  * @param {Command} command - the command instance
322
103
  * @returns {Promise<void>} void
323
104
  */
324
- // createCommand.action = async function run(appname, options, command) {
325
- // const argv = [appname];
326
- // const { bootstrap = true, generate = true } = options;
105
+ createCommand.action = async function run(appname, options, command) {
106
+ const context = makeCreateContext([appname], options);
107
+ const { rawPresets, localPresets } = context;
327
108
 
328
- // let context;
329
- // try {
330
- // context = makeCreateContext(argv, options);
331
- // } catch (error) {
332
- // console.error(chalk.red(error) + '\n');
333
- // command.help();
334
- // }
109
+ try {
110
+ await globalPrompts(null, context);
335
111
 
336
- // try {
337
- // if (bootstrap) {
338
- // await bootstrapHandler(context);
339
- // } else {
340
- // ora('Bootstrap phase skipped.').warn();
341
- // if (generate) {
342
- // await loadPkgForDebug(context);
343
- // }
344
- // }
112
+ if (rawPresets.length || localPresets.length) {
113
+ await loadPreset(null, context);
345
114
 
346
- // if (generate) {
347
- // await generateHandler(context);
348
- // } else {
349
- // ora('Generate phase skipped.').warn();
350
- // }
115
+ const presetGasket = makeGasket({
116
+ plugins: context.presets
117
+ });
351
118
 
352
- // printReport(context);
119
+ await presetPromptHooks(presetGasket, context);
120
+ await presetConfigHooks(presetGasket, context);
121
+ }
353
122
 
354
- // } catch (err) {
355
- // console.error(chalk.red('Exiting with errors.'));
356
- // dumpErrorContext(context, err);
357
- // throw err;
358
- // }
359
- // };
123
+ const pluginGasket = makeGasket({
124
+ ...context.presetConfig,
125
+ plugins: context.presets.concat(context.presetConfig.plugins, defaultPlugins)
126
+ });
127
+
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);
138
+ if (context.tmpDir) await rm(context.tmpDir, { recursive: true });
139
+ printReport(null, context);
140
+ } catch (err) {
141
+ console.error(chalk.red('Exiting with errors.'));
142
+ dumpErrorContext(context, err);
143
+ throw err;
144
+ }
145
+ };
360
146
 
361
147
  export { createCommand };
362
-
363
-
364
-
365
- // fire global prompts to inform pkgmanager
366
-
367
- // const tmpDir = await mkdtemp(path.join(os.tmpdir(), `gasket-create-${context.appName}`));
368
- // console.log(tmpDir);
369
-
370
-
371
-
372
- // new PackageManager https://github.com/godaddy/gasket/blob/v7/packages/gasket-utils/lib/package-manager.js#L75
373
- // const remotePresets = context.rawPresets.map(async preset => {
374
- // const { name: presetName, version: presetVersion } = evaluatePreset(preset)
375
-
376
- // // await runShellCommand('npm', ['i', `${presetName}@${presetVersion}`], { cwd: tmpDir }, true);
377
- // const modPath = path.join(tmpDir, 'node_modules');
378
- // const pkgFile = require(path.join(modPath, presetName, 'package.json'));
379
- // const presetMod = await import(presetName, { from: modPath });
380
-
381
- // const dependencies = Object.entries(pkgFile.dependencies || {})
382
- // .filter(([name]) => name.startsWith('@gasket'))
383
- // .map(([name, version]) => ({ name, version }));
384
-
385
- // const plugins = await Promise.all(dependencies.map(async ({ name }) => {
386
- // const mod = await import(name, { from: modPath });
387
- // return mod.default || mod;
388
- // }));
389
-
390
- // console.log(plugins)
391
- // return {
392
- // // module: await import(preset, { from: modPath }),
393
- // pkgFile,
394
- // dependencies,
395
- // plugins: [
396
- // presetMod.default || presetMod,
397
- // ...plugins
398
- // ]
399
- // }
400
- // });
401
-
402
- // const localPresets = context.localPresets.map(async localPreset => {
403
- // await runShellCommand('npm', ['i', localPreset], { cwd: tmpDir }, true);
404
-
405
- // const modPath = path.join(tmpDir, 'node_modules');
406
- // const pkgFile = require(path.join(localPreset, 'package.json'));
407
- // const presetMod = await import(pkgFile.name, { from: modPath });
408
-
409
-
410
- // const dependencies = Object.entries(pkgFile.dependencies || {})
411
- // .filter(([name]) => name.startsWith('@gasket'))
412
- // .map(([name, version]) => ({ name, version }));
413
-
414
- // const plugins = await Promise.all(dependencies.map(async ({ name }) => {
415
- // const mod = await import(name, { from: modPath });
416
- // return mod.default || mod;
417
- // }));
418
-
419
- // return {
420
- // // module: await import(preset, { from: modPath }),
421
- // pkgFile,
422
- // dependencies,
423
- // plugins: [
424
- // presetMod.default || presetMod,
425
- // ...plugins
426
- // ]
427
- // }
428
- // });
429
-
430
- // const presets = await Promise.all([
431
- // ...remotePresets,
432
- // ...localPresets
433
- // ]);
@@ -1,7 +1,7 @@
1
- import pluginMetadata from '@gasket/plugin-metadata';
2
1
  import pluginGit from '@gasket/plugin-git';
2
+ import pluginLogger from '@gasket/plugin-logger';
3
3
 
4
4
  export const defaultPlugins = [
5
- pluginMetadata,
5
+ pluginLogger,
6
6
  pluginGit
7
7
  ];
@@ -1,6 +1,4 @@
1
1
  import { default as diagnostics } from 'diagnostics';
2
- import { pluginIdentifier } from '@gasket/resolve';
3
- import { defaultPlugins } from './default-plugins.js';
4
2
  const debug = diagnostics('gasket:cli:config:utils');
5
3
 
6
4
  /**
@@ -32,28 +30,3 @@ export function getEnvironment(options, commandId, warn) {
32
30
  warn('No env specified, falling back to "development".');
33
31
  return 'development';
34
32
  }
35
-
36
- /**
37
- * Inject the default plugins into the loaded config
38
- *
39
- * @param {Object} gasketConfig - Gasket config
40
- * @returns {Object} updated config
41
- */
42
- export function addDefaultPlugins(gasketConfig) {
43
- const pluginsConfig = gasketConfig.plugins || {};
44
- const { add = [], remove = [] } = pluginsConfig;
45
- const filteredNames = new Set(
46
- add.concat(remove).map(p => {
47
- const name = typeof p === 'string' ? p : p.name;
48
- return pluginIdentifier(name).fullName;
49
- })
50
- );
51
- const pluginsToAdd = defaultPlugins.filter(p => !filteredNames.has(pluginIdentifier(p.name).fullName));
52
- return {
53
- ...gasketConfig,
54
- plugins: {
55
- ...pluginsConfig,
56
- add: (add).concat(pluginsToAdd)
57
- }
58
- };
59
- }
package/lib/index.d.ts CHANGED
@@ -62,6 +62,72 @@ export interface ConfigBuilder<Config> {
62
62
  value: Config[Key],
63
63
  options?: { force?: boolean }
64
64
  ): void;
65
+
66
+ /**
67
+ * addPlugin - Add plugin import to the gasket file and use the value in the plugins array
68
+ * @param {string} pluginImport - name of the import used as a value - `import pluginImport...`
69
+ * @param {string} pluginName - name of the plugin import/package - `from 'pluginName'`
70
+ * @example
71
+ * addPlugin('pluginA', '@gasket/plugin-a')
72
+ *
73
+ * // gasket.js
74
+ * import pluginA from '@gasket/plugin-a';
75
+ *
76
+ * export default makeGasket({
77
+ * plugins: [
78
+ * pluginA
79
+ * ]
80
+ * });
81
+ */
82
+ addPlugin(pluginImport: string, pluginName: string): void;
83
+
84
+ /**
85
+ * addImport - Add a non-plugin import to the gasket file
86
+ * @param {string} importName - name of the import used as a value - `import fs...`
87
+ * @param {string} importPath - path of the import - `from 'fs'`
88
+ * @returns {ConfigBuilder} - instance for chaining
89
+ * @example
90
+ * Can be default or named import
91
+ * addImport('{ readFileSync }', 'fs')
92
+ * addImport('fs', 'fs')
93
+ *
94
+ * // gasket.js
95
+ * import { readFileSync } from 'fs';
96
+ * import fs from 'fs';
97
+ */
98
+ addImport(importName: string, importPath: string): ConfigBuilder;
99
+
100
+ /**
101
+ * addExpression - add programmatic expression to the gasket file
102
+ * @param {string} expression - expression to add after imports
103
+ * @returns {ConfigBuilder} - instance for chaining
104
+ * @example
105
+ *
106
+ * .addImport('fs', 'fs')
107
+ * .addExpression('const file = fs.readFileSync(\'./file.txt\')')
108
+ *
109
+ * // gasket.js
110
+ * import fs from 'fs';
111
+ * const file = fs.readFileSync('./file.txt');
112
+ */
113
+ addExpression(expression: string): ConfigBuilder;
114
+
115
+ /**
116
+ * injectValue - Inject a value into the gasket config object
117
+ * @param {string} configKey - collapsed object path to inject value into - `express.config.routes`
118
+ * @param {string} injectedValue - string used as a value
119
+ * @example
120
+ * .addImport('{ routes }', './routes')
121
+ * .injectValue('express.routes', 'routes');
122
+ *
123
+ * // gasket.js
124
+ * export default makeGasket({
125
+ * express: {
126
+ * routes: routes
127
+ * }
128
+ * });
129
+ */
130
+ injectValue(configKey: string, injectedValue: any): void;
65
131
  }
66
132
 
67
133
  export interface PackageJsonBuilder extends ConfigBuilder<PackageJson> {
@@ -101,12 +167,6 @@ export interface CreateContext {
101
167
  * load-preset if using localPresets. */
102
168
  rawPresets: Array<string>;
103
169
 
104
- /** Raw plugin desc from flags, prompts, etc. Can include constraints. */
105
- rawPlugins: Array<string>;
106
-
107
- /** Short names of plugins */
108
- plugins: Array<string>;
109
-
110
170
  /** Local packages that should be linked */
111
171
  pkgLinks: Array<string>;
112
172
 
@@ -125,6 +185,12 @@ export interface CreateContext {
125
185
  /** any generated files to show in report */
126
186
  generatedFiles: Set<string>;
127
187
 
188
+ /** Default empty array, populated by load-preset with actual imports */
189
+ presets: Array<any>;
190
+
191
+ /** Default to object w/empty plugins array to be populated by `presetConfig` hook */
192
+ presetConfig: GasketConfigDefinition;
193
+
128
194
  // Added by `global-prompts`
129
195
 
130
196
  /** Description of app */
@@ -148,23 +214,6 @@ export interface CreateContext {
148
214
  /** Whether or not the user wants to override an extant directory */
149
215
  destOverride: boolean;
150
216
 
151
- // Added by `load-preset`
152
-
153
- /** Short name of presets */
154
- presets: Array<string>;
155
-
156
- /** Shallow load of presets with meta data */
157
- presetInfos: Array<PresetInfo>;
158
-
159
- // Added by `cli-version`
160
-
161
- /** Version of current CLI used to issue `create` command */
162
- cliVersion: string;
163
-
164
- /** Version of CLI to install, either current or min compatible version
165
- * required by preset(s) */
166
- cliVersionRequired: string;
167
-
168
217
  // Added by `setup-pkg`
169
218
 
170
219
  /** package.json builder */
@@ -186,11 +235,12 @@ export interface CreateContext {
186
235
 
187
236
  declare module '@gasket/engine' {
188
237
  export interface HookExecTypes {
238
+ presetPrompt(context: CreateContext): Promise<void>;
239
+ presetConfig(context: CreateContext): Promise<void>;
189
240
  prompt(
190
241
  context: CreateContext,
191
242
  utils: {
192
243
  prompt: (prompts: Array<Record<string, any>>) => Promise<Record<string, any>>,
193
- addPlugins: (plugins: Array<string>) => Promise<void>
194
244
  }
195
245
  ): MaybeAsync<CreateContext>;
196
246
 
package/lib/index.js CHANGED
@@ -19,7 +19,7 @@ const gasketBin = program
19
19
 
20
20
  async function main() {
21
21
  const { command, hidden, isDefault } = processCommand(createCommand);
22
- // await warnIfOutdated(pkg.name, pkg.version);
22
+ await warnIfOutdated(pkg.name, pkg.version);
23
23
  gasketBin.addCommand(command, { hidden, isDefault });
24
24
 
25
25
  process.argv.splice(2, 0, 'create');
package/lib/main.js CHANGED
@@ -1,4 +1,6 @@
1
- const { fork } = require('child_process');
1
+ import { fork } from 'child_process';
2
+ import { createRequire } from 'module';
3
+ const require = createRequire(import.meta.url);
2
4
 
3
5
  /**
4
6
  * Executes the @gasket/cli passing through the create command and any arguments.
@@ -6,7 +8,8 @@ const { fork } = require('child_process');
6
8
  * @param {string[]} args - create command arguments
7
9
  * @returns {ChildProcess} process
8
10
  */
9
- function main(...args) {
11
+ export default function main(...args) {
12
+ // import.meta.resolve is not available in Jest without babel transform
10
13
  const gasketBin = require.resolve('@gasket/cli/bin/run');
11
14
 
12
15
  return fork(
@@ -15,5 +18,3 @@ function main(...args) {
15
18
  { stdio: 'inherit', stdin: 'inherit', stderr: 'inherit' }
16
19
  );
17
20
  }
18
-
19
- module.exports = main;
@@ -32,4 +32,4 @@ export default function withSpinner(label, fn, { startSpinner = true } = {}) {
32
32
 
33
33
  wrapper.wrapped = fn;
34
34
  return wrapper;
35
- };
35
+ }
@@ -1,4 +1,3 @@
1
- import { createEngine } from '../create-engine.js';
2
1
  import action from '../action-wrapper.js';
3
2
  import { ConfigBuilder } from '../config-builder.js';
4
3
  import { Files } from '../files.js';
@@ -10,14 +9,13 @@ import { Files } from '../files.js';
10
9
  * @param {CreateContext} context - Create context
11
10
  * @returns {Promise} promise
12
11
  */
13
- async function createHooks(context) {
14
- const { dest, presets = [], plugins = [], warnings } = context;
12
+ async function createHooks(gasket, context) {
13
+ const { plugins = [], warnings } = context;
15
14
 
16
15
  const files = new Files();
17
- const gasketConfig = ConfigBuilder.create({}, { orderBy: ['plugins'], warnings });
16
+ const gasketConfig = ConfigBuilder.create({}, { orderBy: ['plugins'], warnings, plugins });
18
17
  Object.assign(context, { files, gasketConfig });
19
18
 
20
- const gasket = await createEngine(plugins);
21
19
  await gasket.execApply('create', async function applyCreate(plugin, handler) {
22
20
  await handler(context.runWith(plugin));
23
21
  });
@@ -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
-
13
+ // TODOfollowup - look at deps
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) {