├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── bin └── composer-yaml ├── box.json ├── composer.json ├── composer.lock ├── composer.yml └── tests ├── composer-expected.json ├── composer.yml └── yml-to-json-test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.phar 3 | composer-yaml.phar 4 | box.phar 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Igor Wiedler 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | bash tests/yml-to-json-test.sh 3 | 4 | .PHONY: test 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # composer-yaml 2 | 3 | This project allows you to convert a composer.yml file into composer.json 4 | format. It will use those exact filenames of your current working directory. 5 | 6 | Warning: If you already have a composer.json file, it will overwrite it. 7 | 8 | ## Installation 9 | 10 | $ curl -s http://getcomposer.org/installer | php 11 | $ php composer.phar install 12 | 13 | ## Build Phar package 14 | 15 | $ curl -s http://box-project.org/installer.php | php 16 | $ php box.phar build 17 | 18 | ## Usage 19 | 20 | To convert from yaml to json, run: 21 | 22 | $ bin/composer-yaml convert 23 | 24 | To convert from json to yaml, run: 25 | 26 | $ bin/composer-yaml convert composer.json composer.yml 27 | 28 | Alternatively, you can use the phar package to execute the same command using 29 | 30 | $ php composer-yaml.phar [command] 31 | -------------------------------------------------------------------------------- /bin/composer-yaml: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | register('convert') 20 | ->setDefinition(array( 21 | new InputArgument('from', InputArgument::OPTIONAL, null, 'composer.yml'), 22 | new InputArgument('to', InputArgument::OPTIONAL, null, 'composer.json'), 23 | )) 24 | ->setDescription('Converts a composer.yml to json or vice-versa') 25 | ->setCode(function (InputInterface $input, OutputInterface $output) { 26 | $from = $input->getArgument('from'); 27 | $to = $input->getArgument('to'); 28 | 29 | $validFormats = array('json', 'yml'); 30 | 31 | if ($from && !file_exists($from)) { 32 | throw new \InvalidArgumentException(sprintf("The input file '%s' does not exist.", $from)); 33 | } 34 | 35 | if ($to && !file_exists($to)) { 36 | throw new \InvalidArgumentException(sprintf("The output file '%s' does not exist.", $to)); 37 | } 38 | 39 | $inputContent = file_get_contents($from); 40 | $inputFormat = pathinfo($from, PATHINFO_EXTENSION); 41 | 42 | if (!in_array($inputFormat, $validFormats)) { 43 | throw new \InvalidArgumentException( 44 | sprintf("Invalid input format '%s', must be one of: %s", $inputFormat, implode(', ', $validFormats))); 45 | } 46 | 47 | $outputFormat = pathinfo($to, PATHINFO_EXTENSION); 48 | 49 | if (!in_array($outputFormat, $validFormats)) { 50 | throw new \InvalidArgumentException( 51 | sprintf("Invalid output format '%s', must be one of: %s", $outputFormat, implode(', ', $validFormats))); 52 | } 53 | 54 | if ($outputFormat === $inputFormat) { 55 | throw new \InvalidArgumentException('Input format is same as output format.'); 56 | } 57 | 58 | if ('json' === $inputFormat) { 59 | $data = JsonFile::parseJson($inputContent); 60 | } elseif ('yml' === $inputFormat) { 61 | $data = Yaml::parse($inputContent); 62 | } 63 | 64 | if ('json' === $outputFormat) { 65 | $outputContent = JsonFile::encode($data)."\n"; 66 | } else { 67 | $outputContent = Yaml::dump($data); 68 | } 69 | 70 | file_put_contents($to, $outputContent); 71 | }) 72 | ; 73 | 74 | $console->run(); 75 | -------------------------------------------------------------------------------- /box.json: -------------------------------------------------------------------------------- 1 | { 2 | "directories": ["vendor"], 3 | "main": "bin/composer-yaml", 4 | "output": "composer-yaml.phar", 5 | "stub": true 6 | } 7 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "igorw/composer-yaml", 3 | "description": "Tool to convert from composer.yml to composer.json.", 4 | "license": "MIT", 5 | "require": { 6 | "symfony/console": "~2.1", 7 | "symfony/yaml": "~2.1", 8 | "composer/composer": "1.0.*@dev" 9 | }, 10 | "bin": [ 11 | "bin/composer-yaml" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "33b15c9c75b575989f9962dec0788a69", 8 | "packages": [ 9 | { 10 | "name": "composer/composer", 11 | "version": "dev-master", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/composer/composer.git", 15 | "reference": "a309e1d89ded6919935a842faeaed8e888fbfe37" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/composer/composer/zipball/a309e1d89ded6919935a842faeaed8e888fbfe37", 20 | "reference": "a309e1d89ded6919935a842faeaed8e888fbfe37", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "justinrainbow/json-schema": "~1.1", 25 | "php": ">=5.3.2", 26 | "seld/jsonlint": "1.*", 27 | "symfony/console": "~2.3", 28 | "symfony/finder": "~2.2", 29 | "symfony/process": "~2.1" 30 | }, 31 | "require-dev": { 32 | "phpunit/phpunit": "~3.7" 33 | }, 34 | "suggest": { 35 | "ext-openssl": "Enabling the openssl extension allows you to access https URLs for repositories and packages", 36 | "ext-zip": "Enabling the zip extension allows you to unzip archives, and allows gzip compression of all internet traffic" 37 | }, 38 | "bin": [ 39 | "bin/composer" 40 | ], 41 | "type": "library", 42 | "extra": { 43 | "branch-alias": { 44 | "dev-master": "1.0-dev" 45 | } 46 | }, 47 | "autoload": { 48 | "psr-0": { 49 | "Composer": "src/" 50 | } 51 | }, 52 | "notification-url": "https://packagist.org/downloads/", 53 | "license": [ 54 | "MIT" 55 | ], 56 | "authors": [ 57 | { 58 | "name": "Nils Adermann", 59 | "email": "naderman@naderman.de", 60 | "homepage": "http://www.naderman.de" 61 | }, 62 | { 63 | "name": "Jordi Boggiano", 64 | "email": "j.boggiano@seld.be", 65 | "homepage": "http://seld.be" 66 | } 67 | ], 68 | "description": "Composer helps you declare, manage and install dependencies of PHP projects, ensuring you have the right stack everywhere.", 69 | "homepage": "http://getcomposer.org/", 70 | "keywords": [ 71 | "autoload", 72 | "dependency", 73 | "package" 74 | ], 75 | "time": "2014-10-20 19:16:14" 76 | }, 77 | { 78 | "name": "justinrainbow/json-schema", 79 | "version": "1.3.7", 80 | "source": { 81 | "type": "git", 82 | "url": "https://github.com/justinrainbow/json-schema.git", 83 | "reference": "87b54b460febed69726c781ab67462084e97a105" 84 | }, 85 | "dist": { 86 | "type": "zip", 87 | "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/87b54b460febed69726c781ab67462084e97a105", 88 | "reference": "87b54b460febed69726c781ab67462084e97a105", 89 | "shasum": "" 90 | }, 91 | "require": { 92 | "php": ">=5.3.0" 93 | }, 94 | "require-dev": { 95 | "json-schema/json-schema-test-suite": "1.1.0", 96 | "phpdocumentor/phpdocumentor": "~2", 97 | "phpunit/phpunit": "~3.7" 98 | }, 99 | "bin": [ 100 | "bin/validate-json" 101 | ], 102 | "type": "library", 103 | "extra": { 104 | "branch-alias": { 105 | "dev-master": "1.4.x-dev" 106 | } 107 | }, 108 | "autoload": { 109 | "psr-0": { 110 | "JsonSchema": "src/" 111 | } 112 | }, 113 | "notification-url": "https://packagist.org/downloads/", 114 | "license": [ 115 | "BSD-3-Clause" 116 | ], 117 | "authors": [ 118 | { 119 | "name": "Bruno Prieto Reis", 120 | "email": "bruno.p.reis@gmail.com" 121 | }, 122 | { 123 | "name": "Justin Rainbow", 124 | "email": "justin.rainbow@gmail.com" 125 | }, 126 | { 127 | "name": "Igor Wiedler", 128 | "email": "igor@wiedler.ch" 129 | }, 130 | { 131 | "name": "Robert Schönthal", 132 | "email": "seroscho@googlemail.com" 133 | } 134 | ], 135 | "description": "A library to validate a json schema.", 136 | "homepage": "https://github.com/justinrainbow/json-schema", 137 | "keywords": [ 138 | "json", 139 | "schema" 140 | ], 141 | "time": "2014-08-25 02:48:14" 142 | }, 143 | { 144 | "name": "seld/jsonlint", 145 | "version": "1.3.0", 146 | "source": { 147 | "type": "git", 148 | "url": "https://github.com/Seldaek/jsonlint.git", 149 | "reference": "a7bc2ec9520ad15382292591b617c43bdb1fec35" 150 | }, 151 | "dist": { 152 | "type": "zip", 153 | "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/a7bc2ec9520ad15382292591b617c43bdb1fec35", 154 | "reference": "a7bc2ec9520ad15382292591b617c43bdb1fec35", 155 | "shasum": "" 156 | }, 157 | "require": { 158 | "php": ">=5.3.0" 159 | }, 160 | "bin": [ 161 | "bin/jsonlint" 162 | ], 163 | "type": "library", 164 | "autoload": { 165 | "psr-4": { 166 | "Seld\\JsonLint\\": "src/Seld/JsonLint/" 167 | } 168 | }, 169 | "notification-url": "https://packagist.org/downloads/", 170 | "license": [ 171 | "MIT" 172 | ], 173 | "authors": [ 174 | { 175 | "name": "Jordi Boggiano", 176 | "email": "j.boggiano@seld.be", 177 | "homepage": "http://seld.be" 178 | } 179 | ], 180 | "description": "JSON Linter", 181 | "keywords": [ 182 | "json", 183 | "linter", 184 | "parser", 185 | "validator" 186 | ], 187 | "time": "2014-09-05 15:36:20" 188 | }, 189 | { 190 | "name": "symfony/console", 191 | "version": "v2.5.6", 192 | "target-dir": "Symfony/Component/Console", 193 | "source": { 194 | "type": "git", 195 | "url": "https://github.com/symfony/Console.git", 196 | "reference": "6f177fca24200a5b97aef5ce7a5c98124a0f0db0" 197 | }, 198 | "dist": { 199 | "type": "zip", 200 | "url": "https://api.github.com/repos/symfony/Console/zipball/6f177fca24200a5b97aef5ce7a5c98124a0f0db0", 201 | "reference": "6f177fca24200a5b97aef5ce7a5c98124a0f0db0", 202 | "shasum": "" 203 | }, 204 | "require": { 205 | "php": ">=5.3.3" 206 | }, 207 | "require-dev": { 208 | "psr/log": "~1.0", 209 | "symfony/event-dispatcher": "~2.1" 210 | }, 211 | "suggest": { 212 | "psr/log": "For using the console logger", 213 | "symfony/event-dispatcher": "" 214 | }, 215 | "type": "library", 216 | "extra": { 217 | "branch-alias": { 218 | "dev-master": "2.5-dev" 219 | } 220 | }, 221 | "autoload": { 222 | "psr-0": { 223 | "Symfony\\Component\\Console\\": "" 224 | } 225 | }, 226 | "notification-url": "https://packagist.org/downloads/", 227 | "license": [ 228 | "MIT" 229 | ], 230 | "authors": [ 231 | { 232 | "name": "Symfony Community", 233 | "homepage": "http://symfony.com/contributors" 234 | }, 235 | { 236 | "name": "Fabien Potencier", 237 | "email": "fabien@symfony.com" 238 | } 239 | ], 240 | "description": "Symfony Console Component", 241 | "homepage": "http://symfony.com", 242 | "time": "2014-10-05 13:57:04" 243 | }, 244 | { 245 | "name": "symfony/finder", 246 | "version": "v2.5.6", 247 | "target-dir": "Symfony/Component/Finder", 248 | "source": { 249 | "type": "git", 250 | "url": "https://github.com/symfony/Finder.git", 251 | "reference": "cf66df4e783e6aade319b273c9bcf9e42aa9b10f" 252 | }, 253 | "dist": { 254 | "type": "zip", 255 | "url": "https://api.github.com/repos/symfony/Finder/zipball/cf66df4e783e6aade319b273c9bcf9e42aa9b10f", 256 | "reference": "cf66df4e783e6aade319b273c9bcf9e42aa9b10f", 257 | "shasum": "" 258 | }, 259 | "require": { 260 | "php": ">=5.3.3" 261 | }, 262 | "type": "library", 263 | "extra": { 264 | "branch-alias": { 265 | "dev-master": "2.5-dev" 266 | } 267 | }, 268 | "autoload": { 269 | "psr-0": { 270 | "Symfony\\Component\\Finder\\": "" 271 | } 272 | }, 273 | "notification-url": "https://packagist.org/downloads/", 274 | "license": [ 275 | "MIT" 276 | ], 277 | "authors": [ 278 | { 279 | "name": "Symfony Community", 280 | "homepage": "http://symfony.com/contributors" 281 | }, 282 | { 283 | "name": "Fabien Potencier", 284 | "email": "fabien@symfony.com" 285 | } 286 | ], 287 | "description": "Symfony Finder Component", 288 | "homepage": "http://symfony.com", 289 | "time": "2014-10-01 05:50:18" 290 | }, 291 | { 292 | "name": "symfony/process", 293 | "version": "v2.5.6", 294 | "target-dir": "Symfony/Component/Process", 295 | "source": { 296 | "type": "git", 297 | "url": "https://github.com/symfony/Process.git", 298 | "reference": "9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a" 299 | }, 300 | "dist": { 301 | "type": "zip", 302 | "url": "https://api.github.com/repos/symfony/Process/zipball/9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a", 303 | "reference": "9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a", 304 | "shasum": "" 305 | }, 306 | "require": { 307 | "php": ">=5.3.3" 308 | }, 309 | "type": "library", 310 | "extra": { 311 | "branch-alias": { 312 | "dev-master": "2.5-dev" 313 | } 314 | }, 315 | "autoload": { 316 | "psr-0": { 317 | "Symfony\\Component\\Process\\": "" 318 | } 319 | }, 320 | "notification-url": "https://packagist.org/downloads/", 321 | "license": [ 322 | "MIT" 323 | ], 324 | "authors": [ 325 | { 326 | "name": "Symfony Community", 327 | "homepage": "http://symfony.com/contributors" 328 | }, 329 | { 330 | "name": "Fabien Potencier", 331 | "email": "fabien@symfony.com" 332 | } 333 | ], 334 | "description": "Symfony Process Component", 335 | "homepage": "http://symfony.com", 336 | "time": "2014-10-01 05:50:18" 337 | }, 338 | { 339 | "name": "symfony/yaml", 340 | "version": "v2.5.6", 341 | "target-dir": "Symfony/Component/Yaml", 342 | "source": { 343 | "type": "git", 344 | "url": "https://github.com/symfony/Yaml.git", 345 | "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726" 346 | }, 347 | "dist": { 348 | "type": "zip", 349 | "url": "https://api.github.com/repos/symfony/Yaml/zipball/2d9f527449cabfa8543dd7fa3a466d6ae83d6726", 350 | "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726", 351 | "shasum": "" 352 | }, 353 | "require": { 354 | "php": ">=5.3.3" 355 | }, 356 | "type": "library", 357 | "extra": { 358 | "branch-alias": { 359 | "dev-master": "2.5-dev" 360 | } 361 | }, 362 | "autoload": { 363 | "psr-0": { 364 | "Symfony\\Component\\Yaml\\": "" 365 | } 366 | }, 367 | "notification-url": "https://packagist.org/downloads/", 368 | "license": [ 369 | "MIT" 370 | ], 371 | "authors": [ 372 | { 373 | "name": "Symfony Community", 374 | "homepage": "http://symfony.com/contributors" 375 | }, 376 | { 377 | "name": "Fabien Potencier", 378 | "email": "fabien@symfony.com" 379 | } 380 | ], 381 | "description": "Symfony Yaml Component", 382 | "homepage": "http://symfony.com", 383 | "time": "2014-10-01 05:50:18" 384 | } 385 | ], 386 | "packages-dev": [], 387 | "aliases": [], 388 | "minimum-stability": "stable", 389 | "stability-flags": { 390 | "composer/composer": 20 391 | }, 392 | "prefer-stable": false, 393 | "platform": [], 394 | "platform-dev": [] 395 | } 396 | -------------------------------------------------------------------------------- /composer.yml: -------------------------------------------------------------------------------- 1 | name: igorw/composer-yaml 2 | description: Tool to convert from composer.yml to composer.json. 3 | license: MIT 4 | require: 5 | symfony/console: '~2.1' 6 | symfony/yaml: '~2.1' 7 | composer/composer: '1.0.*@dev' 8 | bin: 9 | - bin/composer-yaml 10 | -------------------------------------------------------------------------------- /tests/composer-expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foo/bar", 3 | "description": "The foobar.", 4 | "require": { 5 | "baz/qux": "1.0.*@dev" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/composer.yml: -------------------------------------------------------------------------------- 1 | name: foo/bar 2 | description: The foobar. 3 | require: 4 | baz/qux: 1.0.*@dev 5 | -------------------------------------------------------------------------------- /tests/yml-to-json-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function startTests { 4 | echo "PlaygroundUnit 0.0.1 by Igor Wiedler." 5 | echo 6 | } 7 | 8 | function endTests { 9 | echo 10 | echo 11 | } 12 | 13 | function assertEquals { 14 | if [ "$1" = "$2" ]; then 15 | echo -n . 16 | else 17 | echo "Assertion failed:" 18 | echo "--- Expected" 19 | echo "+++ Actual" 20 | echo "- $1" 21 | echo "+ $2" 22 | 23 | endTests 24 | exit 1 25 | fi 26 | } 27 | 28 | function assertContentsEquals { 29 | diff="$(diff -u $1 $2)" 30 | 31 | if [ "$diff" = "" ]; then 32 | echo -n . 33 | else 34 | echo "Assertion failed:" 35 | echo "$diff" 36 | 37 | endTests 38 | exit 1 39 | fi 40 | } 41 | 42 | startTests 43 | 44 | touch tests/composer-actual.json 45 | bin/composer-yaml convert tests/composer.yml tests/composer-actual.json 46 | assertContentsEquals tests/composer-expected.json tests/composer-actual.json 47 | rm tests/composer-actual.json 48 | 49 | endTests 50 | --------------------------------------------------------------------------------