|
@@ -6,97 +6,95 @@ include "Utility.php";
|
|
|
class PackageClass
|
|
|
{
|
|
|
//当所有包都安装完毕后
|
|
|
- public static function postUpdate($vendorDir, $repoName){
|
|
|
- //获取配置信息
|
|
|
- $cfgPath = getDistributeConfigPath($vendorDir);
|
|
|
- $config = loadDistributeConfig($cfgPath);
|
|
|
- if(!$config){
|
|
|
- printf("Failed to load distribute config -- %s\n",$cfgPath);
|
|
|
- exit();
|
|
|
+ public static function index($vendorDir,$repoName){
|
|
|
+ //设置日志文件路径
|
|
|
+ if(! defined(LOG_PATH)){
|
|
|
+ define('LOG_PATH',getLogPath($vendorDir))
|
|
|
}
|
|
|
-
|
|
|
- //获取当前包信息
|
|
|
- $packageInfo = self::getPackageInfo($config,$vendorDir, $repoName);
|
|
|
-
|
|
|
- //下载当前包的add文件
|
|
|
- $packageFiles = getPackageFiles($packageInfo['configPath']);
|
|
|
- self::fetchAddFiles($packageInfo,$packageFiles['add-files']);
|
|
|
-
|
|
|
- //下载当前包的bin文件
|
|
|
- self::fetchBinFiles($packageInfo,$packageFiles['bin-files']);
|
|
|
-
|
|
|
- //下载当前包的copy文件
|
|
|
- self::fetchCopyFiles($packageInfo,$packageFiles['copy-files']);
|
|
|
- }
|
|
|
- //当某个依赖包安装完毕后
|
|
|
- public static function postPackageInstall($vendorDir, $repoName){
|
|
|
//获取配置信息
|
|
|
- $cfgPath = getDistributeConfigPath($vendorDir);
|
|
|
- $config = loadDistributeConfig($cfgPath);
|
|
|
+ $cfgPath = getConfigPath($vendorDir);
|
|
|
+ $config = loadConfig($cfgPath);
|
|
|
if(!$config){
|
|
|
printf("Failed to load distribute config -- %s\n",$cfgPath);
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
//获取当前包信息
|
|
|
- $packageInfo = self::getPackageInfo($config,$vendorDir, $repoName);
|
|
|
+ $packageInfo = self::getPackageInfo($config,$vendorDir,$repoName);
|
|
|
|
|
|
- //下载当前包的add文件
|
|
|
- $packageFiles = getPackageFiles($packageInfo['configPath']);
|
|
|
- self::fetchAddFiles($packageInfo,$packageFiles['add-files']);
|
|
|
+ //获取当前包的module文件
|
|
|
+ self::fetchModuleFiles($packageInfo);
|
|
|
|
|
|
- //下载当前包的bin文件
|
|
|
- self::fetchBinFiles($packageInfo,$packageFiles['bin-files']);
|
|
|
+ //获取当前包的common文件
|
|
|
+ self::fetchCommonFiles($packageInfo);
|
|
|
|
|
|
- //下载当前包的copy文件
|
|
|
- self::fetchCopyFiles($packageInfo,$packageFiles['copy-files']);
|
|
|
- }
|
|
|
- public static function postPackageUpdate($vendorDir, $repoName){
|
|
|
- }
|
|
|
- public static function setDevMode($devMode){
|
|
|
+ //获取当前包的config文件
|
|
|
+ self::fetchConfigFiles($packageInfo);
|
|
|
+
|
|
|
+ //顶层包的额外工作
|
|
|
+ if($repoName == ""){
|
|
|
+ //注册全局路径
|
|
|
+ self::registerPath($packageInfo);
|
|
|
+ //注册自启动程序
|
|
|
+ self::registerAutorun($packageInfo);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
//获取包相关信息
|
|
|
private static function getPackageInfo($config,$vendorDir, $repoName){
|
|
|
- if($repoName == ""){ //最上层包的信息
|
|
|
- $packageDir = dirname($vendorDir);
|
|
|
- $json = file_get_contents($packageDir . '/composer.json');
|
|
|
- $data = json_decode($json, true);
|
|
|
- $repoName = $data["name"];
|
|
|
+ $rootDir = dirname($vendorDir);
|
|
|
+ if($repoName == ""){
|
|
|
+ $repoDir = $rootDir; //最上层包所在目录
|
|
|
}
|
|
|
- else{ //其他依赖包的信息
|
|
|
- $packageDir = $vendorDir . '/' . $repoName;
|
|
|
+ else{
|
|
|
+ $repoDir = pathJoin($vendorDir,$repoName);//其他依赖包所在目录
|
|
|
}
|
|
|
- $cacheDir = pathJoin($config['cache-dir'],$repoName);
|
|
|
|
|
|
- //获取最上层包配置的 bin-dir
|
|
|
- $cfgPath = dirname($vendorDir)."/composer.json";
|
|
|
- $binDir = getBinDir($cfgPath);
|
|
|
+ //解析composer.json
|
|
|
+ $cfgPath = pathJoin($repoDir,'composer.json');
|
|
|
+ $data = json_decode(file_get_contents($cfgPath), true);
|
|
|
+ $moduleName = $data["distribute-helper"]["module-name"];
|
|
|
+
|
|
|
+ //获取安装目录
|
|
|
+ $commonDir = pathJoin($rootDir,'common');
|
|
|
+ $configDir = pathJoin($rootDir,'config',$moduleName);
|
|
|
+ $moduleDir = pathJoin($rootDir,'module',$moduleName);
|
|
|
+
|
|
|
+ //获取缓存目录
|
|
|
+ $cacheDir = pathJoin($config['cache-dir'],$data["name"]);
|
|
|
|
|
|
- //
|
|
|
+ //返回包的相关信息
|
|
|
return array(
|
|
|
- "repoName" => $repoName,
|
|
|
- "packageDir" => $packageDir,
|
|
|
- "configPath" => $packageDir."/composer.json",
|
|
|
+ "repoName" => $data["name"],
|
|
|
+ "repoDir" => $repoDir,
|
|
|
"cacheDir" => $cacheDir,
|
|
|
- "binDir" => $binDir,
|
|
|
"ossHost" => $config['oss-host'],
|
|
|
+ "moduleName" => $moduleName,
|
|
|
+ "commonDir" => $commonDir,
|
|
|
+ "configDir" => $configDir,
|
|
|
+ "moduleDir" => $moduleDir,
|
|
|
+ "helper" => $data["distribute-helper"],
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- //下载包add文件
|
|
|
- private static function fetchAddFiles($packageInfo,$files){
|
|
|
+ //下载包module文件
|
|
|
+ private static function fetchModuleFiles($packageInfo){
|
|
|
$cacheDir = $packageInfo['cacheDir'];
|
|
|
$repoName = $packageInfo['repoName'];
|
|
|
- $packageDir = $packageInfo['packageDir'];
|
|
|
- $ossUrl = $packageInfo['ossUrl'];
|
|
|
- if(! $files)
|
|
|
+ $moduleDir = $packageInfo['moduleDir'];
|
|
|
+ $ossHost = $packageInfo['ossHost'];
|
|
|
+
|
|
|
+ $moduleFiles = $packageInfo['helper']['module-files'];
|
|
|
+ if(! $moduleFiles){
|
|
|
+ logInfo($repoName,'no module files defined. skip.');
|
|
|
return;
|
|
|
+ }
|
|
|
|
|
|
- foreach($files as $fileName){
|
|
|
+ foreach($moduleFiles as $fileName){
|
|
|
printf("[%s] fetching file -- %s\n",$repoName,$fileName);
|
|
|
|
|
|
//下载文件到缓存区
|
|
|
- $filePath = downloadToDir($ossUrl,$repoName,$fileName,$cacheDir);
|
|
|
+ $filePath = downloadToDir($ossHost,$repoName,$fileName,$cacheDir);
|
|
|
if(! $filePath ){
|
|
|
printf("[%s] fetch file failed -- %s\n",$repoName,$fileName);
|
|
|
continue;
|
|
@@ -104,7 +102,7 @@ class PackageClass
|
|
|
|
|
|
// 解压文件
|
|
|
if( isZipFile($fileName) ){
|
|
|
- if(! unzipFile($filePath,$packageDir)) {
|
|
|
+ if(! unzipFile($filePath,$moduleDir)) {
|
|
|
printf("[%s] unzip file failed -- %s\n ",$repoName,$fileName);
|
|
|
unlink($filePath);
|
|
|
}
|
|
@@ -112,61 +110,69 @@ class PackageClass
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //下载包bin文件
|
|
|
- private static function fetchBinFiles($packageInfo,$binFiles){
|
|
|
+ //下载包common文件
|
|
|
+ private static function fetchCommonFiles($packageInfo){
|
|
|
$cacheDir = $packageInfo['cacheDir'];
|
|
|
$repoName = $packageInfo['repoName'];
|
|
|
- $binDir = $packageInfo['binDir'];
|
|
|
- $ossUrl = $packageInfo['ossUrl'];
|
|
|
- if(! $binDir)
|
|
|
- return;
|
|
|
- if(! $binFiles)
|
|
|
+ $commonDir = $packageInfo['commonDir'];
|
|
|
+ $ossHost = $packageInfo['ossHost'];
|
|
|
+ $commonFiles = $packageInfo['helper']['common-files'];
|
|
|
+ if(! $commonFiles){
|
|
|
+ logInfo($repoName,'no common files defined. skip.');
|
|
|
return;
|
|
|
- foreach($binFiles as $fileName){
|
|
|
- printf("[%s] fetching binfile -- %s\n",$repoName,$fileName);
|
|
|
+ }
|
|
|
+ foreach($commonFiles as $fileName){
|
|
|
+ printf("[%s] fetching common file -- %s\n",$repoName,$fileName);
|
|
|
//下载文件到缓存区
|
|
|
- $filePath = downloadToDir($ossUrl,$repoName,$fileName,$cacheDir);
|
|
|
+ $filePath = downloadToDir($ossHost,$repoName,$fileName,$cacheDir);
|
|
|
if(! $filePath ){
|
|
|
- printf("[%s] fetch binfile failed -- %s\n",$repoName,$fileName);
|
|
|
+ printf("[%s] fetch common file failed -- %s\n",$repoName,$fileName);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// 解压文件
|
|
|
if( isZipFile($fileName) ){
|
|
|
- if(! unzipFile($filePath,$binDir)) {
|
|
|
- printf("[%s] unzip binfile failed -- %s\n ",$repoName,$fileName);
|
|
|
+ if(! unzipFile($filePath,$commonDir)) {
|
|
|
+ printf("[%s] unzip common file failed -- %s\n ",$repoName,$fileName);
|
|
|
unlink($filePath);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //下载包copy文件
|
|
|
- private static function fetchCopyFiles($packageInfo,$binFiles){
|
|
|
+ //下载包config文件
|
|
|
+ private static function fetchConfigFiles($packageInfo){
|
|
|
$cacheDir = $packageInfo['cacheDir'];
|
|
|
$repoName = $packageInfo['repoName'];
|
|
|
- $binDir = $packageInfo['binDir'];
|
|
|
- $ossUrl = $packageInfo['ossUrl'];
|
|
|
- if(! $binDir)
|
|
|
- return;
|
|
|
- if(! $binFiles)
|
|
|
+ $configDir = $packageInfo['configDir'];
|
|
|
+ $ossHost = $packageInfo['ossHost'];
|
|
|
+ $configFiles = $packageInfo['helper']['config-files'];
|
|
|
+ if(! $configFiles){
|
|
|
+ logInfo($repoName,'no config files defined. skip.');
|
|
|
return;
|
|
|
- foreach($binFiles as $fileName){
|
|
|
- printf("[%s] fetching binfile -- %s\n",$repoName,$fileName);
|
|
|
+ }
|
|
|
+ foreach($configFiles as $fileName){
|
|
|
+ printf("[%s] fetching config file -- %s\n",$repoName,$fileName);
|
|
|
//下载文件到缓存区
|
|
|
- $filePath = downloadToDir($ossUrl,$repoName,$fileName,$cacheDir);
|
|
|
+ $filePath = downloadToDir($ossHost,$repoName,$fileName,$cacheDir);
|
|
|
if(! $filePath ){
|
|
|
- printf("[%s] fetch binfile failed -- %s\n",$repoName,$fileName);
|
|
|
+ printf("[%s] fetch config file failed -- %s\n",$repoName,$fileName);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// 解压文件
|
|
|
if( isZipFile($fileName) ){
|
|
|
- if(! unzipFile($filePath,$binDir)) {
|
|
|
- printf("[%s] unzip binfile failed -- %s\n ",$repoName,$fileName);
|
|
|
+ if(! unzipFile($filePath,$configDir)) {
|
|
|
+ printf("[%s] unzip config file failed -- %s\n ",$repoName,$fileName);
|
|
|
unlink($filePath);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private static function registerPath($packageInfo){
|
|
|
+ }
|
|
|
+
|
|
|
+ private static function registerAutorun($packageInfo){
|
|
|
+ }
|
|
|
}
|