UNPKG

next-ts-api

Version:

A powerful TypeScript-first API client generator for Next.js applications with full type safety and automatic api type generation.

24 lines (23 loc) 835 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nextTsApi = void 0; const chokidar_1 = require("chokidar"); const core_js_1 = require("./lib/core.js"); const utils_js_1 = require("./lib/utils.js"); function debounce(fn, ms) { let id; return function (...args) { clearTimeout(id); id = setTimeout(() => fn(...args), ms); }; } const nextTsApi = (options) => { return function (nextConfig) { const watchDirs = (0, utils_js_1.getAppDirectory)(); const watcher = (0, chokidar_1.watch)(watchDirs, { persistent: true }); const generate = debounce(() => (0, core_js_1.writeNextTsApi)(options), 50); watcher.on("add", generate).on("unlink", generate).on('change', generate); return nextConfig; }; }; exports.nextTsApi = nextTsApi;