<NME> build
<BEF> <?php
/*
 * Build Tools for Holy Lance
 * https://github.com/lincanbin/Holy-Lance
 *
 * Copyright 2016 Canbin Lin (lincanbin@hotmail.com)
 * http://www.94cb.com/
 *
 * Licensed under the MIT License:
 * https://opensource.org/licenses/MIT
 * 
 * A Linux environmental probe.
 */
define("BUILD_FILE_NAME", "holy_lance.php");
define("ENTER_FILE_NAME", "index.php");
$file_buffer = array();
$ignore_dir = array(".git", "build", "screenshot");
$file_buffer = array();
$ignore_dir = array(".git", "build", "screenshot");
$ignore_file = array("../build/build");
$build_extension = array("php", "css", "js");
$old_file_name_list = array();
$new_file_name_list = array();

function add_file_to_buffer($file_name)
{
	global $file_buffer, $build_extension, $old_file_name_list, $new_file_name_list;
	$old_file_name = $old_file_name_list[$file_name];
	$new_file_name = $new_file_name_list[$file_name];
	$file_info = pathinfo($file_name);
	$file_extension = empty($file_info['extension']) ? '' : $file_info['extension'];
	if (in_array($file_extension, $build_extension)){
		$file_buffer[$old_file_name]['extension'] = $file_extension;
		$file_buffer[$old_file_name]['content'] = file_get_contents($file_name);
			foreach ($old_file_name_list as $file_name_key => $old_file_name_value) {
				$file_buffer[$old_file_name]['content'] = str_replace($old_file_name_value, $new_file_name_list[$file_name_key], $file_buffer[$old_file_name]['content']);
			}
		$file_buffer[$old_file_name]['content'] = str_replace("	", "", $file_buffer[$old_file_name]['content']);
	}
}

function listDir($dir)
{
	global $ignore_dir, $ignore_file, $old_file_name_list, $new_file_name_list;
	if (is_dir($dir)) {
		if ($dh = opendir($dir)) {
			while (($file = readdir($dh)) !== false) {
				if ((is_dir($dir . "/" . $file)) && $file != "." && $file != "..") {
					if (!in_array($file, $ignore_dir)) {
						// echo $file . "\n";
						listDir($dir . $file . "/");
					}
				} else {
					if ($file != "." && $file != "..") {
						$file_name = $dir . $file;
						if (!in_array($file_name, $ignore_file)) {
							$old_file_name_list[$file_name] = str_replace("../", "", $file_name);
							$new_file_name_list[$file_name] = BUILD_FILE_NAME . "?file=" . urlencode($old_file_name_list[$file_name]);
							echo $file_name . "\n";
						}
					}
				}
			}
			closedir($dh);
		}
	}
}


listDir("../");

foreach ($old_file_name_list as $file_name => $old_file_name) {
	add_file_to_buffer($file_name);
}

$fp = fopen(BUILD_FILE_NAME, 'w');
$entry_file = !empty($file_buffer[ENTER_FILE_NAME]) ? $file_buffer[ENTER_FILE_NAME] : '';
if ($entry_file === '') {
	echo 'Entry file not found! ';
	exit(1);
}
unset($file_buffer[ENTER_FILE_NAME]);
$common_file = !empty($file_buffer[COMMON_FILE_NAME]) ? $file_buffer[COMMON_FILE_NAME] : '';
if ($common_file === '') {
	echo 'Common file not found! ';
	exit(2);
}
fwrite($fp, '<?php
define("HAS_BEEN_COMPILED", true);
?>');
$common_file['content'] = str_replace("define('HOLY_LANCE_PASSWORD', '');", "define('HOLY_LANCE_PASSWORD', '" . $password . "');", $common_file['content']);
fwrite($fp, $common_file['content']);
unset($file_buffer[COMMON_FILE_NAME]);
foreach ($file_buffer as $file_name => $file) {
	fwrite($fp, '<?php
?>');
}
fwrite($fp, $entry_file['content']);
fclose($fp);
		fwrite($fp, 'header("Content-type: text/javascript");');
	}
	fwrite($fp, '?>');
	fwrite($fp, $file['content']);
	fwrite($fp, '<?php
exit();
endif;
?>');
}

fwrite($fp, $entry_file['content']);
fclose($fp);

echo "\n\n" . BUILD_FILE_NAME . " has been generated! \npssword: " . $password . "\n\n";
<MSG> Add parameter to build.

<DFF> @@ -11,7 +11,14 @@
  * 
  * A Linux environmental probe.
  */
-define("BUILD_FILE_NAME", "holy_lance.php");
+$args = getopt('n:');
+$build_file_name = trim(!empty($args['n']) ? $args['n'] : "");
+if (!empty($build_file_name)) {
+	define("BUILD_FILE_NAME", $build_file_name . ".php");
+} else {
+	define("BUILD_FILE_NAME", "holy_lance.php");
+}
+
 define("ENTER_FILE_NAME", "index.php");
 $file_buffer = array();
 $ignore_dir = array(".git", "build", "screenshot");
@@ -96,4 +103,6 @@ endif;
 ?>');
 }
 fwrite($fp, $entry_file['content']);
-fclose($fp);
\ No newline at end of file
+fclose($fp);
+
+echo "\n\n" . BUILD_FILE_NAME . "has been generated! \n\n\n";
\ No newline at end of file

Add parameter to build.