UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

88 lines (87 loc) 5.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JavaGenerator = void 0; const java_version_1 = require("./java-version"); const language_support_1 = require("../../language-support"); const java_framework_enum_1 = require("./java-framework-enum"); const spring_generator_1 = require("./spring/spring-generator"); const quarkus_generator_1 = require("./quarkus/quarkus-generator"); const support_exception_1 = require("../../exception/support-exception"); const file_system_utils_1 = require("../../utils/file-system-utils"); const google_java_format_1 = require("../../code-formatter/google-java-format"); const file_exception_1 = require("../../exception/file-exception"); const application_exception_1 = require("../../exception/application-exception"); class JavaGenerator { async newProject(params) { const framework = java_framework_enum_1.JavaFrameworksEnum[params.framework]; const generatorProperties = { projectName: params.projectName, openapiFilePath: params.openapiFilePath, projectDescription: params.projectDescription, language: language_support_1.LanguageSupportEnum[params.language], applicationPort: params.applicationPort, dockerRegistry: params.dockerRegistry, kubernetesNamespace: params.kubernetesNamespace, newProjectRoot: file_system_utils_1.FileSystemUtils.fullPath(params.newProjectRoot), projectPath: params.projectPathDetails.projectPath, projectSafiraPath: params.projectPathDetails.projectSafiraPath, framework: java_framework_enum_1.JavaFrameworksEnum[params.framework], javaPackManager: params.javaManagement, javaPackage: params.javaPackage, javaVersion: java_version_1.JavaVersionHelper.getByValue(params.javaVersion), useDataBase: params.useDataBase, dataBase: params.dataBase, dataBaseUrl: params.dataBaseUrl, dataBaseUser: params.dataBaseUser, dataBasePassword: params.dataBasePassword, }; if (framework === java_framework_enum_1.JavaFrameworksEnum.springboot) { const springGenerator = new spring_generator_1.SpringGeneratorImpl(); await springGenerator.generate({ ...generatorProperties, javaSpringbootVersion: params.javaSpringbootVersion, }); } else if (framework === java_framework_enum_1.JavaFrameworksEnum.quarkus) { const quarkusGenerator = new quarkus_generator_1.QuarkusGeneratorImpl(); await quarkusGenerator.generate({ ...generatorProperties, quarkusVersion: params.quarkusVersion, }); } else { throw new support_exception_1.FrameworkNotSupportedException(framework); } this.checkProjectFormation(generatorProperties.projectPath, generatorProperties.javaPackManager); await google_java_format_1.GoogleJavaFormatCodeFormatter.instance.format(file_system_utils_1.FileSystemUtils.buildPath(params.projectPathDetails.projectPath, "src")); } checkProjectFormation(projectPath, javaPackManager) { const gradleW = file_system_utils_1.FileSystemUtils.buildPath(projectPath, "gradle", "wrapper", "gradle-wrapper.properties"); const gradleProperties = file_system_utils_1.FileSystemUtils.buildPath(projectPath, "gradle.properties"); const mavenW = file_system_utils_1.FileSystemUtils.buildPath(projectPath, ".mvn", "wrapper", "maven-wrapper.properties"); const applicationProperties = file_system_utils_1.FileSystemUtils.buildPath(projectPath, "src", "main", "resources", "application.properties"); const pomFile = file_system_utils_1.FileSystemUtils.buildPath(projectPath, "pom.xml"); const buildGradleFile = file_system_utils_1.FileSystemUtils.buildPath(projectPath, "build.gradle"); if (!file_system_utils_1.FileSystemUtils.exists(applicationProperties)) { throw new application_exception_1.ApplicationPropertiesNotFound("application.properties file not found"); } if (javaPackManager === "gradle") { if (!file_system_utils_1.FileSystemUtils.exists(gradleW)) { throw new file_exception_1.FileNotFoundException("gradle.wrapper.properties file not found"); } if (!file_system_utils_1.FileSystemUtils.exists(buildGradleFile)) { throw new file_exception_1.FileNotFoundException("build.gradle file not found"); } console.log("Well Formation with gradle"); return; } if (!file_system_utils_1.FileSystemUtils.exists(mavenW)) { throw new file_exception_1.FileNotFoundException("maven.wrapper.properties file not found"); } if (!file_system_utils_1.FileSystemUtils.exists(pomFile)) { throw new file_exception_1.FileNotFoundException("pom.xml file not found"); } console.log("Well Formation with maven"); } } exports.JavaGenerator = JavaGenerator;