gulpclass
gulpclass copied to clipboard
Default task exits prematurely
Hello!
Thank you for this great module!
However, I have an issue when default task is terminating without waiting for all the tasks to properly complete.
Here's my gulpfile.ts
:
import {Gulpclass, Task, SequenceTask} from 'gulpclass';
import * as gulp from 'gulp';
import * as del from 'del';
import * as ts from 'gulp-typescript';
const tsProject = ts.createProject('tsconfig.json');
@Gulpclass()
export class Gulpfile {
@Task()
clean () {
return del(['./dist/']);
}
@Task()
compile () {
return gulp.src('./src/**/*.ts')
.pipe(tsProject()).js
.pipe(gulp.dest('dist'))
;
}
@Task('migrations:copy')
migrationsCopy () {
return gulp
.src('./src/application/migrations/**/*.pgsql')
.pipe(gulp.dest('./dist/application/migrations/'))
;
}
@SequenceTask()
build () {
return ['clean', ['compile', 'migrations:copy']];
}
@Task()
default () {
return ['build'];
}
}
When I run each task individually it works correctly.
Here's the output of the default task:
$ gulp
[13:25:25] Using gulpfile ./gulpfile.js
[13:25:25] Starting 'default'...
$
My gulpfile.js
looks like suggested in the docs:
eval(require('typescript').transpile(require('fs').readFileSync('./gulpfile.ts').toString()));
What could be the problem?
Thanks!
As I found out in the FAQ:
Why? Because the array you are returning is what task is doing, not a task dependencies as you wish:
@Task("default", ["clean", "compile", "build"])
default() {
}
However, your example in the docs contradicts this:
@Task()
default() { // because this task has "default" name it will be run as default gulp task
return ["build"];
}
I suggest to update the README to make this use case more clear.
actually its better to use ts-node
then this .js hack. Can you provide a PR for the changes you propose?
When I try to use ts-node
I'm getting the following:
$ gulp
[09:47:50] Failed to load external module ts-node/register
[09:47:50] Failed to load external module typescript-node/register
[09:47:50] Failed to load external module typescript-register
[09:47:50] Failed to load external module typescript-require
./gulpfile.ts:2
import {Gulpclass, Task, SequenceTask} from 'gulpclass';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:78:16)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Liftoff.handleArguments (~/.nvm/versions/node/v7.2.1/lib/node_modules/gulp/bin/gulp.js:116:3)
at Liftoff.<anonymous> (~/.nvm/versions/node/v7.2.1/lib/node_modules/gulp/node_modules/liftoff/index.js:198:16)
However:
$ ts-node --version
ts-node v3.0.2
node v7.2.1
there were rules how to use ts-node... try to install it both globally and locally and dont forget to putl --save-dev flag
It works after installing locally, thanks. Sadly, this is not mentioned in the docs.