import { FileUtil } from "../libs/hammerc/utils/FileUtil" import fs = require("fs"); import path = require("path"); import { process } from "../libs/hammerc/utils/ProcessUtil" class CreateLocalFhx { constructor(root: string, urlRoot: string) { this.start(root, urlRoot); } async start(root: string, urlRoot: string) { let s = this; await s.updateSvn(root, urlRoot); console.log('SVN 更新完毕'); let fhxDir = path.join(urlRoot, 'artRes'); let avatarres = path.join(urlRoot, 'avatarres'); let resource = path.join(urlRoot, 'resource'); let avatarres_fhx = path.join(urlRoot, 'avatarres_fhx'); let resource_fhx = path.join(urlRoot, 'resource_fhx'); FileUtil.deleteDir(avatarres_fhx); FileUtil.deleteDir(resource_fhx); console.log('开始拷贝:', avatarres, '...'); FileUtil.copyDir(avatarres, avatarres_fhx); console.log('开始拷贝:', resource, '...'); FileUtil.copyDir(resource, resource_fhx); console.log('拷贝完毕'); console.log('开始处理非和谐模型资源'); let cavatarUrl = path.join(path.join(fhxDir, 'artModel')); s.copyArtRes(cavatarUrl, avatarres_fhx); console.log('处理非和谐模型资源完毕'); console.log('开始处理非和谐UI资源'); let cUrl = path.join(path.join(fhxDir, 'artUi')); s.copyArtRes(cUrl, resource_fhx); console.log('处理非和谐UI资源完毕'); console.log('处理完毕,赶紧去提交SVN吧!'); } /**拷贝ui部分非和谐/和谐资源 */ copyArtRes(desUrl: string, srcUrl: string) { let desFiles = FileUtil.getAllFile(desUrl); let srcFiles = FileUtil.getAllFile(srcUrl); let copyUrls: string[]; if (desFiles && desFiles.length) { for (let fileUrl of desFiles) {//目标文件 copyUrls = []; let fileName = path.basename(fileUrl); if (srcFiles && srcFiles.length) { for (let i: number = 0; i < srcFiles.length; i++) { let u = srcFiles[i]; if (u.indexOf(fileName) >= 0) { copyUrls.push(u); } } } if (copyUrls.length > 0) { copyUrls.forEach(value => { FileUtil.copyFile(fileUrl, value); console.log('拷贝:' + fileUrl + "===>" + value); if (!copyUrls) copyUrls = []; copyUrls.push(value); }); } } } return true; } async updateSvn(root: string, updatePath: string) { let state = true; console.log('更新 svn', updatePath); await process(root, "svn_up.bat " + updatePath, true).catch((e) => { state = false, console.error('SVN update fail!', e) }); } } export function run(root: string, artPath: string): void { new CreateLocalFhx(root, artPath); }