@ms-cloudpack/cli 0.72.52 → 0.72.54
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/bundle/execute.d.ts.map +1 -1
- package/lib/commands/bundle/execute.js +5 -10
- package/lib/commands/bundle/execute.js.map +1 -1
- package/lib/commands/info/lockFile/execute.js +1 -1
- package/lib/commands/info/lockFile/execute.js.map +1 -1
- package/lib/commands/info/nonSemverDeps/execute.d.ts.map +1 -1
- package/lib/commands/info/nonSemverDeps/execute.js +1 -2
- package/lib/commands/info/nonSemverDeps/execute.js.map +1 -1
- package/lib/commands/init/InitSummaryData.d.ts +11 -2
- package/lib/commands/init/InitSummaryData.d.ts.map +1 -1
- package/lib/commands/init/InitSummaryData.js +19 -6
- package/lib/commands/init/InitSummaryData.js.map +1 -1
- package/lib/commands/init/execute.d.ts.map +1 -1
- package/lib/commands/init/execute.js +15 -12
- package/lib/commands/init/execute.js.map +1 -1
- package/lib/commands/init/formatInitSummary.d.ts +5 -6
- package/lib/commands/init/formatInitSummary.d.ts.map +1 -1
- package/lib/commands/init/formatInitSummary.js +5 -14
- package/lib/commands/init/formatInitSummary.js.map +1 -1
- package/lib/commands/init/init.d.ts +5 -10
- package/lib/commands/init/init.d.ts.map +1 -1
- package/lib/commands/init/init.js +22 -40
- package/lib/commands/init/init.js.map +1 -1
- package/lib/commands/link/execute.d.ts.map +1 -1
- package/lib/commands/link/execute.js +1 -2
- package/lib/commands/link/execute.js.map +1 -1
- package/lib/commands/setup/execute.js +1 -1
- package/lib/commands/setup/execute.js.map +1 -1
- package/lib/commands/start/execute.d.ts.map +1 -1
- package/lib/commands/start/execute.js +26 -25
- package/lib/commands/start/execute.js.map +1 -1
- package/lib/commands/start/index.d.ts.map +1 -1
- package/lib/commands/start/index.js +4 -1
- package/lib/commands/start/index.js.map +1 -1
- package/lib/commands/start/openBrowser.d.ts +2 -0
- package/lib/commands/start/openBrowser.d.ts.map +1 -1
- package/lib/commands/start/openBrowser.js +4 -0
- package/lib/commands/start/openBrowser.js.map +1 -1
- package/lib/commands/start/types/StartOptions.d.ts +2 -2
- package/lib/commands/start/types/StartOptions.d.ts.map +1 -1
- package/lib/commands/start/types/StartOptions.js.map +1 -1
- package/lib/commands/sync/execute.d.ts.map +1 -1
- package/lib/commands/sync/execute.js +8 -21
- package/lib/commands/sync/execute.js.map +1 -1
- package/lib/commands/unlink/execute.d.ts.map +1 -1
- package/lib/commands/unlink/execute.js +1 -2
- package/lib/commands/unlink/execute.js.map +1 -1
- package/lib/types/AutoDispose.d.ts +1 -1
- package/lib/types/AutoDispose.d.ts.map +1 -1
- package/lib/types/AutoDispose.js.map +1 -1
- package/lib/types/CommandAction.d.ts +26 -18
- package/lib/types/CommandAction.d.ts.map +1 -1
- package/lib/types/CommandAction.js.map +1 -1
- package/lib/types/Disposable.d.ts +1 -1
- package/lib/types/Disposable.d.ts.map +1 -1
- package/lib/types/Disposable.js.map +1 -1
- package/lib/utilities/AutoDisposableList.d.ts +1 -1
- package/lib/utilities/AutoDisposableList.d.ts.map +1 -1
- package/lib/utilities/AutoDisposableList.js +4 -4
- package/lib/utilities/AutoDisposableList.js.map +1 -1
- package/lib/utilities/CloudpackCommand.d.ts +7 -4
- package/lib/utilities/CloudpackCommand.d.ts.map +1 -1
- package/lib/utilities/CloudpackCommand.js +7 -4
- package/lib/utilities/CloudpackCommand.js.map +1 -1
- package/lib/utilities/CommandExecutor.d.ts +16 -16
- package/lib/utilities/CommandExecutor.d.ts.map +1 -1
- package/lib/utilities/CommandExecutor.js +59 -26
- package/lib/utilities/CommandExecutor.js.map +1 -1
- package/lib/utilities/getCliStartTime.d.ts.map +1 -1
- package/lib/utilities/getCliStartTime.js +7 -3
- package/lib/utilities/getCliStartTime.js.map +1 -1
- package/package.json +14 -14
|
@@ -8,9 +8,8 @@ import path from 'path';
|
|
|
8
8
|
*/
|
|
9
9
|
export const execute = async (params) => {
|
|
10
10
|
// Use the current directory as the default package path.
|
|
11
|
-
const { options,
|
|
11
|
+
const { options, appPath, reporter } = params;
|
|
12
12
|
const { logResolveMap, cachePath } = options;
|
|
13
|
-
const { appPath } = contexts[0];
|
|
14
13
|
console.debug('Unlinking packages...');
|
|
15
14
|
const sessionResult = await getSessionToLink({ reporter, cachePath });
|
|
16
15
|
if (!sessionResult.session) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/unlink/execute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAiC,KAAK,EAAE,MAAM,EAAE,EAAE;IACpE,yDAAyD;IACzD,MAAM,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/unlink/execute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAiC,KAAK,EAAE,MAAM,EAAE,EAAE;IACpE,yDAAyD;IACzD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAC9C,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,O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AU,CAAC,CAAC;IAC/E,CAAC;IAED,2BAA2B;IAC3B,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClF,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;IAE5E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAClC,CAAC,CAAC","sourcesContent":["import type { CommandAction } from '../../types/CommandAction.js';\nimport type { UnlinkOptions } from './types/UnlinkOptions.js';\nimport { getSessionToLink } from '../link/getSessionToLink.js';\nimport { createCloudpackClient } from '@ms-cloudpack/api-server';\nimport { formatLinkSummary } from '../link/formatLinkSummary.js';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport path from 'path';\n\n/**\n * Defines the \"unlink\" verb entry point.\n */\nexport const execute: CommandAction<UnlinkOptions> = async (params) => {\n // Use the current directory as the default package path.\n const { options, appPath, reporter } = params;\n const { logResolveMap, cachePath } = options;\n\n console.debug('Unlinking packages...');\n\n const sessionResult = await getSessionToLink({ reporter, cachePath });\n if (!sessionResult.session) {\n return sessionResult;\n }\n const { session } = sessionResult;\n const client = await createCloudpackClient({ url: session.urls.apiServer, reporter });\n\n const message = `Unlinking paths for ${session.projectName} at \"${appPath}\"`;\n const task = reporter.addTask(message);\n\n // Send request to api server to link paths.\n const { resolveMap, linkedPaths } = await client.unlinkPath.query({\n linkedPath: {\n path: appPath,\n },\n });\n await client.close();\n\n if (linkedPaths.some((p) => p.path === appPath)) {\n // Close down with an error.\n task.complete({ status: 'fail', message: `Failed to unlink paths.`, forceShow: true });\n return { hasErrors: true, message: 'Failed to unlink paths.' };\n }\n\n if (logResolveMap) {\n // Write the unlinked resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map-unlinked.json'), resolveMap);\n }\n\n // Close down successfully.\n task.complete({ status: 'complete', message: `Unlinked paths`, forceShow: true });\n const linkSummary = formatLinkSummary({ session, resolveMap, linkedPaths });\n\n return { message: linkSummary };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoDispose.d.ts","sourceRoot":"","sources":["../../src/types/AutoDispose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,SAAS,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"AutoDispose.d.ts","sourceRoot":"","sources":["../../src/types/AutoDispose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,SAAS,UAAU,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoDispose.js","sourceRoot":"","sources":["../../src/types/AutoDispose.ts"],"names":[],"mappings":"","sourcesContent":["import type { Disposable } from './Disposable.js';\n\nexport type AutoDispose = <T extends Disposable>(
|
|
1
|
+
{"version":3,"file":"AutoDispose.js","sourceRoot":"","sources":["../../src/types/AutoDispose.ts"],"names":[],"mappings":"","sourcesContent":["import type { Disposable } from './Disposable.js';\n\nexport type AutoDispose = <T extends Disposable>(item: T) => T;\n"]}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
1
|
+
import type { CreateApiContextOptions } from '@ms-cloudpack/api-server';
|
|
3
2
|
import type { AutoDispose } from './AutoDispose.js';
|
|
4
3
|
import type { SharedOptions } from './SharedOptions.js';
|
|
4
|
+
import type { Span } from '@ms-cloudpack/telemetry';
|
|
5
5
|
/**
|
|
6
6
|
* Context for running a command in a specific app (after initialization).
|
|
7
|
-
* For convenience, this can be passed/spread directly to `
|
|
7
|
+
* For convenience, this can be passed/spread directly to `createApiContext`.
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export interface AppCommandContext extends Pick<CreateApiContextOptions, 'cachePath' | 'config' | 'reporter' | 'taskRunner' | 'telemetryClient'> {
|
|
10
|
+
/** App path (CWD for most operations). */
|
|
11
|
+
appPath: string;
|
|
12
|
+
}
|
|
10
13
|
export declare const ExitCodeSuccessful = 0;
|
|
11
14
|
export declare const ExitCodeGenericError = 1;
|
|
12
15
|
export declare const ExitCodeAuthenticationError = 2;
|
|
@@ -22,16 +25,9 @@ export interface CommandExitParams {
|
|
|
22
25
|
/** Exit code to use. Defaults to 1 if there are errors, 0 if not. */
|
|
23
26
|
exitCode?: ExitCode;
|
|
24
27
|
/** True if the user interrupted an operation (ctrl+C). Sets the message automatically. */
|
|
25
|
-
isInterrupted?:
|
|
28
|
+
isInterrupted?: boolean;
|
|
26
29
|
}
|
|
27
|
-
export interface CommandActionParams<TOptions extends object> {
|
|
28
|
-
/**
|
|
29
|
-
* App paths and corresponding contexts.
|
|
30
|
-
*
|
|
31
|
-
* Unless `discoverAppPaths: 'multi'` was set during command initialization in `<command>/index.ts`,
|
|
32
|
-
* there will only be one path/context.
|
|
33
|
-
*/
|
|
34
|
-
contexts: AppCommandContext[];
|
|
30
|
+
export interface CommandActionParams<TOptions extends object> extends AppCommandContext {
|
|
35
31
|
/**
|
|
36
32
|
* Command-specific options, parsed from `process.argv`.
|
|
37
33
|
* Types are generally defined in each command's `src/commands/<name>/types/<Name>Types.ts` module.
|
|
@@ -43,8 +39,15 @@ export interface CommandActionParams<TOptions extends object> {
|
|
|
43
39
|
* For example, in `echo somestring`, `somestring` is an argument.
|
|
44
40
|
*/
|
|
45
41
|
args: string[];
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Whether the command is being run for multiple apps. (It only runs on one app at a time, but
|
|
44
|
+
* multi-app may impact formatting choices or other behaviors.)
|
|
45
|
+
*/
|
|
46
|
+
isMultiApp: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Parent span for the command.
|
|
49
|
+
*/
|
|
50
|
+
span: Span;
|
|
48
51
|
/**
|
|
49
52
|
* Function that can be called with any `Disposable`s that should be cleaned up automatically
|
|
50
53
|
* when the program exits. (See `AutoDisposableList.add` for implementation.)
|
|
@@ -57,10 +60,15 @@ export interface CommandActionParams<TOptions extends object> {
|
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
62
|
* Command action function (executor). This is the type of the `execute` function which should
|
|
60
|
-
* be exported from each command's `src/commands/<name>/execute.ts` module
|
|
63
|
+
* be exported from each command's `src/commands/<name>/execute.ts` module and is called by
|
|
64
|
+
* `CommandExecutor` against each app.
|
|
61
65
|
*
|
|
62
|
-
* If it returns an object,
|
|
63
|
-
*
|
|
66
|
+
* - If it returns an object, CommandExecutor will call the exit handler with that object.
|
|
67
|
+
* - For multi-app, it will exit immediately if `isInterrupted` is set, but otherwise it will
|
|
68
|
+
* keep running and use the accumulation of the results.
|
|
69
|
+
* - If it returns null, it's assumed that this command is meant to keep running, such as `start`.
|
|
70
|
+
* - NOTE: Multi-app commands should not return null (if this is needed in the future, it will
|
|
71
|
+
* require extra logic in CommandExecutor).
|
|
64
72
|
*/
|
|
65
73
|
export type CommandAction<TOptions> = (params: CommandActionParams<TOptions & SharedOptions>) => Promise<CommandExitParams | null>;
|
|
66
74
|
export type CommandActionModule<TOptions> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandAction.d.ts","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
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,KAA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C,KAClD,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;AAEvC,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":"
|
|
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}\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/**\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 | null>;\n\nexport type CommandActionModule<TOptions> = {\n execute: CommandAction<TOptions>;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Disposable.d.ts","sourceRoot":"","sources":["../../src/types/Disposable.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Disposable.d.ts","sourceRoot":"","sources":["../../src/types/Disposable.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Disposable.js","sourceRoot":"","sources":["../../src/types/Disposable.ts"],"names":[],"mappings":"","sourcesContent":["export interface Disposable {\n dispose
|
|
1
|
+
{"version":3,"file":"Disposable.js","sourceRoot":"","sources":["../../src/types/Disposable.ts"],"names":[],"mappings":"","sourcesContent":["export interface Disposable {\n dispose?: () => void | Promise<void>;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Disposable } from '../types/Disposable.js';
|
|
2
2
|
export declare class AutoDisposableList {
|
|
3
3
|
private readonly disposables;
|
|
4
|
-
add<T extends Disposable>(
|
|
4
|
+
add<T extends Disposable>(item: T): T;
|
|
5
5
|
dispose(): Promise<void>;
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=AutoDisposableList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoDisposableList.d.ts","sourceRoot":"","sources":["../../src/utilities/AutoDisposableList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAEzC,GAAG,CAAC,CAAC,SAAS,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"AutoDisposableList.d.ts","sourceRoot":"","sources":["../../src/utilities/AutoDisposableList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAEzC,GAAG,CAAC,CAAC,SAAS,UAAU,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC;IAK/B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAgBtC"}
|
|
@@ -2,15 +2,15 @@ export class AutoDisposableList {
|
|
|
2
2
|
constructor() {
|
|
3
3
|
this.disposables = [];
|
|
4
4
|
}
|
|
5
|
-
add(
|
|
6
|
-
this.disposables.push(
|
|
7
|
-
return
|
|
5
|
+
add(item) {
|
|
6
|
+
this.disposables.push(item);
|
|
7
|
+
return item;
|
|
8
8
|
}
|
|
9
9
|
async dispose() {
|
|
10
10
|
let errorCount = 0;
|
|
11
11
|
await Promise.all(this.disposables.map(async (d) => {
|
|
12
12
|
try {
|
|
13
|
-
await d.dispose();
|
|
13
|
+
await d.dispose?.();
|
|
14
14
|
}
|
|
15
15
|
catch (err) {
|
|
16
16
|
console.error(`Failed to dispose: ${err.stack || err}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoDisposableList.js","sourceRoot":"","sources":["../../src/utilities/AutoDisposableList.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;IAA/B;QACmB,gBAAW,GAAiB,EAAE,CAAC;IAuBlD,CAAC;IArBQ,GAAG,CAAuB,
|
|
1
|
+
{"version":3,"file":"AutoDisposableList.js","sourceRoot":"","sources":["../../src/utilities/AutoDisposableList.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;IAA/B;QACmB,gBAAW,GAAiB,EAAE,CAAC;IAuBlD,CAAC;IArBQ,GAAG,CAAuB,IAAO;QACtC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,IAAI,UAAU,GAAG,CAAC,CAAC;QACnB,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YAC/B,IAAI,CAAC;gBACH,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;YACtB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,sBAAuB,GAAa,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC;gBACnE,UAAU,EAAE,CAAC;YACf,CAAC;QACH,CAAC,CAAC,CACH,CAAC;QACF,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,qBAAqB,UAAU,gBAAgB,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { Disposable } from '../types/Disposable.js';\n\nexport class AutoDisposableList {\n private readonly disposables: Disposable[] = [];\n\n public add<T extends Disposable>(item: T): T {\n this.disposables.push(item);\n return item;\n }\n\n public async dispose(): Promise<void> {\n let errorCount = 0;\n await Promise.all(\n this.disposables.map(async (d) => {\n try {\n await d.dispose?.();\n } catch (err) {\n console.error(`Failed to dispose: ${(err as Error).stack || err}`);\n errorCount++;\n }\n }),\n );\n if (errorCount) {\n throw new Error(`Failed to dispose ${errorCount} disposable(s)`);\n }\n }\n}\n"]}
|
|
@@ -2,18 +2,21 @@ import { Command, Option, type AddHelpTextPosition, type Argument, type OutputCo
|
|
|
2
2
|
import type { CommandActionModule } from '../types/CommandAction.js';
|
|
3
3
|
import type { ProgramOptions } from '../types/ProgramOptions.js';
|
|
4
4
|
import type { SharedOptions } from '../types/SharedOptions.js';
|
|
5
|
-
import { type
|
|
5
|
+
import { type CommandExecutorParams } from './CommandExecutor.js';
|
|
6
6
|
/**
|
|
7
7
|
* Parameters for creating a command.
|
|
8
8
|
* `TOptions` should be the command-specific options (if any), e.g. `StartOptions`.
|
|
9
9
|
*/
|
|
10
|
-
interface CloudpackCommandParams<TOptions extends object, TArguments extends object> extends
|
|
10
|
+
interface CloudpackCommandParams<TOptions extends object, TArguments extends object> extends Pick<CommandExecutorParams, 'discoverAppPaths'> {
|
|
11
11
|
/** Command name */
|
|
12
12
|
name: string;
|
|
13
13
|
/** Command description */
|
|
14
14
|
description: string;
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Options specific to this command. The record ensures that all options are available in the CLI.
|
|
17
|
+
* Allow multiple options for the same key since commander supports it with negatable options.
|
|
18
|
+
*/
|
|
19
|
+
options?: Record<keyof TOptions, Option | Option[]>;
|
|
17
20
|
/** Arguments specific to this command. Key order determines the arg order. */
|
|
18
21
|
args?: Record<keyof TArguments, Argument>;
|
|
19
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudpackCommand.d.ts","sourceRoot":"","sources":["../../src/utilities/CloudpackCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,EAAE,KAAK,mBAAmB,EAAE,KAAK,QAAQ,EAAE,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAmB,KAAK,
|
|
1
|
+
{"version":3,"file":"CloudpackCommand.d.ts","sourceRoot":"","sources":["../../src/utilities/CloudpackCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,EAAE,KAAK,mBAAmB,EAAE,KAAK,QAAQ,EAAE,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAKnF;;;GAGG;AACH,UAAU,sBAAsB,CAAC,QAAQ,SAAS,MAAM,EAA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Aa,SAAS,MAAM,EAAE,eAAe,SAAS,MAAM,GAAG,KAAK,EACvF,MAAM,EAAE,sBAAsB,CAAC,aAAa,EAAE,eAAe,CAAC,GAC7D,gBAAgB,CAAC,aAAa,EAAE,eAAe,CAAC;IAQnD,qEAAqE;IACxD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAWjC,qGAAqG;IACrG,OAAO,CAAC,aAAa;IAMrB,iGAAiG;IACjG,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,UAAU;CAqCnB"}
|
|
@@ -77,11 +77,14 @@ export class CloudpackCommand {
|
|
|
77
77
|
}
|
|
78
78
|
/** Add options. The generic enforces that option objects are included for all keys of a type. */
|
|
79
79
|
_addOptions(options, hideOptions) {
|
|
80
|
-
for (const [name,
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
for (const [name, optionOrOptions] of Object.entries(options)) {
|
|
81
|
+
const optionArray = Array.isArray(optionOrOptions) ? optionOrOptions : [optionOrOptions];
|
|
82
|
+
for (const option of optionArray) {
|
|
83
|
+
if (hideOptions === true || hideOptions?.includes(name)) {
|
|
84
|
+
option.hideHelp();
|
|
85
|
+
}
|
|
86
|
+
this._command.addOption(option);
|
|
83
87
|
}
|
|
84
|
-
this._command.addOption(option);
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
_addAction(getExecutor) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudpackCommand.js","sourceRoot":"","sources":["../../src/utilities/CloudpackCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAqE,MAAM,WAAW,CAAC;AAIrH,OAAO,EAAE,eAAe,EAAoC,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAwDjD;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IAK3B;;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AAM,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,cAAc,EAAE,IAAI,CAAC,eAAe;gBACpC,IAAI;gBACJ,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;aACzC,CAAC,CAAC;YACH,MAAM,eAAe,CAAC,OAAO,EAAE,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,aAAc,SAAQ,IAAI;IAC9B,cAAc,CAAC,GAAY;QACzB,MAAM,OAAO,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QAE1C,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,WAAW,EAAE,CAAC;YAC/B,4EAA4E;YAC5E,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,SAAS,CAAC,CAAC;QACjE,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import { Command, Help, Option, type AddHelpTextPosition, type Argument, type OutputConfiguration } from 'commander';\nimport type { CommandActionModule } from '../types/CommandAction.js';\nimport type { ProgramOptions } from '../types/ProgramOptions.js';\nimport type { SharedOptions } from '../types/SharedOptions.js';\nimport { CommandExecutor, type CommandExecutorSharedParams } from './CommandExecutor.js';\nimport { environmentInfo } from '@ms-cloudpack/environment';\nimport { parseFeature } from './parseFeature.js';\nimport type { AppPathDiscoveryMode } from '../types/AppPathDiscoveryMode.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 CommandExecutorSharedParams {\n /** Command name */\n name: string;\n\n /** Command description */\n description: string;\n\n /** Options specific to this command. The record ensures that all options are available in the CLI. */\n options?: Record<keyof TOptions, 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 _programOptions: ProgramOptions;\n private _discoverAppPaths: AppPathDiscoveryMode | undefined;\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 programOptions: ProgramOptions;\n /** This must be undefined for the top-level program command */\n parent?: Command;\n },\n ) {\n this._programOptions = params.programOptions;\n this._discoverAppPaths = params.discoverAppPaths;\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 command.createHelp = () => new CloudpackHelp();\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._addArguemnts<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 about the running tasks.'),\n debug: new Option('-d, --debug', 'Show debug information (superset of --verbose).').conflicts('verbose'),\n quiet: new Option('-q, --quiet', 'Disable non-essential logging.').conflicts('verbose').conflicts('debug'),\n color:\n // In the parsed options, this will be a boolean `color` with default value true (except in tests and CI)\n new Option('-n, --no-color', 'Disable colors in the output.').default(\n !environmentInfo.isJest && !environmentInfo.isLage && !environmentInfo.isCI,\n ),\n features: new Option('--features <featureNames...>', 'Enable experimental features.').argParser(parseFeature),\n cachePath: new Option(\n '--cache-path <path>',\n 'Custom cache folder. To change the default, run `cloudpack config set cachePath <path>`.',\n ),\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._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._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 _addArguemnts<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>,\n hideOptions?: Array<keyof TAddOptions> | true,\n ): void {\n for (const [name, option] of Object.entries(options) as [keyof TAddOptions, Option][]) {\n if (hideOptions === true || hideOptions?.includes(name)) {\n option.hideHelp();\n }\n this._command.addOption(option);\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 programOptions: this._programOptions,\n verb,\n discoverAppPaths: this._discoverAppPaths,\n });\n await commandExecutor.execute();\n });\n }\n}\n\nclass CloudpackHelp extends Help {\n visibleOptions(cmd: Command): Option[] {\n const options = super.visibleOptions(cmd);\n\n if (cmd.name() !== 'cloudpack') {\n // Remove --version from help except at the top level (it's not very useful)\n return options.filter((option) => option.name() !== 'version');\n }\n\n return options;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CloudpackCommand.js","sourceRoot":"","sources":["../../src/utilities/CloudpackCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAqE,MAAM,WAAW,CAAC;AAIrH,OAAO,EAAE,eAAe,EAA8B,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA2DjD;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IAK3B;;;OAGG;IACH;IACE,4EAA4E;IAC5E,MAIC;QAED,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAEjD,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;QACpC,OAAO,CAAC,UAAU,GAAG,GAAG,EAAE,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pE,IAAI,EAAE,aAAa;gBACnB,OAAO;gBACP,OAAO;gBACP,cAAc,EAAE,IAAI,CAAC,eAAe;gBACpC,IAAI;gBACJ,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;aACzC,CAAC,CAAC;YACH,MAAM,eAAe,CAAC,OAAO,EAAE,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,aAAc,SAAQ,IAAI;IAC9B,cAAc,CAAC,GAAY;QACzB,MAAM,OAAO,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QAE1C,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,WAAW,EAAE,CAAC;YAC/B,4EAA4E;YAC5E,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,SAAS,CAAC,CAAC;QACjE,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import { Command, Help, Option, type AddHelpTextPosition, type Argument, type OutputConfiguration } from 'commander';\nimport type { CommandActionModule } from '../types/CommandAction.js';\nimport type { ProgramOptions } from '../types/ProgramOptions.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 type { AppPathDiscoveryMode } from '../types/AppPathDiscoveryMode.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 Pick<CommandExecutorParams, 'discoverAppPaths'> {\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 _programOptions: ProgramOptions;\n private _discoverAppPaths: AppPathDiscoveryMode | undefined;\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 programOptions: ProgramOptions;\n /** This must be undefined for the top-level program command */\n parent?: Command;\n },\n ) {\n this._programOptions = params.programOptions;\n this._discoverAppPaths = params.discoverAppPaths;\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 command.createHelp = () => new CloudpackHelp();\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._addArguemnts<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 about the running tasks.'),\n debug: new Option('-d, --debug', 'Show debug information (superset of --verbose).').conflicts('verbose'),\n quiet: new Option('-q, --quiet', 'Disable non-essential logging.').conflicts('verbose').conflicts('debug'),\n color:\n // In the parsed options, this will be a boolean `color` with default value true (except in tests and CI)\n new Option('-n, --no-color', 'Disable colors in the output.').default(\n !environmentInfo.isJest && !environmentInfo.isLage && !environmentInfo.isCI,\n ),\n features: new Option('--features <featureNames...>', 'Enable experimental features.').argParser(parseFeature),\n cachePath: new Option(\n '--cache-path <path>',\n 'Custom cache folder. To change the default, run `cloudpack config set cachePath <path>`.',\n ),\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._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._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 _addArguemnts<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 programOptions: this._programOptions,\n verb,\n discoverAppPaths: this._discoverAppPaths,\n });\n await commandExecutor.execute();\n });\n }\n}\n\nclass CloudpackHelp extends Help {\n visibleOptions(cmd: Command): Option[] {\n const options = super.visibleOptions(cmd);\n\n if (cmd.name() !== 'cloudpack') {\n // Remove --version from help except at the top level (it's not very useful)\n return options.filter((option) => option.name() !== 'version');\n }\n\n return options;\n }\n}\n"]}
|
|
@@ -3,7 +3,18 @@ import type { ProgramOptions } from '../types/ProgramOptions.js';
|
|
|
3
3
|
import type { SharedOptions } from '../types/SharedOptions.js';
|
|
4
4
|
import type { ReusedOptions } from '../types/ReusedOptions.js';
|
|
5
5
|
import type { AppPathDiscoveryMode } from '../types/AppPathDiscoveryMode.js';
|
|
6
|
-
export
|
|
6
|
+
export type BaseCommandExecutorOptions = SharedOptions & Pick<ReusedOptions, 'app'>;
|
|
7
|
+
export interface CommandExecutorParams<TOptions extends BaseCommandExecutorOptions = BaseCommandExecutorOptions> {
|
|
8
|
+
/** Command-specific arguments */
|
|
9
|
+
args: string[];
|
|
10
|
+
/** Command-specific and shared options. */
|
|
11
|
+
options: TOptions;
|
|
12
|
+
/** Function to execute the command. */
|
|
13
|
+
execute: CommandAction<TOptions>;
|
|
14
|
+
/** Shared program-level configuration. */
|
|
15
|
+
programOptions: ProgramOptions;
|
|
16
|
+
/** Verb being run, e.g. `bundle` or `cache clean`. */
|
|
17
|
+
verb: string;
|
|
7
18
|
/**
|
|
8
19
|
* By default, the command will run against `cwd` (usually `process.cwd()`).
|
|
9
20
|
* If this option is set, attempt to discover app path(s) instead.
|
|
@@ -15,7 +26,7 @@ export interface CommandExecutorSharedParams {
|
|
|
15
26
|
/**
|
|
16
27
|
* This class manages orchestration and shared state while executing a command.
|
|
17
28
|
*/
|
|
18
|
-
export declare class CommandExecutor<TOptions extends
|
|
29
|
+
export declare class CommandExecutor<TOptions extends BaseCommandExecutorOptions> {
|
|
19
30
|
private _options;
|
|
20
31
|
private _execute;
|
|
21
32
|
private _programOptions;
|
|
@@ -23,25 +34,14 @@ export declare class CommandExecutor<TOptions extends SharedOptions & Pick<Reuse
|
|
|
23
34
|
private _discoverAppPaths;
|
|
24
35
|
private _reporter;
|
|
25
36
|
private _autoDisposableList;
|
|
26
|
-
private _abortController;
|
|
27
37
|
private _hasCalledExit;
|
|
28
38
|
private _args;
|
|
29
39
|
private _sigintCount;
|
|
30
|
-
private
|
|
40
|
+
private _onInterrupt?;
|
|
41
|
+
private _getMessageOnInterrupt?;
|
|
31
42
|
private static _activeInstances;
|
|
32
43
|
static exitAll(params: CommandExitParams): Promise<void>;
|
|
33
|
-
constructor(params:
|
|
34
|
-
/** Command-specific arguments */
|
|
35
|
-
args: string[];
|
|
36
|
-
/** Command-specific and shared options. */
|
|
37
|
-
options: TOptions;
|
|
38
|
-
/** Function to execute the command. */
|
|
39
|
-
execute: CommandAction<TOptions>;
|
|
40
|
-
/** Shared program-level configuration. */
|
|
41
|
-
programOptions: ProgramOptions;
|
|
42
|
-
/** Verb being run, e.g. `bundle` or `cache clean`. */
|
|
43
|
-
verb: string;
|
|
44
|
-
});
|
|
44
|
+
constructor(params: CommandExecutorParams<TOptions>);
|
|
45
45
|
/** Run the command. */
|
|
46
46
|
execute(): Promise<void>;
|
|
47
47
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandExecutor.d.ts","sourceRoot":"","sources":["../../src/utilities/CommandExecutor.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAqB,MAAM,2BAA2B,CAAC;AACrG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAK/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"CommandExecutor.d.ts","sourceRoot":"","sources":["../../src/utilities/CommandExecutor.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAqB,MAAM,2BAA2B,CAAC;AACrG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA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D,MAAM,EAAE,qBAAqB,CAAC,QAAQ,CAAC;IAWnD,uBAAuB;IAEV,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAsErC;;;OAGG;YACW,mBAAmB;IA6FjC,qEAAqE;IACrE,OAAO,CAAC,+BAA+B;YAYzB,cAAc;IAyE5B,SAAS,CAAC,cAAc,QAAO,IAAI,CAgBjC;IAEF;;;OAGG;cACa,KAAK,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,KAAK,CAAC;CAgCjE"}
|
|
@@ -8,6 +8,7 @@ import { getVersion } from '@ms-cloudpack/package-utilities';
|
|
|
8
8
|
import { environmentInfo } from '@ms-cloudpack/environment';
|
|
9
9
|
import { getCliStartTime } from './getCliStartTime.js';
|
|
10
10
|
import { discoverAppPaths } from './discoverAppPaths.js';
|
|
11
|
+
import { TaskRunner } from '@ms-cloudpack/api-server';
|
|
11
12
|
/**
|
|
12
13
|
* This class manages orchestration and shared state while executing a command.
|
|
13
14
|
*/
|
|
@@ -19,12 +20,11 @@ export class CommandExecutor {
|
|
|
19
20
|
await instance._exit(params);
|
|
20
21
|
process.off('SIGINT', instance._sigintHandler);
|
|
21
22
|
}
|
|
22
|
-
CommandExecutor._activeInstances =
|
|
23
|
+
CommandExecutor._activeInstances = new Set();
|
|
23
24
|
}
|
|
24
25
|
constructor(params) {
|
|
25
26
|
this._hasCalledExit = false;
|
|
26
27
|
this._sigintCount = 0;
|
|
27
|
-
this._getMessageOnInterrupt = () => `Interrupted by user`;
|
|
28
28
|
this._sigintHandler = () => {
|
|
29
29
|
this._sigintCount++;
|
|
30
30
|
if (this._sigintCount > 1) {
|
|
@@ -34,6 +34,7 @@ export class CommandExecutor {
|
|
|
34
34
|
// eslint-disable-next-line no-restricted-properties -- top-level cleanup
|
|
35
35
|
process.exit(1);
|
|
36
36
|
}
|
|
37
|
+
this._onInterrupt?.();
|
|
37
38
|
// We are trying to exit gracefully.
|
|
38
39
|
void this._exit({ isInterrupted: true, message: '' });
|
|
39
40
|
};
|
|
@@ -44,43 +45,72 @@ export class CommandExecutor {
|
|
|
44
45
|
this._verb = params.verb;
|
|
45
46
|
this._discoverAppPaths = params.discoverAppPaths;
|
|
46
47
|
this._reporter = new TaskReporter();
|
|
47
|
-
this._abortController = new AbortController();
|
|
48
48
|
this._autoDisposableList = new AutoDisposableList();
|
|
49
49
|
}
|
|
50
50
|
/** Run the command. */
|
|
51
51
|
// This has to be a separate method because constructors can't be async.
|
|
52
52
|
async execute() {
|
|
53
|
-
CommandExecutor._activeInstances.
|
|
53
|
+
CommandExecutor._activeInstances.add(this);
|
|
54
54
|
try {
|
|
55
55
|
// Handle SIGINT (Ctrl+C) gracefully.
|
|
56
|
-
|
|
56
|
+
if (!environmentInfo.isJest) {
|
|
57
|
+
process.on('SIGINT', this._sigintHandler);
|
|
58
|
+
}
|
|
57
59
|
const contexts = await this._initializeContexts();
|
|
58
60
|
if (!Array.isArray(contexts)) {
|
|
59
61
|
await this._exit(contexts);
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
const spanName = `${this._verb.toUpperCase().replace(/ /g, '_')}_EXECUTE`;
|
|
65
|
+
const results = [];
|
|
66
|
+
for (const context of contexts) {
|
|
67
|
+
// Call the execute function which is the real command logic
|
|
68
|
+
// (ie: real init command logic, real start command logic, etc.)
|
|
69
|
+
const result = await context.telemetryClient.tracer.startActiveSpan(spanName, async (span) => {
|
|
70
|
+
this._onInterrupt = () => {
|
|
71
|
+
span.setAttribute('isInterrupted', true);
|
|
72
|
+
span.end();
|
|
73
|
+
};
|
|
74
|
+
return this._execute({
|
|
75
|
+
...context,
|
|
76
|
+
span,
|
|
77
|
+
isMultiApp: contexts.length > 1,
|
|
78
|
+
args: this._args,
|
|
79
|
+
options: this._options,
|
|
80
|
+
autoDispose: (disposable) => this._autoDisposableList.add(disposable),
|
|
81
|
+
setInterruptMessageHandler: (getMessage) => {
|
|
82
|
+
this._getMessageOnInterrupt = getMessage;
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
if (result?.isInterrupted) {
|
|
87
|
+
return await this._exit(result);
|
|
88
|
+
}
|
|
89
|
+
if (result) {
|
|
90
|
+
results.push(result);
|
|
91
|
+
}
|
|
92
|
+
else if (result !== null) {
|
|
93
|
+
// If the command returned null, this means it should keep running (e.g. start).
|
|
94
|
+
// We disallow returning undefined to avoid accidents.
|
|
95
|
+
throw new Error('Command executor must return exit options or null');
|
|
96
|
+
}
|
|
97
|
+
this._onInterrupt = undefined;
|
|
98
|
+
}
|
|
99
|
+
if (results.length) {
|
|
100
|
+
// If one or more apps returned a result, exit.
|
|
101
|
+
await this._exit({
|
|
102
|
+
message: results.map((r) => r.message).join('\n'),
|
|
103
|
+
hasErrors: results.some((r) => r.hasErrors),
|
|
104
|
+
// If any app returned a non-zero exit code, use that.
|
|
105
|
+
exitCode: results.find(({ exitCode }) => !!exitCode)?.exitCode,
|
|
106
|
+
});
|
|
77
107
|
}
|
|
78
108
|
}
|
|
79
109
|
catch (error) {
|
|
80
110
|
// If an error occurs, exit the process with a non-zero exit code.
|
|
81
111
|
await this._exit({
|
|
82
112
|
hasErrors: true,
|
|
83
|
-
message: error
|
|
113
|
+
message: error.stack || error.message || String(error),
|
|
84
114
|
});
|
|
85
115
|
}
|
|
86
116
|
}
|
|
@@ -108,6 +138,8 @@ export class CommandExecutor {
|
|
|
108
138
|
appPaths = [this._programOptions.cwd];
|
|
109
139
|
}
|
|
110
140
|
const configOptions = this._getConfigOptionsFromCliOptions();
|
|
141
|
+
// The task runner is shared between all apps so that task results can potentially be reused.
|
|
142
|
+
const taskRunner = new TaskRunner();
|
|
111
143
|
const contexts = [];
|
|
112
144
|
const helpMessages = new Set();
|
|
113
145
|
const configs = {};
|
|
@@ -162,6 +194,7 @@ export class CommandExecutor {
|
|
|
162
194
|
config,
|
|
163
195
|
reporter: this._reporter,
|
|
164
196
|
telemetryClient,
|
|
197
|
+
taskRunner,
|
|
165
198
|
});
|
|
166
199
|
}
|
|
167
200
|
return contexts;
|
|
@@ -224,7 +257,7 @@ export class CommandExecutor {
|
|
|
224
257
|
arguments: programOptions.argv.slice(3).join(' '),
|
|
225
258
|
environment: environmentInfo.isCI ? 'ci' : environmentInfo.isCodespaces ? 'codespaces' : 'local',
|
|
226
259
|
appName: appName || '<unknown>',
|
|
227
|
-
mode: config.mode
|
|
260
|
+
mode: config.mode,
|
|
228
261
|
features: enabledFeatureNames,
|
|
229
262
|
externalCorrelationId: environmentInfo.cloudpack.telemetryExternalCorrelationId,
|
|
230
263
|
// Azure DevOps build attributes
|
|
@@ -244,7 +277,7 @@ export class CommandExecutor {
|
|
|
244
277
|
*/
|
|
245
278
|
async _exit(params) {
|
|
246
279
|
const { hasErrors = this._reporter.hasErrors(), exitCode = hasErrors ? 1 : 0 } = params;
|
|
247
|
-
const message = params.isInterrupted ? this._getMessageOnInterrupt() : params.message;
|
|
280
|
+
const message = params.isInterrupted ? this._getMessageOnInterrupt?.() || 'Interrupted by user' : params.message;
|
|
248
281
|
if (this._hasCalledExit) {
|
|
249
282
|
// Skip most of the operations if exit() was called multiple times.
|
|
250
283
|
// But only use the error message if not in a test, due to the way we're mocking process.exit.
|
|
@@ -257,8 +290,6 @@ export class CommandExecutor {
|
|
|
257
290
|
}
|
|
258
291
|
else {
|
|
259
292
|
this._hasCalledExit = true;
|
|
260
|
-
// Let the execute function know that we are exiting.
|
|
261
|
-
this._abortController.abort();
|
|
262
293
|
// Dispose all registered disposables.
|
|
263
294
|
await this._autoDisposableList.dispose();
|
|
264
295
|
// Show the summary message (this will throw if called twice).
|
|
@@ -267,10 +298,12 @@ export class CommandExecutor {
|
|
|
267
298
|
showHelp: exitCode !== 0,
|
|
268
299
|
});
|
|
269
300
|
}
|
|
301
|
+
CommandExecutor._activeInstances.delete(this);
|
|
302
|
+
process.off('SIGINT', this._sigintHandler);
|
|
270
303
|
// eslint-disable-next-line no-restricted-properties -- top-level cleanup
|
|
271
304
|
process.exit(exitCode);
|
|
272
305
|
}
|
|
273
306
|
}
|
|
274
307
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- options type isn't used
|
|
275
|
-
CommandExecutor._activeInstances =
|
|
308
|
+
CommandExecutor._activeInstances = new Set();
|
|
276
309
|
//# sourceMappingURL=CommandExecutor.js.map
|