@modern-js/utils
Version:
A Progressive React Framework for modern web development.
88 lines (87 loc) • 2.87 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.n = (module)=>{
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
__webpack_require__.d(getter, {
a: getter
});
return getter;
};
})();
(()=>{
__webpack_require__.d = (exports1, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
WatchChangeType: ()=>WatchChangeType,
watch: ()=>watch
});
const external_path_namespaceObject = require("path");
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
const external_compiled_js_namespaceObject = require("../compiled.js");
const WatchChangeType = {
ADD: 'add',
UNLINK: 'unlink',
CHANGE: 'change'
};
const watch = (watchDir, runTask, ignored = [])=>{
let ready = false;
const watcher = external_compiled_js_namespaceObject.chokidar.watch(watchDir, {
ignored
});
watcher.on('ready', ()=>ready = true);
watcher.on('change', async (filePath)=>{
const changedFilePath = external_path_default().resolve(filePath);
await runTask({
changedFilePath,
changeType: WatchChangeType.CHANGE
});
});
watcher.on('add', async (filePath)=>{
const changedFilePath = external_path_default().resolve(filePath);
if (ready) await runTask({
changedFilePath,
changeType: WatchChangeType.ADD
});
});
watcher.on('unlink', async (filePath)=>{
const changedFilePath = external_path_default().resolve(filePath);
await runTask({
changedFilePath,
changeType: WatchChangeType.UNLINK
});
});
watcher.on('error', (err)=>{
throw err;
});
return watcher;
};
exports.WatchChangeType = __webpack_exports__.WatchChangeType;
exports.watch = __webpack_exports__.watch;
for(var __rspack_i in __webpack_exports__)if (-1 === [
"WatchChangeType",
"watch"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
value: true
});