Skip to content

Commit 2bec04b

Browse files
committed
Applied current version to CLI title
1 parent 5e24c6d commit 2bec04b

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

app.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,48 @@ function pause() {
187187

188188
// 헤더 출력
189189
function printHeader() {
190+
const version = getAppVersion();
190191
console.clear();
191192
console.log(colors.cyan + '═'.repeat(60) + colors.reset);
192-
console.log(colors.cyan + colors.bright + ` ${msg.title}` + colors.reset);
193+
console.log(colors.cyan + colors.bright + ` ${msg.title} v${version}` + colors.reset);
193194
console.log(colors.cyan + '═'.repeat(60) + colors.reset);
194195
console.log();
195196
}
196197

198+
199+
/**
200+
* Get application version
201+
*/
202+
function getAppVersion() {
203+
// 1) Build-time/runtime injected env (release.bat or CI can set this)
204+
if (process.env.PKG_VERSION && process.env.PKG_VERSION.trim()) {
205+
return process.env.PKG_VERSION.trim();
206+
}
207+
208+
// 2) Bundled package.json via pkg snapshot (require works if referenced)
209+
try {
210+
// This require ensures pkg includes package.json in the snapshot
211+
// eslint-disable-next-line import/no-dynamic-require, global-require
212+
const bundledPkg = require('./package.json');
213+
if (bundledPkg && bundledPkg.version) return bundledPkg.version;
214+
} catch (_) { /* ignore */ }
215+
216+
// 3) Filesystem package.json next to executable (dev or release folder)
217+
try {
218+
const pkgPath = path.join(APP_ROOT, 'package.json');
219+
if (fs.existsSync(pkgPath)) {
220+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
221+
if (pkg && pkg.version) return pkg.version;
222+
}
223+
} catch (_) { /* ignore */ }
224+
225+
// 4) npm-provided env in dev
226+
if (process.env.npm_package_version) return process.env.npm_package_version;
227+
228+
// 5) Fallback
229+
return '0.0.0';
230+
}
231+
197232
// 메뉴 출력
198233
function printMenu() {
199234
console.log(colors.cyan + '═'.repeat(60) + colors.reset);

0 commit comments

Comments
 (0)