create-gasket-app 7.0.0-next.20 → 7.0.0-next.23

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.
@@ -107,17 +107,17 @@ createCommand.action = async function run(appname, options, command) {
107
107
  const { rawPresets, localPresets } = context;
108
108
 
109
109
  try {
110
- await globalPrompts(null, context);
110
+ await globalPrompts({ context });
111
111
 
112
112
  if (rawPresets.length || localPresets.length) {
113
- await loadPreset(null, context);
113
+ await loadPreset({ context });
114
114
 
115
115
  const presetGasket = makeGasket({
116
116
  plugins: context.presets
117
117
  });
118
118
 
119
- await presetPromptHooks(presetGasket, context);
120
- await presetConfigHooks(presetGasket, context);
119
+ await presetPromptHooks({ gasket: presetGasket, context });
120
+ await presetConfigHooks({ gasket: presetGasket, context });
121
121
  }
122
122
 
123
123
  const pluginGasket = makeGasket({
@@ -125,18 +125,18 @@ createCommand.action = async function run(appname, options, command) {
125
125
  plugins: context.presets.concat(context.presetConfig.plugins, defaultPlugins)
126
126
  });
127
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);
128
+ await promptHooks({ gasket: pluginGasket, context });
129
+ await mkDir({ context });
130
+ await setupPkg({ context });
131
+ await createHooks({ gasket: pluginGasket, context });
132
+ await writePkg({ context });
133
+ await generateFiles({ context });
134
+ await writeGasketConfig({ context });
135
+ await installModules({ context });
136
+ await linkModules({ context });
137
+ await postCreateHooks({ gasket: pluginGasket, context });
138
138
  if (context.tmpDir) await rm(context.tmpDir, { recursive: true });
139
- printReport(null, context);
139
+ printReport({ context });
140
140
  } catch (err) {
141
141
  console.error(chalk.red('Exiting with errors.'));
142
142
  dumpErrorContext(context, err);
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 {
@@ -95,7 +95,7 @@ export interface ConfigBuilder<Config> {
95
95
  * import { readFileSync } from 'fs';
96
96
  * import fs from 'fs';
97
97
  */
98
- addImport(importName: string, importPath: string): ConfigBuilder;
98
+ addImport(importName: string, importPath: string): ConfigBuilder<Config>;
99
99
 
100
100
  /**
101
101
  * addExpression - add programmatic expression to the gasket file
@@ -110,7 +110,7 @@ export interface ConfigBuilder<Config> {
110
110
  * import fs from 'fs';
111
111
  * const file = fs.readFileSync('./file.txt');
112
112
  */
113
- addExpression(expression: string): ConfigBuilder;
113
+ addExpression(expression: string): ConfigBuilder<Config>;
114
114
 
115
115
  /**
116
116
  * injectValue - Inject a value into the gasket config object
@@ -127,7 +127,7 @@ export interface ConfigBuilder<Config> {
127
127
  * }
128
128
  * });
129
129
  */
130
- injectValue(configKey: string, injectedValue: any): void;
130
+ injectValue(configKey: string, injectedValue: string): void;
131
131
  }
132
132
 
133
133
  export interface PackageJsonBuilder extends ConfigBuilder<PackageJson> {
@@ -186,7 +186,7 @@ export interface CreateContext {
186
186
  generatedFiles: Set<string>;
187
187
 
188
188
  /** Default empty array, populated by load-preset with actual imports */
189
- presets: Array<any>;
189
+ presets: Array<Plugin>;
190
190
 
191
191
  /** Default to object w/empty plugins array to be populated by `presetConfig` hook */
192
192
  presetConfig: GasketConfigDefinition;
@@ -233,10 +233,16 @@ export interface CreateContext {
233
233
  files: Files;
234
234
  }
235
235
 
236
- declare module '@gasket/engine' {
236
+ export interface ActionWrapperParams {
237
+ gasket: GasketEngine;
238
+ context: CreateContext;
239
+ spinner?: any;
240
+ }
241
+
242
+ declare module '@gasket/core' {
237
243
  export interface HookExecTypes {
238
244
  presetPrompt(context: CreateContext): Promise<void>;
239
- presetConfig(context: CreateContext): Promise<void>;
245
+ presetConfig(context: CreateContext): Promise<CreateContext['presetConfig']>;
240
246
  prompt(
241
247
  context: CreateContext,
242
248
  utils: {
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();
@@ -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) {
@@ -73,7 +73,7 @@ async function chooseTestPlugin(context, prompt) {
73
73
  if (!('testPlugin' in context)) {
74
74
  let testPlugin;
75
75
 
76
- if ('testSuite' in context) {
76
+ if ('testSuite' in context) {
77
77
  testPlugin = knownTestPlugins[context.testSuite];
78
78
  }
79
79
 
@@ -136,7 +136,7 @@ export const questions = [
136
136
  * @param {CreateContext} context - Create context
137
137
  * @returns {Promise} promise
138
138
  */
139
- async function globalPrompts(_, context) {
139
+ async function globalPrompts({ context }) {
140
140
  const prompt = context.prompts ? inquirer.prompt : () => ({});
141
141
  for (var fn of questions) {
142
142
  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,13 +5,13 @@ 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 hasVersion = /@(\^[0-9]\.|[0-9]).+/;
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
 
@@ -23,7 +23,7 @@ async function loadPresets(_, context) {
23
23
  const pkgVerb = pkgManager.isYarn ? 'add' : 'install';
24
24
 
25
25
  const remotePresets = context.rawPresets.map(async preset => {
26
- const parts = /@(\^[0-9]\.|[0-9]).+/.test(preset) && preset.split('@').filter(Boolean);
26
+ const parts = hasVersion.test(preset) && preset.split('@').filter(Boolean);
27
27
  const name = parts ? `@${parts[0]}` : preset;
28
28
  const version = parts ? `@${parts[1]}` : '@latest';
29
29
 
@@ -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
@@ -11,7 +11,7 @@ const { dependencies } = require('../../../package.json');
11
11
  * @param {CreateContext} context - Create context
12
12
  * @returns {Promise} promise
13
13
  */
14
- async function setupPkg(gasket, context) {
14
+ async function setupPkg({ context }) {
15
15
  const { appName, appDescription, warnings } = context;
16
16
 
17
17
  const pkg = ConfigBuilder.createPackageJson({
@@ -24,7 +24,6 @@ async function setupPkg(gasket, context) {
24
24
  // Add critical dependencies
25
25
  pkg.add('dependencies', {
26
26
  '@gasket/core': dependencies['@gasket/core'],
27
- '@gasket/engine': dependencies['@gasket/engine'],
28
27
  '@gasket/utils': dependencies['@gasket/utils']
29
28
  });
30
29
 
@@ -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);
@@ -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);
@@ -3,4 +3,3 @@ export { processArgs } from './process-args.js';
3
3
  export { processOptions } from './process-options.js';
4
4
  export { createOption } from './create-option.js';
5
5
  export { logo } from './logo.js';
6
- export { warnIfOutdated } from './warn-if-outdated.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-gasket-app",
3
- "version": "7.0.0-next.20",
3
+ "version": "7.0.0-next.23",
4
4
  "description": "starter pack for creating a gasket app",
5
5
  "main": "lib",
6
6
  "bin": {
@@ -14,7 +14,7 @@
14
14
  "lint": "eslint .",
15
15
  "lint:fix": "npm run lint -- --fix",
16
16
  "test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict --experimental-vm-modules' jest",
17
- "test:watch": "jest --watch",
17
+ "test:watch": "npm run test -- --watch",
18
18
  "test:coverage": "jest --coverage",
19
19
  "posttest": "npm run lint"
20
20
  },
@@ -32,11 +32,10 @@
32
32
  },
33
33
  "homepage": "https://github.com/godaddy/gasket/tree/main/packages/create-gasket-app",
34
34
  "dependencies": {
35
- "@gasket/core": "^7.0.0-next.20",
36
- "@gasket/engine": "^7.0.0-next.20",
37
- "@gasket/plugin-git": "^7.0.0-next.20",
38
- "@gasket/plugin-logger": "^7.0.0-next.20",
39
- "@gasket/utils": "^7.0.0-next.20",
35
+ "@gasket/core": "^7.0.0-next.23",
36
+ "@gasket/plugin-git": "^7.0.0-next.23",
37
+ "@gasket/plugin-logger": "^7.0.0-next.23",
38
+ "@gasket/utils": "^7.0.0-next.23",
40
39
  "commander": "^12.0.0",
41
40
  "deepmerge": "^4.3.1",
42
41
  "glob": "^8.1.0",
@@ -79,5 +78,5 @@
79
78
  "jest": {
80
79
  "transform": {}
81
80
  },
82
- "gitHead": "9c464bc32c8eade218b6ae094e1a0819e84af7ad"
81
+ "gitHead": "0ba753c8764138e300be1c464065280bcc801239"
83
82
  }
@@ -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
- }
@@ -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
- }