-
Notifications
You must be signed in to change notification settings - Fork 1
/
unify-composer
executable file
·61 lines (47 loc) · 1.94 KB
/
unify-composer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env php
<?php
declare(strict_types=1);
\error_reporting(-1);
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/functions.php';
use Symfony\Component\Finder\Finder;
//******************************************************************************
// Update composer.json files
/**
* This will read the existing `composer.json` file, merge-in certain entries,
* remove known-outdated repositories, then do some custom sorting on some of
* the values (e.g., `php` at the top of the required packages).
*
* It will then re-format the JSON and write the changes back to disk.
*/
$jsonOpts = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
$finder = Finder::create()
->files()
->name('composer.json')
->depth('< 2')
->in(dirname(__DIR__))
->notPath('vendor')
;
foreach ($finder as $file) {
echo sprintf('Processing %s', $file->getRealPath()) . PHP_EOL;
// Take the existing file and overlay what we want
$json = json_decode(file_get_contents($file->getRealPath()), true);
$overlay = json_decode(file_get_contents(__DIR__ . '/templates/composer.json.tmpl'), true);
$merged = array_merge_recursive_adv($json, $overlay);
// Delete the things we want to remove
unset($merged['require-dev']['codeclimate/php-test-reporter']);
unset($merged['require-dev']['skyzyx/utility-pack']);
unset($merged['require']['skyzyx/utility-pack']);
// Do not include itself
if (isset($json['name']) && 'simplepie/utility-pack' === $json['name']) {
unset($merged['require']['simplepie/utility-pack']);
}
// Sort the results
natkeysort($merged['config']);
composersort($merged['require']);
natkeysort($merged['require-dev']);
natkeysort($merged['suggest']);
// Write the file back to disk
file_put_contents($file->getRealPath(), json_encode($merged, $jsonOpts) . PHP_EOL);
echo sprintf('Completed %s', $file->getRealPath()) . PHP_EOL;
}