@tsdi/pack
Version:
@tsdi/pack is simple build tasks, base on AOP, Ioc container, via @tsdi. dev build pack activities.
60 lines (58 loc) • 2.14 kB
JavaScript
import { __awaiter, __decorate, __metadata } from "tslib";
import { PromiseUtil } from '@tsdi/ioc';
import { Input } from '@tsdi/components';
import { Task } from '@tsdi/activities';
import { fromEventPattern } from 'rxjs';
import { bufferTime, filter } from 'rxjs/operators';
import { NodeActivity } from '../NodeActivity';
const chokidar = require('chokidar');
/**
* watch activity.
*
* @export
* @class WatchActivity
* @extends {BuildHandleActivity}
*/
let WatchActivity = class WatchActivity extends NodeActivity {
execute(ctx) {
return __awaiter(this, void 0, void 0, function* () {
let watchSrc = this.watch;
let options = this.options;
let watcher = chokidar.watch(ctx.platform.normalizeSrc(watchSrc), Object.assign({ ignored: /[\/\\]\./, ignoreInitial: true, cwd: ctx.platform.getRootPath() }, options));
let defer = PromiseUtil.defer();
fromEventPattern(handler => {
watcher.on('add', paths => handler(paths));
watcher.on('change', paths => handler(paths));
watcher.on('unlink', paths => handler(paths));
watcher.on('unlinkDir', paths => handler(paths));
}, handler => {
watcher.close();
})
.pipe(bufferTime(300), filter(c => c.length > 0))
.subscribe(chg => {
ctx.getExector().runActivity(this.body);
});
defer.promise;
});
}
static ρAnn() {
return { "name": "WatchActivity", "params": { "execute": ["ctx"] } };
}
};
__decorate([
Input(),
__metadata("design:type", Object)
], WatchActivity.prototype, "watch", void 0);
__decorate([
Input('watchOptions'),
__metadata("design:type", Object)
], WatchActivity.prototype, "options", void 0);
__decorate([
Input({ bindingType: 'dynamic' }),
__metadata("design:type", Object)
], WatchActivity.prototype, "body", void 0);
WatchActivity = __decorate([
Task('watch')
], WatchActivity);
export { WatchActivity };
//# sourceMappingURL=../sourcemaps/tasks/WatchActivity.js.map