Skip to content

Commit

Permalink
Moved Gruntfile and other FE config to the theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk authored and Alex Skrypnyk committed Nov 23, 2019
1 parent 2b367b7 commit 50044e8
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 75 deletions.
6 changes: 3 additions & 3 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ commands:
fe:
usage: Build front-end assets.
cmd: ahoy cli "npm run build"
cmd: ahoy cli "cd docroot/sites/all/themes/custom/your_site_theme && npm run build"

fed:
usage: Build front-end assets for development.
cmd: ahoy cli "npm run build-dev"
cmd: ahoy cli "cd docroot/sites/all/themes/custom/your_site_theme && npm run build-dev"

few:
usage: Watch front-end assets during development.
cmd: ahoy cli "npm run watch"
cmd: ahoy cli "cd docroot/sites/all/themes/custom/your_site_theme && npm run watch"

export-code:
usage: Export built code.
Expand Down
6 changes: 3 additions & 3 deletions .docker/Dockerfile.cli
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ RUN echo "memory_limit=-1" >> /usr/local/etc/php/conf.d/memory.ini \
#: the repository.
#: File Gruntfile.sj is copied into image as it is required to generate
#: front-end assets.
COPY Gruntfile.js package.json package* /app/
COPY docroot/sites/all/themes/custom/your_site_theme/Gruntfile.js docroot/sites/all/themes/custom/your_site_theme/.eslintrc.json docroot/sites/all/themes/custom/your_site_theme/package.json docroot/sites/all/themes/custom/your_site_theme/package* /app/docroot/sites/all/themes/custom/your_site_theme/

#: Install NodeJS dependencies.
#: Since Drupal does not use NodeJS for production, it does not matter if we
#; install development dependencnies here - they are not exposed in any way.
RUN npm install
RUN cd docroot/sites/all/themes/custom/your_site_theme && npm install

#: Copy all files into appllication source directory. Existing files are always
#: overridden.
COPY . /app

#: Compile front-end assets. Running this after copying all files as we need
#: sources to compile assets.
RUN npm run build
RUN cd docroot/sites/all/themes/custom/your_site_theme && npm run build
5 changes: 5 additions & 0 deletions .gitignore.deployment
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ docroot/sites/all/themes/custom/your_site_theme/fonts
docroot/sites/all/themes/custom/your_site_theme/images
docroot/sites/all/themes/custom/your_site_theme/js
docroot/sites/all/themes/custom/your_site_theme/scss
docroot/sites/all/themes/custom/your_site_theme/Gruntfile.js
docroot/sites/all/themes/custom/your_site_theme/package.json
docroot/sites/all/themes/custom/your_site_theme/package-lock.json
docroot/sites/all/themes/custom/your_site_theme/.eslintrc.json
docroot/sites/all/themes/custom/your_site_theme/node_modules
docroot/sites/default/default.settings.php
docroot/sites/default/settings.generated.php
docroot/sites/default/default.settings.local.php
Expand Down
File renamed without changes.
52 changes: 24 additions & 28 deletions Gruntfile.js → ...hemes/custom/your_site_theme/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@
*/

/* global module */
var bootstrapPath = 'vendor/twbs/bootstrap/dist/js/bootstrap.js';

var librariesPaths = [
'../../../libraries/bootstrap/dist/js/bootstrap.js'
];
var themeName = 'your_site_theme';
var themePath = 'docroot/sites/all/themes/custom/' + themeName + '/';
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
eslint: {
src: [
'docroot/profiles/your_site_profile/**/*.js',
'!docroot/profiles/your_site_profile/**/*.min.js',
'docroot/sites/all/modules/custom/**/*.js',
'!docroot/sites/all/modules/custom/**/*.min.js',
'docroot/sites/all/themes/custom/**/*.js',
'!docroot/sites/all/themes/custom/**/*.min.js'
'js/**/*.js',
'!js/**/*.min.js',
],
options: {
config: '.eslintrc.json'
Expand All @@ -33,33 +31,31 @@ module.exports = function (grunt) {
configFile: '.sass-lint.yml'
},
target: [
'docroot/sites/all/themes/custom/**/*.scss',
'docroot/sites/all/modules/custom/**/*.scss'
'scss/**/*.scss',
]
},
sass_globbing: {
dev: {
files: {
[themePath + 'scss/_components.scss']: themePath + 'scss/components/**/*.scss'
['scss/_components.scss']: 'scss/components/**/*.scss'
},
options: {
useSingleQuotes: true,
signature: '//\n// GENERATED FILE. DO NOT MODIFY DIRECTLY.\n//'
}
}
},
clean: [themePath + 'build'],
clean: ['build'],
concat: {
options: {
separator: '\n\n'
},
dist: {
src: [
bootstrapPath,
themePath + 'js/**/*.js',
'!' + themePath + 'js/' + themeName + '.min.js'
],
dest: themePath + 'build/js/' + themeName + '.min.js'
'js/**/*.js',
'!js/' + themeName + '.min.js'
].concat(librariesPaths),
dest: 'build/js/' + themeName + '.min.js'
}
},
uglify: {
Expand All @@ -73,14 +69,14 @@ module.exports = function (grunt) {
}
},
files: {
[themePath + 'build/js/' + themeName + '.min.js']: [themePath + 'build/js/' + themeName + '.min.js']
['build/js/' + themeName + '.min.js']: ['build/js/' + themeName + '.min.js']
}
}
},
sass: {
dev: {
files: {
[themePath + 'build/css/' + themeName + '.min.css']: themePath + 'scss/style.scss'
['build/css/' + themeName + '.min.css']: 'scss/style.scss'
},
options: {
implementation: require('node-sass'),
Expand All @@ -90,7 +86,7 @@ module.exports = function (grunt) {
},
prod: {
files: {
[themePath + 'build/css/' + themeName + '.min.css']: themePath + 'scss/style.scss'
['build/css/' + themeName + '.min.css']: 'scss/style.scss'
},
options: {
implementation: require('node-sass'),
Expand All @@ -107,30 +103,30 @@ module.exports = function (grunt) {
},
dev: {
map: true,
src: themePath + 'build/css/' + themeName + '.min.css'
src: 'build/css/' + themeName + '.min.css'
},
prod: {
map: false,
src: themePath + 'build/css/' + themeName + '.min.css'
src: 'build/css/' + themeName + '.min.css'
}
},
copy: {
images: {
expand: true,
cwd: themePath + 'images/',
cwd: 'images/',
src: '**',
dest: themePath + 'build/images'
dest: 'build/images'
},
fonts: {
expand: true,
cwd: themePath + 'fonts/',
cwd: 'fonts/',
src: '**',
dest: themePath + 'build/fonts'
dest: 'build/fonts'
}
},
watch: {
scripts: {
files: [themePath + 'js/**/*.js'],
files: ['js/**/*.js'],
tasks: ['concat'],
options: {
livereload: true,
Expand All @@ -139,7 +135,7 @@ module.exports = function (grunt) {
},
styles: {
files: [
themePath + 'scss/**/*.scss'
'scss/**/*.scss'
],
tasks: ['sass_globbing', 'sass:dev', 'postcss:dev'],
options: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @file
* Global theme behaviours.
*/

(function ($, Drupal) {
'use strict';
Drupal.behaviors.your_site_theme = {
attach: function (context) {
}
};
}(jQuery
, Drupal));
File renamed without changes.
10 changes: 4 additions & 6 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
<config name="testVersion" value="7.2"/>

<!-- Exclude theme assets. -->
<exclude-pattern>docroot\/sites\/all\/themes\/custom\/.*\/build\/.*
</exclude-pattern>
<exclude-pattern>docroot\/sites\/all\/themes\/custom\/.*\/fonts\/.*
</exclude-pattern>
<exclude-pattern>docroot\/sites\/all\/themes\/custom\/.*\/images\/.*
</exclude-pattern>
<exclude-pattern>docroot\/sites\/all\/themes\/custom\/.*\/build\/.*</exclude-pattern>
<exclude-pattern>docroot\/sites\/all\/themes\/custom\/.*\/fonts\/.*</exclude-pattern>
<exclude-pattern>docroot\/sites\/all\/themes\/custom\/.*\/images\/.*</exclude-pattern>
<exclude-pattern>docroot\/sites\/all\/themes\/custom\/.*\/node_modules\/.*</exclude-pattern>
<exclude-pattern>*\.min\.*</exclude-pattern>

<!-- Exclude CircleCI config files. -->
Expand Down
4 changes: 3 additions & 1 deletion scripts/drupal-dev/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ done
# Remove other directories.
rm -rf \
./vendor \
./node_modules \
./docroot/sites/all/themes/custom/*/build \
./docroot/sites/all/themes/custom/*/scss/_components.scss \
./docroot/sites/default/settings.generated.php

# shellcheck disable=SC2038
find . -type d -name node_modules | xargs rm -Rf
2 changes: 1 addition & 1 deletion scripts/drupal-dev/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fi

if [ -z "${LINT_TYPE##*fe*}" ]; then
# Lint code using front-end linter.
npm run lint || \
npm run --prefix docroot/sites/all/themes/custom/your_site_theme lint || \
# Flag to allow lint to fail.
[ "${ALLOW_LINT_FAIL}" -eq 1 ]
fi
5 changes: 4 additions & 1 deletion tests/bats/_helper_drupaldev.bash
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ assert_files_present_common(){
assert_file_exists "docroot/sites/all/themes/custom/${suffix}/.gitignore"
assert_file_exists "docroot/sites/all/themes/custom/${suffix}/${suffix}.info"
assert_file_exists "docroot/sites/all/themes/custom/${suffix}/template.php"
assert_file_exists "docroot/sites/all/themes/custom/${suffix}/Gruntfile.js"
assert_file_exists "docroot/sites/all/themes/custom/${suffix}/.eslintrc.json"
assert_file_exists "docroot/sites/all/themes/custom/${suffix}/package.json"

# Comparing binary files.
assert_files_equal "${LOCAL_REPO_DIR}/docroot/sites/all/themes/custom/your_site_theme/screenshot.png" "docroot/sites/all/themes/custom/${suffix}/screenshot.png"
Expand Down Expand Up @@ -616,7 +619,7 @@ install_dependencies_stub(){
mktouch "vendor/somevendor/somepackage/somepackage.php"
mktouch "vendor/somevendor/somepackage/somepackage with spaces.php"
mktouch "vendor/somevendor/somepackage/composer.json"
mktouch "node_modules/somevendor/somepackage/somepackage.js"
mktouch "docroot/sites/all/themes/custom/zzzsomecustomtheme/node_modules/somevendor/somepackage/somepackage.js"

mktouch "docroot/sites/all/themes/custom/zzzsomecustomtheme/build/js/zzzsomecustomtheme.min.js"
mktouch "screenshots/s1.jpg"
Expand Down
9 changes: 5 additions & 4 deletions tests/bats/_helper_drupaldev_deployment.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ assert_deployment_files_present(){
assert_file_not_exists .dockerignore
assert_file_not_exists .editorconfig
assert_file_not_exists .env
assert_file_not_exists .eslintrc.json
assert_file_not_exists .lagoon.yml
assert_file_not_exists .sass-lint.yml
assert_file_not_exists behat.yml
assert_file_not_exists composer.json
assert_file_not_exists composer.lock
assert_file_not_exists dependencies.yml
assert_file_not_exists docker-compose.yml
assert_file_not_exists Gruntfile.js
assert_file_not_exists LICENSE
assert_file_not_exists package.json
assert_file_not_exists package-lock.json
assert_file_not_exists phpcs.xml
assert_file_not_exists README.md

Expand All @@ -56,6 +52,11 @@ assert_deployment_files_present(){
assert_file_exists docroot/sites/all/themes/custom/star_wars/.gitignore
assert_file_exists docroot/sites/all/themes/custom/star_wars/star_wars.info
assert_file_exists docroot/sites/all/themes/custom/star_wars/template.php
assert_file_not_exists docroot/sites/all/themes/custom/star_wars/Gruntfile.js
assert_file_not_exists docroot/sites/all/themes/custom/star_wars/package.json
assert_file_not_exists docroot/sites/all/themes/custom/star_wars/package-lock.json
assert_file_not_exists docroot/sites/all/themes/custom/star_wars/.eslintrc.json
assert_dir_not_exists docroot/sites/all/themes/custom/star_wars/node_modules

# Scaffolding files present.
assert_file_exists "docroot/.htaccess"
Expand Down
6 changes: 3 additions & 3 deletions tests/bats/_helper_drupaldev_workflow.bash
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ assert_ahoy_build(){

# Assert that lock files were created.
assert_file_exists "composer.lock"
assert_file_exists "package-lock.json"
assert_file_exists "docroot/sites/all/themes/custom/star_wars/package-lock.json"

# Assert that database file preserved after build.
assert_file_exists .data/db.sql
Expand Down Expand Up @@ -109,7 +109,7 @@ assert_gitignore(){
assert_git_file_is_tracked docroot/robots.txt
# Assert that lock files were added to the git repository.
assert_git_file_is_tracked "composer.lock"
assert_git_file_is_tracked "package-lock.json"
assert_git_file_is_tracked "docroot/sites/all/themes/custom/star_wars/package-lock.json"
# Assert that generated files were not added to the git repository.
assert_git_file_is_not_tracked "docroot/sites/default/settings.generated.php"
assert_git_file_is_not_tracked ".data/db.sql"
Expand Down Expand Up @@ -476,7 +476,7 @@ assert_ahoy_clean(){
assert_dir_not_exists docroot/sites/all/modules/contrib
assert_dir_not_exists docroot/sites/all/themes/contrib
assert_dir_not_exists vendor
assert_dir_not_exists node_modules
assert_dir_not_exists docroot/sites/all/themes/custom/star_wars/node_modules
assert_dir_exists screenshots

# Assert manually created local settings file exists.
Expand Down
Loading

0 comments on commit 50044e8

Please sign in to comment.