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

Adding support for custom commands in frontend and setup targets. #193

Merged
merged 1 commit into from
Jun 21, 2016
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
23 changes: 23 additions & 0 deletions template/build/core/phing/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,27 @@
<exec dir="${repo.root}" command="./blt.sh -q -l" passthru="true"/>
</target>

<target name="task:execute">
<fail unless="task-name"/>

<if>
<available property="${tasks.${task-name}.command}" />
<then>
<if>
<available file="${tasks.${task-name}.dir}" type="dir" property="taskDirExists" />
<then>
<exec dir="${hooks.${task-name}.dir}" command="${scripts.${task-name}.command}" logoutput="true" checkreturn="true" />
</then>
<else>
<fail>The directory ${scripts.${task-name}.dir} does not exist. Will not run command for ${task-name}.</fail>
</else>
</if>
</then>
<else>
<echo>No commands are defined for ${task-name}. Skipping.</echo>
</else>
</if>

</target>

</project>
24 changes: 8 additions & 16 deletions template/build/core/phing/tasks/deploy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@

<!-- Build artifact and commit locally. -->
<phingcall target="deploy:build"/>

<!--Allow custom commands to be run before commit.-->
<phingcall target="task:execute">
<property name="task-name" value="deploy"/>
</phingcall>

<!--Commit artifact. -->
<phingcall target="deploy:commit"/>

<!-- Push up changes to remotes if this is not a dry run.-->
Expand Down Expand Up @@ -63,7 +70,7 @@
</target>

<target name="deploy:build" description="Generates a deploy-ready build in deploy.dir."
depends="frontend:build, deploy:copy, deploy:composer:install, deploy:profile:make, deploy:sanitize">
depends="frontend:build, deploy:copy, deploy:composer:install, deploy:sanitize">
<!-- If we are using ACSF, run the ACSF Deploy command. -->
<if>
<equals arg1="${hosting}" arg2="acsf"/>
Expand All @@ -90,21 +97,6 @@
<exec dir="${deploy.dir}" command="export COMPOSER_EXIT_ON_PATCH_FAILURE=1; composer install --no-dev --prefer-dist --no-interaction" passthru="true" logoutput="true" checkreturn="true"/>
</target>

<target name="deploy:profile:make" description="Build a subsidiary makefile shipped with profile.">
<if>
<equals arg1="${project.profile.contrib}" arg2="true"/>
<then>
<echo message="Building make file for ${project.profile.name}"/>
<property name="profile.dir" value="${deploy.dir}/docroot/profiles/contrib/${project.profile.name}"/>
<drush command="make" assume="yes" verbose="TRUE">
<param>"${profile.dir}/drupal-org.make"</param>
<param>"${profile.dir}"</param>
<option name="no-core"></option>
</drush>
</then>
</if>
</target>

<target name="deploy:copy" description="Copy required files from /docroot/sites to /deploy/docroot/sites.">
<!-- Make sites/default writable so that we can copy files. -->
<!-- @todo Support multisite. -->
Expand Down
52 changes: 4 additions & 48 deletions template/build/core/phing/tasks/frontend.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,9 @@
<project name="frontend" default="frontend:install">

<target name="frontend:build" depends="frontend:install" description="Uses gulp to build front end dependencies for all themes.">
<if>
<isset property="project.themes"/>
<then>
<foreach list="${project.themes}" param="frontend.theme" target="frontend:build:run"/>
</then>
</if>
<target name="frontend:build" description="Uses gulp to build front end dependencies for all themes.">
<phingcall target="task:execute">
<property name="task-name" value="frontend"/>
</phingcall>
</target>

<target name="frontend:build:run" depends="frontend:install" description="Uses gulp to build front end dependencies for a theme.">
<if>
<!-- We assume that if the theme name is not thunder, then a subtheme of thunder is being used. -->
<not><equals arg1="${frontend.theme}" arg2="thunder" /></not>
<then>
<exec dir="${docroot}/themes/custom/${frontend.theme}" command="npm run build" logoutput="true" checkreturn="true" />
</then>
</if>

<property name="project.frontend.nvmrc.file" value="${docroot}/themes/custom/${frontend.theme}/.nvmrc" />
<if>
<available file="${project.frontend.nvmrc.file}" />
<then>
<copy file="${project.frontend.nvmrc.file}" todir="${repo.root}" />
</then>
</if>
</target>

<target name="frontend:install" description="Installs front end dependencies for themes.">
<!-- Enable support for multiple themes (Base + Subtheme or multisite deployments) -->
<if>
<isset property="project.themes" />
<then>
<foreach list="${project.themes}" param="frontend.theme" target="frontend:install:run"/>
</then>
<else>
<!-- Skip and tell user no themes were found -->
<echo message="No Themes were found, skipping frontend:install."/>
</else>
</if>
</target>

<target name="frontend:install:run" description="Installs front end dependencies for a theme.">
<if>
<!-- We assume that if the theme name is not thunder, then a subtheme of thunder is being used. -->
<not><equals arg1="${frontend.theme}" arg2="thunder" /></not>
<then>
<exec dir="${docroot}/themes/custom/${frontend.theme}" command="npm run install-tools" logoutput="true" checkreturn="true" />
</then>
</if>
</target>
</project>
20 changes: 5 additions & 15 deletions template/build/core/phing/tasks/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,12 @@

<!-- This is run when a project is cloned to a new environment. -->
<target name="setup:build:all" description="Generates all required files for a full build. E.g., (re)builds docroot, etc."
depends="setup:git-hooks, setup:drupal:settings, setup:behat, setup:composer:install, setup:build:profile, frontend:build">
</target>
depends="setup:git-hooks, setup:drupal:settings, setup:behat, setup:composer:install, frontend:build">

<phingcall target="task:execute">
<property name="task-name" value="setup"/>
</phingcall>

<target name="setup:build:profile" description="Build a subsidiary makefile shipped with profile">
<if>
<equals arg1="${project.profile.contrib}" arg2="true"/>
<then>
<echo message="Building make file for ${project.profile.name}"/>
<property name="profile.dir" value="${docroot}/profiles/contrib/${project.profile.name}"/>
<drush command="make" assume="yes" verbose="TRUE">
<option name="no-core"></option>
<param>"${profile.dir}/drupal-org.make"</param>
<param>${profile.dir}</param>
</drush>
</then>
</if>
</target>

<target name="setup:clean" description="Removes .gitignored files and directories.">
Expand Down
16 changes: 16 additions & 0 deletions template/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ drush:
# The default drush alias to be used when no environment is specified.
default_alias: ${drush.aliases.local}

# Custom tasks that are triggered at pre-defined times in the build process.
# Available keys are setup, frontend.
tasks:
# Executed after setup:build:all is run.
setup:
dir: ${docroot}/profiles/contrib/lighting
command: npm install && bower install
# Executed when front end assets should be generated.
frontend:
dir: ${docroot}/sites/all/themes/contrib/thunder
command: npm run build
# Executed after deployment artifact is created.
deploy:
dir: ${deploy.dir}
command: cd docroot/profiles/contrib/lightning && npm install && bower install

# Hosting environment flags.
# Examples: acsf (Acquia Cloud Site Factory), ac (Acquia Cloud)
# hosting: "acsf"
Expand Down