有一些类似的问题,但没有一个对我的案子有帮助。所有其他问题都在谈论版本号,但我需要一些只会增加内部版本号的东西。
我需要一个脚本来检查是否有任何文件更改/创建/删除并将内部版本号增加 1。
我在网上找不到这个问题的答案,自己准备了一个脚本。我在问这个问题,所以我可以分享我的脚本作为答案。
这是我想出的脚本。随时进一步改进并修改我的答案或发布您自己的答案:
// Opening the json file that holds the file paths and file modification dates
$jsonArray = json_decode(file_get_contents('files.json'), true);
$jsonFileArray = array();
// Putting the values into a local array
foreach ($jsonArray as $filePath => $modifiedDate) {
$jsonFileArray[$filePath] = $modifiedDate;
}
// Iterating through the directories and putting the file paths and modification dates into a local array
$filesArray = array();
$dir_iterator = new RecursiveDirectoryIterator(".");
$recursive_iterator = new RecursiveIteratorIterator($dir_iterator);
foreach ($recursive_iterator as $file) {
if ($file->isDir()) {
continue;
}
if (substr($file, -9) != 'error_log') {
$fileName = $file->getPathname();
$fileModifiedDate = date('m/d/y H:i:s', $file->getMTime());
$filesArray[$fileName] = $fileModifiedDate;
}
}
// Checking if there are any files that are modified/created/deleted
if ($jsonFileArray != $filesArray) {
// If there are any changes, the build number is increased by 1 and saved into 'build' file
$buildFile = "build";
file_put_contents($buildFile, file_get_contents($buildFile) + 1);
}
// Updating the json file with the latest modifiedDates
$jsonFile = fopen('files.json', 'w');
fwrite($jsonFile, json_encode($filesArray, JSON_UNESCAPED_SLASHES));
fclose($jsonFile);