From 9a8d7436066df27b62755b53c740b3c69a604eda Mon Sep 17 00:00:00 2001 From: Eugene Lukash Date: Fri, 20 Nov 2020 01:34:52 -0500 Subject: [PATCH] module-level pom templates --- center.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/center.js b/center.js index 9e3a2dd..eb23744 100644 --- a/center.js +++ b/center.js @@ -63,9 +63,9 @@ function generateParentTemplate(parentPom) { let template = parentPom.replace('.xml', '.template.xml') if (ops.exists(template)) { let content = ops.read(template) - .replace('G', parentGroup()) - .replace('A', parentArtifact(parentPom)) - .replace('V', parentVersion()) + .replace(/G/g, parentGroup()) + .replace(/A/g, parentArtifact(parentPom)) + .replace(/V/g, parentVersion()) .replace('', artifactModules.map(m => ` ${m.path}`).join('')) @@ -76,11 +76,28 @@ function generateParentTemplate(parentPom) { function generatePom(module, rule, parentPom) { let coords = mvn.coords(jarOf(rule)) // for each - let relativePath = '../' + parentPom + let parentPath = '../' + parentPom for (let ch of module.path) { - if (ch === '/') relativePath = '../' + relativePath + if (ch === '/') parentPath = '../' + parentPath } - let content = ` + + let pom = paths.join(module.path, 'pom.xml') + let template = paths.join(module.path, 'pom.template.xml') + let content + + if (ops.exists(template)) { + content = ops.read(template) + .replace(/G/g, coords.group) + .replace(/A/g, coords.artifact) + .replace(/V/g, coords.version) + .replace(/G/g, parentGroup()) + .replace(/A/g, parentArtifact(parentPom)) + .replace(/V/g, parentVersion()) + .replace(/P/g, parentPath) + .replace('', pomDependencies(module)) + + } else { + content = ` 4.0.0 ${coords.group} @@ -92,13 +109,14 @@ function generatePom(module, rule, parentPom) { ${parentGroup()} ${parentArtifact(parentPom)} ${parentVersion()} - ${relativePath} + ${parentPath} ${pomDependencies(module)} ` - ops.write(paths.join(module.path, 'pom.xml'), content) + } + ops.write(pom, content) } function pomDependencies(module) {