mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
34 lines
1.1 KiB
TypeScript
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);
|
|
};
|
|
};
|