UNPKG

pathpida

Version:

TypeScript friendly pages and static path generator for Next.js

26 lines 1.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseQueryFromTS = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const createHash_1 = require("./createHash"); const parseQueryFromTS = (output, file) => { const fileData = fs_1.default.readFileSync(file, 'utf8'); const typeName = ['Query', 'OptionalQuery'].find((type) => new RegExp(`export (interface ${type} ?{|type ${type} ?=)`).test(fileData)); if (!typeName) return; const importPath = path_1.default .relative(output, file) .replace(/\\/g, '/') .replace(/(\/index)?\.tsx?$/, ''); const importName = `${typeName}_${(0, createHash_1.createHash)(importPath)}`; return { importName, importString: `import type { ${typeName} as ${importName} } from '${importPath}';`, }; }; exports.parseQueryFromTS = parseQueryFromTS; //# sourceMappingURL=parseQueryFromTS.js.map