121 lines
3.8 KiB
PHP
121 lines
3.8 KiB
PHP
<?php
|
|
|
|
define('PROJECT_ID', 'blue-twilight');
|
|
define('PROJECT_KEY', 's7Ebes37ChACHeC8A8AzAXUswestuZ8v');
|
|
define('LICENSE_FILE', 'blue-twilight.lic');
|
|
|
|
// Regex patterns of files we don't want to ship
|
|
$ignoredFiles = [
|
|
'.env*',
|
|
'.git*',
|
|
'.idea/*',
|
|
'artisan',
|
|
'build.php',
|
|
'composer.phar',
|
|
'gulpfile.js',
|
|
'package.json',
|
|
'phpunit.xml',
|
|
'readme.md',
|
|
'server.php',
|
|
'storage/app/*',
|
|
'storage/framework/*',
|
|
'storage/logs/*',
|
|
'tests/*'
|
|
];
|
|
|
|
echo 'Blue Twilight Packaging Script' . PHP_EOL;
|
|
echo '(c) Andy Heathershaw 2016-2017' . PHP_EOL;
|
|
echo '------------------------------' . PHP_EOL . PHP_EOL;
|
|
|
|
if ($argc != 2)
|
|
{
|
|
echo sprintf('Usage: %s [version_number]', $argv[0]) . PHP_EOL . PHP_EOL;
|
|
exit(1);
|
|
}
|
|
|
|
echo 'Checking current folder...' . PHP_EOL . PHP_EOL;
|
|
$appRoot = dirname(dirname(__DIR__));
|
|
if (getcwd() != $appRoot)
|
|
{
|
|
echo sprintf('The build script must be run in the application root - %s', $appRoot) . PHP_EOL;
|
|
exit();
|
|
}
|
|
|
|
echo 'Updating app.version config value...' . PHP_EOL . PHP_EOL;
|
|
$appConfigFile = sprintf('%s/config/app.php', $appRoot);
|
|
file_put_contents($appConfigFile, str_replace('**DEV**', $argv[1], file_get_contents($appConfigFile)));
|
|
|
|
/*echo 'Downloading Composer...' . PHP_EOL . PHP_EOL;
|
|
|
|
copy('https://getcomposer.org/installer', 'composer-setup.php');
|
|
if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); exit; } echo PHP_EOL;
|
|
system('php composer-setup.php');
|
|
unlink('composer-setup.php');
|
|
|
|
echo 'Installing dependencies using Composer...' . PHP_EOL . PHP_EOL;
|
|
system('./composer.phar install');
|
|
echo PHP_EOL;
|
|
|
|
echo 'Licensing and encoding the application using Source Guardian...' . PHP_EOL . PHP_EOL;
|
|
$sgCommand = sprintf(
|
|
'/usr/local/sourceguardian/bin/sourceguardian --phpversion "5.6" --phpversion "7.0" --external "%s" --projid "%s" --projkey "%s" ' .
|
|
'--stop-on-error --strict-errors --deprec-errors -x "build.php" -x "*.blade.php" -x "vendor/*.php" -x "public/raw/*.php" ' .
|
|
'-x public/license-required.php -x public/loader-required.php -x "storage/*" -r -b- ' .
|
|
'-p @./public/raw/sg-license-error.php -j "<?php btw_loader_error(); ?>" --catch ERR_ALL="btw_license_error" "*.php"',
|
|
LICENSE_FILE,
|
|
PROJECT_ID,
|
|
PROJECT_KEY
|
|
);
|
|
system($sgCommand);*/
|
|
|
|
echo 'Creating the release archive...' . PHP_EOL . PHP_EOL;
|
|
|
|
// Initialize archive object
|
|
$zip = new ZipArchive();
|
|
$zip->open(sprintf('%s/blue-twilight_%s.zip', dirname($appRoot), $argv[1]), ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
|
|
|
/** @var SplFileInfo[] $files */
|
|
$files = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator($appRoot),
|
|
RecursiveIteratorIterator::LEAVES_ONLY
|
|
);
|
|
|
|
foreach ($files as $name => $file)
|
|
{
|
|
// Skip directories (they will be added automatically) and unnecessary files
|
|
if (!$file->isDir())
|
|
{
|
|
// Get real and relative path for current file
|
|
$filePath = $file->getRealPath();
|
|
$relativePath = substr($filePath, strlen($appRoot) + 1);
|
|
|
|
// See if the file matches any of ignore patterns
|
|
$includeFile = true;
|
|
if (
|
|
strlen($relativePath) < strlen('vendor') ||
|
|
substr($relativePath, 0, strlen('vendor')) != 'vendor'
|
|
)
|
|
{
|
|
array_walk($ignoredFiles, function ($value) use ($relativePath, &$includeFile)
|
|
{
|
|
$includeFile &= !(preg_match('/^' . preg_quote($value, '/') . '$/', $relativePath));
|
|
});
|
|
}
|
|
|
|
// Add to the archive
|
|
if ($includeFile)
|
|
{
|
|
$zip->addFile($filePath, sprintf('blue-twilight_%s/%s', $argv[1], $relativePath));
|
|
}
|
|
}
|
|
}
|
|
|
|
$zip->close();
|
|
|
|
echo PHP_EOL . PHP_EOL;
|
|
echo 'All done!';
|
|
echo PHP_EOL . PHP_EOL;
|
|
exit();
|
|
|
|
?>
|