Files
openpanel/packages/cli/src/utils/swizzle/provideCliHelpers.ts
Stefan Pejcic 8496a83edb fork refine
2024-02-05 10:23:04 +01:00

34 lines
1.1 KiB
TypeScript

import path from "path";
import * as RefineCLI from "../../index";
import { getFileContent } from "./getFileContent";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Module = require("module");
const originalRequire = Module.prototype.require;
export const provideCliHelpers = (
packagePath: string,
isAbsolute?: boolean,
) => {
Module.prototype.require = function (...args: Parameters<NodeRequire>) {
if ((args[0] as unknown as string) === "@refinedev/cli") {
return {
...RefineCLI,
getFileContent: (filePath: string) => {
return getFileContent.call(
{
absolutePackageDir: isAbsolute
? packagePath
: path.join(process.cwd(), packagePath),
},
filePath,
);
},
};
}
//do your thing here
return originalRequire.apply(this, args);
};
};