parent
237d31581f
commit
6a2ac2f063
@ -27,8 +27,11 @@ export default function modelGenerationPhase(
|
||||
}
|
||||
let entitiesPath = resultPath;
|
||||
if (!generationOptions.noConfigs) {
|
||||
createTsConfigFile(resultPath);
|
||||
createTypeOrmConfig(resultPath, connectionOptions);
|
||||
const tsconfigPath = path.resolve(resultPath, "tsconfig.json");
|
||||
const typeormConfigPath = path.resolve(resultPath, "ormconfig.json");
|
||||
|
||||
createTsConfigFile(tsconfigPath);
|
||||
createTypeOrmConfig(typeormConfigPath, connectionOptions);
|
||||
entitiesPath = path.resolve(resultPath, "./entities");
|
||||
if (!fs.existsSync(entitiesPath)) {
|
||||
fs.mkdirSync(entitiesPath);
|
||||
@ -258,7 +261,13 @@ function createHandlebarsHelpers(generationOptions: IGenerationOptions): void {
|
||||
});
|
||||
}
|
||||
|
||||
function createTsConfigFile(outputPath: string): void {
|
||||
function createTsConfigFile(tsconfigPath: string): void {
|
||||
if (fs.existsSync(tsconfigPath)) {
|
||||
console.warn(
|
||||
`\x1b[33m[${new Date().toLocaleTimeString()}] WARNING: Skipping generation of tsconfig.json file. File already exists. \x1b[0m`
|
||||
);
|
||||
return;
|
||||
}
|
||||
const templatePath = path.resolve(__dirname, "templates", "tsconfig.mst");
|
||||
const template = fs.readFileSync(templatePath, "utf-8");
|
||||
const compliedTemplate = Handlebars.compile(template, {
|
||||
@ -266,16 +275,21 @@ function createTsConfigFile(outputPath: string): void {
|
||||
});
|
||||
const rendered = compliedTemplate({});
|
||||
const formatted = Prettier.format(rendered, { parser: "json" });
|
||||
const resultFilePath = path.resolve(outputPath, "tsconfig.json");
|
||||
fs.writeFileSync(resultFilePath, formatted, {
|
||||
fs.writeFileSync(tsconfigPath, formatted, {
|
||||
encoding: "utf-8",
|
||||
flag: "w",
|
||||
});
|
||||
}
|
||||
function createTypeOrmConfig(
|
||||
outputPath: string,
|
||||
typeormConfigPath: string,
|
||||
connectionOptions: IConnectionOptions
|
||||
): void {
|
||||
if (fs.existsSync(typeormConfigPath)) {
|
||||
console.warn(
|
||||
`\x1b[33m[${new Date().toLocaleTimeString()}] WARNING: Skipping generation of ormconfig.json file. File already exists. \x1b[0m`
|
||||
);
|
||||
return;
|
||||
}
|
||||
const templatePath = path.resolve(__dirname, "templates", "ormconfig.mst");
|
||||
const template = fs.readFileSync(templatePath, "utf-8");
|
||||
const compiledTemplate = Handlebars.compile(template, {
|
||||
@ -283,8 +297,7 @@ function createTypeOrmConfig(
|
||||
});
|
||||
const rendered = compiledTemplate(connectionOptions);
|
||||
const formatted = Prettier.format(rendered, { parser: "json" });
|
||||
const resultFilePath = path.resolve(outputPath, "ormconfig.json");
|
||||
fs.writeFileSync(resultFilePath, formatted, {
|
||||
fs.writeFileSync(typeormConfigPath, formatted, {
|
||||
encoding: "utf-8",
|
||||
flag: "w",
|
||||
});
|
||||
|
@ -101,8 +101,8 @@ export default class MssqlDriver extends AbstractDriver {
|
||||
LEFT JOIN (SELECT tc.TABLE_SCHEMA,tc.TABLE_NAME,cu.COLUMN_NAME,COUNT(1) AS cnt FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc inner join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu on cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME where tc.CONSTRAINT_TYPE = 'UNIQUE' GROUP BY tc.TABLE_SCHEMA,tc.TABLE_NAME,cu.COLUMN_NAME) AS tc
|
||||
on tc.TABLE_NAME = c.TABLE_NAME and tc.COLUMN_NAME = c.COLUMN_NAME and tc.TABLE_SCHEMA=c.TABLE_SCHEMA
|
||||
where c.TABLE_SCHEMA in (${MssqlDriver.buildEscapedObjectList(
|
||||
schemas
|
||||
)}) AND c.TABLE_CATALOG in (${MssqlDriver.buildEscapedObjectList(
|
||||
schemas
|
||||
)}) AND c.TABLE_CATALOG in (${MssqlDriver.buildEscapedObjectList(
|
||||
dbNames
|
||||
)}) order by ordinal_position
|
||||
`)
|
||||
|
Loading…
Reference in New Issue
Block a user