@@ -28,7 +28,7 @@ interface IPackageDependencies extends IPackageDeps {
2828/**
2929 * A TaskRunner task which cleans and builds a project
3030 */
31- export default class ProjectBuildTask implements ITaskDefinition {
31+ export default class ProjectTask implements ITaskDefinition {
3232 public get name ( ) : string {
3333 return this . _rushProject . packageName ;
3434 }
@@ -40,28 +40,29 @@ export default class ProjectBuildTask implements ITaskDefinition {
4040 private _rushConfiguration : RushConfiguration ,
4141 private _commandToRun : string ,
4242 private _customFlags : string [ ] ,
43- public isIncrementalBuildAllowed : boolean
43+ public isIncrementalBuildAllowed : boolean ,
44+ private _optional : boolean
4445 ) { }
4546
4647 public execute ( writer : ITaskWriter ) : Promise < TaskStatus > {
4748 return new Promise < TaskStatus > ( ( resolve : ( status : TaskStatus ) => void , reject : ( errors : TaskError [ ] ) => void ) => {
4849 try {
49- const build : string = this . _getScriptToRun ( ) ;
50- const deps : IPackageDependencies | undefined = this . _getPackageDependencies ( build , writer ) ;
51- this . _executeTask ( build , writer , deps , resolve , reject ) ;
50+ const taskCommand : string = this . _getScriptToRun ( ) ;
51+ const deps : IPackageDependencies | undefined = this . _getPackageDependencies ( taskCommand , writer ) ;
52+ this . _executeTask ( taskCommand , writer , deps , resolve , reject ) ;
5253 } catch ( error ) {
5354 reject ( [ new TaskError ( 'executing' , error . toString ( ) ) ] ) ;
5455 }
5556 } ) ;
5657 }
5758
58- private _getPackageDependencies ( buildCommand : string , writer : ITaskWriter ) : IPackageDependencies | undefined {
59+ private _getPackageDependencies ( taskCommand : string , writer : ITaskWriter ) : IPackageDependencies | undefined {
5960 let deps : IPackageDependencies | undefined = undefined ;
6061 PackageChangeAnalyzer . rushConfig = this . _rushConfiguration ;
6162 try {
6263 deps = {
6364 files : PackageChangeAnalyzer . instance . getPackageDepsHash ( this . _rushProject . packageName ) ! . files ,
64- arguments : buildCommand
65+ arguments : taskCommand
6566 } ;
6667 } catch ( error ) {
6768 writer . writeLine ( 'Unable to calculate incremental build state. ' +
@@ -71,7 +72,7 @@ export default class ProjectBuildTask implements ITaskDefinition {
7172 }
7273
7374 private _executeTask (
74- buildCommand : string ,
75+ taskCommand : string ,
7576 writer : ITaskWriter ,
7677 currentPackageDeps : IPackageDependencies | undefined ,
7778 resolve : ( status : TaskStatus ) => void ,
@@ -107,29 +108,29 @@ export default class ProjectBuildTask implements ITaskDefinition {
107108 fsx . unlinkSync ( currentDepsPath ) ;
108109 }
109110
110- if ( ! buildCommand ) {
111+ if ( ! taskCommand ) {
111112 // tslint:disable-next-line:max-line-length
112- writer . writeLine ( `The 'build' or 'test' command was registered in the package.json but is blank, so no action will be taken.` ) ;
113- resolve ( TaskStatus . Success ) ;
113+ writer . writeLine ( `The task command ${ this . _commandToRun } was registered in the package.json but is blank, so no action will be taken.` ) ;
114+ resolve ( TaskStatus . Skipped ) ;
114115 return ;
115116 }
116117
117- // Run the build step
118- writer . writeLine ( buildCommand ) ;
119- const buildTask : child_process . ChildProcess =
120- Utilities . executeShellCommandAsync ( buildCommand , projectFolder , process . env , true ) ;
118+ // Run the task
119+ writer . writeLine ( taskCommand ) ;
120+ const task : child_process . ChildProcess =
121+ Utilities . executeShellCommandAsync ( taskCommand , projectFolder , process . env , true ) ;
121122
122123 // Hook into events, in order to get live streaming of build log
123- buildTask . stdout . on ( 'data' , ( data : string ) => {
124+ task . stdout . on ( 'data' , ( data : string ) => {
124125 writer . write ( data ) ;
125126 } ) ;
126127
127- buildTask . stderr . on ( 'data' , ( data : string ) => {
128+ task . stderr . on ( 'data' , ( data : string ) => {
128129 writer . writeError ( data ) ;
129130 this . _hasWarningOrError = true ;
130131 } ) ;
131132
132- buildTask . on ( 'close' , ( code : number ) => {
133+ task . on ( 'close' , ( code : number ) => {
133134 // Write the logs to disk
134135 this . _writeLogsToDisk ( writer ) ;
135136
@@ -172,14 +173,14 @@ export default class ProjectBuildTask implements ITaskDefinition {
172173 } else {
173174 script = this . _getScriptCommand ( this . _commandToRun ) ;
174175
175- if ( script === undefined ) {
176+ if ( script === undefined && ! this . _optional ) {
176177 // tslint:disable-next-line:max-line-length
177178 throw new Error ( `The project [${ this . _rushProject . packageName } ] does not define a '${ this . _commandToRun } ' command in the 'scripts' section of its package.json` ) ;
178179 }
179180 }
180181
181- if ( script === '' ) {
182- return script ;
182+ if ( ! script ) {
183+ return '' ;
183184 }
184185
185186 return `${ script } ${ this . _customFlags . join ( ' ' ) } ` ;
0 commit comments