@ms-cloudpack/cli 0.55.7 → 0.56.0
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.
- package/lib/commands/init/InitSummaryData.d.ts +2 -1
- package/lib/commands/init/InitSummaryData.d.ts.map +1 -1
- package/lib/commands/init/InitSummaryData.js +3 -1
- package/lib/commands/init/InitSummaryData.js.map +1 -1
- package/lib/commands/init/evaluateImportsForOverrides.d.ts +3 -0
- package/lib/commands/init/evaluateImportsForOverrides.d.ts.map +1 -1
- package/lib/commands/init/evaluateImportsForOverrides.js +93 -46
- package/lib/commands/init/evaluateImportsForOverrides.js.map +1 -1
- package/lib/commands/init/evaluatePath.d.ts.map +1 -1
- package/lib/commands/init/evaluatePath.js +10 -2
- package/lib/commands/init/evaluatePath.js.map +1 -1
- package/lib/commands/init/execute.d.ts.map +1 -1
- package/lib/commands/init/execute.js +8 -4
- package/lib/commands/init/execute.js.map +1 -1
- package/lib/commands/init/formatInitSummary.d.ts +1 -1
- package/lib/commands/init/formatInitSummary.d.ts.map +1 -1
- package/lib/commands/init/formatInitSummary.js +52 -46
- package/lib/commands/init/formatInitSummary.js.map +1 -1
- package/lib/commands/init/init.d.ts +3 -6
- package/lib/commands/init/init.d.ts.map +1 -1
- package/lib/commands/init/init.js +95 -87
- package/lib/commands/init/init.js.map +1 -1
- package/lib/commands/init/optimizeDependencies.d.ts +2 -2
- package/lib/commands/init/optimizeDependencies.d.ts.map +1 -1
- package/lib/commands/init/optimizeDependencies.js +13 -79
- package/lib/commands/init/optimizeDependencies.js.map +1 -1
- package/lib/commands/init/types/InitSummary.d.ts +1 -0
- package/lib/commands/init/types/InitSummary.d.ts.map +1 -1
- package/lib/commands/init/types/InitSummary.js.map +1 -1
- package/lib/common/CommandExecutor.d.ts +3 -1
- package/lib/common/CommandExecutor.d.ts.map +1 -1
- package/lib/common/CommandExecutor.js +64 -53
- package/lib/common/CommandExecutor.js.map +1 -1
- package/lib/types/CommandAction.d.ts +18 -7
- package/lib/types/CommandAction.d.ts.map +1 -1
- package/lib/types/CommandAction.js.map +1 -1
- package/package.json +8 -8
|
@@ -14,58 +14,6 @@ import { getMergedFeatureFlags } from './getMergedFeatureFlags.js';
|
|
|
14
14
|
export class CommandExecutor {
|
|
15
15
|
constructor(params) {
|
|
16
16
|
this._hasCalledExit = false;
|
|
17
|
-
/**
|
|
18
|
-
* This is the `initialize` function passed to the command's execute function.
|
|
19
|
-
* (It must be an arrow function to ensure the correct `this` context.)
|
|
20
|
-
*/
|
|
21
|
-
this._initialize = async (initializeParams) => {
|
|
22
|
-
const { appPath } = initializeParams;
|
|
23
|
-
const actionOptions = {
|
|
24
|
-
...this._options,
|
|
25
|
-
...initializeParams.overrideOptions,
|
|
26
|
-
};
|
|
27
|
-
const config = await readConfig(appPath);
|
|
28
|
-
const definition = (await readJson(path.join(appPath, 'package.json')));
|
|
29
|
-
// Set reporter options and print the product info header
|
|
30
|
-
this._reporter.setOptions({
|
|
31
|
-
productName: 'Cloudpack',
|
|
32
|
-
version: this._programOptions.version,
|
|
33
|
-
description: () => `Running "${bold(this._programOptions.argv.slice(2).join(' '))}"`,
|
|
34
|
-
helpMessage: config.helpMessage,
|
|
35
|
-
plainTextMode: !actionOptions.color,
|
|
36
|
-
...(actionOptions.debug
|
|
37
|
-
? debugLoggingConfig
|
|
38
|
-
: actionOptions.verbose
|
|
39
|
-
? verboseLoggingConfig
|
|
40
|
-
: actionOptions.quiet
|
|
41
|
-
? noLoggingConfig
|
|
42
|
-
: defaultLoggingConfig),
|
|
43
|
-
});
|
|
44
|
-
const telemetryClient = await this._initTelemetry(definition.name, config);
|
|
45
|
-
// Dispose the telemetry client when the app is closing
|
|
46
|
-
this._autoDisposableList.add({
|
|
47
|
-
dispose: () => telemetryClient.shutdown(),
|
|
48
|
-
});
|
|
49
|
-
// Merge in any additional features from the command line and remote feature flags.
|
|
50
|
-
config.features = await getMergedFeatureFlags(config, actionOptions, appPath, definition.name);
|
|
51
|
-
const featureErrors = checkFeatures({ configFeatures: config.features });
|
|
52
|
-
// If there are any invalid features, exit with an error.
|
|
53
|
-
if (featureErrors.length) {
|
|
54
|
-
featureErrors.forEach((error) => console.error(error));
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
const enabledFeatureNames = Object.entries(config.features)
|
|
58
|
-
.filter(([, value]) => value)
|
|
59
|
-
.map(([key]) => key);
|
|
60
|
-
if (enabledFeatureNames.length) {
|
|
61
|
-
telemetryClient.setSharedSpanAttribute('features', enabledFeatureNames);
|
|
62
|
-
console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
telemetryClient,
|
|
66
|
-
config,
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
17
|
/**
|
|
70
18
|
* This is the `exit` function passed to the command's execute function.
|
|
71
19
|
* (It must be an arrow function to ensure the correct `this` context.)
|
|
@@ -119,7 +67,7 @@ export class CommandExecutor {
|
|
|
119
67
|
options: this._options,
|
|
120
68
|
cwd: this._programOptions.cwd,
|
|
121
69
|
reporter: this._reporter,
|
|
122
|
-
initialize: this._initialize,
|
|
70
|
+
initialize: this._initialize.bind(this),
|
|
123
71
|
abortSignal: this._abortController.signal,
|
|
124
72
|
autoDispose: (disposable) => this._autoDisposableList.add(disposable),
|
|
125
73
|
exit: this._exit,
|
|
@@ -133,6 +81,69 @@ export class CommandExecutor {
|
|
|
133
81
|
});
|
|
134
82
|
}
|
|
135
83
|
}
|
|
84
|
+
async _initialize(initializeParams) {
|
|
85
|
+
const { appPath: singleAppPath } = initializeParams;
|
|
86
|
+
let { appPaths } = initializeParams;
|
|
87
|
+
if (singleAppPath && appPaths) {
|
|
88
|
+
throw Error('appPath and appPaths cannot both be specified at the same time');
|
|
89
|
+
}
|
|
90
|
+
if (!singleAppPath && !appPaths) {
|
|
91
|
+
throw Error('one of appPath or appPaths must be specified');
|
|
92
|
+
}
|
|
93
|
+
if (!appPaths || appPaths.length === 0) {
|
|
94
|
+
appPaths = singleAppPath ? [singleAppPath] : [];
|
|
95
|
+
}
|
|
96
|
+
const initContexts = [];
|
|
97
|
+
for (const appPath of appPaths) {
|
|
98
|
+
const actionOptions = {
|
|
99
|
+
...this._options,
|
|
100
|
+
...initializeParams.overrideOptions,
|
|
101
|
+
};
|
|
102
|
+
const config = await readConfig(appPath);
|
|
103
|
+
const definition = (await readJson(path.join(appPath, 'package.json')));
|
|
104
|
+
// Set reporter options and print the product info header
|
|
105
|
+
this._reporter.setOptions({
|
|
106
|
+
productName: 'Cloudpack',
|
|
107
|
+
version: this._programOptions.version,
|
|
108
|
+
description: () => `Running "${bold(this._programOptions.argv.slice(2).join(' '))}"`,
|
|
109
|
+
helpMessage: config.helpMessage,
|
|
110
|
+
plainTextMode: !actionOptions.color,
|
|
111
|
+
...(actionOptions.debug
|
|
112
|
+
? debugLoggingConfig
|
|
113
|
+
: actionOptions.verbose
|
|
114
|
+
? verboseLoggingConfig
|
|
115
|
+
: actionOptions.quiet
|
|
116
|
+
? noLoggingConfig
|
|
117
|
+
: defaultLoggingConfig),
|
|
118
|
+
});
|
|
119
|
+
const telemetryClient = await this._initTelemetry(definition.name, config);
|
|
120
|
+
// Dispose the telemetry client when the app is closing
|
|
121
|
+
this._autoDisposableList.add({
|
|
122
|
+
dispose: () => telemetryClient.shutdown(),
|
|
123
|
+
});
|
|
124
|
+
// Merge in any additional features from the command line and remote feature flags.
|
|
125
|
+
config.features = await getMergedFeatureFlags(config, actionOptions, appPath, definition.name);
|
|
126
|
+
const featureErrors = checkFeatures({ configFeatures: config.features });
|
|
127
|
+
// If there are any invalid features, exit with an error.
|
|
128
|
+
if (featureErrors.length) {
|
|
129
|
+
featureErrors.forEach((error) => console.error(error));
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
const enabledFeatureNames = Object.entries(config.features)
|
|
133
|
+
.filter(([, value]) => value)
|
|
134
|
+
.map(([key]) => key);
|
|
135
|
+
if (enabledFeatureNames.length) {
|
|
136
|
+
telemetryClient.setSharedSpanAttribute('features', enabledFeatureNames);
|
|
137
|
+
console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);
|
|
138
|
+
}
|
|
139
|
+
initContexts.push({
|
|
140
|
+
appPath: appPath,
|
|
141
|
+
telemetryClient,
|
|
142
|
+
config,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return singleAppPath ? initContexts[0] : initContexts;
|
|
146
|
+
}
|
|
136
147
|
async _initTelemetry(appName, config) {
|
|
137
148
|
const programOptions = this._programOptions;
|
|
138
149
|
const options = this._options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandExecutor.js","sourceRoot":"","sources":["../../src/common/CommandExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,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,qBAAqB,EAAwB,MAAM,yBAAyB,CAAC;AACtF,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,MAAM,gDAAgD,CAAC;AAI9F,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;GAEG;AACH,MAAM,OAAO,eAAe;IAU1B,YAAY,MASX;QAXO,mBAAc,GAAG,KAAK,CAAC;QA+D/B;;;WAGG;QACK,gBAAW,GAAgD,KAAK,EAA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,MAAM,CAAC,SAAS,EAAE,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC;QAE5F,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QACnF,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACnB,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;QAC1D,CAAC;QAED,MAAM,eAAe,GAAG,MAAM,qBAAqB,CAAC;YAClD,cAAc,EAAE,cAAc,CAAC,OAAO;YACtC,gBAAgB;YAChB,QAAQ;YACR,gBAAgB,EAAE,WAAW;YAC7B,WAAW,EAAE,KAAK;YAClB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QAEH,eAAe,CAAC,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3D,eAAe,CAAC,sBAAsB,CAAC,WAAW,EAAE,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5F,eAAe,CAAC,sBAAsB,CAAC,aAAa,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACpF,eAAe,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,IAAI,WAAW,CAAC,CAAC;QAE1E,qFAAqF;QACrF,4BAA4B,CAAC,eAAe,CAAC,CAAC;QAE9C,OAAO,eAAe,CAAC;IACzB,CAAC;CAiCF","sourcesContent":["import { readConfig } from '@ms-cloudpack/config';\nimport type { CloudpackConfig, PackageJson } from '@ms-cloudpack/config-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 { createTelemetryClient, type TelemetryClient } from '@ms-cloudpack/telemetry';\nimport path from 'path';\nimport { registerPerformanceObservers } from '../performance/registerPerformanceObservers.js';\nimport type { CommandAction, CommandActionParams } from '../types/CommandAction.js';\nimport type { ProgramOptions } from '../types/ProgramOptions.js';\nimport type { SharedOptions } from '../types/SharedOptions.js';\nimport { isCIBuild } from '../utilities/isCIBuild.js';\nimport { AutoDisposableList } from './AutoDisposableList.js';\nimport { checkFeatures } from './checkFeatures.js';\nimport { getMergedFeatureFlags } from './getMergedFeatureFlags.js';\n\n/**\n * This class manages orchestration and shared state while executing a command.\n */\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 _reporter: TaskReporter;\n private _autoDisposableList: AutoDisposableList;\n private _abortController: AbortController;\n private _hasCalledExit = false;\n\n constructor(params: {\n /** Command-specific and shared options. */\n options: TOptions;\n /** Function to execute the command. */\n execute: CommandAction<TOptions>;\n /** Shared program-level configuration. */\n programOptions: ProgramOptions;\n /** Verb being run, e.g. `bundle` or `cache clean`. */\n verb: string;\n }) {\n this._options = params.options;\n this._execute = params.execute;\n this._programOptions = params.programOptions;\n this._verb = params.verb;\n this._reporter = new TaskReporter();\n this._abortController = new AbortController();\n this._autoDisposableList = new AutoDisposableList();\n }\n\n /** Run the command. */\n // This has to be a separate method because constructors can't be async.\n public async execute() {\n try {\n // Setup cleanup and close things on completion.\n let sigintCount = 0;\n\n // Handle SIGINT (Ctrl+C) gracefully.\n process.on('SIGINT', () => {\n sigintCount++;\n if (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 process.exit(1);\n }\n\n // We are trying to exit gracefully.\n void this._exit();\n });\n\n // Call the execute function which is the real command logic\n // (ie: real init command logic, real start command logic, etc.)\n await this._execute({\n options: this._options,\n cwd: this._programOptions.cwd,\n reporter: this._reporter,\n initialize: this._initialize,\n abortSignal: this._abortController.signal,\n autoDispose: (disposable) => this._autoDisposableList.add(disposable),\n exit: this._exit,\n });\n } catch (error) {\n // If an error occurs, exit the process with a non-zero exit code.\n await this._exit({\n hasErrors: true,\n message: error instanceof Error ? error.stack || error.message : String(error),\n });\n }\n }\n\n /**\n * This is the `initialize` function passed to the command's execute function.\n * (It must be an arrow function to ensure the correct `this` context.)\n */\n private _initialize: CommandActionParams<TOptions>['initialize'] = async (initializeParams) => {\n const { appPath } = initializeParams;\n\n const actionOptions: SharedOptions = {\n ...this._options,\n ...initializeParams.overrideOptions,\n };\n\n const config = await readConfig(appPath);\n const definition = (await readJson(path.join(appPath, 'package.json'))) as PackageJson;\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: config.helpMessage,\n plainTextMode: !actionOptions.color,\n ...(actionOptions.debug\n ? debugLoggingConfig\n : actionOptions.verbose\n ? verboseLoggingConfig\n : actionOptions.quiet\n ? noLoggingConfig\n : defaultLoggingConfig),\n });\n\n const telemetryClient = await this._initTelemetry(definition.name, config);\n // Dispose the telemetry client when the app is closing\n this._autoDisposableList.add({\n dispose: () => telemetryClient.shutdown(),\n });\n\n // Merge in any additional features from the command line and remote feature flags.\n config.features = await getMergedFeatureFlags(config, actionOptions, appPath, definition.name);\n\n const featureErrors = checkFeatures({ configFeatures: config.features });\n // If there are any invalid features, exit with an error.\n if (featureErrors.length) {\n featureErrors.forEach((error) => console.error(error));\n process.exit(1);\n }\n\n const enabledFeatureNames = Object.entries(config.features)\n .filter(([, value]) => value)\n .map(([key]) => key);\n\n if (enabledFeatureNames.length) {\n telemetryClient.setSharedSpanAttribute('features', enabledFeatureNames);\n console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);\n }\n\n return {\n telemetryClient,\n config,\n };\n };\n\n private async _initTelemetry(appName: string | undefined, config: CloudpackConfig): Promise<TelemetryClient> {\n const programOptions = this._programOptions;\n const options = this._options;\n\n const connectionString = programOptions.disableTelemetry\n ? undefined\n : config.telemetry?.connectionString || process.env.CLOUDPACK_TELEMETRY_CONNECTION_STRING;\n\n const logLevel = options.verbose ? 'VERBOSE' : options.debug ? 'DEBUG' : undefined;\n if (!options.debug) {\n this._reporter.ignoreLogMessage('ApplicationInsights:');\n }\n\n const telemetryClient = await createTelemetryClient({\n productVersion: programOptions.version,\n connectionString,\n logLevel,\n serviceNamespace: 'cloudpack',\n serviceName: 'cli',\n rootSpanName: 'CLI',\n });\n\n telemetryClient.setSharedSpanAttribute('verb', this._verb);\n telemetryClient.setSharedSpanAttribute('arguments', programOptions.argv.slice(3).join(' '));\n telemetryClient.setSharedSpanAttribute('environment', isCIBuild() ? 'ci' : 'local');\n telemetryClient.setSharedSpanAttribute('appName', appName || '<unknown>');\n\n // Register performance observers to track performance metrics as events of CLI span.\n registerPerformanceObservers(telemetryClient);\n\n return telemetryClient;\n }\n\n /**\n * This is the `exit` function passed to the command's execute function.\n * (It must be an arrow function to ensure the correct `this` context.)\n */\n private _exit = async (\n exitOptions: {\n hasErrors?: boolean;\n message?: string;\n exitCode?: number;\n } = {},\n ) => {\n const { message, hasErrors = this._reporter.hasErrors(), exitCode = hasErrors ? 1 : 0 } = exitOptions;\n\n if (this._hasCalledExit) {\n // Skip most of the operations if exit() was called multiple times.\n console.warn(\"exit() was called multiple times. This call's options:\", exitOptions);\n } else {\n this._hasCalledExit = true;\n\n // Let the execute function know that we are exiting.\n this._abortController.abort();\n\n // Dispose all registered disposables.\n await this._autoDisposableList.dispose();\n\n // Show the summary message (this will throw if called twice).\n this._reporter.complete(hasErrors ? red(message) : message);\n }\n\n process.exit(exitCode);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CommandExecutor.js","sourceRoot":"","sources":["../../src/common/Comm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,eAAe,CAAC;IACzB,CAAC;CAiCF","sourcesContent":["import { readConfig } from '@ms-cloudpack/config';\nimport type { CloudpackConfig, PackageJson } from '@ms-cloudpack/config-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 { createTelemetryClient, type TelemetryClient } from '@ms-cloudpack/telemetry';\nimport path from 'path';\nimport { registerPerformanceObservers } from '../performance/registerPerformanceObservers.js';\nimport type { CommandAction, InitContext } from '../types/CommandAction.js';\nimport type { ProgramOptions } from '../types/ProgramOptions.js';\nimport type { SharedOptions } from '../types/SharedOptions.js';\nimport { isCIBuild } from '../utilities/isCIBuild.js';\nimport { AutoDisposableList } from './AutoDisposableList.js';\nimport { checkFeatures } from './checkFeatures.js';\nimport { getMergedFeatureFlags } from './getMergedFeatureFlags.js';\n\n/**\n * This class manages orchestration and shared state while executing a command.\n */\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 _reporter: TaskReporter;\n private _autoDisposableList: AutoDisposableList;\n private _abortController: AbortController;\n private _hasCalledExit = false;\n\n constructor(params: {\n /** Command-specific and shared options. */\n options: TOptions;\n /** Function to execute the command. */\n execute: CommandAction<TOptions>;\n /** Shared program-level configuration. */\n programOptions: ProgramOptions;\n /** Verb being run, e.g. `bundle` or `cache clean`. */\n verb: string;\n }) {\n this._options = params.options;\n this._execute = params.execute;\n this._programOptions = params.programOptions;\n this._verb = params.verb;\n this._reporter = new TaskReporter();\n this._abortController = new AbortController();\n this._autoDisposableList = new AutoDisposableList();\n }\n\n /** Run the command. */\n // This has to be a separate method because constructors can't be async.\n public async execute() {\n try {\n // Setup cleanup and close things on completion.\n let sigintCount = 0;\n\n // Handle SIGINT (Ctrl+C) gracefully.\n process.on('SIGINT', () => {\n sigintCount++;\n if (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 process.exit(1);\n }\n\n // We are trying to exit gracefully.\n void this._exit();\n });\n\n // Call the execute function which is the real command logic\n // (ie: real init command logic, real start command logic, etc.)\n await this._execute({\n options: this._options,\n cwd: this._programOptions.cwd,\n reporter: this._reporter,\n initialize: this._initialize.bind(this),\n abortSignal: this._abortController.signal,\n autoDispose: (disposable) => this._autoDisposableList.add(disposable),\n exit: this._exit,\n });\n } catch (error) {\n // If an error occurs, exit the process with a non-zero exit code.\n await this._exit({\n hasErrors: true,\n message: error instanceof Error ? error.stack || error.message : String(error),\n });\n }\n }\n\n /**\n * This is the `initialize` function passed to the command's execute function.\n * This function uses `this` to references several class members, which is why\n * the `execute` method must use `.bind(this)`.\n * (An arrow function isn't possible here due to the overloaded method signature).\n */\n private async _initialize(initializeParams: {\n appPath: string;\n overrideOptions?: Partial<SharedOptions>;\n }): Promise<InitContext>;\n private async _initialize(initializeParams: {\n appPaths: string[];\n overrideOptions?: Partial<SharedOptions>;\n }): Promise<InitContext[]>;\n private async _initialize(initializeParams: {\n appPath?: string;\n appPaths?: string[];\n overrideOptions?: Partial<SharedOptions>;\n }): Promise<InitContext | InitContext[]> {\n const { appPath: singleAppPath } = initializeParams;\n let { appPaths } = initializeParams;\n\n if (singleAppPath && appPaths) {\n throw Error('appPath and appPaths cannot both be specified at the same time');\n }\n if (!singleAppPath && !appPaths) {\n throw Error('one of appPath or appPaths must be specified');\n }\n\n if (!appPaths || appPaths.length === 0) {\n appPaths = singleAppPath ? [singleAppPath] : [];\n }\n\n const initContexts = [];\n\n for (const appPath of appPaths) {\n const actionOptions: SharedOptions = {\n ...this._options,\n ...initializeParams.overrideOptions,\n };\n\n const config = await readConfig(appPath);\n const definition = (await readJson(path.join(appPath, 'package.json'))) as PackageJson;\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: config.helpMessage,\n plainTextMode: !actionOptions.color,\n ...(actionOptions.debug\n ? debugLoggingConfig\n : actionOptions.verbose\n ? verboseLoggingConfig\n : actionOptions.quiet\n ? noLoggingConfig\n : defaultLoggingConfig),\n });\n\n const telemetryClient = await this._initTelemetry(definition.name, config);\n // Dispose the telemetry client when the app is closing\n this._autoDisposableList.add({\n dispose: () => telemetryClient.shutdown(),\n });\n\n // Merge in any additional features from the command line and remote feature flags.\n config.features = await getMergedFeatureFlags(config, actionOptions, appPath, definition.name);\n\n const featureErrors = checkFeatures({ configFeatures: config.features });\n // If there are any invalid features, exit with an error.\n if (featureErrors.length) {\n featureErrors.forEach((error) => console.error(error));\n process.exit(1);\n }\n\n const enabledFeatureNames = Object.entries(config.features)\n .filter(([, value]) => value)\n .map(([key]) => key);\n\n if (enabledFeatureNames.length) {\n telemetryClient.setSharedSpanAttribute('features', enabledFeatureNames);\n console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);\n }\n\n initContexts.push({\n appPath: appPath,\n telemetryClient,\n config,\n });\n }\n\n return singleAppPath ? initContexts[0] : initContexts;\n }\n\n private async _initTelemetry(appName: string | undefined, config: CloudpackConfig): Promise<TelemetryClient> {\n const programOptions = this._programOptions;\n const options = this._options;\n\n const connectionString = programOptions.disableTelemetry\n ? undefined\n : config.telemetry?.connectionString || process.env.CLOUDPACK_TELEMETRY_CONNECTION_STRING;\n\n const logLevel = options.verbose ? 'VERBOSE' : options.debug ? 'DEBUG' : undefined;\n if (!options.debug) {\n this._reporter.ignoreLogMessage('ApplicationInsights:');\n }\n\n const telemetryClient = await createTelemetryClient({\n productVersion: programOptions.version,\n connectionString,\n logLevel,\n serviceNamespace: 'cloudpack',\n serviceName: 'cli',\n rootSpanName: 'CLI',\n });\n\n telemetryClient.setSharedSpanAttribute('verb', this._verb);\n telemetryClient.setSharedSpanAttribute('arguments', programOptions.argv.slice(3).join(' '));\n telemetryClient.setSharedSpanAttribute('environment', isCIBuild() ? 'ci' : 'local');\n telemetryClient.setSharedSpanAttribute('appName', appName || '<unknown>');\n\n // Register performance observers to track performance metrics as events of CLI span.\n registerPerformanceObservers(telemetryClient);\n\n return telemetryClient;\n }\n\n /**\n * This is the `exit` function passed to the command's execute function.\n * (It must be an arrow function to ensure the correct `this` context.)\n */\n private _exit = async (\n exitOptions: {\n hasErrors?: boolean;\n message?: string;\n exitCode?: number;\n } = {},\n ) => {\n const { message, hasErrors = this._reporter.hasErrors(), exitCode = hasErrors ? 1 : 0 } = exitOptions;\n\n if (this._hasCalledExit) {\n // Skip most of the operations if exit() was called multiple times.\n console.warn(\"exit() was called multiple times. This call's options:\", exitOptions);\n } else {\n this._hasCalledExit = true;\n\n // Let the execute function know that we are exiting.\n this._abortController.abort();\n\n // Dispose all registered disposables.\n await this._autoDisposableList.dispose();\n\n // Show the summary message (this will throw if called twice).\n this._reporter.complete(hasErrors ? red(message) : message);\n }\n\n process.exit(exitCode);\n };\n}\n"]}
|
|
@@ -4,6 +4,11 @@ import type { CloudpackConfig } from '@ms-cloudpack/config-types';
|
|
|
4
4
|
import type { TelemetryClient } from '@ms-cloudpack/telemetry';
|
|
5
5
|
import type { AutoDispose } from './AutoDispose.js';
|
|
6
6
|
import type { SharedOptions } from './SharedOptions.js';
|
|
7
|
+
export type InitContext = {
|
|
8
|
+
appPath: string;
|
|
9
|
+
telemetryClient: TelemetryClient;
|
|
10
|
+
config: CloudpackConfig;
|
|
11
|
+
};
|
|
7
12
|
export interface CommandActionParams<TOptions extends object> {
|
|
8
13
|
/**
|
|
9
14
|
* Initial working directory (usually `process.cwd()` except in tests).
|
|
@@ -26,14 +31,20 @@ export interface CommandActionParams<TOptions extends object> {
|
|
|
26
31
|
/**
|
|
27
32
|
* This should be called at or near the beginning of the action to initialize the config,
|
|
28
33
|
* telemetry, and reporting. (See `createInitializeFunction` for implementation.)
|
|
34
|
+
* `initialize` can be called with either a single string, `appPath` or an a string[], `appPaths`.
|
|
35
|
+
* If it is called with a single string, it returns `Promise<InitContext>`
|
|
36
|
+
* If it is called with a string[], it returns `Promise<InitContext[]>`
|
|
29
37
|
*/
|
|
30
|
-
initialize:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
initialize: {
|
|
39
|
+
(initializeOptions: {
|
|
40
|
+
appPath: string;
|
|
41
|
+
overrideOptions?: Partial<SharedOptions>;
|
|
42
|
+
}): Promise<InitContext>;
|
|
43
|
+
(initializeOptions: {
|
|
44
|
+
appPaths: string[];
|
|
45
|
+
overrideOptions?: Partial<SharedOptions>;
|
|
46
|
+
}): Promise<InitContext[]>;
|
|
47
|
+
};
|
|
37
48
|
/**
|
|
38
49
|
* This should be called at the end of the action to dispose resources, log completion,
|
|
39
50
|
* and exit the program. (See `createExitFunction` for implementation.)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandAction.d.ts","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,WAAW,mBAAmB,CAAC,QAAQ,SAAS,MAAM;IAC1D;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;;OAIG;IACH,OAAO,EAAE,QAAQ,CAAC;IAElB,QAAQ,EAAE,YAAY,CAAC;IAEvB,WAAW,EAAE,WAAW,CAAC;IAEzB;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC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MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzE;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,QAAQ,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,QAAQ,GAAG,aAAa,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/G,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":"","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { AutoDispose } from './AutoDispose.js';\nimport type { SharedOptions } from './SharedOptions.js';\n\nexport interface CommandActionParams<TOptions extends object> {\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 /**\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 reporter: TaskReporter;\n\n abortSignal: AbortSignal;\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 * This should be called at or near the beginning of the action to initialize the config,\n * telemetry, and reporting. (See `createInitializeFunction` for implementation.)\n */\n initialize: (initializeOptions: { appPath: string; overrideOptions?: Partial<SharedOptions> })
|
|
1
|
+
{"version":3,"file":"CommandAction.js","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { AutoDispose } from './AutoDispose.js';\nimport type { SharedOptions } from './SharedOptions.js';\n\nexport type InitContext = {\n appPath: string;\n telemetryClient: TelemetryClient;\n config: CloudpackConfig;\n};\n\nexport interface CommandActionParams<TOptions extends object> {\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 /**\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 reporter: TaskReporter;\n\n abortSignal: AbortSignal;\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 * This should be called at or near the beginning of the action to initialize the config,\n * telemetry, and reporting. (See `createInitializeFunction` for implementation.)\n * `initialize` can be called with either a single string, `appPath` or an a string[], `appPaths`.\n * If it is called with a single string, it returns `Promise<InitContext>`\n * If it is called with a string[], it returns `Promise<InitContext[]>`\n */\n initialize: {\n (initializeOptions: { appPath: string; overrideOptions?: Partial<SharedOptions> }): Promise<InitContext>;\n (initializeOptions: { appPaths: string[]; overrideOptions?: Partial<SharedOptions> }): Promise<InitContext[]>;\n };\n\n /**\n * This should be called at the end of the action to dispose resources, log completion,\n * and exit the program. (See `createExitFunction` for implementation.)\n */\n exit: (result: { exitCode: number; message?: string }) => Promise<void>;\n}\n\n/**\n * Command action function. This is the type of the `execute` function which should be exported\n * from each command's `src/commands/<name>/execute.ts` module.\n */\nexport type CommandAction<TOptions> = (params: CommandActionParams<TOptions & SharedOptions>) => Promise<void>;\n\nexport type CommandActionModule<TOptions> = {\n execute: CommandAction<TOptions>;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.0",
|
|
4
4
|
"description": "The Cloudpack command line interface - a tool for managing fast inner and outer looping in web apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
"cloudpack": "./bin/cloudpack.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@ms-cloudpack/api-server": "^0.
|
|
14
|
-
"@ms-cloudpack/bundle-server": "^0.2.
|
|
15
|
-
"@ms-cloudpack/config": "^0.17.
|
|
16
|
-
"@ms-cloudpack/config-types": "^0.
|
|
13
|
+
"@ms-cloudpack/api-server": "^0.31.0",
|
|
14
|
+
"@ms-cloudpack/bundle-server": "^0.2.24",
|
|
15
|
+
"@ms-cloudpack/config": "^0.17.28",
|
|
16
|
+
"@ms-cloudpack/config-types": "^0.5.0",
|
|
17
17
|
"@ms-cloudpack/feature-flags": "^0.0.2",
|
|
18
18
|
"@ms-cloudpack/json-utilities": "^0.1.4",
|
|
19
|
-
"@ms-cloudpack/package-utilities": "^5.10.
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^5.10.3",
|
|
20
20
|
"@ms-cloudpack/path-string-parsing": "^1.1.3",
|
|
21
21
|
"@ms-cloudpack/path-utilities": "^2.5.0",
|
|
22
|
-
"@ms-cloudpack/remote-cache": "^0.
|
|
23
|
-
"@ms-cloudpack/app-server": "^0.1.
|
|
22
|
+
"@ms-cloudpack/remote-cache": "^0.5.0",
|
|
23
|
+
"@ms-cloudpack/app-server": "^0.1.27",
|
|
24
24
|
"@ms-cloudpack/task-reporter": "^0.11.1",
|
|
25
25
|
"@ms-cloudpack/telemetry": "^0.4.6",
|
|
26
26
|
"@yarnpkg/lockfile": "^1.1.0",
|