Skip to content

Commit 7c6d7cc

Browse files
author
Nicholas Pape
authored
Add enabled toggle to both GulpTask and IExecutable (microsoft#113)
* Adds an enabled toggle to both the IExecutable and Gulptask * Changefile * Lint errors
1 parent e14e08b commit 7c6d7cc

4 files changed

Lines changed: 31 additions & 10 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/gulp-core-build",
5+
"comment": "Add an enabled toggle to IExecutable and GulpTask. Using this toggle is now preferred to overriding the isEnabled function.",
6+
"type": "minor"
7+
}
8+
],
9+
"email": "nickpape@users.noreply.github.com"
10+
}

common/reviews/api/gulp-core-build.api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ class GulpTask<TASK_CONFIG> implements IExecutable {
4242
public buildConfig: IBuildConfig;
4343
public cleanMatch: string[];
4444
public copyFile(localSourcePath: string, localDestPath?: string): void;
45+
public enabled: boolean;
4546
public execute(config: IBuildConfig): Promise<void>;
4647
public abstract executeTask(gulp: gulp.Gulp | GulpProxy, completeCallback?: (result?: Object) => void): Promise<Object> | NodeJS.ReadWriteStream | void;
4748
public fileError(filePath: string, line: number, column: number, errorCode: string, message: string): void;
4849
public fileExists(localPath: string): boolean;
4950
public fileWarning(filePath: string, line: number, column: number, warningCode: string, message: string): void;
5051
public getCleanMatch(buildConfig: IBuildConfig, taskConfig: TASK_CONFIG = this.taskConfig): string[];
51-
public isEnabled(buildConfig: IBuildConfig): boolean;
52+
public isEnabled(config?: IBuildConfig): boolean;
5253
protected loadSchema(): Object;
5354
public log(message: string): void;
5455
public logError(message: string): void;
@@ -108,6 +109,8 @@ interface ICustomGulpTask {
108109

109110
// (undocumented)
110111
interface IExecutable {
112+
// (undocumented)
113+
enabled?: boolean;
111114
execute: (config: IBuildConfig) => Promise<void>;
112115
getCleanMatch?: (config: IBuildConfig, taskConfig?: any) => string[];
113116
isEnabled?: (config?: IBuildConfig) => boolean;

gulp-core-build/src/IExecutable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export interface IExecutable {
1010
/** Optional name to give the task. If no name is provided, the "Running subtask" logging will be silent. */
1111
name?: string;
1212

13+
enabled?: boolean;
14+
1315
/** Optional callback to indicate if the task is enabled or not. */
1416
isEnabled?: (config?: IBuildConfig) => boolean;
1517

gulp-core-build/src/tasks/GulpTask.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,27 @@ export abstract class GulpTask<TASK_CONFIG> implements IExecutable {
3636
* will return this value.
3737
*/
3838
public cleanMatch: string[];
39+
/**
40+
* Indicates whether this task should be executed or not. This toggle is used by isEnabled() to determine
41+
* if the task should run. Since some tasks have more complex logic to determine if they should run or
42+
* not, the isEnabled() function can be overriden.
43+
*/
44+
public enabled: boolean = true;
3945

4046
/**
4147
* The memoized schema for this task. Should not be utilized by child classes, use schema property instead.
4248
*/
4349
private _schema: Object;
4450

51+
/**
52+
* Overridable function which returns true if this task should be executed, or false if it should be skipped.
53+
* @param buildConfig - the build configuration which should be used when determining if the task is enabled
54+
* @returns true if the build is not redundant and the enabled toggle is true
55+
*/
56+
public isEnabled(config?: IBuildConfig): boolean {
57+
return (!config || !config.isRedundantBuild) && this.enabled;
58+
};
59+
4560
/**
4661
* A JSON Schema object which will be used to validate this task's configuration file.
4762
* @returns a z-schema schema definition
@@ -110,15 +125,6 @@ export abstract class GulpTask<TASK_CONFIG> implements IExecutable {
110125
}
111126
}
112127

113-
/**
114-
* Overridable function which returns true if this task should be executed, or false if it should be skipped.
115-
* @param buildConfig - the build configuration which should be used when determining if the task is enabled
116-
* @returns true if the build is not redundant
117-
*/
118-
public isEnabled(buildConfig: IBuildConfig): boolean {
119-
return (!buildConfig || !buildConfig.isRedundantBuild);
120-
}
121-
122128
/**
123129
* When the task is executed by the build system, this function is called once. Note that this function
124130
* must either return a Promise, a Stream, or call the completeCallback() parameter.

0 commit comments

Comments
 (0)