elviss 2 роки тому
батько
коміт
ae27153637
1 змінених файлів з 61 додано та 6 видалено
  1. 61 6
      src/PackageClass.php

+ 61 - 6
src/PackageClass.php

@@ -172,19 +172,23 @@ class PackageClass
 			
 			//获取当前包的module文件
 			if(! self::fetchModuleFiles($packageInfo) ){
-				self::setProgressFailed('FETCH_MODULE_FAILED');
+				self::setProgressFailed('FETCH_MODULE_FILES_FAILED');
 				return false;
 			}
 			self::setProgressStep2($count,$i,1);
 			
 			//获取当前包的common文件
 			if(! self::fetchCommonFiles($packageInfo) ){
-				self::setProgressFailed('FETCH_COMMON_FAILED');
+				self::setProgressFailed('FETCH_COMMON_FILES_FAILED');
 				return false;
 			}
 			self::setProgressStep2($count,$i,2);
 
-			//拷贝当前包的config文件
+			//拷贝当前包的vendor文件
+			if(! self::fetchVendorFiles($packageInfo) ){
+				self::setProgressFailed('FETCH_VENDOR_FILES_FAILED');
+				return false;
+			}
 			self::setProgressStep2($count,$i,3);
 		}
 		return true;
@@ -362,6 +366,7 @@ class PackageClass
 			"repoName" => $repoName,
 			"version" => $pkg->getPrettyVersion(),
 			"rootDir" => $rootDir,
+			"vendorDir" => $vendorDir,
 			"cacheDir" => $cacheDir,
 			"toolDir" => $config['tool-dir'],
 			"ossHost" => $config['oss-host'],
@@ -404,12 +409,18 @@ class PackageClass
 				}
 			}
 
-			// 解压文件
+			// 解压或拷贝文件
 			if( isZipFile($fileName) ){
 				if(! unzipFile($toolDir,$filePath,$moduleDir)) {
 					logError($repoName,"unzip module file failed",$fileName);
 					return false;
 				}
+			}else{
+				$targetPath = pathJoin($moduleDir,$fileName);
+				if(! fileCopy($filePath,$targetPath) ){
+					logError($repoName,"copy module file failed",$filePath,'-->',$targetPath);
+					return false;
+				}
 			}
 		}
 		return true;
@@ -436,18 +447,62 @@ class PackageClass
 			}
 			logInfo("succeeded to fetch common file --",$repoName,$fileName);
 
-			// 解压文件
+			// 解压或拷贝文件
+			$targetDir = pathJoin($commonDir,$target);
 			if( isZipFile($fileName) ){
-				$targetDir = pathJoin($commonDir,$target);
 				if(! unzipFile($toolDir,$filePath,$targetDir)) {
 					logError($repoName,"unzip common file failed",$fileName);
 					return false;
 				}
+			}else{
+				$targetPath = pathJoin($targetDir,$fileName);
+				if(! fileCopy($filePath,$targetPath) ){
+					logError($repoName,"copy common file failed",$filePath,'-->',$targetPath);
+					return false;
+				}
 			}
 		}
 		return true;
 	}
 	
+	//下载包vendor文件
+	private static function fetchVendorFiles($packageInfo)
+	{
+		$toolDir = $packageInfo['toolDir'];
+		$cacheDir = $packageInfo['cacheDir'];
+		$repoName = $packageInfo['repoName'];
+		$version  = $packageInfo['version'];
+		$vendorDir = $packageInfo['vendorDir'];
+		$ossHost = $packageInfo['ossHost'];
+		$vendorFiles = $packageInfo['helper']['vendor-files']? : array();
+		foreach($vendorFiles as $fileInfo){
+			$fileName = $fileInfo['name'];
+			$target = $fileInfo['target'];
+			//下载文件到缓存区
+			$filePath = downloadToDir($toolDir,$ossHost,$repoName,$fileName,$cacheDir);
+			if(! $filePath ){
+				logError($repoName,"fetch common file failed",$fileName);
+				return false;
+			}
+			logInfo("succeeded to fetch common file --",$repoName,$fileName);
+
+			// 解压或拷贝文件
+			if( isZipFile($fileName) ){
+				$targetDir = pathJoin($vendorDir,$target);
+				if(! unzipFile($toolDir,$filePath,$targetDir)) {
+					logError($repoName,"unzip common file failed",$fileName);
+					return false;
+				}
+			}else{
+				$targetPath = pathJoin($vendorDir,$repoName,$fileName);
+				if(! fileCopy($filePath,$targetPath) ){
+					logError($repoName,"offpkg file copy failed",$filePath,'-->',$targetPath);
+					return false;
+				}
+			}
+		}
+		return true;
+	}	
 	//拷贝config文件
 	/*
 	private static function copyConfigFiles($packageInfo)