Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(satis) Added build satis task to buildfile #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions BuildSatisConfigTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/**
* Copy a specified set of folders from one location to another
*
* @author marcus
*
*/
class BuildSatisConfigTask extends Task
{
private $lockfile = null;
private $outfile = null;

public function setLockfile($file)
{
$this->lockfile = $file;
}

public function setOutfile($file)
{
$this->outfile = $file;
}

public function main()
{
$file = $this->lockfile ? $this->lockfile : __DIR__ . '/../composer.lock';
$lockfile = json_decode(file_get_contents($file), true);

$satis = [
'name' => 'my/project-dependencies',
// depends on php -S 0.0.0.0:6789 from the satis/web directory
'homepage' => 'http://localhost:6789',
'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;

$output = json_encode($satis, JSON_PRETTY_PRINT);
$outfile = $this->outfile ? $this->outfile : dirname(__DIR__) . '/mysite/build/satis.json';

file_put_contents($outfile, $output);
}
}
10 changes: 10 additions & 0 deletions buildfile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
<taskdef name="sstest" classname="build.SilverStripeTestTask" classpath="${project.basedir}" />
<taskdef name="ssmodules" classname="build.LoadModulesTask" classpath="${project.basedir}" />
<taskdef name="sspatches" classname="build.ApplyPatchesTask" classpath="${project.basedir}" />
<taskdef name="buildsatis" classname="build.BuildSatisConfigTask" classpath="${project.basedir}" />


<taskdef name="ssdeploy" classname="build.SilverStripeDeployTask" classpath="${project.basedir}" />

Expand Down Expand Up @@ -108,6 +110,10 @@ Other features

</target>

<target name="build_satis">
<buildsatis />
</target>

<!-- deprecated target; defers to base install target now -->
<target name="update-composer" depends="composer-install">

Expand Down Expand Up @@ -283,6 +289,8 @@ Allow from 127.0.0.1
<exclude name="build.xml" />
<exclude name="**/*.env" />
<exclude name=".gitlab-ci.yml" />
<exclude name="satis.json" />
<exclude name="mysite/build" />
<exclude name="**/*dockerfile*" />
<exclude name="${project.root}/local.conf.php" />
<exclude name="${project.root}/_config/local.yml" />
Expand Down Expand Up @@ -382,6 +390,8 @@ Allow from 127.0.0.1
<exclude name="${project.root}/db.conf.php" />
<exclude name="**/*.env" />
<exclude name=".gitlab-ci.yml" />
<exclude name="satis.json" />
<exclude name="mysite/build" />
<exclude name="**/*dockerfile*" />
<exclude name="_ss_environment.php" />
<exclude name="${project.root}/local.conf.php" />
Expand Down