create-gasket-app 7.0.0-next.4 → 7.0.0-next.6

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 (34) hide show
  1. package/lib/commands/create.js +22 -12
  2. package/lib/config/utils.js +0 -27
  3. package/lib/index.d.ts +71 -27
  4. package/lib/index.js +1 -1
  5. package/lib/main.js +5 -4
  6. package/lib/scaffold/action-wrapper.js +1 -1
  7. package/lib/scaffold/actions/create-hooks.js +1 -2
  8. package/lib/scaffold/actions/generate-files.js +1 -1
  9. package/lib/scaffold/actions/global-prompts.js +1 -16
  10. package/lib/scaffold/actions/index.js +3 -12
  11. package/lib/scaffold/actions/install-modules.js +1 -4
  12. package/lib/scaffold/actions/link-modules.js +1 -3
  13. package/lib/scaffold/actions/load-preset.js +14 -6
  14. package/lib/scaffold/actions/mkdir.js +1 -1
  15. package/lib/scaffold/actions/post-create-hooks.js +1 -2
  16. package/lib/scaffold/actions/preset-config-hooks.js +5 -5
  17. package/lib/scaffold/actions/preset-prompt-hooks.js +5 -1
  18. package/lib/scaffold/actions/print-report.js +1 -1
  19. package/lib/scaffold/actions/prompt-hooks.js +3 -47
  20. package/lib/scaffold/actions/setup-pkg.js +1 -21
  21. package/lib/scaffold/actions/write-gasket-config.js +34 -3
  22. package/lib/scaffold/config-builder.js +58 -2
  23. package/lib/scaffold/create-context.js +9 -12
  24. package/lib/scaffold/dump-error-context.js +3 -3
  25. package/lib/scaffold/files.js +1 -1
  26. package/lib/scaffold/utils.js +2 -87
  27. package/lib/utils/index.js +1 -1
  28. package/lib/utils/warn-if-outdated.js +4 -2
  29. package/package.json +15 -11
  30. package/lib/scaffold/actions/apply-preset-config.js +0 -29
  31. package/lib/scaffold/actions/cli-version.js +0 -88
  32. package/lib/scaffold/actions/load-pkg-for-debug.js +0 -24
  33. package/lib/scaffold/create-engine.js +0 -21
  34. package/lib/scaffold/fetcher.js +0 -194
@@ -1,4 +1,4 @@
1
- /* eslint-disable max-statements */
1
+ /* eslint-disable max-statements, no-unused-vars */
2
2
  import chalk from 'chalk';
3
3
  import { makeCreateContext } from '../scaffold/create-context.js';
4
4
  import { dumpErrorContext } from '../scaffold/dump-error-context.js';
@@ -87,28 +87,38 @@ const createCommand = {
87
87
  conflicts: ['config']
88
88
  },
89
89
  {
90
- name: 'prompts',
90
+ name: 'no-prompts',
91
91
  description: '(INTERNAL) Disable to skip the prompts',
92
- default: true,
93
92
  type: 'boolean',
94
93
  hidden: true
95
94
  }
96
95
  ]
97
96
  };
98
97
 
98
+ /**
99
+ * createCommand action
100
+ * @param {string} appname Required cmd arg - name of the app to create
101
+ * @param {object} options cmd options
102
+ * @param {Command} command - the command instance
103
+ * @returns {Promise<void>} void
104
+ */
99
105
  createCommand.action = async function run(appname, options, command) {
100
106
  const context = makeCreateContext([appname], options);
107
+ const { rawPresets, localPresets } = context;
101
108
 
102
109
  try {
103
- await loadPreset(null, context);
104
110
  await globalPrompts(null, context);
105
111
 
106
- const presetGasket = makeGasket({
107
- plugins: context.presets
108
- });
112
+ if (rawPresets.length || localPresets.length) {
113
+ await loadPreset(null, context);
109
114
 
110
- await presetPromptHooks(presetGasket, context);
111
- await presetConfigHooks(presetGasket, context);
115
+ const presetGasket = makeGasket({
116
+ plugins: context.presets
117
+ });
118
+
119
+ await presetPromptHooks(presetGasket, context);
120
+ await presetConfigHooks(presetGasket, context);
121
+ }
112
122
 
113
123
  const pluginGasket = makeGasket({
114
124
  ...context.presetConfig,
@@ -125,13 +135,13 @@ createCommand.action = async function run(appname, options, command) {
125
135
  await installModules(null, context);
126
136
  await linkModules(null, context);
127
137
  await postCreateHooks(pluginGasket, context);
128
- await rm(context.tmpDir, { recursive: true });
129
- printReport(context);
138
+ if (context.tmpDir) await rm(context.tmpDir, { recursive: true });
139
+ printReport(null, context);
130
140
  } catch (err) {
131
141
  console.error(chalk.red('Exiting with errors.'));
132
142
  dumpErrorContext(context, err);
133
143
  throw err;
134
144
  }
135
- }
145
+ };
136
146
 
137
147
  export { createCommand };
@@ -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
@@ -63,11 +63,71 @@ export interface ConfigBuilder<Config> {
63
63
  options?: { force?: boolean }
64
64
  ): void;
65
65
 
66
- // TODO Document
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
+ */
67
82
  addPlugin(pluginImport: string, pluginName: string): void;
68
- addImport(importName: string, importPath: string, isDefault?: boolean): ConfigBuilder;
69
- useImport(configPath: string, importName: string): void;
70
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;
71
131
  }
72
132
 
73
133
  export interface PackageJsonBuilder extends ConfigBuilder<PackageJson> {
@@ -107,12 +167,6 @@ export interface CreateContext {
107
167
  * load-preset if using localPresets. */
108
168
  rawPresets: Array<string>;
109
169
 
110
- /** Raw plugin desc from flags, prompts, etc. Can include constraints. */
111
- rawPlugins: Array<string>;
112
-
113
- /** Short names of plugins */
114
- plugins: Array<string>;
115
-
116
170
  /** Local packages that should be linked */
117
171
  pkgLinks: Array<string>;
118
172
 
@@ -131,6 +185,12 @@ export interface CreateContext {
131
185
  /** any generated files to show in report */
132
186
  generatedFiles: Set<string>;
133
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
+
134
194
  // Added by `global-prompts`
135
195
 
136
196
  /** Description of app */
@@ -154,23 +214,6 @@ export interface CreateContext {
154
214
  /** Whether or not the user wants to override an extant directory */
155
215
  destOverride: boolean;
156
216
 
157
- // Added by `load-preset`
158
-
159
- /** Short name of presets */
160
- presets: Array<string>;
161
-
162
- /** Shallow load of presets with meta data */
163
- presetInfos: Array<PresetInfo>;
164
-
165
- // Added by `cli-version`
166
-
167
- /** Version of current CLI used to issue `create` command */
168
- cliVersion: string;
169
-
170
- /** Version of CLI to install, either current or min compatible version
171
- * required by preset(s) */
172
- cliVersionRequired: string;
173
-
174
217
  // Added by `setup-pkg`
175
218
 
176
219
  /** package.json builder */
@@ -192,11 +235,12 @@ export interface CreateContext {
192
235
 
193
236
  declare module '@gasket/engine' {
194
237
  export interface HookExecTypes {
238
+ presetPrompt(context: CreateContext): Promise<void>;
239
+ presetConfig(context: CreateContext): Promise<void>;
195
240
  prompt(
196
241
  context: CreateContext,
197
242
  utils: {
198
243
  prompt: (prompts: Array<Record<string, any>>) => Promise<Record<string, any>>,
199
- addPlugins: (plugins: Array<string>) => Promise<void>
200
244
  }
201
245
  ): MaybeAsync<CreateContext>;
202
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';
@@ -11,7 +10,7 @@ import { Files } from '../files.js';
11
10
  * @returns {Promise} promise
12
11
  */
13
12
  async function createHooks(gasket, context) {
14
- const { dest, presets = [], plugins = [], warnings } = context;
13
+ const { plugins = [], warnings } = context;
15
14
 
16
15
  const files = new Files();
17
16
  const gasketConfig = ConfigBuilder.create({}, { orderBy: ['plugins'], warnings, plugins });
@@ -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(gasket, context, spinner) {
167
+ async function generateFiles(_, context, spinner) {
168
168
  const { files } = context;
169
169
 
170
170
  if (!files.globSets.length) {
@@ -1,9 +1,6 @@
1
1
  import inquirer from 'inquirer';
2
2
  import action from '../action-wrapper.js';
3
3
 
4
- import { pluginIdentifier, flattenPresets } from '@gasket/resolve';
5
- import { addPluginsToContext } from '../utils.js';
6
-
7
4
  /**
8
5
  * What is your app description?
9
6
  *
@@ -71,20 +68,9 @@ async function choosePackageManager(context, prompt) {
71
68
  * @returns {Promise} promise
72
69
  */
73
70
  async function chooseTestPlugin(context, prompt) {
74
- // Combine user-provided plugins with preset-provided plugins.
75
- const { presetInfos = [], plugins = [] } = context;
76
-
77
- // Flatten all plugins from presets and concat short names with cli plugins
78
- // const allPlugins = flattenPresets(presetInfos)
79
- // .map((presetInfo) => presetInfo.plugins || [])
80
- // .reduce((acc, arr) => acc.concat(arr), [])
81
- // .map((pluginInfo) => pluginIdentifier(pluginInfo.name).shortName)
82
- // .concat(plugins);
83
-
84
71
  const knownTestPlugins = { mocha: '@gasket/plugin-mocha', jest: '@gasket/plugin-jest', cypress: '@gasket/plugin-cypress' };
85
72
 
86
73
  if (!('testPlugin' in context)) {
87
- // let testPlugin = Object.values(knownTestPlugins).find((p) => allPlugins.includes(p));
88
74
  let testPlugin;
89
75
 
90
76
  if ('testSuite' in context) {
@@ -108,7 +94,6 @@ async function chooseTestPlugin(context, prompt) {
108
94
  }
109
95
 
110
96
  if (testPlugin && testPlugin !== 'none') {
111
- // addPluginsToContext([testPlugin], context);
112
97
  Object.assign(context, { testPlugin });
113
98
  }
114
99
  }
@@ -151,7 +136,7 @@ export const questions = [
151
136
  * @param {CreateContext} context - Create context
152
137
  * @returns {Promise} promise
153
138
  */
154
- async function globalPrompts(gasket, context) {
139
+ async function globalPrompts(_, context) {
155
140
  const prompt = context.prompts ? inquirer.prompt : () => ({});
156
141
  for (var fn of questions) {
157
142
  await fn(context, prompt);
@@ -1,42 +1,33 @@
1
1
  import mkDir from './mkdir.js';
2
2
  import loadPreset from './load-preset.js';
3
- import cliVersion from './cli-version.js';
4
3
  import globalPrompts from './global-prompts.js';
5
4
  import setupPkg from './setup-pkg.js';
6
- import writePkg, { writePkgUpdate } from './write-pkg.js';
7
- import installModules, { installModulesUpdate } from './install-modules.js';
8
- import linkModules, { linkModulesUpdate } from './link-modules.js';
5
+ import writePkg from './write-pkg.js';
6
+ import installModules from './install-modules.js';
7
+ import linkModules from './link-modules.js';
9
8
  import writeGasketConfig from './write-gasket-config.js';
10
- import loadPkgForDebug from './load-pkg-for-debug.js';
11
9
  import presetPromptHooks from './preset-prompt-hooks.js';
12
10
  import presetConfigHooks from './preset-config-hooks.js';
13
11
  import promptHooks from './prompt-hooks.js';
14
12
  import createHooks from './create-hooks.js';
15
13
  import generateFiles from './generate-files.js';
16
14
  import postCreateHooks from './post-create-hooks.js';
17
- import applyPresetConfig from './apply-preset-config.js';
18
15
  import printReport from './print-report.js';
19
16
 
20
17
  export {
21
18
  mkDir,
22
19
  loadPreset,
23
- cliVersion,
24
20
  globalPrompts,
25
21
  setupPkg,
26
22
  writePkg,
27
- writePkgUpdate,
28
23
  installModules,
29
- installModulesUpdate,
30
24
  linkModules,
31
- linkModulesUpdate,
32
25
  writeGasketConfig,
33
- loadPkgForDebug,
34
26
  presetPromptHooks,
35
27
  presetConfigHooks,
36
28
  promptHooks,
37
29
  createHooks,
38
30
  postCreateHooks,
39
31
  generateFiles,
40
- applyPresetConfig,
41
32
  printReport
42
33
  };
@@ -6,13 +6,10 @@ import action from '../action-wrapper.js';
6
6
  * @param {CreateContext} context - Create context
7
7
  * @returns {Promise} promise
8
8
  */
9
- async function installModules(gasket, context) {
9
+ async function installModules(_, context) {
10
10
  const { pkgManager } = context;
11
11
 
12
12
  await pkgManager.install();
13
13
  }
14
14
 
15
-
16
15
  export default action('Install node modules', installModules);
17
-
18
- export const installModulesUpdate = action('Update node modules', installModules);
@@ -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(gasket, context, spinner) {
10
+ async function linkModules(_, context, spinner) {
11
11
  const { pkgLinks, pkgManager } = context;
12
12
 
13
13
  if (pkgLinks && pkgLinks.length) {
@@ -17,5 +17,3 @@ async function linkModules(gasket, context, spinner) {
17
17
  }
18
18
 
19
19
  export default action('Link node modules', linkModules, { startSpinner: false });
20
-
21
- export const linkModulesUpdate = action('Relink node modules', linkModules, { startSpinner: false });
@@ -6,27 +6,35 @@ import { mkdtemp } from 'fs/promises';
6
6
  import { createRequire } from 'module';
7
7
  const require = createRequire(import.meta.url);
8
8
 
9
- async function loadPresets(gasket, context) {
9
+ /**
10
+ * loadPresets - Load presets to temp directory
11
+ * @param {null} _ - no input
12
+ * @param {CreateContext} context - Create context
13
+ */
14
+ async function loadPresets(_, context) {
10
15
  const tmpDir = await mkdtemp(path.join(os.tmpdir(), `gasket-create-${context.appName}`));
11
16
  context.tmpDir = tmpDir;
12
17
 
13
- const modPath = path.join(tmpDir, 'node_modules');
14
- const pkgManager = new gasketUtils.PackageManager({ packageManager: context.packageManager, dest: tmpDir });
18
+ const pkgManager = new gasketUtils.PackageManager({
19
+ packageManager: context.packageManager,
20
+ dest: tmpDir
21
+ });
15
22
  const pkgVerb = pkgManager.isYarn ? 'add' : 'install';
16
23
 
17
24
  const remotePresets = context.rawPresets.map(async preset => {
18
- const parts = /@([0-9]\.|[0-9]).+/.test(preset) && preset.split('@').filter(Boolean);
25
+ const parts = /@(\^[0-9]\.|[0-9]).+/.test(preset) && preset.split('@').filter(Boolean);
19
26
  const name = parts ? `@${parts[0]}` : preset;
20
27
  const version = parts ? `@${parts[1]}` : '@latest';
21
28
  await pkgManager.exec(pkgVerb, [`${name}${version}`]);
22
- const mod = await import(name, { from: modPath });
29
+ // eslint-disable-next-line
30
+ const mod = await import(name);
23
31
  return mod.default || mod;
24
32
  });
25
33
 
26
34
  const localPresets = context.localPresets.map(async localPresetPath => {
27
35
  await pkgManager.exec(pkgVerb, [localPresetPath]);
28
36
  const pkgFile = require(path.join(localPresetPath, 'package.json'));
29
- const mod = await import(pkgFile.name, { from: modPath });
37
+ const mod = await import(pkgFile.name);
30
38
  return mod.default || mod;
31
39
  });
32
40
 
@@ -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(gasket, 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
@@ -1,5 +1,4 @@
1
1
  import action from '../action-wrapper.js';
2
- import { createEngine } from '../create-engine.js';
3
2
  import { runShellCommand } from '@gasket/utils';
4
3
 
5
4
  /**
@@ -9,7 +8,7 @@ import { runShellCommand } from '@gasket/utils';
9
8
  * @returns {Promise} promise
10
9
  */
11
10
  async function postCreateHooks(gasket, context) {
12
- const { dest, presets = [], plugins = [] } = context;
11
+ const { dest } = context;
13
12
 
14
13
  /**
15
14
  * Run an npm script in the context of the created application
@@ -1,12 +1,12 @@
1
1
  import action from '../action-wrapper.js';
2
2
 
3
+ /**
4
+ * presetConfigHooks - exec `presetConfig` hook
5
+ * @param {Gasket} gasket - Preset gasket instance
6
+ * @param {CreateContext} context - Create context
7
+ */
3
8
  async function presetConfigHooks(gasket, context) {
4
- if (!context.presetConig) {
5
- context.presetConfig = {};
6
- }
7
-
8
9
  const config = await gasket.execWaterfall('presetConfig', context);
9
-
10
10
  Object.assign(context.presetConfig, config);
11
11
  }
12
12
 
@@ -1,7 +1,11 @@
1
1
  import inquirer from 'inquirer';
2
2
  import action from '../action-wrapper.js';
3
3
 
4
-
4
+ /**
5
+ * presetPromptHooks - exec `presetPrompt` hook
6
+ * @param {Gasket} gasket - Preset gasket instance
7
+ * @param {CreateContext} context - Create context
8
+ */
5
9
  async function presetPromptHooks(gasket, context) {
6
10
  const prompt = context.prompts ? inquirer.createPromptModule() : () => ({});
7
11
 
@@ -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
 
@@ -1,47 +1,5 @@
1
1
  import inquirer from 'inquirer';
2
2
  import action from '../action-wrapper.js';
3
- import { addPluginsToContext, addPluginsToPkg, getPluginsWithVersions } from '../utils.js';
4
- import { createEngine } from '../create-engine.js';
5
-
6
- /**
7
- * Create the `addPlugins` function with context
8
- *
9
- * @param {CreateContext} context - Create context
10
- * @returns {addPlugins} addPlugins
11
- */
12
- const createAddPlugins = context => {
13
- /**
14
- * Allows plugins to add plugins based on user input.
15
- *
16
- * @typedef {Function} addPlugins
17
- *
18
- * @param {...PluginDesc} pluginsToAdd - Additional plugins to add
19
- * @returns {Promise} promise
20
- */
21
- return async function addPlugins(...pluginsToAdd) {
22
- const { pkg, pkgLinks = [], pkgManager } = context;
23
-
24
- addPluginsToContext(pluginsToAdd, context);
25
- const pluginIds = await getPluginsWithVersions(pluginsToAdd, pkgManager);
26
- addPluginsToPkg(pluginIds, pkg);
27
-
28
- //
29
- // Install new plugins if not already linked
30
- //
31
- const toInstall = pluginIds.filter(p => !pkgLinks.includes(p.fullName));
32
- if (toInstall.length) {
33
- await pkgManager.install(toInstall.map(p => p.full));
34
- //
35
- // relink because npm blows them away on installs...
36
- //
37
- if (pkgLinks.length) {
38
- await pkgManager.link(pkgLinks);
39
- }
40
- }
41
-
42
- await execPluginPrompts(context, pluginIds.map(p => p.shortName));
43
- };
44
- };
45
3
 
46
4
  /**
47
5
  * Initializes engine with provide preset and plugins
@@ -53,14 +11,12 @@ const createAddPlugins = context => {
53
11
  * @returns {Promise} promise
54
12
  * @private
55
13
  */
56
- async function execPluginPrompts(gasket, context, plugins = [], presets = []) {
14
+ async function execPluginPrompts(gasket, context) {
57
15
  //
58
16
  // @see: https://github.com/SBoudrias/Inquirer.js/#inquirercreatepromptmodule---prompt-function
59
17
  //
60
18
  const prompt = context.prompts ? inquirer.createPromptModule() : () => ({});
61
- const addPlugins = createAddPlugins(context);
62
-
63
- const nextContext = await gasket.execWaterfall('prompt', context, { prompt, addPlugins });
19
+ const nextContext = await gasket.execWaterfall('prompt', context, { prompt });
64
20
  //
65
21
  // Ensure the original context is transformed in case a prompt returns a new object
66
22
  //
@@ -69,7 +25,7 @@ async function execPluginPrompts(gasket, context, plugins = [], presets = []) {
69
25
 
70
26
  /**
71
27
  * Executes the `prompt` hook for all registered plugins.
72
- * Adds `prompt` and `addPlugins` util functions for prompting features.
28
+ * Adds `prompt` util function for prompting features.
73
29
  *
74
30
  * @param {CreateContext} context - Create context
75
31
  * @returns {Promise} promise
@@ -1,8 +1,6 @@
1
1
  import action from '../action-wrapper.js';
2
2
  import { ConfigBuilder } from '../config-builder.js';
3
- import { addPluginsToPkg, getPluginsWithVersions } from '../utils.js';
4
3
  import { default as gasketUtils } from '@gasket/utils';
5
- import { presetIdentifier } from '@gasket/resolve';
6
4
 
7
5
  /**
8
6
  * Initializes the ConfigBuilder builder and adds to context.
@@ -11,9 +9,7 @@ import { presetIdentifier } from '@gasket/resolve';
11
9
  * @returns {Promise} promise
12
10
  */
13
11
  async function setupPkg(gasket, context) {
14
- // console.log(context);
15
- // throw new Error('Not implemented');
16
- const { appName, appDescription, presetInfos = [], rawPlugins = [], cliVersionRequired, warnings } = context;
12
+ const { appName, appDescription, warnings } = context;
17
13
 
18
14
  const pkg = ConfigBuilder.createPackageJson({
19
15
  name: appName,
@@ -22,23 +18,7 @@ async function setupPkg(gasket, context) {
22
18
  type: context.typescript ? 'commonjs' : 'module'
23
19
  }, { warnings });
24
20
 
25
- // The preset package itself must be included in the dependencies
26
- // of the `pkg` to be bootstrapped.
27
- // pkg.add('dependencies', presetInfos.reduce((acc, presetInfo) => {
28
- // // Use rawName in case version or file path was set in cli args
29
- // // Otherwise fallback to resolved version
30
- // const { fullName, version } = presetIdentifier(presetInfo.rawName).withVersion(`^${presetInfo.version}`);
31
-
32
- // acc[fullName] = version;
33
- // return acc;
34
- // }, {
35
- // // '@gasket/cli': cliVersionRequired
36
- // }));
37
-
38
21
  const pkgManager = new gasketUtils.PackageManager(context);
39
- const pluginIds = await getPluginsWithVersions(rawPlugins, pkgManager);
40
- addPluginsToPkg(pluginIds, pkg);
41
-
42
22
  Object.assign(context, { pkg, pkgManager });
43
23
  }
44
24