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

Executing create-project on initial install using Composer plugin. #913

Merged
merged 3 commits into from
Jan 5, 2017
Merged
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ script:
# BLT is the only dependency at this point. Install it.
- composer install -v
- export PATH=$TRAVIS_BUILD_DIR/../blt-project/vendor/bin:$PATH
# BLT added new dependencies for us, so we must update.
- composer update
# The local.hostname must be set to 127.0.0.1:8888 because we are using drush runserver to run the site on Travis CI.
- yaml-cli update:value blt/project.yml project.local.hostname '127.0.0.1:8888'
# Execute all updates with fake "dev" => "dev" version specs. This must be done manually since BLT was not installed prior to this.
- blt-console blt:update dev dev $(pwd) --yes
# BLT added new dependencies for us, so we must update.
- composer update
# Create a .travis.yml, just to make sure it works. It won't be executed.
- blt ci:travis:init
- blt ci:pipelines:init
Expand Down
12 changes: 7 additions & 5 deletions phing/tasks/blt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<target name="create-project" hidden="true">
<exec dir="${repo.root}" command="git init" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>

<!-- Write BLT version to blt/.schema-version. -->
<exec dir="${repo.root}" command="echo ${blt.version} > ${blt.config-files.schema-version}" checkreturn="true" logoutput="true" passthru="false" level="${blt.exec_level}"/>

<!-- Remove files leftover from acquia/blt-project. -->
<delete failonerror="false">
<fileset dir="${repo.root}">
Expand All @@ -15,17 +18,17 @@
<exec dir="${repo.root}" command="blt blt:rsync-template" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec dir="${repo.root}" command="blt blt:update-composer" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>

<echo>Updating composer dependencies, this make take a while...</echo>
<exec dir="${repo.root}" command="export COMPOSER_PROCESS_TIMEOUT=600; composer update --no-interaction" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<copy file="${repo.root}/docroot/profiles/contrib/lightning/lightning.extend.yml" tofile="${repo.root}/docroot/sites/default/lightning.extend.yml"/>

<!--Write project.machine_name to project.yml, using name of working directory as value.. -->
<exec dir="${repo.root}" command="result=${PWD##*/}; printf '%s\n' &quot;${PWD##*/}&quot;" logoutput="false" checkreturn="true" level="${blt.exec_level}" passthru="false" outputProperty="dirname"/>
<exec dir="${repo.root}" command="${composer.bin}/yaml-cli update:value ${blt.config-files.project} project.machine_name '${dirname}'" logoutput="true" checkreturn="false" level="${blt.exec_level}" passthru="true"/>

<!-- Remove default git remote -->
<exec dir="${repo.root}" command="${composer.bin}/yaml-cli update:value ${blt.config-files.project} git.remotes.0 ''" logoutput="true" checkreturn="false" level="${blt.exec_level}" passthru="true"/>

<echo>Updating composer dependencies, this make take a while...</echo>
<exec dir="${repo.root}" command="composer update --no-interaction" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<copy file="${repo.root}/docroot/profiles/contrib/lightning/lightning.extend.yml" tofile="${repo.root}/docroot/sites/default/lightning.extend.yml"/>

<exec dir="${repo.root}" command="git add -A" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec dir="${repo.root}" command="git commit -m 'Initial commit.'" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec dir="${repo.root}" command="cat ${blt.root}/scripts/blt/ascii-art.txt" logoutput="true" passthru="true" checkreturn="false"/>
Expand Down Expand Up @@ -72,7 +75,6 @@
</target>

<target name="blt:update-composer" description="Updates project composer.json with a subset of new key value pairs from upstream. This WILL overwrite existing values." hidden="true">
<!--@todo Output different message if composer.json does not exist.-->
<echo level="verbose">Merging BLT's composer.json template with your project's composer.json.</echo>
<echo level="verbose">This MAY overwrite some existing values.</echo>
<exec dir="${repo.root}" command="${repo.root}/vendor/bin/blt-console composer:munge ${repo.root}/composer.json ${blt.root}/template/composer.json > ${repo.root}/composer.json.tmp" logoutput="true" checkreturn="true" level="${blt.exec_level}" returnProperty="composer.munge.return"/>
Expand Down
2 changes: 1 addition & 1 deletion phing/tasks/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<property file="${phing.dir}/build.yml" override="true" logoutput="false"/>

<!-- Load the root project.yml file for this project. -->
<property file="${blt.config-files.project}" override="true" logoutput="false"/>
<property file="${blt.config-files.project}" override="true" logoutput="${blt.verbose}"/>

<!-- Load the local project.local.yml file for this project. -->
<!--@todo Change this so that it is only loaded for local:* targets. -->
Expand Down
34 changes: 26 additions & 8 deletions src/Composer/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ protected function getBltPackage($operation) {
*/
protected function executeBltUpdate($version) {
$options = $this->getOptions();
if ($options['blt']['update']) {

if ($this->isInitialInstall()) {
$this->io->write('<info>Creating BLT templated files...</info>');
$success = $this->executeCommand('blt create-project', [], TRUE);
}
elseif ($options['blt']['update']) {
$this->io->write('<info>Updating BLT templated files...</info>');

// Rsyncs, updates composer.json, project.yml, executes scripted updates for version delta.
Expand All @@ -148,6 +153,25 @@ protected function executeBltUpdate($version) {
}
}

/**
* Determine if BLT is being installed for the first time on this project.
*
* This would execute in the context of `composer create-project`.
*
* @return bool
* TRUE if this is the initial install of BLT.
*/
protected function isInitialInstall() {
if (!file_exists($this->getRepoRoot() . '/blt/project.yml')
&& !file_exists($this->getRepoRoot() . '/blt/.schema-version')
&& file_exists($this->getRepoRoot() . '/README.md')
) {
return TRUE;
}

return FALSE;
}

/**
* Returns the repo root's filepath, assumed to be one dir above vendor dir.
*
Expand Down Expand Up @@ -215,13 +239,7 @@ protected function executeCommand($cmd, $args = [], $display_output = FALSE) {
$this->io->write('<comment> > ' . $command . '</comment>');
$io = $this->io;
$output = function ($type, $buffer) use ($io) {
if ($type == Process::ERR) {
$io->write('<error>' . $buffer . '</error>');
}
else {
// @todo Figure out how to preserve color!
$io->write($buffer);
}
$io->write($buffer);
};
}
return ($this->executor->execute($command, $output) == 0);
Expand Down