UNPKG

@gluestack-v2/framework-cli

Version:

Gluestack V2 Framework CLI

76 lines (75 loc) 3.29 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "chokidar", "path", "./print"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chokidar_1 = __importDefault(require("chokidar")); const path_1 = __importDefault(require("path")); const print_1 = require("./print"); class Watcher { constructor() { this.instanceWatcherFlag = false; } instanceWatcher() { const watcherPath = path_1.default.join(process.cwd(), '.glue', 'internals', 'plugin-instances.json'); const instanceWatcher = chokidar_1.default.watch(watcherPath, { persistent: true, cwd: process.cwd(), ignored: [ '**/node_modules/**', '**/dist/**', '**/build/**', '**/.next/**', ], }); instanceWatcher.on('change', (_event, _path) => __awaiter(this, void 0, void 0, function* () { (0, print_1.warning)('New plugin instance detected, restart your app!'); })); } watch(cwd, pattern, callback) { const globs = typeof pattern === 'string' ? [pattern] : pattern; try { const watcher = chokidar_1.default.watch(globs, { persistent: true, cwd: cwd, ignored: [ '**/node_modules/**', '**/dist/**', '**/build/**', '**/.next/**', ], }); watcher.on('all', (event, path) => __awaiter(this, void 0, void 0, function* () { if (callback) callback(event, path); })); if (!this.instanceWatcherFlag) { this.instanceWatcher(); this.instanceWatcherFlag = true; } } catch (err) { (0, print_1.error)('> watcher error:', err); } } } exports.default = new Watcher(); });