Skip to content

Commit 495bc61

Browse files
committed
feat: kotlin 기반 spring boot 프로젝트 버전 bump 지원
1 parent efb1695 commit 495bc61

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

scripts/compute-bump.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import { existsSync, readFileSync } from 'node:fs';
33
import path from 'node:path';
4-
import { detectProjectType, ensureDir, parseSemverXyz, setOutput, tryExecOut } from "./utils.mjs";
4+
import { detectProjectType, parseSemverXyz, resolveGradleFilePath, setOutput, tryExecOut } from "./utils.mjs";
55

66
/**
77
* projectType 자동 판별 (Next.js / Spring Boot / Plain)
@@ -75,7 +75,7 @@ if (lastTag) {
7575
}
7676
}
7777
} else if (projectType === 'spring') {
78-
const gradlePath = path.join(workdir, 'build.gradle');
78+
const gradlePath = resolveGradleFilePath(workdir);
7979
if (existsSync(gradlePath)) {
8080
const txt = readFileSync(gradlePath, 'utf8');
8181

scripts/sync-files.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import path from 'node:path';
33
import {
44
ensureDir,
5+
resolveGradleFilePath,
56
runCmd,
67
updateApplicationYamlVersion,
78
updateGradleVersionFile,
@@ -27,7 +28,10 @@ const repoRoot = process.cwd();
2728
const workdir = inputWorkdir ? path.join(repoRoot, inputWorkdir) : repoRoot;
2829

2930
if (projectType === 'spring') {
30-
const gradlePath = path.join(workdir, 'build.gradle');
31+
const gradlePath = resolveGradleFilePath(workdir);
32+
if (!gradlePath) {
33+
console.error("Gradle 파일(build.gradle 또는 build.gradle.kts)을 찾을 수 없습니다.");
34+
}
3135

3236
try {
3337
updateGradleVersionFile(gradlePath, newVersion);

scripts/utils.mjs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,54 @@ export function extractVersionDescription(subject) {
6464
}
6565

6666
// ===== Project detection =====
67+
export function resolveGradleFilePath(workdir) {
68+
const kts = path.join(workdir, 'build.gradle.kts');
69+
const groovy = path.join(workdir, 'build.gradle');
70+
if (fs.existsSync(kts)) {
71+
return kts;
72+
}
73+
if (fs.existsSync(groovy)) {
74+
return groovy;
75+
}
76+
return '';
77+
}
78+
6779
export function detectProjectType(workdir, hint = 'auto') {
6880
if (hint !== 'auto') {
6981
return hint;
7082
}
7183
const pkg = path.join(workdir, 'package.json');
72-
const gradle = path.join(workdir, 'build.gradle');
84+
const gradlePath = resolveGradleFilePath(workdir);
7385
if (fs.existsSync(pkg)) {
7486
return 'next';
7587
}
76-
if (fs.existsSync(gradle)) {
88+
if (gradlePath) {
7789
return 'spring';
7890
}
79-
console.log("package.json 또는 build.gradle 을 찾을 수 없습니다. 일반 프로젝트로 설정합니다.");
91+
console.log("package.json 또는 build.gradle(.kts) 을 찾을 수 없습니다. 일반 프로젝트로 설정합니다.");
8092
return 'plain';
8193
}
8294

95+
function isKtsFile(filePath) {
96+
return filePath.endsWith('.kts');
97+
}
98+
8399
// ===== Gradle version helpers =====
84100

85101
export function replaceGradleVersionInText(txt, newVersion) {
86102
let out = txt;
87-
// 통일: 모두 assignment 스타일로 교체
103+
const kts = isKtsFile(filePath);
104+
const quote = kts ? '"' : "'";
105+
106+
// 라인 선두의 version= 또는 version '...' 스타일 모두 갱신 (Groovy만 method 스타일 허용)
88107
const reAssign = /(^|\n)\s*version\s*=\s*['"]\d+\.\d+\.\d+(?:-[^'"]+)?['"]/gm;
89108
const reMethod = /(^|\n)\s*version\s+['"]\d+\.\d+\.\d+(?:-[^'"]+)?['"]/gm;
90109

91110
if (reAssign.test(out)) {
92-
out = out.replace(reAssign, (m, p1) => `${p1}version = '${newVersion}'`);
111+
out = out.replace(reAssign, (m, p1) => `${p1}version = ${quote}${newVersion}${quote}`);
93112
}
94-
if (reMethod.test(out)) {
95-
out = out.replace(reMethod, (m, p1) => `${p1}version = '${newVersion}'`);
113+
if (!kts && reMethod.test(out)) { // [CHANGED] .kts에서는 method 스타일 금지
114+
out = out.replace(reMethod, (m, p1) => `${p1}version = ${quote}${newVersion}${quote}`);
96115
}
97116

98117
// 둘 다 없었다면 파일 하단에 추가
@@ -107,7 +126,7 @@ export function updateGradleVersionFile(filePath, newVersion) {
107126
throw new Error(`build.gradle 파일을 찾을 수 없습니다: ${filePath}`);
108127
}
109128
const txt = fs.readFileSync(filePath, 'utf8');
110-
const updated = replaceGradleVersionInText(txt, newVersion);
129+
const updated = replaceGradleVersionInText(txt, newVersion, filePath);
111130
fs.writeFileSync(filePath, updated, 'utf8');
112131
}
113132

0 commit comments

Comments
 (0)