<commit_before>import "reflect-metadata";
import {createConnection, ConnectionOptions} from "typeorm";
import {render, renderString, configure} from "nunjucks";
import {DbOptions} from "./model/options";
import {parseStruct} from "ts-structure-parser";

function generateDatabase(grunt: any) {
    grunt.registerMultiTask("generateDatabase", function() {
        let dbOptions = new DbOptions();
        dbOptions.type = process.env.dbtype;
        dbOptions.host = process.env.dbhost;
        dbOptions.port =   process.env.dbport;
        dbOptions.username = process.env.dbusername;
        dbOptions.password = <PASSWORD>;
        dbOptions.database = process.env.dbdatabase;
        dbOptions.reCreate = this.data.reCreate;
        dbOptions.declarationPath = this.data.pathToDeclaration;
        var declaration = grunt.file.read(this.data.pathToDeclaration);
        var jsonDeclaration = JSON.parse(declaration);
        var options = this.options({
            encoding: grunt.file.defaultEncoding,
            processContent: false,
            processContentExclude: [],
            timestamp: false,
            mode: false
          });
          var stringFile = "";
          var globalStringFile = "";
          for (var index = 0; index < jsonDeclaration.length; index++) {
              var schms = jsonDeclaration[index].schemas;
              stringFile = "";
              for (var innerIndex = 0; innerIndex < schms.length; innerIndex++) {
                  for (var tableIndex = 0; tableIndex < schms[innerIndex].tables.length; tableIndex++) {
                    var table = schms[innerIndex].tables[tableIndex];
                    var pathtobaseModel = this.data.baseModelPath + table.pathToModel + ".ts";
                    stringFile += grunt.file.read(pathtobaseModel, options);
                    var pathtoHistory = this.data.pathToHistory +  table.pathToModel + ".ts";
                    stringFile += grunt.file.read(this.data.pathToHistory +  table.pathToModel + ".ts", options);
                  }
                  var jsonStructure = parseStruct(stringFile, {}, "");
                  CreateFileForTableCreate(jsonDeclaration[index], dbOptions, grunt, this.data, jsonStructure, schms[innerIndex]);
                  CreateFileForTriggersCreateForSchema(jsonDeclaration[index], dbOptions, grunt, this.data, jsonStructure , schms[innerIndex]);
                  stringFile = "";
              }
        }
        CreateDBCreator(grunt, this.data, jsonDeclaration);
    });
}
module.exports = generateDatabase;

function CreateOtherFile(jsonDeclaration: any, pathes: any, grunt: any) {
    configure("./src/tasks/view", {autoescape: true, trimBlocks: true});
    var rendererTemplate = render("createTablesTemplate.njk", {declaration: jsonDeclaration ,
basePath: pathes.destinationDB});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "generateDB.ts", rendererTemplate);
    }
}

function CreateFileForTableCreate(datas: any, dboptions : any, grunt: any, pathes: any, historyStruct: any, schema: any) {
    configure("./src/tasks/view", {autoescape: true, trimBlocks: true});
    var rendererTemplate = render("createBaseTemplate.njk", {data: datas, options: dboptions,
        historyPath: pathes.pathToHistory, basePath: pathes.baseModelPath, schema: schema});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "/" +  datas.name + "/" +  schema.namespace + "/" + "schema.ts", rendererTemplate);
    }
}
 function CreateFileForTriggersCreateForSchema(datas: any, dboptions : any, grunt: any, pathes: any, historyStruct: any, schema: any) {
    configure("./src/tasks/view", {autoescape: true, trimBlocks: true});
    var rendererTemplate = render("createTriggerFunctionTemplate.njk", {data: datas, options: dboptions, hStr: historyStruct,
        historyPath: pathes.pathToHistory, schema: schema});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "/" +  datas.name + "/" +  schema.namespace + "/" + "function.ts", rendererTemplate);
    }
    configure("./src/tasks/view", {autoescape: true, trimBlocks: true});
    rendererTemplate = render("createTriggerTemplate.njk", {data: datas, options: dboptions, historyPath: pathes.pathToHistory, schema: schema});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "/" +  datas.name + "/" +  schema.namespace + "/" + "trigger.ts", rendererTemplate);
    }
 }

 function CreateDBCreator(grunt: any, pathes: any, jsonDeclaration: any) {
    configure("./src/tasks/view", {autoescape: true, trimBlocks: true});
    var rendererTemplate = render("createDBTemplate.njk", {scriptsDestination : pathes.destinationDB, declaration: jsonDeclaration});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "/generateDB.ts", rendererTemplate);
    }

 }



<commit_msg>9 com<commit_after>import "reflect-metadata";
import {createConnection, ConnectionOptions} from "typeorm";
import {render, renderString, configure} from "nunjucks";
import {DbOptions} from "./model/options";
import {parseStruct} from "ts-structure-parser";
import * as path from "path";

function generateDatabase(grunt: any) {
    grunt.registerMultiTask("generateDatabase", function() {
        let dbOptions = new DbOptions();
        dbOptions.type = process.env.dbtype;
        dbOptions.host = process.env.dbhost;
        dbOptions.port =   process.env.dbport;
        dbOptions.username = process.env.dbusername;
        dbOptions.password = <PASSWORD>;
        dbOptions.database = process.env.dbdatabase;
        dbOptions.reCreate = this.data.reCreate;
        dbOptions.declarationPath = this.data.pathToDeclaration;
        var declaration = grunt.file.read(this.data.pathToDeclaration);
        var jsonDeclaration = JSON.parse(declaration);
        var options = this.options({
            encoding: grunt.file.defaultEncoding,
            processContent: false,
            processContentExclude: [],
            timestamp: false,
            mode: false
          });
          var stringFile = "";
          var globalStringFile = "";
          for (var index = 0; index < jsonDeclaration.length; index++) {
              var schms = jsonDeclaration[index].schemas;
              stringFile = "";
              for (var innerIndex = 0; innerIndex < schms.length; innerIndex++) {
                  for (var tableIndex = 0; tableIndex < schms[innerIndex].tables.length; tableIndex++) {
                    var table = schms[innerIndex].tables[tableIndex];
                    var pathtobaseModel = this.data.baseModelPath + table.pathToModel + ".ts";
                    stringFile += grunt.file.read(pathtobaseModel, options);
                    var pathtoHistory = this.data.pathToHistory +  table.pathToModel + ".ts";
                    stringFile += grunt.file.read(this.data.pathToHistory +  table.pathToModel + ".ts", options);
                  }
                  var jsonStructure = parseStruct(stringFile, {}, "");
                  CreateFileForTableCreate(jsonDeclaration[index], dbOptions, grunt, this.data, jsonStructure, schms[innerIndex]);
                  CreateFileForTriggersCreateForSchema(jsonDeclaration[index], dbOptions, grunt, this.data, jsonStructure , schms[innerIndex]);
                  stringFile = "";
              }
        }
        CreateDBCreator(grunt, this.data, jsonDeclaration);
    });
}
module.exports = generateDatabase;

function CreateOtherFile(jsonDeclaration: any, pathes: any, grunt: any) {
    configure("./src/tasks/view", {autoescape: true, trimBlocks: true});
    var rendererTemplate = render("createTablesTemplate.njk", {declaration: jsonDeclaration ,
basePath: pathes.destinationDB});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "generateDB.ts", rendererTemplate);
    }
}

function CreateFileForTableCreate(datas: any, dboptions : any, grunt: any, pathes: any, historyStruct: any, schema: any) {
    let scriptFolder = path.resolve(__dirname, "view/");
    configure(scriptFolder, {autoescape: true, trimBlocks: true});
    var rendererTemplate = render("createBaseTemplate.njk", {data: datas, options: dboptions,
        historyPath: pathes.pathToHistory, basePath: pathes.baseModelPath, schema: schema});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "/" +  datas.name + "/" +  schema.namespace + "/" + "schema.ts", rendererTemplate);
    }
}
 function CreateFileForTriggersCreateForSchema(datas: any, dboptions : any, grunt: any, pathes: any, historyStruct: any, schema: any) {
    let scriptFolder = path.resolve(__dirname, "view/");
    configure(scriptFolder, {autoescape: true, trimBlocks: true});
    var rendererTemplate = render("createTriggerFunctionTemplate.njk", {data: datas, options: dboptions, hStr: historyStruct,
        historyPath: pathes.pathToHistory, schema: schema});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "/" +  datas.name + "/" +  schema.namespace + "/" + "function.ts", rendererTemplate);
    }
    configure(scriptFolder, {autoescape: true, trimBlocks: true});
    rendererTemplate = render("createTriggerTemplate.njk", {data: datas, options: dboptions, historyPath: pathes.pathToHistory, schema: schema});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "/" +  datas.name + "/" +  schema.namespace + "/" + "trigger.ts", rendererTemplate);
    }
 }

 function CreateDBCreator(grunt: any, pathes: any, jsonDeclaration: any) {
    let scriptFolder = path.resolve(__dirname, "view/");
    configure(scriptFolder, {autoescape: true, trimBlocks: true});
    var rendererTemplate = render("createDBTemplate.njk", {scriptsDestination : pathes.destinationDB, declaration: jsonDeclaration});
    if (rendererTemplate && rendererTemplate.trim()) {
        grunt.file.write(pathes.destinationDB + "/generateDB.ts", rendererTemplate);
    }

 }




{'fraction_non_alphanumeric': 0.12641194381691387, 'fraction_numerical': 0.0006875552499754445, 'mean_word_length': 3.272765421737306, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6915940', 'n_tokens_mistral': 2829, 'n_tokens_neox': 2813, 'n_words': 590}