2016-10-06 12:48:04 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
define('PROJECT_ID', 'blue-twilight');
|
|
|
|
define('PROJECT_KEY', 's7Ebes37ChACHeC8A8AzAXUswestuZ8v');
|
|
|
|
define('LICENSE_FILE', 'blue-twilight.lic');
|
|
|
|
|
|
|
|
echo 'Blue Twilight Packaging Script' . PHP_EOL;
|
|
|
|
echo '(c) Andy Heathershaw 2016' . PHP_EOL;
|
|
|
|
echo '------------------------------' . PHP_EOL . PHP_EOL;
|
|
|
|
|
2016-10-06 16:37:35 +01:00
|
|
|
if ($argc != 3)
|
|
|
|
{
|
|
|
|
echo sprintf('Usage: %s [version_number] [output_directory]', $argv[0]) . PHP_EOL . PHP_EOL;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2016-10-06 12:48:04 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-10-20 09:18:29 +01:00
|
|
|
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)));
|
|
|
|
|
2016-10-06 12:48:04 +01:00
|
|
|
echo 'Downloading Composer...' . PHP_EOL . PHP_EOL;
|
|
|
|
|
|
|
|
copy('https://getcomposer.org/installer', 'composer-setup.php');
|
2016-11-06 16:53:23 +00:00
|
|
|
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;
|
2016-10-06 12:48:04 +01:00
|
|
|
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 'Removing environment-related files...' . PHP_EOL . PHP_EOL;
|
|
|
|
@unlink(sprintf('%s/.env', $appRoot));
|
|
|
|
system(sprintf('rm -rf %s/storage/app/*', $appRoot));
|
|
|
|
system(sprintf('rm -rf %s/storage/framework/cache/*.log', $appRoot));
|
|
|
|
system(sprintf('rm -rf %s/storage/framework/sessions/*.log', $appRoot));
|
|
|
|
system(sprintf('rm -rf %s/storage/framework/views/*.log', $appRoot));
|
|
|
|
system(sprintf('rm -rf %s/storage/logs/*.log', $appRoot));
|
|
|
|
|
|
|
|
echo 'Removing build files...' . PHP_EOL . PHP_EOL;
|
|
|
|
|
|
|
|
// Remove development-related files
|
2016-10-27 13:04:37 +01:00
|
|
|
system(sprintf('rm -rf %s/.idea', $appRoot));
|
2016-10-06 12:48:04 +01:00
|
|
|
system(sprintf('rm -rf %s/resources/build', $appRoot));
|
|
|
|
system(sprintf('rm -rf %s/tests', $appRoot));
|
2016-10-06 15:07:30 +01:00
|
|
|
@unlink(sprintf('%s/composer.phar', $appRoot));
|
2016-10-06 12:48:04 +01:00
|
|
|
@unlink(sprintf('%s/server.php', $appRoot));
|
|
|
|
|
|
|
|
// Can't use Artisan once encoded
|
|
|
|
@unlink(sprintf('%s/artisan', $appRoot));
|
|
|
|
|
|
|
|
// We don't use Gulp or PHPUnit (yet, maybe one day!)
|
|
|
|
@unlink(sprintf('%s/gulpfile.js', $appRoot));
|
|
|
|
@unlink(sprintf('%s/package.json', $appRoot));
|
|
|
|
@unlink(sprintf('%s/phpunit.xml', $appRoot));
|
|
|
|
|
|
|
|
// The Readme.md is currently Laravel's, not our own, so get rid
|
|
|
|
@unlink(sprintf('%s/readme.md', $appRoot));
|
|
|
|
|
|
|
|
echo 'Licensing and encoding the application using Source Guardian...' . PHP_EOL . PHP_EOL;
|
|
|
|
$sgCommand = sprintf(
|
2016-10-06 13:25:50 +01:00
|
|
|
'/usr/local/sourceguardian/bin/sourceguardian --phpversion "5.6" --phpversion "7.0" --external "%s" --projid "%s" --projkey "%s" ' .
|
2016-10-06 12:48:04 +01:00
|
|
|
'--stop-on-error --strict-errors --deprec-errors -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);
|
2016-10-06 16:37:35 +01:00
|
|
|
|
|
|
|
echo 'Creating the release archive...' . PHP_EOL . PHP_EOL;
|
2016-11-06 17:00:44 +00:00
|
|
|
$rootPath = dirname(dirname(__DIR__));
|
|
|
|
|
|
|
|
// Initialize archive object
|
|
|
|
$zip = new ZipArchive();
|
|
|
|
$zip->open(sprintf('%s/blue-twilight_%s.zip', $argv[1], $argv[0]), ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
|
|
|
|
|
|
|
/** @var SplFileInfo[] $files */
|
|
|
|
$files = new RecursiveIteratorIterator(
|
|
|
|
new RecursiveDirectoryIterator($rootPath),
|
|
|
|
RecursiveIteratorIterator::LEAVES_ONLY
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($files as $name => $file)
|
|
|
|
{
|
|
|
|
// Skip directories (they will be added automatically)
|
|
|
|
if (!$file->isDir())
|
|
|
|
{
|
|
|
|
// Get real and relative path for current file
|
|
|
|
$filePath = $file->getRealPath();
|
|
|
|
$relativePath = substr($filePath, strlen($rootPath) + 1);
|
|
|
|
|
|
|
|
// Add current file to archive
|
|
|
|
$zip->addFile($filePath, $relativePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$zip->close();
|
2016-10-06 16:37:35 +01:00
|
|
|
|
2016-10-06 12:48:04 +01:00
|
|
|
echo PHP_EOL . PHP_EOL;
|
|
|
|
echo 'All done!';
|
2016-10-06 16:37:35 +01:00
|
|
|
echo PHP_EOL . PHP_EOL;
|
2016-10-06 12:48:04 +01:00
|
|
|
exit();
|
|
|
|
|
|
|
|
?>
|