-
Notifications
You must be signed in to change notification settings - Fork 683
Expand file tree
/
Copy pathBaseScriptAction.ts
More file actions
55 lines (47 loc) · 2.17 KB
/
BaseScriptAction.ts
File metadata and controls
55 lines (47 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import type { CommandLineParameter } from '@rushstack/ts-command-line';
import { BaseRushAction, type IBaseRushActionOptions } from '../actions/BaseRushAction';
import type { Command, CommandLineConfiguration, IParameterJson } from '../../api/CommandLineConfiguration';
import { defineCustomParameters } from '../parsing/defineCustomParameters';
/**
* Constructor parameters for BaseScriptAction
*/
export interface IBaseScriptActionOptions<TCommand extends Command> extends IBaseRushActionOptions {
commandLineConfiguration: CommandLineConfiguration;
command: TCommand;
}
/**
* Base class for command-line actions that are implemented using user-defined scripts.
*
* @remarks
* Compared to the normal built-in actions, these actions are special because (1) they
* can be discovered dynamically via common/config/command-line.json, and (2)
* user-defined command-line parameters can be passed through to the script.
*
* The two subclasses are BulkScriptAction and GlobalScriptAction.
*/
export abstract class BaseScriptAction<TCommand extends Command> extends BaseRushAction {
protected readonly commandLineConfiguration: CommandLineConfiguration;
protected readonly customParameters: Map<IParameterJson, CommandLineParameter> = new Map();
protected readonly command: TCommand;
public constructor(options: IBaseScriptActionOptions<TCommand>) {
super(options);
this.commandLineConfiguration = options.commandLineConfiguration;
this.command = options.command;
}
protected defineScriptParameters(): void {
if (!this.commandLineConfiguration) {
return;
}
// Define remainder parameter if the command allows it
if (this.command.allowRemainderArguments) {
this.defineCommandLineRemainder({
description:
'Additional command-line arguments to be passed through to the shell command or npm script'
});
}
// Use the centralized helper to create CommandLineParameter instances
defineCustomParameters(this, this.command.associatedParameters, this.customParameters);
}
}