UNPKG

generator-begcode

Version:

Spring Boot + Angular/React/Vue in one handy generator

56 lines (55 loc) 2.83 kB
import { SERVER_MAIN_RES_DIR, SERVER_MAIN_SRC_DIR, SERVER_TEST_RES_DIR, SERVER_TEST_SRC_DIR } from '../../generator-constants.js'; export const replaceEntityFilePathVariables = (data, filePath) => { filePath = filePath ?.replace(/_package_/, data.packageFolder) ?.replace(/_entityPackage_/, data.entityJavaPackageFolder) ?.replace(/_mainClass_/, data.mainClass) ?.replace(/_persistClass_/, data.persistClass) ?.replace(/_entityClass_/, data.entityClass) ?.replace(/_dtoClass_/, data.dtoClass); return filePath?.includes('.jhi.') ? filePath : filePath?.replace(/_\w*/, ''); }; export const moveToJavaPackageSrcDir = (data, filePath) => `${data.javaPackageSrcDir}${replaceEntityFilePathVariables(data, filePath) ?? ''}`; export const moveToJavaPackageTestDir = (data, filePath) => `${data.javaPackageTestDir}${replaceEntityFilePathVariables(data, filePath) ?? ''}`; export const moveToSrcMainResourcesDir = (data, filePath) => `${data.srcMainResources}${replaceEntityFilePathVariables(data, filePath) ?? ''}`; export const moveToSrcTestResourcesDir = (data, filePath) => `${data.srcTestResources}${replaceEntityFilePathVariables(data, filePath) ?? ''}`; export function javaMainPackageTemplatesBlock(blockOrRelativePath = '') { return javaBlock({ srcPath: `${SERVER_MAIN_SRC_DIR}_package_/`, destProperty: 'javaPackageSrcDir', blockOrRelativePath, }); } export function javaMainResourceTemplatesBlock(blockOrRelativePath = '') { return javaBlock({ srcPath: SERVER_MAIN_RES_DIR, destProperty: 'srcMainResources', blockOrRelativePath, }); } export function javaTestResourceTemplatesBlock(blockOrRelativePath = '') { return javaBlock({ srcPath: SERVER_TEST_RES_DIR, destProperty: 'srcTestResources', blockOrRelativePath, }); } export function javaTestPackageTemplatesBlock(blockOrRelativePath = '') { return javaBlock({ srcPath: `${SERVER_TEST_SRC_DIR}_package_/`, destProperty: 'javaPackageTestDir', blockOrRelativePath, }); } function javaBlock({ srcPath, destProperty, blockOrRelativePath = '', }) { const block = typeof blockOrRelativePath !== 'string' ? blockOrRelativePath : undefined; const blockRenameTo = typeof block?.renameTo === 'function' ? block.renameTo : undefined; const relativePath = typeof blockOrRelativePath === 'string' ? blockOrRelativePath : (blockOrRelativePath.relativePath ?? ''); return { path: `${srcPath}${relativePath}`, ...block, renameTo(data, filePath) { return `${data[destProperty]}${replaceEntityFilePathVariables(data, relativePath) ?? ''}${replaceEntityFilePathVariables(data, blockRenameTo?.call?.(this, data, filePath) ?? filePath) ?? ''}`; }, }; }