mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-10-26 15:23:14 +03:00
php: add packagist translator
This commit is contained in:
parent
4b9538fca2
commit
26a0088b9d
@ -26,6 +26,12 @@ Resolves dependencies in `composer.json` using `composer` to generate a
|
||||
`composer.lock` lockfile, then invokes the `composer-lock` translator to
|
||||
generate a dream2nix lockfile.
|
||||
|
||||
### packagist (impure)
|
||||
|
||||
Downloads a package version from [Packagist](https://packagist.org/).
|
||||
Then uses `composer-lock` if a `composer.lock` file is present,
|
||||
or `composer-json` otherwise to translate the package.
|
||||
|
||||
## Builders
|
||||
|
||||
### granular (pure) (default)
|
||||
|
97
src/subsystems/php/translators/packagist/default.nix
Normal file
97
src/subsystems/php/translators/packagist/default.nix
Normal file
@ -0,0 +1,97 @@
|
||||
{
|
||||
dlib,
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
type = "impure";
|
||||
|
||||
# the input format is specified in /specifications/translator-call-example.json
|
||||
# this script receives a json file including the input paths and specialArgs
|
||||
translateBin = {
|
||||
# dream2nix utils
|
||||
apps,
|
||||
subsystems,
|
||||
utils,
|
||||
# nixpkgs dependenies
|
||||
coreutils,
|
||||
curl,
|
||||
jq,
|
||||
git,
|
||||
moreutils,
|
||||
...
|
||||
}:
|
||||
utils.writePureShellScript
|
||||
[
|
||||
coreutils
|
||||
curl
|
||||
jq
|
||||
git
|
||||
moreutils
|
||||
]
|
||||
''
|
||||
# according to the spec, the translator reads the input from a json file
|
||||
jsonInput=$1
|
||||
|
||||
# read the json input
|
||||
outputFile=$(realpath -m $(jq '.outputFile' -c -r $jsonInput))
|
||||
name=$(jq '.project.name' -c -r $jsonInput)
|
||||
version=$(jq '.project.version' -c -r $jsonInput)
|
||||
|
||||
pushd $TMPDIR
|
||||
|
||||
# download and unpack package source
|
||||
curl https://packagist.org/packages/$name.json | \
|
||||
jq -rcM ".package.versions.\"$version\".source" \
|
||||
> source_manifest
|
||||
SOURCE_URL=$(jq -rcM ".url" source_manifest)
|
||||
SOURCE_REV=$(jq -rcM ".reference" source_manifest)
|
||||
|
||||
mkdir source
|
||||
pushd source
|
||||
git init
|
||||
git remote add origin $SOURCE_URL
|
||||
git fetch --depth 1 origin $SOURCE_REV
|
||||
git checkout FETCH_HEAD
|
||||
popd
|
||||
|
||||
# generate arguments for package-lock translator
|
||||
echo "{
|
||||
\"source\": \"$TMPDIR/source\",
|
||||
\"outputFile\": \"$outputFile\",
|
||||
\"project\": {
|
||||
\"name\": \"$name\",
|
||||
\"relPath\": \"\"
|
||||
}
|
||||
}" > $TMPDIR/newJsonInput
|
||||
|
||||
popd
|
||||
|
||||
if [ -e $TMPDIR/source/composer.lock ]
|
||||
then
|
||||
${subsystems.php.translators.composer-lock.translateBin} $TMPDIR/newJsonInput
|
||||
else
|
||||
${subsystems.php.translators.composer-json.translateBin} $TMPDIR/newJsonInput
|
||||
fi
|
||||
|
||||
# add main package source info to dream-lock.json
|
||||
echo "
|
||||
{
|
||||
\"type\": \"git\",
|
||||
\"url\": \"$SOURCE_URL\",
|
||||
\"rev\": \"$SOURCE_REV\"
|
||||
}
|
||||
" > $TMPDIR/sourceInfo.json
|
||||
|
||||
${apps.callNixWithD2N} eval --json "
|
||||
with dream2nix.utils.dreamLock;
|
||||
replaceRootSources {
|
||||
dreamLock = l.fromJSON (l.readFile \"$outputFile\");
|
||||
newSourceRoot = l.fromJSON (l.readFile \"$TMPDIR/sourceInfo.json\");
|
||||
}
|
||||
" \
|
||||
| sponge "$outputFile"
|
||||
'';
|
||||
|
||||
# inherit options from composer-json translator
|
||||
extraArgs = dlib.translators.translators.php.composer-json.extraArgs;
|
||||
}
|
Loading…
Reference in New Issue
Block a user