Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 196078e

Browse files
committed
Automating PhantomJS setup.
1 parent b733d8b commit 196078e

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

bin/blt-console

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env php
22
<?php
33

4+
use Acquia\Blt\Console\Command\ConfigurePhantomJsCommand;
45
use Acquia\Blt\Console\Command\ComposerMungeCommand;
56
use Acquia\Blt\Console\Command\YamlMungeCommand;
67
use Acquia\Blt\Console\Command\UpdateCommand;
@@ -23,6 +24,7 @@ else {
2324
}
2425

2526
$application = new Application();
27+
$application->add(new ConfigurePhantomJsCommand());
2628
$application->add(new ComposerMungeCommand());
2729
$application->add(new YamlMungeCommand());
2830
$application->add(new UpdateCommand());

phing/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ behat:
1010
# If true, Selenium standalone server will be launched with Behat.
1111
launch-selenium: true
1212
# If true, PhantomJS GhostDriver will be launched with Behat.
13-
launch-phantom: true
13+
launch-phantom: false
1414
# An array of paths with behat tests that should be executed.
1515
paths:
1616
# - ${docroot}/modules

phing/tasks/tests.xml

+26
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,32 @@
154154
description="Launches a GhostDriver."
155155
hidden="true">
156156

157+
<exec dir="${repo.root}" command="grep 'jakoch/phantomjs-installer' composer.json" logoutput="false" level="${blt.exec_level}" passthru="false" returnProperty="phantom.required"/>
158+
<if>
159+
<isfailure code="${phantom.required}"/>
160+
<then>
161+
<echo level="Warning">behat.launch-phantom is true, but jakoch/phantomjs-installer is not required in composer.json. Attempting to install via composer... </echo>
162+
<exec dir="${repo.root}" command="composer require jakoch/phantomjs-installer --dev" logoutput="true" level="${blt.exec_level}" passthru="true" />
163+
</then>
164+
</if>
165+
<exec dir="${repo.root}" command="grep 'PhantomInstaller\\Installer::installPhantomJS' composer.json" logoutput="false" level="${blt.exec_level}" passthru="false" returnProperty="phantom.scripts"/>
166+
<if>
167+
<isfailure code="${phantom.scripts}"/>
168+
<then>
169+
<echo level="warning">behat.launch-phantom is true, but no corresponding scripts have been defined in composer.json. Updating composer config...</echo>
170+
<exec command="${composer.bin}/blt-console configure:phantomjs ${repo.root}" logoutput="true" level="${blt.exec_level}" passthru="false" checkreturn="true"/>
171+
</then>
172+
</if>
173+
<if>
174+
<not><available file="${composer.bin}/phantomjs"/></not>
175+
<then>
176+
<exec dir="${repo.root}" command="composer install-phantom" checkreturn="true" logoutput="true" passthru="true" level="${blt.exec_level}"/>
177+
</then>
178+
<else>
179+
<echo>Found PhantomJS at ${phantomjs.bin}</echo>
180+
</else>
181+
</if>
182+
157183
<if>
158184
<equals arg1="${behat.launch-phantom}" arg2="true"/>
159185
<then>

readme/ci.md

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ To initialize Pipelines support for your BLT project:
3636

3737
curl -o pipelines https://cloud.acquia.com/pipeline-client/download
3838
chmod a+x pipelines
39+
# Move to a location specified in $PATH. E.g.,
40+
mv pipelines /usr/local/bin
3941

4042
1. [Configure the Pipelines client](https://docs.acquia.com/pipelines/install#authenticate)
4143
1. Initialize Pipelines for your project
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Acquia\Blt\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputArgument;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Input\InputOption;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
class ConfigurePhantomJsCommand extends Command
12+
{
13+
protected function configure()
14+
{
15+
$this
16+
->setName('configure:phantomjs')
17+
->setDescription('Configure PhantomJs')
18+
->addArgument(
19+
'repo-root',
20+
InputArgument::REQUIRED,
21+
'The root directory for the repository.'
22+
)
23+
;
24+
}
25+
26+
protected function execute(InputInterface $input, OutputInterface $output)
27+
{
28+
$repo_root = $input->getArgument('repo-root');
29+
$composer_json = json_decode(file_get_contents($repo_root . '/composer.json'), TRUE);
30+
$composer_json['scripts']['post-install-cmd'] = array_merge(
31+
(array) $composer_json['scripts']['post-install-cmd'],
32+
[
33+
"PhantomInstaller\\Installer::installPhantomJS",
34+
]
35+
);
36+
$composer_json['scripts']['post-update-cmd'] = array_merge(
37+
(array) $composer_json['scripts']['post-update-cmd'],
38+
[
39+
"PhantomInstaller\\Installer::installPhantomJS",
40+
]
41+
);
42+
$composer_json['scripts']['install-phantomjs'] = [
43+
"rm -rf vendor/bin/phantomjs",
44+
"PhantomInstaller\\Installer::installPhantomJS",
45+
];
46+
file_put_contents($repo_root . '/composer.json', json_encode($composer_json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
47+
}
48+
}

0 commit comments

Comments
 (0)