Skip to content

Instantly share code, notes, and snippets.

@nyeholt
Created February 18, 2020 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nyeholt/e976274226982433a2b09a9a04e74f23 to your computer and use it in GitHub Desktop.
Save nyeholt/e976274226982433a2b09a9a04e74f23 to your computer and use it in GitHub Desktop.
Builds satis config from a composer.lock file
<?php
$lockfile = json_decode(file_get_contents(__DIR__ . '/../composer.lock'), true);
$satis = [
'name' => 'my/project-dependencies',
'homepage' => 'http://apache/satis/web',
'repositories' => [
[
"type" => "composer",
"url" => "https://packagist.org"
]
],
"require-all" => false,
"require-dependencies" => false,
"require-dev-dependencies" => false,
"archive" => [
"directory" => "dist",
"format" => "zip"
]
];
$require = [];
foreach ($lockfile['packages'] as $package) {
$version = $package['version'];
if ($version == 'dev-master') {
// see if there's a branch-alias we can use
if (isset($package['extra']['branch-alias'][$version])) {
$version = $package['extra']['branch-alias'][$version];
// convert -xdev stuff
$version = "~" . str_replace(["x-dev", "-dev"], ["0", ".0"], $version);
} else {
$version = $version . '#' . $package['source']['reference'];
}
}
$require[$package['name']] = $version;
}
foreach ($lockfile['packages-dev'] as $package) {
$version = $package['version'];
if ($version == 'dev-master') {
// see if there's a branch-alias we can use
if (isset($package['extra']['branch-alias'][$version])) {
$version = $package['extra']['branch-alias'][$version];
// convert -xdev stuff
$version = "~" . str_replace(["x-dev", "-dev"], ["0", ".0"], $version);
} else {
$version = $version . '#' . $package['source']['reference'];
}
}
$require[$package['name']] = $version;
}
$satis['require'] = $require;
echo json_encode($satis, JSON_PRETTY_PRINT);
echo "\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment