@ms-cloudpack/cli 0.77.28 → 0.77.29

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.
@@ -1 +1 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAqB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAIrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAW5D;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,YAAY,CAsH/C,CAAC"}
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAqB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAIrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAU5D;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,YAAY,CAsH/C,CAAC"}
@@ -12,7 +12,6 @@ import { resolveCloudpackInternalPath } from '../../utilities/resolveCloudpackIn
12
12
  import { getDomain, parseHttpsConfig } from '@ms-cloudpack/create-express-app';
13
13
  import { handleKnownParseHttpsErrors } from '../../utilities/handleKnownParseHttpsErrors.js';
14
14
  import { createWatcher } from '@ms-cloudpack/file-watcher';
15
- import { commandEvents } from '../../utilities/commandEvents.js';
16
15
  import { readConfig } from '@ms-cloudpack/config';
17
16
  import { disposeServer } from '../../utilities/disposeServer.js';
18
17
  /**
@@ -101,7 +100,7 @@ export const execute = async (params) => {
101
100
  handleOpenBrowser(options, apiContext);
102
101
  }
103
102
  });
104
- commandEvents.emit('ready');
103
+ params.commandEvents.emit('ready');
105
104
  })().catch((err) => {
106
105
  console.error('Error in start command:', err);
107
106
  resolve({ hasErrors: true, message: `Error in start command: ${err}` });
@@ -1 +1 @@
1
- {"version":3,"file":"execute.js","sourceRoot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,+FAA+F;YAC/F,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;gBAChF,SAAS,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;YAC7E,CAAC;iBAAM,CAAC;gBACN,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;YAC3B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,8DAA8D;YAC9D,SAAS,GAAG,UAAU,CAAC;QACzB,CAAC;QAED,KAAK,WAAW,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACtE,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAG,GAAyB,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;YACjF,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,UAAU,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,wBAAwB","sourcesContent":["import { createApiContext, ensurePackageBundled, type PartialContext } from '@ms-cloudpack/api-server';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { yellow } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport type { CommandExitParams, CommandAction } from '../../types/CommandAction.js';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { openBrowser } from './openBrowser.js';\nimport { trackSession } from './trackSession.js';\nimport type { StartOptions } from './types/StartOptions.js';\nimport { getCliStartTime } from '../../utilities/getCliStartTime.js';\nimport { createApiServer } from '../../utilities/createApiServer.js';\nimport { resolveCloudpackInternalPath } from '../../utilities/resolveCloudpackInternalPath.js';\nimport { getDomain, parseHttpsConfig } from '@ms-cloudpack/create-express-app';\nimport { handleKnownParseHttpsErrors } from '../../utilities/handleKnownParseHttpsErrors.js';\nimport { createWatcher } from '@ms-cloudpack/file-watcher';\nimport { commandEvents } from '../../utilities/commandEvents.js';\nimport { readConfig } from '@ms-cloudpack/config';\nimport { disposeServer } from '../../utilities/disposeServer.js';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async (params) => {\n const { appPath, config, options, autoDispose, isRestart } = params;\n\n console.log('App path:', yellow(appPath));\n console.log('Bundle mode:', yellow(options.mode));\n\n await runPrerequisites(params);\n\n // If the user has specified https options in the config, parse them at start.\n // This makes sure that the HTTPS configuration is ready before starting the servers and shows errors early.\n // We need to do this after prerequisites are run, in case users setup their certs there.\n if (config?.server?.https) {\n try {\n const domain = getDomain(config.server.domain);\n config.server.parsedHttps = await parseHttpsConfig({ domain, https: config.server.https, cwd: appPath });\n } catch (err) {\n handleKnownParseHttpsErrors({ err, projectName: path.basename(appPath) });\n throw err;\n }\n }\n\n const overlayPath = await resolveCloudpackInternalPath({\n packageName: '@ms-cloudpack/overlay',\n importMetaUrl: import.meta.url,\n });\n\n const shouldUseRemoteCache = config.features?.enableCloudHosted || config.features?.enableRemoteCacheDownloads;\n const apiContext = autoDispose(\n await createApiContext({\n ...params,\n remoteCacheClientLoginMethod: shouldUseRemoteCache ? options.login : undefined,\n additionalPaths: overlayPath ? [overlayPath] : undefined,\n }),\n );\n const { packages, session, telemetryClient } = apiContext;\n\n return new Promise<CommandExitParams>((resolve) => {\n (async () => {\n let hasConfigChanged = false;\n const configWatcher = createWatcher();\n await Promise.all(\n config.configPaths?.appConfigPaths.map(\n (configPath) =>\n configWatcher.watch({ path: path.basename(configPath), watchPaths: [configPath] }, () => {\n if (hasConfigChanged) {\n return;\n }\n void readConfig(appPath)\n .then(() => {\n hasConfigChanged = true;\n resolve({ restart: true, message: 'Config changed. Restarting Cloudpack...' });\n })\n .catch((error) => console.warn('Config change detected, but the config file is invalid.', error));\n }) ?? [],\n ) ?? [],\n );\n\n // Set up config watcher disposal (up here in case the config changes before setup completes).\n autoDispose(configWatcher);\n\n // Increment the session version if caching is disabled.\n if (options.cache === false) {\n session.incrementSessionVersion();\n }\n\n // Make sure the package has a valid definition.\n const definition = await packages.get(appPath);\n\n if (options.logResolveMap) {\n // Write the resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n }\n\n // Start api server for tracking status and handling remote requests.\n const apiServerResult = await createApiServer({ port: options.apiServerPort }, apiContext);\n if (apiServerResult.hasErrors) {\n return apiServerResult;\n }\n const { apiServer } = apiServerResult;\n autoDispose({ dispose: () => disposeServer('API server', apiServer) });\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({ name: definition.name, version: definition.version }, apiContext);\n\n // Then start bundle and app servers for hosting the app.\n const { startServers } = await import('@ms-cloudpack/app-server');\n const servers = await startServers(\n {\n definition,\n bundleServerOptions: { disableCache: !options.cache, port: options.bundleServerPort },\n port: options.appServerPort,\n },\n apiContext,\n );\n autoDispose({ dispose: () => disposeServer('app server', servers.appServer) });\n autoDispose({ dispose: () => disposeServer('bundle server', servers.bundleServer) });\n\n // Save the session to active sessions.\n const sessionTracker = await trackSession(session);\n autoDispose({ dispose: () => sessionTracker.close() });\n\n // Log the time elapsed from when the CLI started until the browser is ready to be opened.\n await telemetryClient.tracer.startActiveSpan(\n 'TIME_TO_OPEN_BROWSER',\n { startTime: getCliStartTime(), attributes: { open: options.open } },\n () => {\n if (!isRestart) {\n handleOpenBrowser(options, apiContext);\n }\n },\n );\n\n commandEvents.emit('ready');\n })().catch((err) => {\n console.error('Error in start command:', err);\n resolve({ hasErrors: true, message: `Error in start command: ${err}` });\n });\n });\n};\n\nfunction handleOpenBrowser(\n options: StartOptions,\n apiContext: PartialContext<'telemetryClient', 'config' | 'urls'>,\n): void {\n const { config, urls } = apiContext.session;\n\n const defaultUrl = makeUrl(config.server?.defaultPath || '', urls.appServer).href;\n\n // Open the browser.\n if (options.open === false) {\n console.log('Please open the browser manually to:', defaultUrl);\n } else {\n let urlToOpen: string;\n if (typeof options.open === 'string') {\n // If the string doesn't start with http or https, pick a protocol based on config.server.https\n if (!options.open.startsWith('http://') && !options.open.startsWith('https://')) {\n urlToOpen = `${config.server?.https ? 'https' : 'http'}://${options.open}`;\n } else {\n urlToOpen = options.open;\n }\n } else {\n // Use the default path from the config with the first domain.\n urlToOpen = defaultUrl;\n }\n\n void openBrowser({ url: urlToOpen }, apiContext).catch((err: unknown) => {\n console.warn('Error opening browser:', (err as Error | undefined)?.stack || err);\n console.warn('Please open the browser manually to:', defaultUrl);\n });\n }\n}\n\n// cspell:ignore Prereqs\n"]}
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAuB,MAAM,0BAA0B,CAAC;AACvG,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,2BAA2B,EAAE,MAAM,gDAAgD,CAAC;AAC7F,OAAO,EAAE,aAAa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urePackageBundled, type PartialContext } from '@ms-cloudpack/api-server';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { yellow } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport type { CommandExitParams, CommandAction } from '../../types/CommandAction.js';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { openBrowser } from './openBrowser.js';\nimport { trackSession } from './trackSession.js';\nimport type { StartOptions } from './types/StartOptions.js';\nimport { getCliStartTime } from '../../utilities/getCliStartTime.js';\nimport { createApiServer } from '../../utilities/createApiServer.js';\nimport { resolveCloudpackInternalPath } from '../../utilities/resolveCloudpackInternalPath.js';\nimport { getDomain, parseHttpsConfig } from '@ms-cloudpack/create-express-app';\nimport { handleKnownParseHttpsErrors } from '../../utilities/handleKnownParseHttpsErrors.js';\nimport { createWatcher } from '@ms-cloudpack/file-watcher';\nimport { readConfig } from '@ms-cloudpack/config';\nimport { disposeServer } from '../../utilities/disposeServer.js';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async (params) => {\n const { appPath, config, options, autoDispose, isRestart } = params;\n\n console.log('App path:', yellow(appPath));\n console.log('Bundle mode:', yellow(options.mode));\n\n await runPrerequisites(params);\n\n // If the user has specified https options in the config, parse them at start.\n // This makes sure that the HTTPS configuration is ready before starting the servers and shows errors early.\n // We need to do this after prerequisites are run, in case users setup their certs there.\n if (config?.server?.https) {\n try {\n const domain = getDomain(config.server.domain);\n config.server.parsedHttps = await parseHttpsConfig({ domain, https: config.server.https, cwd: appPath });\n } catch (err) {\n handleKnownParseHttpsErrors({ err, projectName: path.basename(appPath) });\n throw err;\n }\n }\n\n const overlayPath = await resolveCloudpackInternalPath({\n packageName: '@ms-cloudpack/overlay',\n importMetaUrl: import.meta.url,\n });\n\n const shouldUseRemoteCache = config.features?.enableCloudHosted || config.features?.enableRemoteCacheDownloads;\n const apiContext = autoDispose(\n await createApiContext({\n ...params,\n remoteCacheClientLoginMethod: shouldUseRemoteCache ? options.login : undefined,\n additionalPaths: overlayPath ? [overlayPath] : undefined,\n }),\n );\n const { packages, session, telemetryClient } = apiContext;\n\n return new Promise<CommandExitParams>((resolve) => {\n (async () => {\n let hasConfigChanged = false;\n const configWatcher = createWatcher();\n await Promise.all(\n config.configPaths?.appConfigPaths.map(\n (configPath) =>\n configWatcher.watch({ path: path.basename(configPath), watchPaths: [configPath] }, () => {\n if (hasConfigChanged) {\n return;\n }\n void readConfig(appPath)\n .then(() => {\n hasConfigChanged = true;\n resolve({ restart: true, message: 'Config changed. Restarting Cloudpack...' });\n })\n .catch((error) => console.warn('Config change detected, but the config file is invalid.', error));\n }) ?? [],\n ) ?? [],\n );\n\n // Set up config watcher disposal (up here in case the config changes before setup completes).\n autoDispose(configWatcher);\n\n // Increment the session version if caching is disabled.\n if (options.cache === false) {\n session.incrementSessionVersion();\n }\n\n // Make sure the package has a valid definition.\n const definition = await packages.get(appPath);\n\n if (options.logResolveMap) {\n // Write the resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n }\n\n // Start api server for tracking status and handling remote requests.\n const apiServerResult = await createApiServer({ port: options.apiServerPort }, apiContext);\n if (apiServerResult.hasErrors) {\n return apiServerResult;\n }\n const { apiServer } = apiServerResult;\n autoDispose({ dispose: () => disposeServer('API server', apiServer) });\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({ name: definition.name, version: definition.version }, apiContext);\n\n // Then start bundle and app servers for hosting the app.\n const { startServers } = await import('@ms-cloudpack/app-server');\n const servers = await startServers(\n {\n definition,\n bundleServerOptions: { disableCache: !options.cache, port: options.bundleServerPort },\n port: options.appServerPort,\n },\n apiContext,\n );\n autoDispose({ dispose: () => disposeServer('app server', servers.appServer) });\n autoDispose({ dispose: () => disposeServer('bundle server', servers.bundleServer) });\n\n // Save the session to active sessions.\n const sessionTracker = await trackSession(session);\n autoDispose({ dispose: () => sessionTracker.close() });\n\n // Log the time elapsed from when the CLI started until the browser is ready to be opened.\n await telemetryClient.tracer.startActiveSpan(\n 'TIME_TO_OPEN_BROWSER',\n { startTime: getCliStartTime(), attributes: { open: options.open } },\n () => {\n if (!isRestart) {\n handleOpenBrowser(options, apiContext);\n }\n },\n );\n\n params.commandEvents.emit('ready');\n })().catch((err) => {\n console.error('Error in start command:', err);\n resolve({ hasErrors: true, message: `Error in start command: ${err}` });\n });\n });\n};\n\nfunction handleOpenBrowser(\n options: StartOptions,\n apiContext: PartialContext<'telemetryClient', 'config' | 'urls'>,\n): void {\n const { config, urls } = apiContext.session;\n\n const defaultUrl = makeUrl(config.server?.defaultPath || '', urls.appServer).href;\n\n // Open the browser.\n if (options.open === false) {\n console.log('Please open the browser manually to:', defaultUrl);\n } else {\n let urlToOpen: string;\n if (typeof options.open === 'string') {\n // If the string doesn't start with http or https, pick a protocol based on config.server.https\n if (!options.open.startsWith('http://') && !options.open.startsWith('https://')) {\n urlToOpen = `${config.server?.https ? 'https' : 'http'}://${options.open}`;\n } else {\n urlToOpen = options.open;\n }\n } else {\n // Use the default path from the config with the first domain.\n urlToOpen = defaultUrl;\n }\n\n void openBrowser({ url: urlToOpen }, apiContext).catch((err: unknown) => {\n console.warn('Error opening browser:', (err as Error | undefined)?.stack || err);\n console.warn('Please open the browser manually to:', defaultUrl);\n });\n }\n}\n\n// cspell:ignore Prereqs\n"]}
package/lib/main.d.ts CHANGED
@@ -1,11 +1,7 @@
1
- import type { OutputConfiguration } from 'commander';
1
+ import { type CloudpackCommandParams } from './utilities/CloudpackCommand.js';
2
+ import type { ProgramOptions } from './types/ProgramOptions.js';
2
3
  /** Override options for tests */
3
- export interface MainOptions {
4
- cwd?: string;
5
- disableTelemetry?: boolean;
6
- argv?: string[];
7
- outputOptions?: OutputConfiguration;
8
- }
4
+ export type MainOptions = Partial<Pick<ProgramOptions, 'cwd' | 'disableTelemetry' | 'argv' | 'commandEvents'>> & Pick<CloudpackCommandParams<object, never>, 'outputOptions'>;
9
5
  /**
10
6
  * Entry point for the cloudpack CLI.
11
7
  * Resolves all commands defined within the "./commands" folder.
package/lib/main.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AASrD,iCAAiC;AACjC,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED;;;GAGG;AACH,wBAAsB,IAAI,CAAC,OAAO,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwD5E"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAMA,OAAO,EAAoB,KAAK,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAGhG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,iCAAiC;AACjC,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,GAAG,kBAAkB,GAAG,MAAM,GAAG,eAAe,CAAC,CAAC,GAC5G,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,eAAe,CAAC,CAAC;AAE/D;;;GAGG;AACH,wBAAsB,IAAI,CAAC,OAAO,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAyD5E"}
package/lib/main.js CHANGED
@@ -6,6 +6,7 @@ import { PerfMarkerCliEntry } from './performance/markers.js';
6
6
  import { CloudpackCommand } from './utilities/CloudpackCommand.js';
7
7
  import { getNodeEngineRequirement } from './utilities/getNodeEngineRequirement.js';
8
8
  import { satisfies } from 'semver';
9
+ import { createCommandEvents } from './utilities/commandEvents.js';
9
10
  /**
10
11
  * Entry point for the cloudpack CLI.
11
12
  * Resolves all commands defined within the "./commands" folder.
@@ -21,7 +22,7 @@ export async function main(options = {}) {
21
22
  }
22
23
  const { argv = [...process.argv],
23
24
  // eslint-disable-next-line no-restricted-properties -- this is where the default is supplied
24
- cwd = process.cwd(), disableTelemetry, outputOptions, } = options;
25
+ cwd = process.cwd(), disableTelemetry, outputOptions, commandEvents = createCommandEvents(), } = options;
25
26
  performance.mark(PerfMarkerCliEntry);
26
27
  if (argv[3] === '--') {
27
28
  // Remove the "--" argument in case it's added by lage
@@ -35,7 +36,7 @@ export async function main(options = {}) {
35
36
  description: 'A tool for managing fast inner and outer looping in web apps. Requires a sub-command.',
36
37
  usage: '<command> [options]',
37
38
  outputOptions,
38
- programOptions: { cwd, version, argv, disableTelemetry },
39
+ programOptions: { cwd, version, argv, disableTelemetry, commandEvents },
39
40
  // The top-level command should realistically only ever be used with --help or --version,
40
41
  // so hide most of the options.
41
42
  hideSharedOptions: true,
package/lib/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAUnC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,UAAgC,EAAE;IAC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AC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IACtE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,+BAA+B,UAAU,IAAI,YAAY,MAAM,CAAC,CAAC;IACnF,CAAC;IAED,KAAK,MAAM,WAAW,IAAI,QAAQ,EAAE,CAAC;QACnC,MAAM,UAAU,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;QACzD,MAAM,aAAa,GAAG,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,CAAsB,CAAC;QAEtE,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC;AACtB,CAAC","sourcesContent":["import { getDisplayVersion } from '@ms-cloudpack/package-utilities';\nimport { globSourceFiles } from '@ms-cloudpack/path-utilities';\nimport type { OutputConfiguration } from 'commander';\nimport path from 'path';\nimport { fileURLToPath, pathToFileURL } from 'url';\nimport type { CommandInitModule } from './types/CommandInitFunction.js';\nimport { PerfMarkerCliEntry } from './performance/markers.js';\nimport { CloudpackCommand } from './utilities/CloudpackCommand.js';\nimport { getNodeEngineRequirement } from './utilities/getNodeEngineRequirement.js';\nimport { satisfies } from 'semver';\n\n/** Override options for tests */\nexport interface MainOptions {\n cwd?: string;\n disableTelemetry?: boolean;\n argv?: string[];\n outputOptions?: OutputConfiguration;\n}\n\n/**\n * Entry point for the cloudpack CLI.\n * Resolves all commands defined within the \"./commands\" folder.\n */\nexport async function main(options: Partial<MainOptions> = {}): Promise<void> {\n process.title = 'cloudpack';\n // Check Node.js version compatibility before doing anything else\n const requiredNodeVersion = getNodeEngineRequirement();\n if (requiredNodeVersion && !satisfies(process.version, requiredNodeVersion)) {\n console.error(`Cloudpack requires Node.js ${requiredNodeVersion}. Current version: ${process.version}.`);\n // eslint-disable-next-line no-restricted-properties -- exit immediately\n process.exit(1);\n }\n\n const {\n argv = [...process.argv],\n // eslint-disable-next-line no-restricted-properties -- this is where the default is supplied\n cwd = process.cwd(),\n disableTelemetry,\n outputOptions,\n } = options;\n\n performance.mark(PerfMarkerCliEntry);\n\n if (argv[3] === '--') {\n // Remove the \"--\" argument in case it's added by lage\n argv.splice(3, 1);\n }\n\n const version = getDisplayVersion(import.meta.url);\n\n // Create the top-level command and apply common options\n // (avoids \"unknown option\" errors if they're specified without a verb)\n const program = new CloudpackCommand({\n name: 'cloudpack',\n description: 'A tool for managing fast inner and outer looping in web apps. Requires a sub-command.',\n usage: '<command> [options]',\n outputOptions,\n programOptions: { cwd, version, argv, disableTelemetry },\n // The top-level command should realistically only ever be used with --help or --version,\n // so hide most of the options.\n hideSharedOptions: true,\n });\n\n // Get all the available commands\n const commandsGlob = 'commands/*/index';\n const commands = await globSourceFiles(import.meta.url, commandsGlob);\n if (!commands.length) {\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n throw new Error(`No commands found matching \"${currentDir}/${commandsGlob}.*\".`);\n }\n\n for (const commandPath of commands) {\n const commandUrl = pathToFileURL(commandPath).toString();\n const commandModule = (await import(commandUrl)) as CommandInitModule;\n\n commandModule.init(program);\n }\n\n await program.run();\n}\n"]}
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAA+B,MAAM,iCAAiC,CAA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AC5B,aAAa;QACb,cAAc,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,aAAa,EAAE;QACvE,yFAAyF;QACzF,+BAA+B;QAC/B,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;IAEH,iCAAiC;IACjC,MAAM,YAAY,GAAG,kBAAkB,CAAC;IACxC,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IACtE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,+BAA+B,UAAU,IAAI,YAAY,MAAM,CAAC,CAAC;IACnF,CAAC;IAED,KAAK,MAAM,WAAW,IAAI,QAAQ,EAAE,CAAC;QACnC,MAAM,UAAU,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;QACzD,MAAM,aAAa,GAAG,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,CAAsB,CAAC;QAEtE,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC;AACtB,CAAC","sourcesContent":["import { getDisplayVersion } from '@ms-cloudpack/package-utilities';\nimport { globSourceFiles } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { fileURLToPath, pathToFileURL } from 'url';\nimport type { CommandInitModule } from './types/CommandInitFunction.js';\nimport { PerfMarkerCliEntry } from './performance/markers.js';\nimport { CloudpackCommand, type CloudpackCommandParams } from './utilities/CloudpackCommand.js';\nimport { getNodeEngineRequirement } from './utilities/getNodeEngineRequirement.js';\nimport { satisfies } from 'semver';\nimport type { ProgramOptions } from './types/ProgramOptions.js';\nimport { createCommandEvents } from './utilities/commandEvents.js';\n\n/** Override options for tests */\nexport type MainOptions = Partial<Pick<ProgramOptions, 'cwd' | 'disableTelemetry' | 'argv' | 'commandEvents'>> &\n Pick<CloudpackCommandParams<object, never>, 'outputOptions'>;\n\n/**\n * Entry point for the cloudpack CLI.\n * Resolves all commands defined within the \"./commands\" folder.\n */\nexport async function main(options: Partial<MainOptions> = {}): Promise<void> {\n process.title = 'cloudpack';\n // Check Node.js version compatibility before doing anything else\n const requiredNodeVersion = getNodeEngineRequirement();\n if (requiredNodeVersion && !satisfies(process.version, requiredNodeVersion)) {\n console.error(`Cloudpack requires Node.js ${requiredNodeVersion}. Current version: ${process.version}.`);\n // eslint-disable-next-line no-restricted-properties -- exit immediately\n process.exit(1);\n }\n\n const {\n argv = [...process.argv],\n // eslint-disable-next-line no-restricted-properties -- this is where the default is supplied\n cwd = process.cwd(),\n disableTelemetry,\n outputOptions,\n commandEvents = createCommandEvents(),\n } = options;\n\n performance.mark(PerfMarkerCliEntry);\n\n if (argv[3] === '--') {\n // Remove the \"--\" argument in case it's added by lage\n argv.splice(3, 1);\n }\n\n const version = getDisplayVersion(import.meta.url);\n\n // Create the top-level command and apply common options\n // (avoids \"unknown option\" errors if they're specified without a verb)\n const program = new CloudpackCommand({\n name: 'cloudpack',\n description: 'A tool for managing fast inner and outer looping in web apps. Requires a sub-command.',\n usage: '<command> [options]',\n outputOptions,\n programOptions: { cwd, version, argv, disableTelemetry, commandEvents },\n // The top-level command should realistically only ever be used with --help or --version,\n // so hide most of the options.\n hideSharedOptions: true,\n });\n\n // Get all the available commands\n const commandsGlob = 'commands/*/index';\n const commands = await globSourceFiles(import.meta.url, commandsGlob);\n if (!commands.length) {\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n throw new Error(`No commands found matching \"${currentDir}/${commandsGlob}.*\".`);\n }\n\n for (const commandPath of commands) {\n const commandUrl = pathToFileURL(commandPath).toString();\n const commandModule = (await import(commandUrl)) as CommandInitModule;\n\n commandModule.init(program);\n }\n\n await program.run();\n}\n"]}
@@ -2,6 +2,7 @@ import type { CreateApiContextOptions } from '@ms-cloudpack/api-server';
2
2
  import type { AutoDispose } from './AutoDispose.js';
3
3
  import type { SharedOptions } from './SharedOptions.js';
4
4
  import type { Span } from '@ms-cloudpack/telemetry';
5
+ import type { ProgramOptions } from './ProgramOptions.js';
5
6
  /**
6
7
  * Context for running a command in a specific app (after initialization).
7
8
  * For convenience, this can be passed/spread directly to `createApiContext`.
@@ -29,7 +30,7 @@ export interface CommandExitParams {
29
30
  /** Whether to restart the command after it exits. */
30
31
  restart?: boolean;
31
32
  }
32
- export interface CommandActionParams<TOptions extends object> extends AppCommandContext {
33
+ export interface CommandActionParams<TOptions extends object> extends AppCommandContext, Pick<ProgramOptions, 'commandEvents'> {
33
34
  /**
34
35
  * Command-specific options, parsed from `process.argv`.
35
36
  * Types are generally defined in each command's `src/commands/<name>/types/<Name>Types.ts` module.
@@ -44,6 +45,8 @@ export interface CommandActionParams<TOptions extends object> extends AppCommand
44
45
  /**
45
46
  * Whether the command is being run for multiple apps. (It only runs on one app at a time, but
46
47
  * multi-app may impact formatting choices or other behaviors.)
48
+ *
49
+ * Note that this will only ever be true for commands initialized with `discoverAppPaths: 'multi'`.
47
50
  */
48
51
  isMultiApp: boolean;
49
52
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"CommandAction.d.ts","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD;;;GAGG;AACH,MAAM,WAAW,iBACf,SAAQ,IAAI,CAAC,uBAAuB,EAAE,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,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,QAAQ,CAAC;IAElB;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf;;;;;OAKG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IAEX;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC;IAEzB;;OAEG;IACH,0BAA0B,EAAE,CAAC,UAAU,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;IAE/D;;;;OAIG;IACH,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,aAAa,CAAC,QAAQ,IAAI,CACpC,MAAM,EAAE,mBAAmB,CAAC,QAAQ,GAAG,aAAa,CAAC,KAClD,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAEhC,MAAM,MAAM,mBAAmB,CAAC,QAAQ,IAAI;IAC1C,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;CAClC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandAction.js","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC","sourcesContent":["import type { CreateApiContextOptions } from '@ms-cloudpack/api-server';\nimport type { AutoDispose } from './AutoDispose.js';\nimport type { SharedOptions } from './SharedOptions.js';\nimport type { Span } from '@ms-cloudpack/telemetry';\n\n/**\n * Context for running a command in a specific app (after initialization).\n * For convenience, this can be passed/spread directly to `createApiContext`.\n */\nexport interface AppCommandContext\n extends Pick<CreateApiContextOptions, 'cachePath' | 'config' | 'reporter' | 'taskRunner' | 'telemetryClient'> {\n /** App path (CWD for most operations). */\n appPath: string;\n}\n\nexport const ExitCodeSuccessful = 0;\nexport const ExitCodeGenericError = 1;\nexport const ExitCodeAuthenticationError = 2;\nexport type ExitCode = typeof ExitCodeSuccessful | typeof ExitCodeGenericError | typeof ExitCodeAuthenticationError;\n\nexport interface CommandExitParams {\n /**\n * Message to show on exit.\n * If `isInterrupted` is true, use an empty string (it will show a default interrupt message).\n */\n message: string;\n /** Whether there are errors. By default, checks the reporter for failed tasks. */\n hasErrors?: boolean;\n /** Exit code to use. Defaults to 1 if there are errors, 0 if not. */\n exitCode?: ExitCode;\n /** True if the user interrupted an operation (ctrl+C). Sets the message automatically. */\n isInterrupted?: boolean;\n /** Whether to restart the command after it exits. */\n restart?: boolean;\n}\n\nexport interface CommandActionParams<TOptions extends object> extends AppCommandContext {\n /**\n * Command-specific options, parsed from `process.argv`.\n * Types are generally defined in each command's `src/commands/<name>/types/<Name>Types.ts` module.\n * The command line options are defined in each command's `src/commands/<name>/index.ts` module.\n */\n options: TOptions;\n\n /**\n * Command-specific arguments. Arguments in commander are positional arguments that are not options.\n * For example, in `echo somestring`, `somestring` is an argument.\n */\n args: string[];\n\n /**\n * Whether the command is being run for multiple apps. (It only runs on one app at a time, but\n * multi-app may impact formatting choices or other behaviors.)\n */\n isMultiApp: boolean;\n\n /**\n * Parent span for the command.\n */\n span: Span;\n\n /**\n * Function that can be called with any `Disposable`s that should be cleaned up automatically\n * when the program exits. (See `AutoDisposableList.add` for implementation.)\n */\n autoDispose: AutoDispose;\n\n /**\n * Set a callback to get the message to display if ctrl+C is pressed.\n */\n setInterruptMessageHandler: (getMessage: () => string) => void;\n\n /**\n * Indicates whether this command execution is a restart of a previous execution.\n * When true, the command is being run again due to a restart trigger (e.g., config changes).\n * This can be used to modify behavior on restart, such as skipping browser opening.\n */\n isRestart: boolean;\n}\n\n/**\n * Command action function (executor). This is the type of the `execute` function which should\n * be exported from each command's `src/commands/<name>/execute.ts` module and is called by\n * `CommandExecutor` against each app.\n *\n * - If it returns an object, CommandExecutor will call the exit handler with that object.\n * - For multi-app, it will exit immediately if `isInterrupted` is set, but otherwise it will\n * keep running and use the accumulation of the results.\n * - If it returns null, it's assumed that this command is meant to keep running, such as `start`.\n * - NOTE: Multi-app commands should not return null (if this is needed in the future, it will\n * require extra logic in CommandExecutor).\n */\nexport type CommandAction<TOptions> = (\n params: CommandActionParams<TOptions & SharedOptions>,\n) => Promise<CommandExitParams>;\n\nexport type CommandActionModule<TOptions> = {\n execute: CommandAction<TOptions>;\n};\n"]}
1
+ {"version":3,"file":"CommandAction.js","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC","sourcesContent":["import type { CreateApiContextOptions } from '@ms-cloudpack/api-server';\nimport type { AutoDispose } from './AutoDispose.js';\nimport type { SharedOptions } from './SharedOptions.js';\nimport type { Span } from '@ms-cloudpack/telemetry';\nimport type { ProgramOptions } from './ProgramOptions.js';\n\n/**\n * Context for running a command in a specific app (after initialization).\n * For convenience, this can be passed/spread directly to `createApiContext`.\n */\nexport interface AppCommandContext\n extends Pick<CreateApiContextOptions, 'cachePath' | 'config' | 'reporter' | 'taskRunner' | 'telemetryClient'> {\n /** App path (CWD for most operations). */\n appPath: string;\n}\n\nexport const ExitCodeSuccessful = 0;\nexport const ExitCodeGenericError = 1;\nexport const ExitCodeAuthenticationError = 2;\nexport type ExitCode = typeof ExitCodeSuccessful | typeof ExitCodeGenericError | typeof ExitCodeAuthenticationError;\n\nexport interface CommandExitParams {\n /**\n * Message to show on exit.\n * If `isInterrupted` is true, use an empty string (it will show a default interrupt message).\n */\n message: string;\n /** Whether there are errors. By default, checks the reporter for failed tasks. */\n hasErrors?: boolean;\n /** Exit code to use. Defaults to 1 if there are errors, 0 if not. */\n exitCode?: ExitCode;\n /** True if the user interrupted an operation (ctrl+C). Sets the message automatically. */\n isInterrupted?: boolean;\n /** Whether to restart the command after it exits. */\n restart?: boolean;\n}\n\nexport interface CommandActionParams<TOptions extends object>\n extends AppCommandContext,\n Pick<ProgramOptions, 'commandEvents'> {\n /**\n * Command-specific options, parsed from `process.argv`.\n * Types are generally defined in each command's `src/commands/<name>/types/<Name>Types.ts` module.\n * The command line options are defined in each command's `src/commands/<name>/index.ts` module.\n */\n options: TOptions;\n\n /**\n * Command-specific arguments. Arguments in commander are positional arguments that are not options.\n * For example, in `echo somestring`, `somestring` is an argument.\n */\n args: string[];\n\n /**\n * Whether the command is being run for multiple apps. (It only runs on one app at a time, but\n * multi-app may impact formatting choices or other behaviors.)\n *\n * Note that this will only ever be true for commands initialized with `discoverAppPaths: 'multi'`.\n */\n isMultiApp: boolean;\n\n /**\n * Parent span for the command.\n */\n span: Span;\n\n /**\n * Function that can be called with any `Disposable`s that should be cleaned up automatically\n * when the program exits. (See `AutoDisposableList.add` for implementation.)\n */\n autoDispose: AutoDispose;\n\n /**\n * Set a callback to get the message to display if ctrl+C is pressed.\n */\n setInterruptMessageHandler: (getMessage: () => string) => void;\n\n /**\n * Indicates whether this command execution is a restart of a previous execution.\n * When true, the command is being run again due to a restart trigger (e.g., config changes).\n * This can be used to modify behavior on restart, such as skipping browser opening.\n */\n isRestart: boolean;\n}\n\n/**\n * Command action function (executor). This is the type of the `execute` function which should\n * be exported from each command's `src/commands/<name>/execute.ts` module and is called by\n * `CommandExecutor` against each app.\n *\n * - If it returns an object, CommandExecutor will call the exit handler with that object.\n * - For multi-app, it will exit immediately if `isInterrupted` is set, but otherwise it will\n * keep running and use the accumulation of the results.\n * - If it returns null, it's assumed that this command is meant to keep running, such as `start`.\n * - NOTE: Multi-app commands should not return null (if this is needed in the future, it will\n * require extra logic in CommandExecutor).\n */\nexport type CommandAction<TOptions> = (\n params: CommandActionParams<TOptions & SharedOptions>,\n) => Promise<CommandExitParams>;\n\nexport type CommandActionModule<TOptions> = {\n execute: CommandAction<TOptions>;\n};\n"]}
@@ -1,3 +1,4 @@
1
+ import type { CommandEvents } from '../utilities/commandEvents.js';
1
2
  /**
2
3
  * These options are not provided on the command line but need to be shared between commands.
3
4
  */
@@ -11,7 +12,13 @@ export interface ProgramOptions {
11
12
  argv: string[];
12
13
  /** CLI version. */
13
14
  version: string;
15
+ /**
16
+ * Shared event emitter for lifecycle events across an entire command run.
17
+ * This is currently only used for tests, and it will only exist if the test creates it.
18
+ * (It must be passed around instead of being a global singleton to ensure test isolation.)
19
+ */
20
+ commandEvents: CommandEvents;
14
21
  /** Disable telemetry, e.g. for tests. */
15
- disableTelemetry?: boolean;
22
+ disableTelemetry: boolean | undefined;
16
23
  }
17
24
  //# sourceMappingURL=ProgramOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ProgramOptions.d.ts","sourceRoot":"","sources":["../../src/types/ProgramOptions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ,yDAAyD;IACzD,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAEhB,yCAAyC;IACzC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B"}
1
+ {"version":3,"file":"ProgramOptions.d.ts","sourceRoot":"","sources":["../../src/types/ProgramOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ,yDAAyD;IACzD,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,aAAa,EAAE,aAAa,CAAC;IAE7B,yCAAyC;IACzC,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAC;CACvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ProgramOptions.js","sourceRoot":"","sources":["../../src/types/ProgramOptions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * These options are not provided on the command line but need to be shared between commands.\n */\nexport interface ProgramOptions {\n /**\n * Initial working directory (usually `process.cwd()` except in tests).\n * Note that this may differ from the `appPath` used by individual commands.\n */\n cwd: string;\n\n /** Raw argv (usually `process.argv` except in tests). */\n argv: string[];\n\n /** CLI version. */\n version: string;\n\n /** Disable telemetry, e.g. for tests. */\n disableTelemetry?: boolean;\n}\n"]}
1
+ {"version":3,"file":"ProgramOptions.js","sourceRoot":"","sources":["../../src/types/ProgramOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { CommandEvents } from '../utilities/commandEvents.js';\n\n/**\n * These options are not provided on the command line but need to be shared between commands.\n */\nexport interface ProgramOptions {\n /**\n * Initial working directory (usually `process.cwd()` except in tests).\n * Note that this may differ from the `appPath` used by individual commands.\n */\n cwd: string;\n\n /** Raw argv (usually `process.argv` except in tests). */\n argv: string[];\n\n /** CLI version. */\n version: string;\n\n /**\n * Shared event emitter for lifecycle events across an entire command run.\n * This is currently only used for tests, and it will only exist if the test creates it.\n * (It must be passed around instead of being a global singleton to ensure test isolation.)\n */\n commandEvents: CommandEvents;\n\n /** Disable telemetry, e.g. for tests. */\n disableTelemetry: boolean | undefined;\n}\n"]}
@@ -6,7 +6,7 @@ import { type CommandExecutorParams } from './CommandExecutor.js';
6
6
  * Parameters for creating a command.
7
7
  * `TOptions` should be the command-specific options (if any), e.g. `StartOptions`.
8
8
  */
9
- interface CloudpackCommandParams<TOptions extends object, TArguments extends object> extends Partial<Pick<CommandExecutorParams<TOptions>, 'discoverAppPaths' | 'applyOptionsToConfig'>> {
9
+ export interface CloudpackCommandParams<TOptions extends object, TArguments extends object> extends Partial<Pick<CommandExecutorParams<TOptions>, 'discoverAppPaths' | 'applyOptionsToConfig'>> {
10
10
  /** Command name */
11
11
  name: string;
12
12
  /** Command description */
@@ -76,5 +76,4 @@ export declare class CloudpackCommand<TOptions extends object, TArguments extend
76
76
  private _addOptions;
77
77
  private _addAction;
78
78
  }
79
- export {};
80
79
  //# sourceMappingURL=CloudpackCommand.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CloudpackCommand.d.ts","sourceRoot":"","sources":["../../src/utilities/CloudpackCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,mBAAmB,EAAE,KAAK,QAAQ,EAAE,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAC/G,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAMnF;;;GAGG;AACH,UAAU,sBAAsB,CAAC,QAAQ,SAAS,MAAM,EAAE,UAAU,SAAS,MAAM,CACjF,SAAQ,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,kBAAkB,GAAG,sBAAsB,CAAC,CAAC;IACnG,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IAEb,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAEpD,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE1C;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE3D,6BAA6B;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,yDAAyD;IACzD,WAAW,CAAC,EAAE;QACZ;;;WAGG;QACH,QAAQ,EAAE,mBAAmB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AED,MAAM,eAAe,GAAG,IAAI,eAAe,CAA2B;gBACpE,IAAI,EAAE,aAAa;gBACnB,OAAO;gBACP,OAAO;gBACP,IAAI;gBACJ,GAAG,IAAI,CAAC,gBAAgB;aACzB,CAAC,CAAC;YACH,MAAM,eAAe,CAAC,OAAO,EAAE,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { Command, Option, type AddHelpTextPosition, type Argument, type OutputConfiguration } from 'commander';\nimport type { CommandActionModule } from '../types/CommandAction.js';\nimport type { SharedOptions } from '../types/SharedOptions.js';\nimport { CommandExecutor, type CommandExecutorParams } from './CommandExecutor.js';\nimport { environmentInfo } from '@ms-cloudpack/environment';\nimport { parseFeature } from './parseFeature.js';\nimport { parseDefine } from './parseDefine.js';\nimport { CloudpackHelp, optionGroups } from './CloudpackHelp.js';\n\n/**\n * Parameters for creating a command.\n * `TOptions` should be the command-specific options (if any), e.g. `StartOptions`.\n */\ninterface CloudpackCommandParams<TOptions extends object, TArguments extends object>\n extends Partial<Pick<CommandExecutorParams<TOptions>, 'discoverAppPaths' | 'applyOptionsToConfig'>> {\n /** Command name */\n name: string;\n\n /** Command description */\n description: string;\n\n /**\n * Options specific to this command. The record ensures that all options are available in the CLI.\n * Allow multiple options for the same key since commander supports it with negatable options.\n */\n options?: Record<keyof TOptions, Option | Option[]>; //\n\n /** Arguments specific to this command. Key order determines the arg order. */\n args?: Record<keyof TArguments, Argument>;\n\n /**\n * Function returning an async import of the command's `src/commands/<name>/execute.ts` module.\n * Importing only on demand makes Cloudpack start up faster since it doesn't have to parse\n * every command's dependencies (many of which may be unrelated to the command being run).\n *\n * This can be undefined for a command that only has sub-commands.\n */\n getExecutor?: () => Promise<CommandActionModule<TOptions>>;\n\n /** Usage message override */\n usage?: string;\n\n /** Alternative name for the command */\n alias?: string;\n\n /** Extra text to be displayed with the built-in help. */\n addHelpText?: {\n /**\n * `'before'` or `'after'` to affect just this command.\n * `'beforeAll'` or `'afterAll'` to affect this command and all its subcommands.\n */\n position: AddHelpTextPosition;\n text: string;\n };\n\n /** Output options override (mainly for testing) */\n outputOptions?: OutputConfiguration;\n\n /**\n * The shared options are relevant for most commands, but this allows omitting them from help\n * where they're not relevant. `true` hides all shared options, or an array hides specific ones.\n */\n hideSharedOptions?: Array<keyof SharedOptions> | true;\n}\n\n/**\n * This wraps the `Command` class from [`commander`](https://www.npmjs.com/package/commander) with\n * Cloudpack-specific functionality and simpler APIs.\n *\n * Similar to the pattern from `commander`, this class represents both the program and its sub-commands.\n * - The top-level \"program\" command should be created with `new CloudpackCommand()`.\n * - Sub-commands should be created with the `.addSubCommand` method on the parent.\n */\nexport class CloudpackCommand<TOptions extends object, TArguments extends object> {\n private _command: Command;\n private _executorOptions: Pick<\n CommandExecutorParams<TOptions>,\n 'programOptions' | 'discoverAppPaths' | 'applyOptionsToConfig'\n >;\n\n /**\n * This should only be used directly (outside this class) to create the top-level `program` command.\n * To add sub-commands, use `.addSubCommand` instead.\n */\n constructor(\n // The extra options here shouldn't be exposed to the `createSubCommand` API\n params: CloudpackCommandParams<TOptions, TArguments> &\n Pick<CommandExecutorParams<TOptions>, 'programOptions'> & {\n /** This must be undefined for the top-level program command */\n parent?: Command;\n },\n ) {\n this._executorOptions = {\n programOptions: params.programOptions,\n discoverAppPaths: params.discoverAppPaths,\n applyOptionsToConfig: params.applyOptionsToConfig,\n };\n\n const command = params.parent?.command(params.name) || new Command(params.name);\n this._command = command;\n\n command.version(params.programOptions.version);\n command.description(params.description);\n command.allowExcessArguments(false);\n\n const isTopLevel = !params.parent;\n command.createHelp = () => new CloudpackHelp({ isTopLevel });\n // set the default help group for options\n command.optionsGroup(optionGroups.default);\n\n params.usage && command.usage(params.usage);\n params.alias && command.alias(params.alias);\n params.addHelpText && command.addHelpText(params.addHelpText.position, params.addHelpText.text);\n params.outputOptions && command.configureOutput(params.outputOptions);\n params.getExecutor && this._addAction(params.getExecutor);\n\n if (params.args) {\n this._addArguments<TArguments>(params.args);\n }\n\n if (params.options) {\n // Add the command-specific options first so they show up first in help\n this._addOptions<TOptions>(params.options);\n }\n\n // Add shared options. These must be manually added to the program command and each sub-command\n // because commander doesn't natively support inheriting options.\n this._addOptions<SharedOptions>(\n {\n verbose: new Option('-v, --verbose', 'Show additional details in logging.').helpGroup(optionGroups.logging),\n debug: new Option('-d, --debug', 'Show debug information (superset of --verbose).')\n .conflicts('verbose')\n .helpGroup(optionGroups.logging),\n quiet: new Option('-q, --quiet', 'Disable non-essential logging.')\n .conflicts('verbose')\n .conflicts('debug')\n .helpGroup(optionGroups.logging),\n color:\n // In the parsed options, this will be a boolean `color` with default value true, except in tests, CI, or environments without a TTY (e.g., concurrently).\n new Option('-n, --no-color', 'Disable colors in the output.')\n .helpGroup(optionGroups.logging)\n .default(\n !environmentInfo.isJest && !environmentInfo.isLage && !environmentInfo.isCI && !!process.stdout.isTTY,\n ),\n logFile: new Option('--log-file', 'Write a log file with all console output.').helpGroup(optionGroups.logging),\n cachePath: new Option(\n '--cache-path <path>',\n 'Custom cache folder. To change the default, run `cloudpack config set cachePath <path>`.',\n ).helpGroup(optionGroups.common),\n config: new Option(\n '-c, --config <filename>',\n 'Custom config file name to use instead of cloudpack.config.json.',\n ).helpGroup(optionGroups.common),\n define: new Option('--define <key=value>', 'Define a global variable. Can be specified multiple times.')\n .helpGroup(optionGroups.common)\n .argParser(parseDefine),\n features: new Option('--features <featureNames...>', 'Enable experimental features.')\n .helpGroup(optionGroups.common)\n .argParser(parseFeature),\n },\n params.hideSharedOptions,\n );\n }\n\n /** Create a child command. */\n public addSubCommand<TChildOptions extends object, TChildArguments extends object = never>(\n params: CloudpackCommandParams<TChildOptions, TChildArguments>,\n ): CloudpackCommand<TChildOptions, TChildArguments> {\n return new CloudpackCommand<TChildOptions, TChildArguments>({\n ...params,\n programOptions: this._executorOptions.programOptions,\n parent: this._command,\n });\n }\n\n /** Run the program (only works on the top-level program command). */\n public async run(): Promise<void> {\n if (this._command.parent) {\n throw new Error('Only the top-level program command can be run directly.');\n }\n\n await this._command.parseAsync(this._executorOptions.programOptions.argv);\n if (this._command.args.length === 0) {\n this._command.help();\n }\n }\n\n /** Add arguments. The generic enforces that argument objects are included for all keys of a type. */\n private _addArguments<TAddArguments extends object>(args: Record<keyof TAddArguments, Argument>): void {\n for (const argument of Object.values(args)) {\n this._command.addArgument(argument as Argument);\n }\n }\n\n /** Add options. The generic enforces that option objects are included for all keys of a type. */\n private _addOptions<TAddOptions extends object>(\n options: Record<keyof TAddOptions, Option | Option[]>,\n hideOptions?: Array<keyof TAddOptions> | true,\n ): void {\n for (const [name, optionOrOptions] of Object.entries(options) as [keyof TAddOptions, Option | Option[]][]) {\n const optionArray = Array.isArray(optionOrOptions) ? optionOrOptions : [optionOrOptions];\n for (const option of optionArray) {\n if (hideOptions === true || hideOptions?.includes(name)) {\n option.hideHelp();\n }\n this._command.addOption(option);\n }\n }\n }\n\n private _addAction(getExecutor: NonNullable<CloudpackCommandParams<TOptions, TArguments>['getExecutor']>): void {\n const command = this._command;\n // The action function receives parsed options as its first parameter, but we ignore those\n // because they only contain options *specific to this command*, not shared options like `debug`.\n command.action(async () => {\n // Commander has support for custom parsers that parse arguments.\n // Use processedArgs instead of args to get the parsed arguments.\n const processedArgs = command.processedArgs as string[];\n\n // Get the shared options too, not just the ones for this command.\n // (In `cloudpackCommand`, we added the shared options to each command object so that they show up\n // in help, but commander still seems to respect options only at the first command where they're\n // encountered, which for shared options will always be the program command.)\n const options = command.optsWithGlobals<TOptions & SharedOptions>();\n\n // Usually `command` will be a sub-command (e.g. \"bundle\"), but it could also be a sub-sub-command\n // (e.g. \"cache clean\").\n const verb = command.parent?.parent ? `${command.parent.name()} ${command.name()}` : command.name();\n\n // Dynamically import the execute function\n const { execute } = await getExecutor();\n if (typeof execute !== 'function') {\n // throw instead of exiting politely, since this is a major developer error\n throw new Error(`No execute function was exported from the command module for ${verb}.`);\n }\n\n const commandExecutor = new CommandExecutor<TOptions & SharedOptions>({\n args: processedArgs,\n options,\n execute,\n verb,\n ...this._executorOptions,\n });\n await commandExecutor.execute();\n });\n }\n}\n"]}
1
+ {"version":3,"file":"CloudpackCommand.js","sourceRoot":"","sources":["../../src/utilities/CloudpackCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAqE,MAAM,WAAW,CAAC;AAG/G,OAAO,EAAE,eAAe,EAA8B,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA0DjE;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IACnB,QAAQ,CAAU;IAClB,gBAAgB,CAGtB;IAEF;;;OAGG;IACH;IACE,4EAA4E;IAC5E,MAIG;QAEH,IAAI,CAAC,gBAAgB,GAAG;YACtB,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;SAClD,CAAC;QAEF,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC/C,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACxC,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAEpC,MAAM,UAAU,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;QAClC,OAAO,CAAC,UAAU,GAAG,GAAG,EAA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AAO,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,0FAA0F;QAC1F,iGAAiG;QACjG,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE;YACxB,iEAAiE;YACjE,iEAAiE;YACjE,MAAM,aAAa,GAAG,OAAO,CAAC,aAAyB,CAAC;YAExD,kEAAkE;YAClE,kGAAkG;YAClG,gGAAgG;YAChG,6EAA6E;YAC7E,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,EAA4B,CAAC;YAEpE,kGAAkG;YAClG,wBAAwB;YACxB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAEpG,0CAA0C;YAC1C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,WAAW,EAAE,CAAC;YACxC,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;gBAClC,2EAA2E;gBAC3E,MAAM,IAAI,KAAK,CAAC,gEAAgE,IAAI,GAAG,CAAC,CAAC;YAC3F,CAAC;YAED,MAAM,eAAe,GAAG,IAAI,eAAe,CAA2B;gBACpE,IAAI,EAAE,aAAa;gBACnB,OAAO;gBACP,OAAO;gBACP,IAAI;gBACJ,GAAG,IAAI,CAAC,gBAAgB;aACzB,CAAC,CAAC;YACH,MAAM,eAAe,CAAC,OAAO,EAAE,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { Command, Option, type AddHelpTextPosition, type Argument, type OutputConfiguration } from 'commander';\nimport type { CommandActionModule } from '../types/CommandAction.js';\nimport type { SharedOptions } from '../types/SharedOptions.js';\nimport { CommandExecutor, type CommandExecutorParams } from './CommandExecutor.js';\nimport { environmentInfo } from '@ms-cloudpack/environment';\nimport { parseFeature } from './parseFeature.js';\nimport { parseDefine } from './parseDefine.js';\nimport { CloudpackHelp, optionGroups } from './CloudpackHelp.js';\n\n/**\n * Parameters for creating a command.\n * `TOptions` should be the command-specific options (if any), e.g. `StartOptions`.\n */\nexport interface CloudpackCommandParams<TOptions extends object, TArguments extends object>\n extends Partial<Pick<CommandExecutorParams<TOptions>, 'discoverAppPaths' | 'applyOptionsToConfig'>> {\n /** Command name */\n name: string;\n\n /** Command description */\n description: string;\n\n /**\n * Options specific to this command. The record ensures that all options are available in the CLI.\n * Allow multiple options for the same key since commander supports it with negatable options.\n */\n options?: Record<keyof TOptions, Option | Option[]>; //\n\n /** Arguments specific to this command. Key order determines the arg order. */\n args?: Record<keyof TArguments, Argument>;\n\n /**\n * Function returning an async import of the command's `src/commands/<name>/execute.ts` module.\n * Importing only on demand makes Cloudpack start up faster since it doesn't have to parse\n * every command's dependencies (many of which may be unrelated to the command being run).\n *\n * This can be undefined for a command that only has sub-commands.\n */\n getExecutor?: () => Promise<CommandActionModule<TOptions>>;\n\n /** Usage message override */\n usage?: string;\n\n /** Alternative name for the command */\n alias?: string;\n\n /** Extra text to be displayed with the built-in help. */\n addHelpText?: {\n /**\n * `'before'` or `'after'` to affect just this command.\n * `'beforeAll'` or `'afterAll'` to affect this command and all its subcommands.\n */\n position: AddHelpTextPosition;\n text: string;\n };\n\n /** Output options override (mainly for testing) */\n outputOptions?: OutputConfiguration;\n\n /**\n * The shared options are relevant for most commands, but this allows omitting them from help\n * where they're not relevant. `true` hides all shared options, or an array hides specific ones.\n */\n hideSharedOptions?: Array<keyof SharedOptions> | true;\n}\n\n/**\n * This wraps the `Command` class from [`commander`](https://www.npmjs.com/package/commander) with\n * Cloudpack-specific functionality and simpler APIs.\n *\n * Similar to the pattern from `commander`, this class represents both the program and its sub-commands.\n * - The top-level \"program\" command should be created with `new CloudpackCommand()`.\n * - Sub-commands should be created with the `.addSubCommand` method on the parent.\n */\nexport class CloudpackCommand<TOptions extends object, TArguments extends object> {\n private _command: Command;\n private _executorOptions: Pick<\n CommandExecutorParams<TOptions>,\n 'programOptions' | 'discoverAppPaths' | 'applyOptionsToConfig'\n >;\n\n /**\n * This should only be used directly (outside this class) to create the top-level `program` command.\n * To add sub-commands, use `.addSubCommand` instead.\n */\n constructor(\n // The extra options here shouldn't be exposed to the `createSubCommand` API\n params: CloudpackCommandParams<TOptions, TArguments> &\n Pick<CommandExecutorParams<TOptions>, 'programOptions'> & {\n /** This must be undefined for the top-level program command */\n parent?: Command;\n },\n ) {\n this._executorOptions = {\n programOptions: params.programOptions,\n discoverAppPaths: params.discoverAppPaths,\n applyOptionsToConfig: params.applyOptionsToConfig,\n };\n\n const command = params.parent?.command(params.name) || new Command(params.name);\n this._command = command;\n\n command.version(params.programOptions.version);\n command.description(params.description);\n command.allowExcessArguments(false);\n\n const isTopLevel = !params.parent;\n command.createHelp = () => new CloudpackHelp({ isTopLevel });\n // set the default help group for options\n command.optionsGroup(optionGroups.default);\n\n params.usage && command.usage(params.usage);\n params.alias && command.alias(params.alias);\n params.addHelpText && command.addHelpText(params.addHelpText.position, params.addHelpText.text);\n params.outputOptions && command.configureOutput(params.outputOptions);\n params.getExecutor && this._addAction(params.getExecutor);\n\n if (params.args) {\n this._addArguments<TArguments>(params.args);\n }\n\n if (params.options) {\n // Add the command-specific options first so they show up first in help\n this._addOptions<TOptions>(params.options);\n }\n\n // Add shared options. These must be manually added to the program command and each sub-command\n // because commander doesn't natively support inheriting options.\n this._addOptions<SharedOptions>(\n {\n verbose: new Option('-v, --verbose', 'Show additional details in logging.').helpGroup(optionGroups.logging),\n debug: new Option('-d, --debug', 'Show debug information (superset of --verbose).')\n .conflicts('verbose')\n .helpGroup(optionGroups.logging),\n quiet: new Option('-q, --quiet', 'Disable non-essential logging.')\n .conflicts('verbose')\n .conflicts('debug')\n .helpGroup(optionGroups.logging),\n color:\n // In the parsed options, this will be a boolean `color` with default value true, except in tests, CI, or environments without a TTY (e.g., concurrently).\n new Option('-n, --no-color', 'Disable colors in the output.')\n .helpGroup(optionGroups.logging)\n .default(\n !environmentInfo.isJest && !environmentInfo.isLage && !environmentInfo.isCI && !!process.stdout.isTTY,\n ),\n logFile: new Option('--log-file', 'Write a log file with all console output.').helpGroup(optionGroups.logging),\n cachePath: new Option(\n '--cache-path <path>',\n 'Custom cache folder. To change the default, run `cloudpack config set cachePath <path>`.',\n ).helpGroup(optionGroups.common),\n config: new Option(\n '-c, --config <filename>',\n 'Custom config file name to use instead of cloudpack.config.json.',\n ).helpGroup(optionGroups.common),\n define: new Option('--define <key=value>', 'Define a global variable. Can be specified multiple times.')\n .helpGroup(optionGroups.common)\n .argParser(parseDefine),\n features: new Option('--features <featureNames...>', 'Enable experimental features.')\n .helpGroup(optionGroups.common)\n .argParser(parseFeature),\n },\n params.hideSharedOptions,\n );\n }\n\n /** Create a child command. */\n public addSubCommand<TChildOptions extends object, TChildArguments extends object = never>(\n params: CloudpackCommandParams<TChildOptions, TChildArguments>,\n ): CloudpackCommand<TChildOptions, TChildArguments> {\n return new CloudpackCommand<TChildOptions, TChildArguments>({\n ...params,\n programOptions: this._executorOptions.programOptions,\n parent: this._command,\n });\n }\n\n /** Run the program (only works on the top-level program command). */\n public async run(): Promise<void> {\n if (this._command.parent) {\n throw new Error('Only the top-level program command can be run directly.');\n }\n\n await this._command.parseAsync(this._executorOptions.programOptions.argv);\n if (this._command.args.length === 0) {\n this._command.help();\n }\n }\n\n /** Add arguments. The generic enforces that argument objects are included for all keys of a type. */\n private _addArguments<TAddArguments extends object>(args: Record<keyof TAddArguments, Argument>): void {\n for (const argument of Object.values(args)) {\n this._command.addArgument(argument as Argument);\n }\n }\n\n /** Add options. The generic enforces that option objects are included for all keys of a type. */\n private _addOptions<TAddOptions extends object>(\n options: Record<keyof TAddOptions, Option | Option[]>,\n hideOptions?: Array<keyof TAddOptions> | true,\n ): void {\n for (const [name, optionOrOptions] of Object.entries(options) as [keyof TAddOptions, Option | Option[]][]) {\n const optionArray = Array.isArray(optionOrOptions) ? optionOrOptions : [optionOrOptions];\n for (const option of optionArray) {\n if (hideOptions === true || hideOptions?.includes(name)) {\n option.hideHelp();\n }\n this._command.addOption(option);\n }\n }\n }\n\n private _addAction(getExecutor: NonNullable<CloudpackCommandParams<TOptions, TArguments>['getExecutor']>): void {\n const command = this._command;\n // The action function receives parsed options as its first parameter, but we ignore those\n // because they only contain options *specific to this command*, not shared options like `debug`.\n command.action(async () => {\n // Commander has support for custom parsers that parse arguments.\n // Use processedArgs instead of args to get the parsed arguments.\n const processedArgs = command.processedArgs as string[];\n\n // Get the shared options too, not just the ones for this command.\n // (In `cloudpackCommand`, we added the shared options to each command object so that they show up\n // in help, but commander still seems to respect options only at the first command where they're\n // encountered, which for shared options will always be the program command.)\n const options = command.optsWithGlobals<TOptions & SharedOptions>();\n\n // Usually `command` will be a sub-command (e.g. \"bundle\"), but it could also be a sub-sub-command\n // (e.g. \"cache clean\").\n const verb = command.parent?.parent ? `${command.parent.name()} ${command.name()}` : command.name();\n\n // Dynamically import the execute function\n const { execute } = await getExecutor();\n if (typeof execute !== 'function') {\n // throw instead of exiting politely, since this is a major developer error\n throw new Error(`No execute function was exported from the command module for ${verb}.`);\n }\n\n const commandExecutor = new CommandExecutor<TOptions & SharedOptions>({\n args: processedArgs,\n options,\n execute,\n verb,\n ...this._executorOptions,\n });\n await commandExecutor.execute();\n });\n }\n}\n"]}
@@ -20,6 +20,9 @@ export interface CommandExecutorParams<TOptions extends SharedOptions> {
20
20
  * If this option is set, attempt to discover app path(s) instead.
21
21
  * (`cwd` will still be preferred if it has a `cloudpack.config.json`.)
22
22
  * See {@link AppPathDiscoveryMode} for details.
23
+ *
24
+ * Note that `isMultiApp` elsewhere will only be true if this is set to `'multi'` and
25
+ * multiple apps are found.
23
26
  */
24
27
  discoverAppPaths: AppPathDiscoveryMode | undefined;
25
28
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"CommandExecutor.d.ts","sourceRoot":"","sources":["../../src/utilities/CommandExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBA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,OAAO,CAAC,+BAA+B;YAgBzB,cAAc;IAkD5B,SAAS,CAAC,cAAc,QAAO,IAAI,CAgBjC;IAEF;;;OAGG;cACa,KAAK,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,KAAK,CAAC;CAoCjE"}
@@ -11,7 +11,6 @@ import { TaskRunner } from '@ms-cloudpack/api-server';
11
11
  import { readLocalConfigs } from './readLocalConfigs.js';
12
12
  import { readRemoteConfigs } from './readRemoteConfigs.js';
13
13
  import { getCliStartTime } from './getCliStartTime.js';
14
- import { commandEvents } from './commandEvents.js';
15
14
  /**
16
15
  * This class manages orchestration and shared state while executing a command.
17
16
  */
@@ -103,6 +102,7 @@ export class CommandExecutor {
103
102
  isMultiApp: contexts.length > 1,
104
103
  args: this._args,
105
104
  options: this._options,
105
+ commandEvents: this._programOptions.commandEvents,
106
106
  isRestart,
107
107
  autoDispose: (disposable) => this._autoDisposableList.add(disposable),
108
108
  setInterruptMessageHandler: (getMessage) => {
@@ -316,7 +316,7 @@ export class CommandExecutor {
316
316
  await this._autoDisposableList.dispose();
317
317
  // Remove all event listeners. Currently this is only done on final disposal because one of
318
318
  // the start tests relies on a 'ready' event listener carrying over across restarts.
319
- commandEvents.removeAllListeners();
319
+ this._programOptions.commandEvents.removeAllListeners();
320
320
  // Show the summary message (this will throw if called twice).
321
321
  await this._reporter.complete({
322
322
  summary: hasErrors ? red(message) : message,
@@ -1 +1 @@
1
- {"version":3,"file":"CommandExecutor.js","sourceRoot":"","sources":["../../src/utilities/CommandExecutor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EACL,YAAY,EACZ,IAAI,EACJ,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,GAAG,EACH,oBAAoB,EACpB,MAAM,GACP,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAA2C,MAAM,yBAAyB,CAAC;AAClG,OAAO,IAAI,MAAM,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;YACxB,mEAAmE;YACnE,8FAA8F;YAC9F,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;gBAC5B,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;qBACxC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,KAAK,GAAG,CAAC;qBAC1C,IAAI,CAAC,IAAI,CAAC,CAAC;gBACd,OAAO,CAAC,IAAI,CAAC,0DAA0D,YAAY,GAAG,CAAC,CAAC;YAC1F,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAE3B,sCAAsC;YACtC,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;YAEzC,2FAA2F;YAC3F,oFAAoF;YACpF,aAAa,CAAC,kBAAkB,EAAE,CAAC;YAEnC,8DAA8D;YAC9D,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;gBAC5B,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO;gBAC3C,QAAQ,EAAE,QAAQ,KAAK,CAAC;aACzB,CAAC,CAAC;QACL,CAAC;QAED,eAAe,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAE3C,yEAAyE;QACzE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC","sourcesContent":["import type { ReadConfigOptions } from '@ms-cloudpack/config';\nimport type { CloudpackConfig, PackageJson } from '@ms-cloudpack/common-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport {\n TaskReporter,\n bold,\n debugLoggingConfig,\n defaultLoggingConfig,\n noLoggingConfig,\n red,\n verboseLoggingConfig,\n yellow,\n} from '@ms-cloudpack/task-reporter';\nimport { startTelemetry, type TelemetryApi, type TelemetryClient } from '@ms-cloudpack/telemetry';\nimport path from 'path';\nimport type { CommandAction, CommandExitParams, AppCommandContext } from '../types/CommandAction.js';\nimport type { ProgramOptions } from '../types/ProgramOptions.js';\nimport type { SharedOptions } from '../types/SharedOptions.js';\nimport { AutoDisposableList } from './AutoDisposableList.js';\nimport { getVersion } from '@ms-cloudpack/package-utilities';\nimport { environmentInfo } from '@ms-cloudpack/environment';\nimport type { ReusedOptions } from '../types/ReusedOptions.js';\nimport type { AppPathDiscoveryMode } from '../types/AppPathDiscoveryMode.js';\nimport { discoverRemoteAppPaths } from './discoverRemoteAppPaths.js';\nimport { discoverLocalAppPaths } from './discoverLocalAppPaths.js';\nimport { TaskRunner } from '@ms-cloudpack/api-server';\nimport { readLocalConfigs, type InvalidCloudpackConfigError } from './readLocalConfigs.js';\nimport { readRemoteConfigs } from './readRemoteConfigs.js';\nimport { getCliStartTime } from './getCliStartTime.js';\nimport { commandEvents } from './commandEvents.js';\n\nexport interface CommandExecutorParams<TOptions extends SharedOptions> {\n /** Command-specific arguments */\n args: string[];\n\n /** Command-specific and shared options. */\n options: TOptions;\n\n /** Function to execute the command. */\n execute: CommandAction<TOptions>;\n\n /** Shared program-level configuration. */\n programOptions: ProgramOptions;\n\n /** Verb being run, e.g. `bundle` or `cache clean`. */\n verb: string;\n\n /**\n * By default, the command will run against `cwd` (usually `process.cwd()`).\n * If this option is set, attempt to discover app path(s) instead.\n * (`cwd` will still be preferred if it has a `cloudpack.config.json`.)\n * See {@link AppPathDiscoveryMode} for details.\n */\n discoverAppPaths: AppPathDiscoveryMode | undefined;\n\n /**\n * Apply any command-specific CLI options that need to be passed through to `readConfig`.\n * (Shared and reused options are applied automatically.)\n */\n applyOptionsToConfig:\n | ((\n options: Omit<TOptions, keyof (SharedOptions & ReusedOptions)>,\n ) => Pick<ReadConfigOptions, 'extraServerConfig'> | undefined)\n | undefined;\n}\n\n/**\n * This class manages orchestration and shared state while executing a command.\n */\n// 'app' is an optional reused option\nexport class CommandExecutor<TOptions extends SharedOptions> {\n private _options: TOptions;\n private _execute: CommandAction<TOptions>;\n private _programOptions: ProgramOptions;\n private _verb: string;\n private _discoverAppPaths: AppPathDiscoveryMode | undefined;\n private _applyOptionsToConfig: CommandExecutorParams<TOptions>['applyOptionsToConfig'];\n private _reporter: TaskReporter;\n private _autoDisposableList: AutoDisposableList;\n private _hasCalledExit = false;\n private _args: string[];\n private _sigintCount = 0;\n private _onInterrupt?: () => void;\n private _getMessageOnInterrupt?: () => string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- options type isn't used\n private static _activeInstances = new Set<CommandExecutor<any>>();\n\n public static async exitAll(params: CommandExitParams): Promise<void> {\n // There should only be one instance at a time, but we assume multiple instances for safety.\n for (const instance of CommandExecutor._activeInstances) {\n await instance._exit(params);\n process.off('SIGINT', instance._sigintHandler);\n }\n CommandExecutor._activeInstances = new Set();\n }\n\n constructor(params: CommandExecutorParams<TOptions>) {\n this._args = params.args;\n this._options = params.options;\n this._execute = params.execute;\n this._programOptions = params.programOptions;\n this._verb = params.verb;\n this._discoverAppPaths = params.discoverAppPaths;\n this._applyOptionsToConfig = params.applyOptionsToConfig;\n this._reporter = new TaskReporter();\n this._autoDisposableList = new AutoDisposableList();\n }\n\n /**\n * Run the command, including handling for restarts.\n */\n // This has to be a separate method because constructors can't be async.\n public async execute(): Promise<void> {\n CommandExecutor._activeInstances.add(this);\n // Handle SIGINT (Ctrl+C) gracefully.\n if (!environmentInfo.isJest) {\n process.on('SIGINT', this._sigintHandler);\n }\n\n try {\n let shouldRestart = false;\n do {\n shouldRestart = await this._executeOnce(shouldRestart);\n } while (shouldRestart);\n } catch (error) {\n // If an error occurs, exit the process with a non-zero exit code.\n const err = error as InvalidCloudpackConfigError;\n const message = err.isExpected\n ? err.message // Only show message for expected errors\n : err.stack || err.message || String(error); // Show full stack for unexpected errors\n\n await this._exit({\n hasErrors: true,\n message,\n });\n }\n }\n\n /**\n * Execute a single iteration of the command.\n */\n private async _executeOnce(isRestart: boolean): Promise<boolean> {\n const contexts = await this._initializeContexts();\n\n if (!Array.isArray(contexts)) {\n return await this._exit(contexts);\n }\n\n const spanName = `${this._verb.toUpperCase().replace(/ /g, '_')}_EXECUTE`;\n const results: CommandExitParams[] = [];\n\n for (const context of contexts) {\n // Call the execute function which is the real command logic\n // (ie: real init command logic, real start command logic, etc.)\n const result = await context.telemetryClient.tracer.startActiveSpan(spanName, async (span) => {\n this._onInterrupt = () => {\n span.setAttribute('isInterrupted', true);\n span.end();\n };\n\n return this._execute({\n ...context,\n span,\n isMultiApp: contexts.length > 1,\n args: this._args,\n options: this._options,\n isRestart,\n autoDispose: (disposable) => this._autoDisposableList.add(disposable),\n setInterruptMessageHandler: (getMessage) => {\n this._getMessageOnInterrupt = getMessage;\n },\n });\n });\n if (result?.isInterrupted) {\n return await this._exit(result);\n }\n if (result) {\n results.push(result);\n } else {\n // If the command returned null, this means it should keep running (e.g. start).\n // We disallow returning undefined to avoid accidents.\n throw new Error('Command executor must return exit options or null');\n }\n this._onInterrupt = undefined;\n }\n\n // Determine whether a command requested a restart in this iteration.\n const shouldRestart = results.some((r) => r.restart);\n\n if (shouldRestart) {\n // Dispose all registered disposables.\n await this._autoDisposableList.dispose();\n this._reporter.reset(true /* clearOutputs */);\n\n console.warn(results.map((r) => r.message).join('\\n'));\n } else if (results.length) {\n // If one or more apps returned a result, exit.\n return await this._exit({\n message: results.map((r) => r.message).join('\\n'),\n hasErrors: results.some((r) => r.hasErrors),\n // If any app returned a non-zero exit code, use that.\n exitCode: results.find(({ exitCode }) => !!exitCode)?.exitCode,\n });\n }\n\n return shouldRestart;\n }\n\n /**\n * Determine the app paths and initialize the context for each app.\n * @returns Context(s), or an exit options object if there was an error. (might also throw on error)\n */\n private async _initializeContexts(): Promise<AppCommandContext[] | CommandExitParams> {\n let appPaths: string[];\n\n if (this._discoverAppPaths) {\n // Search for cloudpack configs to determine the app path(s)\n const { app, login } = this._options as unknown as Pick<ReusedOptions, 'app' | 'login'>;\n const appPathsResult =\n this._discoverAppPaths === 'remote'\n ? await discoverRemoteAppPaths({\n options: {\n login,\n cachePath: this._options.cachePath,\n desiredApp: app,\n },\n context: { reporter: this._reporter },\n })\n : await discoverLocalAppPaths({\n cwd: this._programOptions.cwd,\n discover: this._discoverAppPaths,\n desiredApp: app,\n });\n if (!Array.isArray(appPathsResult)) {\n // This means there was an error (or the user cancelled) while getting app paths.\n return appPathsResult;\n }\n appPaths = appPathsResult;\n } else {\n // Just use the cwd\n appPaths = [this._programOptions.cwd];\n }\n\n // The task runner is shared between all apps so that task results can potentially be reused.\n const taskRunner = new TaskRunner();\n\n const readConfig = this._discoverAppPaths === 'remote' ? readRemoteConfigs : readLocalConfigs;\n const configs = await readConfig(appPaths, {\n ...this._getConfigOptionsFromCliOptions(),\n enableDefaultFeatures: true,\n });\n\n const helpMessages = new Set<string>(\n Object.values(configs)\n .filter((c) => c.helpMessage)\n .map((c) => c.helpMessage) as string[],\n );\n\n // Set reporter options and print the product info header\n this._reporter.setOptions({\n productName: 'Cloudpack',\n version: this._programOptions.version,\n description: () => `Running \"${bold(this._programOptions.argv.slice(2).join(' '))}\"`,\n helpMessage: [...helpMessages].join('\\n'),\n plainTextMode: !this._options.color,\n logFile: !!this._options.logFile,\n cwd: this._programOptions.cwd,\n ...(this._options.debug\n ? debugLoggingConfig\n : this._options.verbose\n ? verboseLoggingConfig\n : this._options.quiet\n ? noLoggingConfig\n : defaultLoggingConfig),\n });\n\n const logLevel = this._options.verbose ? 'VERBOSE' : this._options.debug ? 'DEBUG' : undefined;\n if (!this._options.debug) {\n this._reporter.ignoreLogMessage('ApplicationInsights:');\n }\n\n const telemetryApi = startTelemetry({\n productVersion: getVersion(import.meta.url),\n logLevel,\n serviceName: 'cli',\n });\n\n this._autoDisposableList.add({ dispose: () => telemetryApi.shutdown() });\n\n const contexts: AppCommandContext[] = [];\n\n for (const appPath of Object.keys(configs)) {\n const config = configs[appPath];\n const definition = await readJson<PackageJson>(path.join(appPath, 'package.json'));\n const { name = path.basename(appPath) } = definition || {};\n\n const telemetryClient = await this._initTelemetry(name, config, telemetryApi);\n\n contexts.push({\n appPath,\n cachePath: this._options.cachePath,\n config,\n reporter: this._reporter,\n telemetryClient,\n taskRunner,\n });\n }\n\n return contexts;\n }\n\n /** Translate certain CLI options into options for `readConfig()`. */\n private _getConfigOptionsFromCliOptions(): ReadConfigOptions {\n // These options don't exist for all commands, but that's fine.\n const options = this._options as Partial<ReusedOptions & SharedOptions>;\n return {\n mode: options.mode,\n logBundleInfo: options.logBundleInfo,\n configFileName: options.config,\n // Handle --bundler by passing it as a universal package override, which will be appended\n // to any user-provided packageSettings so that it takes precedence.\n extraPackageSettings: options.bundler ? [{ match: '*', bundler: options.bundler }] : undefined,\n extraFeatures: options.features,\n extraDefineFlags: options.define,\n ...(this._applyOptionsToConfig?.(this._options) || {}),\n };\n }\n\n private async _initTelemetry(\n appName: string | undefined,\n config: CloudpackConfig,\n telemetryApi: TelemetryApi,\n ): Promise<TelemetryClient> {\n // Mark the start time for telemetry.\n const startTime = performance.now();\n\n const programOptions = this._programOptions;\n\n const connectionString =\n this._programOptions.disableTelemetry || environmentInfo.isJest\n ? undefined\n : config.telemetry?.connectionString || environmentInfo.cloudpack.telemetryConnectionString;\n\n const telemetryClient = await telemetryApi.createClient(connectionString);\n\n telemetryClient.tracer.startSpan('CLI_ENTRY', { startTime: getCliStartTime() }).end();\n\n await telemetryClient.tracer.startActiveSpan('INIT_TELEMETRY', { startTime }, (span) => {\n const enabledFeatureNames = Object.entries(config.features || {})\n .filter(([, value]) => value)\n .map(([key]) => key);\n\n if (enabledFeatureNames.length) {\n console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);\n }\n\n const telemetryAttributes = {\n verb: this._verb,\n arguments: programOptions.argv.slice(3).join(' '),\n environment: environmentInfo.isCI ? 'ci' : environmentInfo.isCodespaces ? 'codespaces' : 'local',\n appName: appName || '<unknown>',\n mode: config.mode,\n features: enabledFeatureNames,\n externalCorrelationId: environmentInfo.cloudpack.telemetryExternalCorrelationId,\n // Azure DevOps build attributes\n ...environmentInfo.ado,\n };\n\n for (const [key, value] of Object.entries(telemetryAttributes)) {\n if (value) {\n span.setAttribute(key, value);\n }\n }\n });\n\n return telemetryClient;\n }\n\n protected _sigintHandler = (): void => {\n this._sigintCount++;\n\n if (this._sigintCount > 1) {\n console.debug('Forcing exit');\n\n // We are forcing the process to exit.\n // No clean-up is needed because user pressed Ctrl+C twice.\n // eslint-disable-next-line no-restricted-properties -- top-level cleanup\n process.exit(1);\n }\n\n this._onInterrupt?.();\n\n // We are trying to exit gracefully.\n void this._exit({ isInterrupted: true, message: '' });\n };\n\n /**\n * Exit function called with the result returned by the command's execute function,\n * or manually via `CommandExecutor.exitAll()` in tests.\n */\n protected async _exit(params: CommandExitParams): Promise<never> {\n const { hasErrors = this._reporter.hasErrors(), exitCode = hasErrors ? 1 : 0 } = params;\n const message = params.isInterrupted ? this._getMessageOnInterrupt?.() || 'Interrupted by user' : params.message;\n\n if (this._hasCalledExit) {\n // Skip most of the operations if exit() was called multiple times.\n // But only use the error message if not in a test, due to the way we're mocking process.exit.\n if (!environmentInfo.isJest) {\n const prettyParams = Object.entries(params)\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(', ');\n console.warn(`exit() was called multiple times. This call's options: ${prettyParams}.`);\n }\n } else {\n this._hasCalledExit = true;\n\n // Dispose all registered disposables.\n await this._autoDisposableList.dispose();\n\n // Remove all event listeners. Currently this is only done on final disposal because one of\n // the start tests relies on a 'ready' event listener carrying over across restarts.\n commandEvents.removeAllListeners();\n\n // Show the summary message (this will throw if called twice).\n await this._reporter.complete({\n summary: hasErrors ? red(message) : message,\n showHelp: exitCode !== 0,\n });\n }\n\n CommandExecutor._activeInstances.delete(this);\n process.off('SIGINT', this._sigintHandler);\n\n // eslint-disable-next-line no-restricted-properties -- top-level cleanup\n process.exit(exitCode);\n }\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,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAE3C,yEAAyE;QACzE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC","sourcesContent":["import type { ReadConfigOptions } from '@ms-cloudpack/config';\nimport type { CloudpackConfig, PackageJson } from '@ms-cloudpack/common-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport {\n TaskReporter,\n bold,\n debugLoggingConfig,\n defaultLoggingConfig,\n noLoggingConfig,\n red,\n verboseLoggingConfig,\n yellow,\n} from '@ms-cloudpack/task-reporter';\nimport { startTelemetry, type TelemetryApi, type TelemetryClient } from '@ms-cloudpack/telemetry';\nimport path from 'path';\nimport type { CommandAction, CommandExitParams, AppCommandContext } from '../types/CommandAction.js';\nimport type { ProgramOptions } from '../types/ProgramOptions.js';\nimport type { SharedOptions } from '../types/SharedOptions.js';\nimport { AutoDisposableList } from './AutoDisposableList.js';\nimport { getVersion } from '@ms-cloudpack/package-utilities';\nimport { environmentInfo } from '@ms-cloudpack/environment';\nimport type { ReusedOptions } from '../types/ReusedOptions.js';\nimport type { AppPathDiscoveryMode } from '../types/AppPathDiscoveryMode.js';\nimport { discoverRemoteAppPaths } from './discoverRemoteAppPaths.js';\nimport { discoverLocalAppPaths } from './discoverLocalAppPaths.js';\nimport { TaskRunner } from '@ms-cloudpack/api-server';\nimport { readLocalConfigs, type InvalidCloudpackConfigError } from './readLocalConfigs.js';\nimport { readRemoteConfigs } from './readRemoteConfigs.js';\nimport { getCliStartTime } from './getCliStartTime.js';\n\nexport interface CommandExecutorParams<TOptions extends SharedOptions> {\n /** Command-specific arguments */\n args: string[];\n\n /** Command-specific and shared options. */\n options: TOptions;\n\n /** Function to execute the command. */\n execute: CommandAction<TOptions>;\n\n /** Shared program-level configuration. */\n programOptions: ProgramOptions;\n\n /** Verb being run, e.g. `bundle` or `cache clean`. */\n verb: string;\n\n /**\n * By default, the command will run against `cwd` (usually `process.cwd()`).\n * If this option is set, attempt to discover app path(s) instead.\n * (`cwd` will still be preferred if it has a `cloudpack.config.json`.)\n * See {@link AppPathDiscoveryMode} for details.\n *\n * Note that `isMultiApp` elsewhere will only be true if this is set to `'multi'` and\n * multiple apps are found.\n */\n discoverAppPaths: AppPathDiscoveryMode | undefined;\n\n /**\n * Apply any command-specific CLI options that need to be passed through to `readConfig`.\n * (Shared and reused options are applied automatically.)\n */\n applyOptionsToConfig:\n | ((\n options: Omit<TOptions, keyof (SharedOptions & ReusedOptions)>,\n ) => Pick<ReadConfigOptions, 'extraServerConfig'> | undefined)\n | undefined;\n}\n\n/**\n * This class manages orchestration and shared state while executing a command.\n */\n// 'app' is an optional reused option\nexport class CommandExecutor<TOptions extends SharedOptions> {\n private _options: TOptions;\n private _execute: CommandAction<TOptions>;\n private _programOptions: ProgramOptions;\n private _verb: string;\n private _discoverAppPaths: AppPathDiscoveryMode | undefined;\n private _applyOptionsToConfig: CommandExecutorParams<TOptions>['applyOptionsToConfig'];\n private _reporter: TaskReporter;\n private _autoDisposableList: AutoDisposableList;\n private _hasCalledExit = false;\n private _args: string[];\n private _sigintCount = 0;\n private _onInterrupt?: () => void;\n private _getMessageOnInterrupt?: () => string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- options type isn't used\n private static _activeInstances = new Set<CommandExecutor<any>>();\n\n public static async exitAll(params: CommandExitParams): Promise<void> {\n // There should only be one instance at a time, but we assume multiple instances for safety.\n for (const instance of CommandExecutor._activeInstances) {\n await instance._exit(params);\n process.off('SIGINT', instance._sigintHandler);\n }\n CommandExecutor._activeInstances = new Set();\n }\n\n constructor(params: CommandExecutorParams<TOptions>) {\n this._args = params.args;\n this._options = params.options;\n this._execute = params.execute;\n this._programOptions = params.programOptions;\n this._verb = params.verb;\n this._discoverAppPaths = params.discoverAppPaths;\n this._applyOptionsToConfig = params.applyOptionsToConfig;\n this._reporter = new TaskReporter();\n this._autoDisposableList = new AutoDisposableList();\n }\n\n /**\n * Run the command, including handling for restarts.\n */\n // This has to be a separate method because constructors can't be async.\n public async execute(): Promise<void> {\n CommandExecutor._activeInstances.add(this);\n // Handle SIGINT (Ctrl+C) gracefully.\n if (!environmentInfo.isJest) {\n process.on('SIGINT', this._sigintHandler);\n }\n\n try {\n let shouldRestart = false;\n do {\n shouldRestart = await this._executeOnce(shouldRestart);\n } while (shouldRestart);\n } catch (error) {\n // If an error occurs, exit the process with a non-zero exit code.\n const err = error as InvalidCloudpackConfigError;\n const message = err.isExpected\n ? err.message // Only show message for expected errors\n : err.stack || err.message || String(error); // Show full stack for unexpected errors\n\n await this._exit({\n hasErrors: true,\n message,\n });\n }\n }\n\n /**\n * Execute a single iteration of the command.\n */\n private async _executeOnce(isRestart: boolean): Promise<boolean> {\n const contexts = await this._initializeContexts();\n\n if (!Array.isArray(contexts)) {\n return await this._exit(contexts);\n }\n\n const spanName = `${this._verb.toUpperCase().replace(/ /g, '_')}_EXECUTE`;\n const results: CommandExitParams[] = [];\n\n for (const context of contexts) {\n // Call the execute function which is the real command logic\n // (ie: real init command logic, real start command logic, etc.)\n const result = await context.telemetryClient.tracer.startActiveSpan(spanName, async (span) => {\n this._onInterrupt = () => {\n span.setAttribute('isInterrupted', true);\n span.end();\n };\n\n return this._execute({\n ...context,\n span,\n isMultiApp: contexts.length > 1,\n args: this._args,\n options: this._options,\n commandEvents: this._programOptions.commandEvents,\n isRestart,\n autoDispose: (disposable) => this._autoDisposableList.add(disposable),\n setInterruptMessageHandler: (getMessage) => {\n this._getMessageOnInterrupt = getMessage;\n },\n });\n });\n if (result?.isInterrupted) {\n return await this._exit(result);\n }\n if (result) {\n results.push(result);\n } else {\n // If the command returned null, this means it should keep running (e.g. start).\n // We disallow returning undefined to avoid accidents.\n throw new Error('Command executor must return exit options or null');\n }\n this._onInterrupt = undefined;\n }\n\n // Determine whether a command requested a restart in this iteration.\n const shouldRestart = results.some((r) => r.restart);\n\n if (shouldRestart) {\n // Dispose all registered disposables.\n await this._autoDisposableList.dispose();\n this._reporter.reset(true /* clearOutputs */);\n\n console.warn(results.map((r) => r.message).join('\\n'));\n } else if (results.length) {\n // If one or more apps returned a result, exit.\n return await this._exit({\n message: results.map((r) => r.message).join('\\n'),\n hasErrors: results.some((r) => r.hasErrors),\n // If any app returned a non-zero exit code, use that.\n exitCode: results.find(({ exitCode }) => !!exitCode)?.exitCode,\n });\n }\n\n return shouldRestart;\n }\n\n /**\n * Determine the app paths and initialize the context for each app.\n * @returns Context(s), or an exit options object if there was an error. (might also throw on error)\n */\n private async _initializeContexts(): Promise<AppCommandContext[] | CommandExitParams> {\n let appPaths: string[];\n\n if (this._discoverAppPaths) {\n // Search for cloudpack configs to determine the app path(s)\n const { app, login } = this._options as unknown as Pick<ReusedOptions, 'app' | 'login'>;\n const appPathsResult =\n this._discoverAppPaths === 'remote'\n ? await discoverRemoteAppPaths({\n options: {\n login,\n cachePath: this._options.cachePath,\n desiredApp: app,\n },\n context: { reporter: this._reporter },\n })\n : await discoverLocalAppPaths({\n cwd: this._programOptions.cwd,\n discover: this._discoverAppPaths,\n desiredApp: app,\n });\n if (!Array.isArray(appPathsResult)) {\n // This means there was an error (or the user cancelled) while getting app paths.\n return appPathsResult;\n }\n appPaths = appPathsResult;\n } else {\n // Just use the cwd\n appPaths = [this._programOptions.cwd];\n }\n\n // The task runner is shared between all apps so that task results can potentially be reused.\n const taskRunner = new TaskRunner();\n\n const readConfig = this._discoverAppPaths === 'remote' ? readRemoteConfigs : readLocalConfigs;\n const configs = await readConfig(appPaths, {\n ...this._getConfigOptionsFromCliOptions(),\n enableDefaultFeatures: true,\n });\n\n const helpMessages = new Set<string>(\n Object.values(configs)\n .filter((c) => c.helpMessage)\n .map((c) => c.helpMessage) as string[],\n );\n\n // Set reporter options and print the product info header\n this._reporter.setOptions({\n productName: 'Cloudpack',\n version: this._programOptions.version,\n description: () => `Running \"${bold(this._programOptions.argv.slice(2).join(' '))}\"`,\n helpMessage: [...helpMessages].join('\\n'),\n plainTextMode: !this._options.color,\n logFile: !!this._options.logFile,\n cwd: this._programOptions.cwd,\n ...(this._options.debug\n ? debugLoggingConfig\n : this._options.verbose\n ? verboseLoggingConfig\n : this._options.quiet\n ? noLoggingConfig\n : defaultLoggingConfig),\n });\n\n const logLevel = this._options.verbose ? 'VERBOSE' : this._options.debug ? 'DEBUG' : undefined;\n if (!this._options.debug) {\n this._reporter.ignoreLogMessage('ApplicationInsights:');\n }\n\n const telemetryApi = startTelemetry({\n productVersion: getVersion(import.meta.url),\n logLevel,\n serviceName: 'cli',\n });\n\n this._autoDisposableList.add({ dispose: () => telemetryApi.shutdown() });\n\n const contexts: AppCommandContext[] = [];\n\n for (const appPath of Object.keys(configs)) {\n const config = configs[appPath];\n const definition = await readJson<PackageJson>(path.join(appPath, 'package.json'));\n const { name = path.basename(appPath) } = definition || {};\n\n const telemetryClient = await this._initTelemetry(name, config, telemetryApi);\n\n contexts.push({\n appPath,\n cachePath: this._options.cachePath,\n config,\n reporter: this._reporter,\n telemetryClient,\n taskRunner,\n });\n }\n\n return contexts;\n }\n\n /** Translate certain CLI options into options for `readConfig()`. */\n private _getConfigOptionsFromCliOptions(): ReadConfigOptions {\n // These options don't exist for all commands, but that's fine.\n const options = this._options as Partial<ReusedOptions & SharedOptions>;\n return {\n mode: options.mode,\n logBundleInfo: options.logBundleInfo,\n configFileName: options.config,\n // Handle --bundler by passing it as a universal package override, which will be appended\n // to any user-provided packageSettings so that it takes precedence.\n extraPackageSettings: options.bundler ? [{ match: '*', bundler: options.bundler }] : undefined,\n extraFeatures: options.features,\n extraDefineFlags: options.define,\n ...(this._applyOptionsToConfig?.(this._options) || {}),\n };\n }\n\n private async _initTelemetry(\n appName: string | undefined,\n config: CloudpackConfig,\n telemetryApi: TelemetryApi,\n ): Promise<TelemetryClient> {\n // Mark the start time for telemetry.\n const startTime = performance.now();\n\n const programOptions = this._programOptions;\n\n const connectionString =\n this._programOptions.disableTelemetry || environmentInfo.isJest\n ? undefined\n : config.telemetry?.connectionString || environmentInfo.cloudpack.telemetryConnectionString;\n\n const telemetryClient = await telemetryApi.createClient(connectionString);\n\n telemetryClient.tracer.startSpan('CLI_ENTRY', { startTime: getCliStartTime() }).end();\n\n await telemetryClient.tracer.startActiveSpan('INIT_TELEMETRY', { startTime }, (span) => {\n const enabledFeatureNames = Object.entries(config.features || {})\n .filter(([, value]) => value)\n .map(([key]) => key);\n\n if (enabledFeatureNames.length) {\n console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);\n }\n\n const telemetryAttributes = {\n verb: this._verb,\n arguments: programOptions.argv.slice(3).join(' '),\n environment: environmentInfo.isCI ? 'ci' : environmentInfo.isCodespaces ? 'codespaces' : 'local',\n appName: appName || '<unknown>',\n mode: config.mode,\n features: enabledFeatureNames,\n externalCorrelationId: environmentInfo.cloudpack.telemetryExternalCorrelationId,\n // Azure DevOps build attributes\n ...environmentInfo.ado,\n };\n\n for (const [key, value] of Object.entries(telemetryAttributes)) {\n if (value) {\n span.setAttribute(key, value);\n }\n }\n });\n\n return telemetryClient;\n }\n\n protected _sigintHandler = (): void => {\n this._sigintCount++;\n\n if (this._sigintCount > 1) {\n console.debug('Forcing exit');\n\n // We are forcing the process to exit.\n // No clean-up is needed because user pressed Ctrl+C twice.\n // eslint-disable-next-line no-restricted-properties -- top-level cleanup\n process.exit(1);\n }\n\n this._onInterrupt?.();\n\n // We are trying to exit gracefully.\n void this._exit({ isInterrupted: true, message: '' });\n };\n\n /**\n * Exit function called with the result returned by the command's execute function,\n * or manually via `CommandExecutor.exitAll()` in tests.\n */\n protected async _exit(params: CommandExitParams): Promise<never> {\n const { hasErrors = this._reporter.hasErrors(), exitCode = hasErrors ? 1 : 0 } = params;\n const message = params.isInterrupted ? this._getMessageOnInterrupt?.() || 'Interrupted by user' : params.message;\n\n if (this._hasCalledExit) {\n // Skip most of the operations if exit() was called multiple times.\n // But only use the error message if not in a test, due to the way we're mocking process.exit.\n if (!environmentInfo.isJest) {\n const prettyParams = Object.entries(params)\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(', ');\n console.warn(`exit() was called multiple times. This call's options: ${prettyParams}.`);\n }\n } else {\n this._hasCalledExit = true;\n\n // Dispose all registered disposables.\n await this._autoDisposableList.dispose();\n\n // Remove all event listeners. Currently this is only done on final disposal because one of\n // the start tests relies on a 'ready' event listener carrying over across restarts.\n this._programOptions.commandEvents.removeAllListeners();\n\n // Show the summary message (this will throw if called twice).\n await this._reporter.complete({\n summary: hasErrors ? red(message) : message,\n showHelp: exitCode !== 0,\n });\n }\n\n CommandExecutor._activeInstances.delete(this);\n process.off('SIGINT', this._sigintHandler);\n\n // eslint-disable-next-line no-restricted-properties -- top-level cleanup\n process.exit(exitCode);\n }\n}\n"]}
@@ -10,7 +10,12 @@ import { EventEmitter } from 'node:events';
10
10
  * - `'ready'`: An interactive command is ready.
11
11
  * - For `start`, all servers are ready (and browser opening has started).
12
12
  */
13
- export declare const commandEvents: EventEmitter<{
13
+ export type CommandEvents = EventEmitter<{
14
14
  ready: [];
15
15
  }>;
16
+ /**
17
+ * Create an event emitter for command lifecycle events. Not all events are applicable to all commands.
18
+ * @see {@link CommandEvents}
19
+ */
20
+ export declare function createCommandEvents(): CommandEvents;
16
21
  //# sourceMappingURL=commandEvents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commandEvents.d.ts","sourceRoot":"","sources":["../../src/utilities/commandEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa;WAA6B,EAAE;EAAK,CAAC"}
1
+ {"version":3,"file":"commandEvents.d.ts","sourceRoot":"","sources":["../../src/utilities/commandEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC;IAAE,KAAK,EAAE,EAAE,CAAA;CAAE,CAAC,CAAC;AAExD;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD"}