pleerock / gulpclass

Make a beautiful class-based gulpfiles with TypeScript and Gulpclass.
156 stars 24 forks source link

Loading tasks from multiple files #15

Open iamrakesh opened 8 years ago

iamrakesh commented 8 years ago

Hi, FAQ section of readme, explains about what needs to be in gulpfile.js, but I couldn't make it work, I've trouble with how to add tasks in other .ts files.

The way I tried is to have a class 'MyTasks' with tasks in one.ts, in gulpfile.ts have Gulpfile class extend MyTasks. But this doesn't seems to work.

Could please provide a full example on how to do this ?

Thanks, Rakesh.A

pleerock commented 8 years ago

everything is already described in faq section, try more and you'll success. Alternatively you can try ts-node to run gulp tasks without this compilation hack in .js

apazureck commented 6 years ago

Hi @iamrakesh,

I also had issues loading my gulpfiles from different files. I had some settings in my tscofnig.json and did not want to load this when evaling the scripts, as I did not want to have more dependencies. I think the problem was that my tsconfig did resolve the require differently.

I simply fixed this by creating a static init method on the loaded gulpclass:

gulpfile.ts:

import { Deploy } from "./deployment";
...
Deploy.init();

deployment.ts:

@Gulpclass()
export class Deploy {
    @SequenceTask()
    deploy() { ... }
    ...
    static init() {
        console.log("Initialized Deyployment");
    }
}

This init call forces to load the module and, thus, create the missing tasks on the Deploy class.

@pleerock: Maybe you could add this als alternative route.