import path from "path"; import commandLineArgs from "command-line-args"; // 명령줄 인수 정의 const CMD_ARGS = Object.freeze({ TYPE: { name: 'env', type: String, alias: 'e', defaultValue: 'prod' }, PATH: { name: 'path', type: String, alias: 'p', defaultValue: './' } }); const options = commandLineArgs([CMD_ARGS.TYPE, CMD_ARGS.PATH], { partial: true }); // 기본 경로 설정 let pwd = path.dirname(process.execPath); const isElectron = process.env.ELECTRONAPP === "true"; const env = options.env || 'prod'; // 옵션이 없을 경우 기본값 'prod' const platform = process.platform; // Electron 앱과 관련된 경로 설정 if (isElectron && env === "prod" && (platform === "darwin" || platform === "win32")) { pwd = path.join((process as any).resourcesPath, "app"); } // 환경별 경로 조정 let approot = pwd; let businesspath = path.join(approot, "business", "service"); switch (env) { case "local": approot = path.join(process.cwd(), "src", "main"); businesspath = path.join(approot, "js", "business", "service"); break; case "dev": approot = path.join(pwd, "dist"); businesspath = path.join(approot, "business", "service"); break; case "prod": approot = path.join(pwd, '../Resources/app', "dist"); businesspath = path.join(approot, "business", "service"); break; } // 추가 경로 설정 let resourcePath = path.join(approot, "resources"); let assetPath = path.join(approot, "assets"); // 사용자 지정 경로 설정 if (options.path && options.path !== "./") { approot = path.join(pwd, options.path); } // Windows에서 경로 구분자 문제 해결 if (platform === "win32") { [approot, businesspath, resourcePath, assetPath].forEach(path => { path = path.replace(/\\/g, '/'); }); } // 외부에서 사용할 변수들 export const __node_modules_path = path.join(approot, "node_modules"); export const __approot = approot; export const __businesspath = businesspath; export const __resourcepath = resourcePath; export const __assetspath = assetPath; export const __ENV = env; export const __PATH = options.path; export const __env_type = env; export const __is_prod = env === 'prod'; export const __default_lang = "ko"; // 로깅 부분은 주석 처리된 상태로 유지 console.log(`env : ${env}`); console.log(`__approot : ${__approot}`); console.log(`__resourcepath : ${__resourcepath}`); console.log(`__assetspath : ${__assetspath}`); console.log(`__businesspath : ${__businesspath}`) ; // import FileUtil from "../utils/FileUtil"; // let logstr = "" // logstr += `\n __approot : ${__approot}`; // logstr += `\n __resourcepath : ${__resourcepath}`; // logstr += `\n __assetspath : ${__assetspath}`; // logstr += `\n __businesspath : ${__businesspath}`; // logstr += `\n pwd : ${process.env.PWD}`; // logstr += `\n cwd : ${process.cwd()}`; // logstr += `\n ELECTRONAPP : ${process.env.ELECTRONAPP}`; // logstr += `\n node_modules_path : ${__node_modules_path}`; // logstr += `\n process resource : ${(process as any).resourcesPath}`; // FileUtil.writeString('/Users/solutionhlp/Downloads/testLog.txt', logstr)