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

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 (39) hide show
  1. package/lib/commands/create.js +301 -60
  2. package/lib/config/default-plugins.js +6 -6
  3. package/lib/config/utils.js +59 -0
  4. package/lib/index.js +8 -7
  5. package/lib/scaffold/action-wrapper.js +4 -5
  6. package/lib/scaffold/actions/apply-preset-config.js +3 -3
  7. package/lib/scaffold/actions/cli-version.js +9 -5
  8. package/lib/scaffold/actions/create-hooks.js +6 -6
  9. package/lib/scaffold/actions/generate-files.js +16 -14
  10. package/lib/scaffold/actions/global-prompts.js +7 -8
  11. package/lib/scaffold/actions/index.js +22 -18
  12. package/lib/scaffold/actions/install-modules.js +3 -3
  13. package/lib/scaffold/actions/link-modules.js +3 -3
  14. package/lib/scaffold/actions/load-pkg-for-debug.js +5 -5
  15. package/lib/scaffold/actions/load-preset.js +14 -13
  16. package/lib/scaffold/actions/mkdir.js +3 -3
  17. package/lib/scaffold/actions/post-create-hooks.js +5 -5
  18. package/lib/scaffold/actions/preset-prompt-hooks.js +14 -0
  19. package/lib/scaffold/actions/print-report.js +8 -7
  20. package/lib/scaffold/actions/prompt-hooks.js +6 -7
  21. package/lib/scaffold/actions/setup-pkg.js +11 -13
  22. package/lib/scaffold/actions/write-gasket-config.js +5 -5
  23. package/lib/scaffold/actions/write-pkg.js +5 -6
  24. package/lib/scaffold/config-builder.js +17 -18
  25. package/lib/scaffold/create-context.js +23 -21
  26. package/lib/scaffold/create-engine.js +5 -5
  27. package/lib/scaffold/dump-error-context.js +3 -3
  28. package/lib/scaffold/fetcher.js +19 -19
  29. package/lib/scaffold/files.js +1 -1
  30. package/lib/scaffold/utils.js +8 -16
  31. package/lib/utils/create-option.js +2 -4
  32. package/lib/utils/index.js +6 -16
  33. package/lib/utils/logo.js +1 -3
  34. package/lib/utils/process-args.js +1 -3
  35. package/lib/utils/process-command.js +3 -7
  36. package/lib/utils/process-options.js +1 -3
  37. package/lib/utils/warn-if-outdated.js +8 -8
  38. package/package.json +11 -10
  39. package/lib/utils/setup.js +0 -25
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable max-statements */
2
- const ora = require('ora');
3
- const chalk = require('chalk');
4
- const makeCreateContext = require('../scaffold/create-context');
5
- const dumpErrorContext = require('../scaffold/dump-error-context');
6
- const {
2
+ import ora from 'ora';
3
+ import chalk from 'chalk';
4
+ import { makeCreateContext } from '../scaffold/create-context.js';
5
+ import { dumpErrorContext } from '../scaffold/dump-error-context.js';
6
+ import {
7
7
  applyPresetConfig,
8
8
  cliVersion,
9
9
  createHooks,
@@ -16,11 +16,19 @@ const {
16
16
  mkDir,
17
17
  postCreateHooks,
18
18
  printReport,
19
+ presetPromptHooks,
19
20
  promptHooks,
20
21
  setupPkg,
21
22
  writeGasketConfig,
22
23
  writePkg
23
- } = require('../scaffold/actions');
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);
24
32
 
25
33
  /**
26
34
  * Parses comma separated option input to array
@@ -114,36 +122,197 @@ const createCommand = {
114
122
  ]
115
123
  };
116
124
 
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
+
117
286
  /**
118
287
  * bootstrap - Bootstrap the application
119
288
  * @param {CreateContext} context - Create context
120
289
  */
121
- async function bootstrapHandler(context) {
122
- await loadPreset(context);
123
- cliVersion(context);
124
- applyPresetConfig(context);
125
- await globalPrompts(context);
126
- await mkDir(context);
127
- await setupPkg(context);
128
- await writePkg(context);
129
- await installModules(context);
130
- await linkModules(context);
131
- }
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
+ // }
132
301
 
133
302
  /**
134
303
  * generate - Generate the application
135
304
  * @param {CreateContext} context - Create context
136
305
  */
137
- async function generateHandler(context) {
138
- await promptHooks(context);
139
- await createHooks(context);
140
- await generateFiles(context);
141
- await writeGasketConfig(context);
142
- await writePkg.update(context);
143
- await installModules.update(context);
144
- await linkModules.update(context); // relink any that were messed up by re-install
145
- await postCreateHooks(context);
146
- }
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
+ // }
147
316
 
148
317
  /**
149
318
  * createCommand action
@@ -152,41 +321,113 @@ async function generateHandler(context) {
152
321
  * @param {Command} command - the command instance
153
322
  * @returns {Promise<void>} void
154
323
  */
155
- createCommand.action = async function run(appname, options, command) {
156
- const argv = [appname];
157
- const { bootstrap = true, generate = true } = options;
158
-
159
- let context;
160
- try {
161
- context = makeCreateContext(argv, options);
162
- } catch (error) {
163
- console.error(chalk.red(error) + '\n');
164
- command.help();
165
- }
324
+ // createCommand.action = async function run(appname, options, command) {
325
+ // const argv = [appname];
326
+ // const { bootstrap = true, generate = true } = options;
166
327
 
167
- try {
168
- if (bootstrap) {
169
- await bootstrapHandler(context);
170
- } else {
171
- ora('Bootstrap phase skipped.').warn();
172
- if (generate) {
173
- await loadPkgForDebug(context);
174
- }
175
- }
328
+ // let context;
329
+ // try {
330
+ // context = makeCreateContext(argv, options);
331
+ // } catch (error) {
332
+ // console.error(chalk.red(error) + '\n');
333
+ // command.help();
334
+ // }
176
335
 
177
- if (generate) {
178
- await generateHandler(context);
179
- } else {
180
- ora('Generate phase skipped.').warn();
181
- }
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
+ // }
182
345
 
183
- printReport(context);
346
+ // if (generate) {
347
+ // await generateHandler(context);
348
+ // } else {
349
+ // ora('Generate phase skipped.').warn();
350
+ // }
184
351
 
185
- } catch (err) {
186
- console.error(chalk.red('Exiting with errors.'));
187
- dumpErrorContext(context, err);
188
- throw err;
189
- }
190
- };
352
+ // printReport(context);
353
+
354
+ // } catch (err) {
355
+ // console.error(chalk.red('Exiting with errors.'));
356
+ // dumpErrorContext(context, err);
357
+ // throw err;
358
+ // }
359
+ // };
360
+
361
+ 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
+ // });
191
429
 
192
- module.exports = createCommand;
430
+ // const presets = await Promise.all([
431
+ // ...remotePresets,
432
+ // ...localPresets
433
+ // ]);
@@ -1,7 +1,7 @@
1
- module.exports = [
2
- require('@gasket/plugin-lifecycle'),
3
- require('@gasket/plugin-metadata'),
4
- require('@gasket/plugin-start'),
5
- require('@gasket/plugin-git'),
6
- require('@gasket/plugin-logger')
1
+ import pluginMetadata from '@gasket/plugin-metadata';
2
+ import pluginGit from '@gasket/plugin-git';
3
+
4
+ export const defaultPlugins = [
5
+ pluginMetadata,
6
+ pluginGit
7
7
  ];
@@ -0,0 +1,59 @@
1
+ import { default as diagnostics } from 'diagnostics';
2
+ import { pluginIdentifier } from '@gasket/resolve';
3
+ import { defaultPlugins } from './default-plugins.js';
4
+ const debug = diagnostics('gasket:cli:config:utils');
5
+
6
+ /**
7
+ * Returns specified env option if set or appropriate fallback
8
+ *
9
+ * @param {Object} options - CLI Option
10
+ * @param {string} commandId - Name of the command
11
+ * @param {function} warn - Warning logger
12
+ * @returns {string} environment
13
+ */
14
+ export function getEnvironment(options, commandId, warn) {
15
+ if (options.env) {
16
+ debug('Environment was passed through command line options', options.env);
17
+ return options.env;
18
+ }
19
+
20
+ // special snowflake case to match up `local` env with command unless set
21
+ if (commandId === 'local') {
22
+ debug('Environment defaulting to `local` due to `local` command');
23
+ return 'local';
24
+ }
25
+
26
+ const { NODE_ENV } = process.env;
27
+ if (NODE_ENV) {
28
+ warn(`No env specified, falling back to NODE_ENV: "${ NODE_ENV }".`);
29
+ return NODE_ENV;
30
+ }
31
+
32
+ warn('No env specified, falling back to "development".');
33
+ return 'development';
34
+ }
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.js CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
- require('./utils/setup');
2
+ import { Command } from 'commander';
3
+ import { createRequire } from 'module';
4
+ import { createCommand } from './commands/create.js';
5
+ import { processCommand, logo, warnIfOutdated } from './utils/index.js';
6
+
7
+ const require = createRequire(import.meta.url);
3
8
  const pkg = require('../package.json');
4
- const { Command } = require('commander');
5
9
  const program = new Command();
6
- const CreateCommand = require('./commands/create');
7
-
8
- const { processCommand, logo, warnIfOutdated } = require('./utils');
9
10
 
10
11
  // Create Gasket CLI
11
12
  const gasketBin = program
@@ -17,8 +18,8 @@ const gasketBin = program
17
18
 
18
19
 
19
20
  async function main() {
20
- const { command, hidden, isDefault } = processCommand(CreateCommand);
21
- await warnIfOutdated(pkg.name, pkg.version);
21
+ const { command, hidden, isDefault } = processCommand(createCommand);
22
+ // await warnIfOutdated(pkg.name, pkg.version);
22
23
  gasketBin.addCommand(command, { hidden, isDefault });
23
24
 
24
25
  process.argv.splice(2, 0, 'create');
@@ -1,4 +1,4 @@
1
- const ora = require('ora');
1
+ import ora from 'ora';
2
2
 
3
3
  /**
4
4
  * Decorate a create action with spinner.
@@ -10,19 +10,18 @@ const ora = require('ora');
10
10
  * @param {Boolean} startSpinner - Should the spinner start
11
11
  * @returns {Function} decorated action
12
12
  */
13
- module.exports = function withSpinner(label, fn, { startSpinner = true } = {}) {
14
-
13
+ export default function withSpinner(label, fn, { startSpinner = true } = {}) {
15
14
  /**
16
15
  * Decorated function
17
16
  *
18
17
  * @param {CreateContext} context - Create context
19
18
  * @returns {Promise} promise
20
19
  */
21
- async function wrapper(context) {
20
+ async function wrapper(gasket = {}, context) {
22
21
  const spinner = ora(label);
23
22
  if (startSpinner) spinner.start();
24
23
  try {
25
- await fn(context, spinner);
24
+ await fn(gasket, context, spinner);
26
25
  if (spinner.isSpinning) spinner.succeed();
27
26
  } catch (err) {
28
27
  spinner.fail();
@@ -1,5 +1,5 @@
1
- const { flattenPresets } = require('@gasket/resolve');
2
- const action = require('../action-wrapper');
1
+ import { flattenPresets } from '@gasket/resolve';
2
+ import action from '../action-wrapper.js';
3
3
 
4
4
  /**
5
5
  * Extracts predefined createContext from presets and applies to context.
@@ -26,4 +26,4 @@ function applyPresetConfig(context) {
26
26
  Object.assign(context, presetContext);
27
27
  }
28
28
 
29
- module.exports = action('Apply preset context', applyPresetConfig, { startSpinner: false });
29
+ export default action('Apply preset context', applyPresetConfig, { startSpinner: false });
@@ -1,7 +1,11 @@
1
- const semver = require('semver');
2
- const { flattenPresets } = require('@gasket/resolve');
3
- const action = require('../action-wrapper');
4
- const pkgVersion = require('../../../package.json').version;
1
+ import semver from 'semver';
2
+ import { flattenPresets } from '@gasket/resolve';
3
+ import action from '../action-wrapper.js';
4
+ import { createRequire } from 'node:module';
5
+ const require = createRequire(import.meta.url);
6
+ const pkg = require('../../../package.json');
7
+
8
+ const pkgVersion = pkg.version;
5
9
  const pkgVersionCompatible = `^${pkgVersion}`;
6
10
 
7
11
  /**
@@ -81,4 +85,4 @@ function resolveCliVersion(context, spinner) {
81
85
  });
82
86
  }
83
87
 
84
- module.exports = action('Resolve CLI versions', resolveCliVersion, { startSpinner: false });
88
+ export default action('Resolve CLI versions', resolveCliVersion, { startSpinner: false });
@@ -1,7 +1,7 @@
1
- const createEngine = require('../create-engine');
2
- const action = require('../action-wrapper');
3
- const ConfigBuilder = require('../config-builder');
4
- const Files = require('../files');
1
+ import { createEngine } from '../create-engine.js';
2
+ import action from '../action-wrapper.js';
3
+ import { ConfigBuilder } from '../config-builder.js';
4
+ import { Files } from '../files.js';
5
5
 
6
6
  /**
7
7
  * Executes the `create` hook for all registered plugins.
@@ -17,10 +17,10 @@ async function createHooks(context) {
17
17
  const gasketConfig = ConfigBuilder.create({}, { orderBy: ['plugins'], warnings });
18
18
  Object.assign(context, { files, gasketConfig });
19
19
 
20
- const gasket = await createEngine({ dest, presets, plugins });
20
+ const gasket = await createEngine(plugins);
21
21
  await gasket.execApply('create', async function applyCreate(plugin, handler) {
22
22
  await handler(context.runWith(plugin));
23
23
  });
24
24
  }
25
25
 
26
- module.exports = action('Execute create hooks', createHooks);
26
+ export default action('Execute create hooks', createHooks);
@@ -1,14 +1,16 @@
1
- /* eslint-disable max-statements */
2
- const debug = require('diagnostics')('gasket:create-gasket-app:generate-files');
3
- const fs = require('fs').promises;
4
- const { promisify } = require('util');
5
- const Handlebars = require('handlebars');
6
- const path = require('path');
7
- const mkdirp = require('mkdirp');
8
- const { dim } = require('chalk');
9
- const action = require('../action-wrapper');
10
-
11
- const glob = promisify(require('glob'));
1
+ import { default as diagnostics } from 'diagnostics';
2
+ const debug = diagnostics('gasket:cli:generate-files');
3
+ import fs from 'fs/promises';
4
+ import { promisify } from 'util';
5
+ import Handlebars from 'handlebars';
6
+ import path from 'path';
7
+ import mkdirp from 'mkdirp';
8
+ import chalk from 'chalk';
9
+ const { dim } = chalk;
10
+ import action from '../action-wrapper.js';
11
+ import * as syncGlob from 'glob';
12
+ const glob = promisify(syncGlob.default);
13
+
12
14
  const flatten = (acc, values) => (acc || []).concat(values);
13
15
  const reSep = /[/\\]+/;
14
16
  const joinSep = pthArr => pthArr.join(path.sep);
@@ -177,7 +179,7 @@ async function generateFiles(context, spinner) {
177
179
  if (hasError) spinner.fail();
178
180
  }
179
181
 
180
- module.exports = action('Generate app contents', generateFiles);
182
+ export default action('Generate app contents', generateFiles);
181
183
  // exported for unit testing
182
- module.exports._getDescriptors = getDescriptors;
183
- module.exports._assembleDescriptors = assembleDescriptors;
184
+ export const _getDescriptors = getDescriptors;
185
+ export const _assembleDescriptors = assembleDescriptors;
@@ -1,7 +1,8 @@
1
- const inquirer = require('inquirer');
2
- const { pluginIdentifier, flattenPresets } = require('@gasket/resolve');
3
- const action = require('../action-wrapper');
4
- const { addPluginsToContext } = require('../utils');
1
+ import inquirer from 'inquirer';
2
+ import action from '../action-wrapper.js';
3
+
4
+ import { pluginIdentifier, flattenPresets } from '@gasket/resolve';
5
+ import { addPluginsToContext } from '../utils.js';
5
6
 
6
7
  /**
7
8
  * What is your app description?
@@ -136,7 +137,7 @@ async function allowExtantOverwriting(context, prompt) {
136
137
  }
137
138
  }
138
139
 
139
- const questions = [
140
+ export const questions = [
140
141
  chooseAppDescription,
141
142
  choosePackageManager,
142
143
  chooseTestPlugin,
@@ -156,6 +157,4 @@ async function globalPrompts(context) {
156
157
  }
157
158
  }
158
159
 
159
- module.exports = action('Global prompts', globalPrompts, { startSpinner: false });
160
-
161
- module.exports.questions = questions;
160
+ export default action('Global prompts', globalPrompts, { startSpinner: false });