-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools): do not invoke tasks if not required
In dev executes tasks only when a specific file type has changed. Fix #1432.
- Loading branch information
Showing
11 changed files
with
211 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Task } from './task'; | ||
|
||
export abstract class AssetsTask extends Task { | ||
shallRun(files: String[]) { | ||
return files.reduce((a, f) => { | ||
return a || (!f.endsWith('.css') && !f.endsWith('.sass') && | ||
!f.endsWith('.scss') && !f.endsWith('.ts')); | ||
}, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Task } from './task'; | ||
|
||
export abstract class CssTask extends Task { | ||
|
||
shallRun(files: String[]) { | ||
return files.some(f => | ||
f.endsWith('.css') || f.endsWith('.sass') || f.endsWith('.scss')); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import * as gulp from 'gulp'; | ||
import { join } from 'path'; | ||
|
||
import { AssetsTask } from '../assets_task'; | ||
import Config from '../../config'; | ||
|
||
/** | ||
* Executes the build process, copying the assets located in `src/client` over to the appropriate | ||
* `dist/dev` directory. | ||
*/ | ||
export = () => { | ||
let paths: string[] = [ | ||
join(Config.APP_SRC, '**'), | ||
'!' + join(Config.APP_SRC, '**', '*.ts'), | ||
'!' + join(Config.APP_SRC, '**', '*.scss'), | ||
'!' + join(Config.APP_SRC, '**', '*.sass') | ||
].concat(Config.TEMP_FILES.map((p) => { return '!' + p; })); | ||
export = | ||
class BuildAssetsTask extends AssetsTask { | ||
run() { | ||
let paths: string[] = [ | ||
join(Config.APP_SRC, '**'), | ||
'!' + join(Config.APP_SRC, '**', '*.ts'), | ||
'!' + join(Config.APP_SRC, '**', '*.scss'), | ||
'!' + join(Config.APP_SRC, '**', '*.sass') | ||
].concat(Config.TEMP_FILES.map((p) => { return '!' + p; })); | ||
|
||
return gulp.src(paths) | ||
.pipe(gulp.dest(Config.APP_DEST)); | ||
} | ||
}; | ||
|
||
return gulp.src(paths) | ||
.pipe(gulp.dest(Config.APP_DEST)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Base class for all tasks. | ||
*/ | ||
export abstract class Task { | ||
/** | ||
* Override this task if you want to implement some custom | ||
* task activation mechanism. By default each task will be always executed. | ||
* | ||
* @param {string[]} files A list of files changed since the previous watch. | ||
*/ | ||
shallRun(files: string[]): boolean { | ||
return true; | ||
} | ||
|
||
/** | ||
* Implements your task behavior. | ||
* | ||
* @param {any} done A function which should be activated once your task completes. | ||
* @return {ReadWriteStream | Promise<any> | void} This method can either return a promise | ||
* which should be resolved once your task execution completes, a stream | ||
* which should throw an end event once your task execution completes | ||
* or nothing in case you will manually invoke the `done` method. | ||
*/ | ||
abstract run(done?: any): any | Promise<any> | void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Task } from './task'; | ||
|
||
export abstract class TypeScriptTask extends Task { | ||
shallRun(files: String[]) { | ||
return files.reduce((a, f) => { | ||
return a || f.endsWith('.ts'); | ||
}, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters