50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
|
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
|
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
|
|
var Promise = require("bluebird");
|
|
|
|
var chokidar = require("chokidar");
|
|
|
|
var slash = require("slash");
|
|
|
|
module.exports =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _ref = (0, _asyncToGenerator2.default)(
|
|
/*#__PURE__*/
|
|
_regenerator.default.mark(function _callee(path, glob, onNewFile, onRemovedFile) {
|
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
chokidar.watch(glob, {
|
|
cwd: path
|
|
}).on("add", function (path) {
|
|
path = slash(path);
|
|
onNewFile(path);
|
|
}).on("unlink", function (path) {
|
|
path = slash(path);
|
|
onRemovedFile(path);
|
|
}).on("ready", function () {
|
|
return resolve();
|
|
});
|
|
}));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
return function (_x, _x2, _x3, _x4) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}(); |