UNPKG

1.68 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || function (d, b) {
3 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4 function __() { this.constructor = d; }
5 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6};
7var node_watch = require('node-watch');
8var nest_1 = require('./nest');
9var fileJob_1 = require('./../job/fileJob');
10var fs = require('fs');
11var path_mod = require('path');
12var Folder = (function (_super) {
13 __extends(Folder, _super);
14 function Folder(e, path) {
15 var nest_name = path_mod.basename(path);
16 _super.call(this, e, nest_name);
17 this.path = path;
18 }
19 Folder.prototype.load = function () {
20 var fl = this;
21 fs.readdir(fl.path, function (err, items) {
22 items = items.filter(function (item) { return !(/(^|\/)\.[^\/\.]/g).test(item); });
23 items.forEach(function (filename) {
24 // Make a new Job and trigger arrived
25 var job = new fileJob_1.FileJob(fl.e, fl.path + "/" + filename);
26 // job.setPath(fl.path + item);
27 fl.arrive(job);
28 });
29 });
30 };
31 Folder.prototype.watch = function () {
32 var fl = this;
33 node_watch(fl.path, function (filename) {
34 // Make a new Job and trigger arrived
35 var job = new fileJob_1.FileJob(fl.e, fl.path + "/" + filename);
36 // job.setPath(fl.path + filename);
37 fl.arrive(job);
38 });
39 };
40 Folder.prototype.arrive = function (job) {
41 _super.prototype.arrive.call(this, job);
42 };
43 return Folder;
44}(nest_1.Nest));
45exports.Folder = Folder;