【发布时间】:2015-12-31 15:07:22
【问题描述】:
有一些类似的问题,但没有一个对我的案子有帮助。所有其他问题都在谈论版本号,但我需要一些只会增加内部版本号的东西。
我需要一个脚本来检查是否有任何文件更改/创建/删除并将内部版本号增加 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);
【问题讨论】:
-
哇,这是一个快速的投票(在 2 秒内)。我认为你甚至不可能在 2 秒内读完问题。
-
我相信你被否决了,因为你的问题没有表现出任何努力,而且非常广泛。你也有几票接近,这两个都表明你的问题太宽泛了。
-
拒绝投票很好,我不反对。但是,甚至没有阅读问题就投反对票是荒谬的。他/她应该添加评论,所以我可以改进问题。我在问题中添加了我的代码,并试图在文本中进一步澄清。我试图将其作为一个质量问题,但否决票不是很有帮助。如果您想改进问题,请添加评论或自行编辑问题。
标签: php build versioning build-numbers