휴가 신청 삭제시 로그파일에 기록되도록 함
This commit is contained in:
177
Project/_project_updater.js
Normal file
177
Project/_project_updater.js
Normal file
@@ -0,0 +1,177 @@
|
||||
// C# 프로젝트 파일 자동 업데이트 헬퍼
|
||||
// 새로운 파일을 생성할 때 EETGW.csproj에 자동으로 등록하는 스크립트
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
class ProjectUpdater {
|
||||
constructor(projectPath = 'EETGW.csproj') {
|
||||
this.projectPath = projectPath;
|
||||
this.projectContent = '';
|
||||
this.loadProject();
|
||||
}
|
||||
|
||||
loadProject() {
|
||||
try {
|
||||
this.projectContent = fs.readFileSync(this.projectPath, 'utf8');
|
||||
} catch (error) {
|
||||
console.error('프로젝트 파일을 읽을 수 없습니다:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 새로운 파일을 프로젝트에 등록
|
||||
* @param {string} filePath - Web/wwwroot로 시작하는 상대 경로
|
||||
* @param {string} fileType - 'Content' 또는 'None' (기본값: 'None')
|
||||
*/
|
||||
addFile(filePath, fileType = 'None') {
|
||||
// 파일 경로를 백슬래시로 변경 (Windows 형식)
|
||||
const windowsPath = filePath.replace(/\//g, '\\');
|
||||
|
||||
// 이미 등록된 파일인지 확인
|
||||
if (this.isFileAlreadyRegistered(windowsPath)) {
|
||||
console.log(`파일이 이미 등록되어 있습니다: ${windowsPath}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 새로운 항목 생성
|
||||
const newEntry = ` <${fileType} Include="${windowsPath}">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</${fileType}>`;
|
||||
|
||||
// 마지막 wwwroot 관련 항목 찾기
|
||||
const lastWwwrootMatch = this.findLastWwwrootEntry();
|
||||
|
||||
if (lastWwwrootMatch) {
|
||||
// 마지막 wwwroot 항목 다음에 삽입
|
||||
const insertPosition = lastWwwrootMatch.index + lastWwwrootMatch[0].length;
|
||||
this.projectContent =
|
||||
this.projectContent.slice(0, insertPosition) +
|
||||
'\n' + newEntry +
|
||||
this.projectContent.slice(insertPosition);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
console.error('wwwroot 섹션을 찾을 수 없습니다.');
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 파일이 이미 등록되어 있는지 확인
|
||||
*/
|
||||
isFileAlreadyRegistered(filePath) {
|
||||
const patterns = [
|
||||
`Include="${filePath}"`,
|
||||
`Include='${filePath}'`,
|
||||
filePath.replace(/\\/g, '/') // 슬래시 형태도 확인
|
||||
];
|
||||
|
||||
return patterns.some(pattern => this.projectContent.includes(pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* 마지막 wwwroot 관련 항목 찾기
|
||||
*/
|
||||
findLastWwwrootEntry() {
|
||||
const wwwrootPattern = /<(?:Content|None) Include="Web\\wwwroot.*?<\/(?:Content|None)>/gs;
|
||||
let lastMatch = null;
|
||||
let match;
|
||||
|
||||
while ((match = wwwrootPattern.exec(this.projectContent)) !== null) {
|
||||
lastMatch = match;
|
||||
}
|
||||
|
||||
return lastMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* 프로젝트 파일 저장
|
||||
*/
|
||||
saveProject() {
|
||||
try {
|
||||
fs.writeFileSync(this.projectPath, this.projectContent, 'utf8');
|
||||
console.log('프로젝트 파일이 업데이트되었습니다.');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('프로젝트 파일 저장 실패:', error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 여러 파일을 한 번에 등록
|
||||
*/
|
||||
addFiles(files) {
|
||||
let hasChanges = false;
|
||||
|
||||
files.forEach(({ path, type = 'None' }) => {
|
||||
if (this.addFile(path, type)) {
|
||||
hasChanges = true;
|
||||
console.log(`추가됨: ${path}`);
|
||||
}
|
||||
});
|
||||
|
||||
return hasChanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* React 관련 파일들 자동 등록
|
||||
*/
|
||||
addReactFiles(basePath) {
|
||||
const reactFiles = [
|
||||
{ path: `${basePath}.html`, type: 'None' },
|
||||
{ path: `${basePath}.jsx`, type: 'None' }
|
||||
];
|
||||
|
||||
return this.addFiles(reactFiles);
|
||||
}
|
||||
}
|
||||
|
||||
// 사용 예시
|
||||
function addNewReactComponent(componentName) {
|
||||
const updater = new ProjectUpdater();
|
||||
const basePath = `Web\\wwwroot\\react\\${componentName}`;
|
||||
|
||||
const files = [
|
||||
{ path: `${basePath}.jsx`, type: 'None' },
|
||||
{ path: `Web\\wwwroot\\react-${componentName.toLowerCase()}.html`, type: 'None' }
|
||||
];
|
||||
|
||||
if (updater.addFiles(files)) {
|
||||
updater.saveProject();
|
||||
console.log(`✅ ${componentName} 컴포넌트 파일들이 프로젝트에 등록되었습니다.`);
|
||||
}
|
||||
}
|
||||
|
||||
// 일반 파일 추가
|
||||
function addNewFile(filePath, fileType = 'None') {
|
||||
const updater = new ProjectUpdater();
|
||||
|
||||
if (updater.addFile(filePath, fileType)) {
|
||||
updater.saveProject();
|
||||
console.log(`✅ 파일이 프로젝트에 등록되었습니다: ${filePath}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ProjectUpdater,
|
||||
addNewReactComponent,
|
||||
addNewFile
|
||||
};
|
||||
|
||||
// CLI에서 직접 실행할 수 있도록
|
||||
if (require.main === module) {
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
if (args.length === 0) {
|
||||
console.log('사용법: node _project_updater.js <파일경로> [파일타입]');
|
||||
console.log('예시: node _project_updater.js "Web\\wwwroot\\react\\NewComponent.jsx" None');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const filePath = args[0];
|
||||
const fileType = args[1] || 'None';
|
||||
|
||||
addNewFile(filePath, fileType);
|
||||
}
|
||||
Reference in New Issue
Block a user