fix naming strategy with relative path(#171)
This commit is contained in:
parent
3496c0647b
commit
9e931025b9
@ -35,10 +35,9 @@ export default function modelCustomizationPhase(
|
||||
generationOptions.customNamingStrategyPath !== ""
|
||||
) {
|
||||
// TODO: change form of logging
|
||||
// eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
|
||||
const req = require(generationOptions.customNamingStrategyPath) as Partial<
|
||||
NamingStrategy
|
||||
>;
|
||||
const req = TomgUtils.requireLocalFile(
|
||||
generationOptions.customNamingStrategyPath
|
||||
) as Partial<NamingStrategy>;
|
||||
if (req.columnName) {
|
||||
console.log(
|
||||
`[${new Date().toLocaleTimeString()}] Using custom naming strategy for column names.`
|
||||
|
@ -1,11 +1,8 @@
|
||||
import { plural } from "pluralize";
|
||||
import * as changeCase from "change-case";
|
||||
import { Relation } from "./models/Relation";
|
||||
import { RelationId } from "./models/RelationId";
|
||||
|
||||
import changeCase = require("change-case");
|
||||
|
||||
// TODO: Fix naming strategy relative path
|
||||
|
||||
export function relationIdName(
|
||||
relationId: RelationId,
|
||||
relation: Relation
|
||||
|
14
src/Utils.ts
14
src/Utils.ts
@ -1,4 +1,5 @@
|
||||
import * as changeCase from "change-case";
|
||||
import * as path from "path";
|
||||
import * as packagejson from "../package.json";
|
||||
import { Entity } from "./models/Entity";
|
||||
|
||||
@ -66,3 +67,16 @@ export function findNameForNewField(
|
||||
}
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
export function requireLocalFile(fileName: string): any {
|
||||
try {
|
||||
// eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
|
||||
return require(fileName);
|
||||
} catch (err) {
|
||||
if (!path.isAbsolute(fileName)) {
|
||||
// eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
|
||||
return require(path.resolve(process.cwd(), fileName));
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ describe("Model customization phase", async () => {
|
||||
clearGenerationDir();
|
||||
|
||||
generationOptions.customNamingStrategyPath =
|
||||
"../test/modelCustomization/testNamingStrategy.ts";
|
||||
"test/modelCustomization/testNamingStrategy.ts";
|
||||
// TODO: relationId
|
||||
|
||||
const customizedModel = modelCustomizationPhase(
|
||||
|
Loading…
Reference in New Issue
Block a user