From 8e785956c1f69526aa34eb1c8d507c02d10f6400 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Fri, 20 Sep 2013 19:41:20 +0200 Subject: New utility script to convert plugin package.xml files into new composer.json meta files --- bin/package2composer.sh | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100755 bin/package2composer.sh (limited to 'bin') diff --git a/bin/package2composer.sh b/bin/package2composer.sh new file mode 100755 index 000000000..165018d2f --- /dev/null +++ b/bin/package2composer.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env php + | + +-----------------------------------------------------------------------+ +*/ + +ini_set('error_reporting', E_ALL & ~E_NOTICE); + +list(, $filename, $vendor) = $_SERVER['argv']; + +if (!$filename || !is_readable($filename)) { + die("Invalid input file name!\nUsage: " . $_SERVER['argv'][0] . " XMLFILE VENDOR\n"); +} + +if (!$vendor) { + $vendor = 'anonymous'; +} + +$package = new SimpleXMLElement(file_get_contents($filename)); + +$data = array( + 'name' => $vendor . '/' . strval($package->name), + 'type' => 'roundcube-plugin', + 'description' => trim(strval($package->summary) . '; ' . strval($package->description), ';- '), + 'homepage' => strval($package->uri), + 'license' => 'GPLv3+', + 'authors' => array(), + 'repositories' => array( + array('type' => 'composer', 'url' => 'http://plugins.roundcube.net'), + ), + 'require' => array( + 'php' => '>=5.3.0', + 'roundcube/plugin-installer' => '>=0.1.3', + ), +); + +if ($package->license) { + $data['license'] = strval($package->license); +} + +if ($package->lead) { + $data['authors'][] = array( + 'name' => strval($package->lead->name), + 'email' => strval($package->lead->email), + 'role' => 'Lead', + ); +} + +if ($devs = $package->developer) { + if (!is_array($devs)) { + $devs = array($package->developer); + } + foreach ($devs as $dev) { + $data['authors'][] = array( + 'name' => strval($dev->name), + 'email' => strval($dev->email), + 'role' => 'Developer', + ); + } +} + +// remove empty values +$data = array_filter($data); + +// use the JSON encoder from the Composer package +if (is_file('composer.phar')) { + include 'phar://composer.phar/src/Composer/Json/JsonFile.php'; + echo \Composer\Json\JsonFile::encode($data); +} +// PHP 5.4's json_encode() does the job, too +else if (defined('JSON_PRETTY_PRINT')) { + $flags = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT & JSON_UNESCAPED_SLASHES : 0; + echo json_encode($data, $flags); +} +else { + fputs(STDERR, +"FAILED! composer.phar not found in current directory. + +Please download it from http://getcomposer.org/download/ or with + curl -s http://getcomposer.org/installer | php +"); +} + +echo "\n"; + -- cgit v1.2.3