#!/usr/bin/env php -dphar.readonly=0 <?php define('ROOT', realpath(__DIR__ . '/../../')); include 'functions.php'; // get information from CLI $package_name_full = $_SERVER['argv'][1]; $package_source = $_SERVER['argv'][2]; $package_filter = isset($_SERVER['argv'][3]) ? trim($_SERVER['argv'][3], '/') : null; list($package_name, $package_release) = preg_split('#-#', $package_name_full); script_run_command('rm -Rf ' . ROOT . '/packages/apidoc/' . $package_name_full . '*'); mkdir(ROOT . '/packages/apidoc/' . $package_name_full); copy(ROOT . '/build/scripts/phpdocumentor-template/phpdoc.xml', ROOT . '/packages/apidoc/' . $package_name_full . '.xml'); file_put_contents(ROOT . '/packages/apidoc/' . $package_name_full . '.xml', apply_replacements(file_get_contents(ROOT . '/packages/apidoc/' . $package_name_full . '.xml'), array('{target}' => ROOT . '/packages/apidoc/' . $package_name_full . '/', '{directory}' => $package_source . '/' . $package_filter))); chdir(ROOT . '/packages/apidoc/'); script_run_command('php -dmemory_limit=-1 ' . ROOT . '/build/scripts/phpDocumentor.phar -c ' . ROOT . '/packages/apidoc/' . $package_name_full . '.xml'); script_run_command('zip -rq ' . ROOT . '/packages/apidoc/' . $package_name_full . '-apidoc.zip ' . $package_name_full); script_run_command('tar czf ' . ROOT . '/packages/apidoc/' . $package_name_full . '-apidoc.tgz ' . '-C ' . ROOT . '/packages/plain ' . $package_name_full);
if (isset($package_info['required'])) { if (is_string($package_info['required'])) { $package_info['required'] = array($package_info['required']); } foreach ($package_info['required'] as $dependency) { $file_replacements['{PACKAGE_REQUIRE_DEPENDENCIES}'] .= 'require_once \'' . $dependency . '-' . trim($package_release) . '.phar\';' . "\n"; $file_replacements['{PACKAGE_DEPENDENCY}'] = trim($dependency); $packagexmlsetup_content .= apply_replacements(file_get_contents(ROOT . '/build/scripts/pyrus-templates/packagexmlsetup-required.php'), $file_replacements); } } if (isset($package_info['optional'])) { if (is_string($package_info['optional'])) { $package_info['optional'] = array($package_info['optional']); } foreach ($package_info['optional'] as $dependency) { $file_replacements['{PACKAGE_REQUIRE_DEPENDENCIES}'] .= 'require_once \'' . $dependency . '-' . trim($package_release) . '.phar\';' . "\n"; $file_replacements['{PACKAGE_DEPENDENCY}'] = trim($dependency); $packagexmlsetup_content .= apply_replacements(file_get_contents(ROOT . '/build/scripts/pyrus-templates/packagexmlsetup-optional.php'), $file_replacements); } } echo 'Writing: packagexmlsetup.php' . PHP_EOL; file_put_contents('packagexmlsetup.php', $packagexmlsetup_content); } echo 'Writing: stub.php' . PHP_EOL; file_put_contents('stub.php', '<?php' . "\n" . trim(apply_replacements(file_get_contents(ROOT . '/build/scripts/pyrus-templates/stub.php'), $file_replacements))); script_run_command($pyrus_path . ' make'); script_run_command($pyrus_path . ' package -p'); script_run_command('rm -Rf ' . ROOT . '/packages/component-pyrus/' . $package_name . '-' . $package_release . '.*'); script_run_command('mv ' . $package_name . '-' . $package_release . '.* ' . ROOT . '/packages/component-pyrus/'); chdir(ROOT . '/packages/component-pyrus/' . $package_name); script_run_command('rm -Rf ' . ROOT . '/packages/component-pyrus/' . $package_name);
$file_replacements['{PACKAGE_REQUIRE_DEPENDENCIES}'] = null; if (file_exists(__DIR__ . DS . 'data' . DS . $package_name . '-info.php')) { $package_info = (include __DIR__ . DS . 'data' . DS . $package_name . '-info.php'); if (isset($package_info['dependencies'])) { $packagexmlsetup_content = '<?php' . PHP_EOL; foreach ($package_info['dependencies'] as $dependency) { $file_replacements['{PACKAGE_REQUIRE_DEPENDENCIES}'] .= 'require_once \'' . $dependency . '-' . trim($release) . '.phar\';' . "\n"; $file_replacements['{PACKAGE_DEPENDENCY}'] = trim($dependency); $packagexmlsetup_content .= apply_replacements(file_get_contents(__DIR__ . DS . 'data' . DS . 'packagexmlsetup.php.template'), $file_replacements); } echo 'Writing: packagexmlsetup.php' . PHP_EOL; file_put_contents('packagexmlsetup.php', $packagexmlsetup_content); } } echo 'Writing: stub.php' . PHP_EOL; file_put_contents('stub.php', '<?php' . "\n" . trim(apply_replacements(file_get_contents(__DIR__ . DS . 'data' . DS . 'stub.php.template'), $file_replacements))); $command = $pyrus_path . ' make'; $output = script_run_command($command); $command = $pyrus_path . ' package -g'; $output = script_run_command($command); $command = $pyrus_path . ' package -z'; $output = script_run_command($command); if ($ini['with_phar']) { $command = $pyrus_path . ' package -p'; $output = script_run_command($command); } function apply_replacements($source, $replacements) { foreach ($replacements as $var => $value) { $source = str_replace($var, $value, $source); }