This is a sample grunt configuration that can be used for building and deploying a TYPO3 project. It has been developed, assuming a modernpackage setup.
- Make sure node and the grunt-cli package is installed by running
npm install -g grunt-cli
- Copy all the files in this repository (except for this README of course) into the typo3conf/ext folder
- Run
npm install
to install all the dependencies - Adapt the props.yml file to your needs.
- (Optional but recommended) Add the folder node_modules and the file npm-debug.log to your .gitignore
There are two main tasks
- default
- deploy
to get an overview of what each task does, just run
grunt --help
The first task, the default task, is an alias for several sub-tasks, which do the following actions
- Clean up by removing previous builds
- Minify and concatenate Javascript files using UglifyJS
- Build and compress a CSS file from a less source using recess
- Generate pre-compressed versions of the result of the two aforementioned tasks
- Update a typoscript file to use the newly generated assets. A sample of how this Typoscript may look like is available in the setup.ts file.
Versioning is done by defining an environment variable called BUILDNUMBER, usefull if using this together with a CI tool like jenkins. If it is not available the current timestamp is used.
All settings that may need to be adjusted, as set as properties in the props.yml file. You can set globally valid settings their and may override them in a props.SOMEVALUE.yml if you have an environment variable called ENVIRONMENT.
Example:
env ENVIRONMENT=dev BUILDNUMBER=4 grunt
Will try to read props.yml and props.dev.yml
Example output
Running "clean:build" (clean) task
Cleaning theme_mytheme/Resources/Public/Production...OK
Running "uglify:build" (uglify) task
File "theme_mytheme/Resources/Public/Production/scripts.4.js" created.
Running "recess:build" (recess) task
File "theme_mytheme/Resources/Public/Production/styles.4.css" created.
Uncompressed size: 60040 bytes.
Compressed size: 7025 bytes gzipped (47815 bytes minified).
Running "compress:build" (compress) task
Created theme_mytheme/Resources/Public/Production/styles.4.css.gz (8937 bytes)
Created theme_mytheme/Resources/Public/Production/scripts.4.js.gz (39654 bytes)
Running "tsconfig" task
Done, without errors.
Inside the build.yml is the build configuration in YAML format for third party tasks, like ssh or UglifyJS. Before grunt is initialized with it, it's values are processed via the grunt template processor. You can the default references like the grunt documentation says, all values in the props.yml and all environment variables using env.
Example: Write the result from UglifyJS to the users home, giving it the users name
uglify:
'[...]'
files:
-
dest: '<%= env.HOME %>/scripts.<%= env.USER %>.js'
src:
- '<%= assetsPath %>/Javascript/jquery.js'
- '<%= assetsPath %>/Javascript/bootstrap.js'
The second task is grunt deploy
It runs all the tasks of the default tasks and deploys the result onto a remote host using ssh. This is what happens:
- Create a tgz file with the contents of the typo3conf/ext folder. ".git" paths and documentations are always excluded. Additional excludes (in the example development extensions like phpunit or extension builder) can be listed in the props.yml
- Copy the tar into the /tmp/ folder of a remote host
- Unpack that tgz
- Backup the existing ext folder and move the fresh one into it's place
- Remove the caching folder typo3temp/Cache/Code/core_cache of the target installation. Otherwise a fatal error will be generated if an extension was heavily refactored or even removed.
- Run the coreapi task "dbcompare" to have the latest DB schema in place
- Run the coreapi task clearallcachesexceptpagecache
- Go back to the local installation and reset the typoscript changed in step 5 of the default task. This way git won't complain about changed files if you deploy from your local machine.
- Add PHP specific tasks like running phpunit and behat tests or a code sniffer
Provided under the BSD 3-Clause License
Copyright (c) 2013, Georg Großberger All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Georg Großberger nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.