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. #195

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

<target name="task:execute" description="Executes a task defined in the tasks array.">
<fail unless="task-name"/>
<if>
<isset property="tasks.${task-name}.command"/>
<then>
<if>
<available file="${tasks.${task-name}.dir}" type="dir" property="taskDirExists" />
<then>
<exec dir="${tasks.${task-name}.dir}" command="${tasks.${task-name}.command}" logoutput="true" checkreturn="true" />
</then>
<else>
<fail>The directory ${tasks.${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="post-deploy-build"/>
</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.">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description here feels a bit misleading to me. As a user I might expect there to already be some magic built in to find and compile my sass files with gulp. It's not clear by the description that I would need to define the command in my project.yml file. Unless I'm missing something which very well could be the case...

<phingcall target="task:execute">
<property name="task-name" value="frontend-build"/>
</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="post-setup-build"/>
</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
18 changes: 18 additions & 0 deletions template/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ 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 frontend-build, post-deploy-build, and post-setup-build.
tasks:
# Executed when front end assets should be generated.
frontend-build:
# E.g., ${docroot}/sites/all/themes/custom/mytheme.
dir: ${docroot}
# E.g., `npm install` or `bower install`.
command: echo 'Hello world!'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not crazy about "Hello world" here.

I think it could be confusing to see it go past during a build, out of context.

I'd rather see something like echo 'Frontend build not configured.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

# Executed after deployment artifact is created.
post-deploy-build:
dir: ${deploy.dir}/docroot/profiles/contrib/lightning
command: npm install && bower install
# Executed after setup:build:all is run.
post-setup-build:
dir: ${docroot}/profiles/contrib/lightning
command: npm install && bower install

# Hosting environment flags.
# Examples: acsf (Acquia Cloud Site Factory), ac (Acquia Cloud)
# hosting: "acsf"
Expand Down
45 changes: 35 additions & 10 deletions template/readme/project-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,41 @@ Please see [Deploy](deploy.md) for a detailed description of how to deploy to Ac

Please see [tests/README.md](../tests/README.md) for information on running tests.

To execute PHP codesniffer and PHP lint against the project codebase, run: `./blt.sh validate:all`
To execute PHP codesniffer and PHP lint against the project codebase, run:

```
./blt.sh validate:all
```

## <a name="frontend"></a>Build front end assets

Ideally, you will be using a theme that uses SASS/SCSS, a styleguide, and other tools that require compilation. Like dependencies, the compiled assets should not be directly committed to the project repository. Instead, they should be built during the creation of a production-ready build artifact.

BLT only natively supports the [Acquia PS Thunder](https://github.com/acquia-pso/thunder) base theme.
BLT allows you to define a custom command that will be run to compile your project's frontend assets. You can specify the command in your project's `project.yml` file under the `tasks.frontend-build` key:

```
tasks:
frontend-build:
# The directory in which the command will be executed.
dir: ${docroot}
command: npm install.
```

To install Thunder's dependencies:
If you need to run more than one command, you may use this feature to call a custom script:

1. See [Acquia PS Thunder](https://github.com/acquia-pso/thunder) for system requirements.
1. Execute `/.blt.sh frontend:install`.
```
tasks:
frontend-build:
# The directory in which the command will be executed.
dir: ${repo.root}
command: ./scripts/custom/my-script.sh
```

To build Thunder's assets, execute:
This command will be executed when dependencies are built in a local or CI environment, and when a deployment artifact is generated. You may execute the command directly by calling the `frontend:build` target:

`/.blt.sh frontend:build`.
```
./blt.sh frontend:build
```

## <a name="local-tasks"></a>Updating you local environment

Expand All @@ -87,14 +106,20 @@ The project is configured to update the local environment with a local drush ali

This all in one command will make sure your local is in sync with the remote site.

`./blt.sh local:refresh`
```
./blt.sh local:refresh
```

### Sync: Copy the database from the remote site

`./blt.sh local:sync`
```
./blt.sh local:sync
```

### Update: Run update tasks locally

`./blt.sh local:update`
```
./blt.sh local:update
```

These tasks can be seen in `build/core/phing/tasks/local-sync.xml`. An additional script can be added at `/hooks/dev/post-db-copy/dev-mode.sh` which would run at the end of this task.