91 lines
3.5 KiB
PHP
91 lines
3.5 KiB
PHP
<?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;
|
|
|
|
if ($argc != 3)
|
|
{
|
|
echo sprintf('Usage: %s [version_number] [output_directory]', $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') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { 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 '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
|
|
system(sprintf('rm -rf %s/resources/build', $appRoot));
|
|
system(sprintf('rm -rf %s/tests', $appRoot));
|
|
@unlink(sprintf('%s/composer.phar', $appRoot));
|
|
@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(
|
|
'/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 "*.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;
|
|
system('git add --force vendor/');
|
|
system('git stash');
|
|
system(sprintf('git archive --format zip --output %1$s/blue-twilight_%2$s.zip --prefix=blue-twilight_%2$s/ "stash@{0}"', $argv[2], $argv[1]));
|
|
system('git stash pop');
|
|
|
|
echo PHP_EOL . PHP_EOL;
|
|
echo 'All done!';
|
|
echo PHP_EOL . PHP_EOL;
|
|
exit();
|
|
|
|
?>
|