1 | # Make a beautiful class-based gulpfiles with Typescript and Gulpfile.ts
|
2 |
|
3 | Allows to create a gulp files in classes, each method of which can be a gulp task.
|
4 |
|
5 | ## Installation
|
6 |
|
7 | 1. Install module:
|
8 |
|
9 | `npm install --save gulpclass`
|
10 |
|
11 | 2. Install required [tsd](http://definitelytyped.org/tsd/) dependencies:
|
12 |
|
13 | `tsd install --save gulp`
|
14 |
|
15 | ## Usage
|
16 |
|
17 | 1. Create a `gulpfile.ts` and describe your tasks
|
18 |
|
19 | ```javascript
|
20 | import {Gulpclass, Task} from "gulpclass/Annotations";
|
21 | import * as gulp from "gulp";
|
22 |
|
23 | let del: any = require('del'); // you probably want to define a classes that does not have type definition this way
|
24 |
|
25 | @Gulpclass()
|
26 | export class Gulpfile {
|
27 |
|
28 | @Task()
|
29 | clean(cb: Function) {
|
30 | return del(['./dist/**'], cb);
|
31 | }
|
32 |
|
33 | @Task()
|
34 | copyFiles() {
|
35 | return gulp.src(['./README.md'])
|
36 | .pipe(gulp.dest('./dist'));
|
37 | }
|
38 |
|
39 | @Task('copy-source-files') // you can specify custom task name if you need
|
40 | copySourceFiles() {
|
41 | return gulp.src(['./src/**.js'])
|
42 | .pipe(gulp.dest('./dist/src'));
|
43 | }
|
44 |
|
45 | @SequenceTask() // this special annotation using "run-sequence" module to run returned tasks in sequence
|
46 | build() {
|
47 | return ['copyFiles', 'copy-source-files'];
|
48 | }
|
49 |
|
50 | @Task()
|
51 | default() { // because this task has "default" name it will be run as default gulp task
|
52 | return ['build'];
|
53 | }
|
54 |
|
55 | }
|
56 | ```
|
57 |
|
58 | 2. How to run
|
59 |
|
60 | The way you run gulp depend of your tsconfig configuration. If you are not using "outDir" in the tsconfig then
|
61 | you probably don't need to do anything - since you are outputting .js code right to the same directory as your
|
62 | gulpfile.ts you will have gulpfile.js right in the same directory, so you can run `gulp` as you usually do.
|
63 |
|
64 | But if you are using "outDir" in your tsconfig, you need to do some extra stuff.
|
65 | Lets say you have specified "build/" as "outDir" in tsconfig.
|
66 | There are two options what you can do:
|
67 |
|
68 | * create `gulpfile.js` and put there ```require('build/gulpfile')```
|
69 | * or run gulp in cmd with extra parameters: `gulp --gulpfile build/gulpfile.js --cwd .`
|
70 |
|
71 | First option is preferred because most probably it will be annoying for you to run gulp every time you need to run some task.
|
72 |
|
73 |
|
74 | ## Caveats
|
75 |
|
76 | Its important to understand that you will not able to run your gulp tasks *until* you compile your `gulpfile.ts` file.
|
77 | This means that if compiling is a part of your gulp tasks you will not be able to use it,
|
78 | because there is no gulpfile.js compiled from gulpfile.ts file.
|
79 |
|
80 | ## Samples
|
81 |
|
82 | This project itself using [gulpfile.ts](https://github.com/PLEEROCK/gulpclass/blob/master/gulpfile.ts).
|
83 | Take a look on it as an example.
|
84 |
|
85 |
|
86 | [1]: https://github.com/PLEEROCK/microframework
|
87 | [2]: https://github.com/gulpclass/gulpfile.ts
|
88 |
|
\ | No newline at end of file |