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

Allow the use of separate files for configuration #332

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
20 changes: 20 additions & 0 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ module.exports = function(grunt) {
grunt.config.set('config', config);
}

var configDir = grunt.config.get('config.srcPaths.configDir');
if (configDir && grunt.file.isDir(configDir)) {
var options = {
config: {
src: [
configDir + '/*.js*',
configDir + '/*.coffee',
configDir + '/*.y*ml',
configDir + '/*.cson'
]
}
};
var configs = require('load-grunt-configs')(grunt, options);
for (var configName in configs) {
if (configName !== 'config') {
grunt.config.set('config.' + configName, configs[configName]);
}
}
}

var GDT = require('./lib/init')(grunt);
GDT.init();

Expand Down
5 changes: 5 additions & 0 deletions docs/10_BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ The following build output paths are optional to specify in the project's
**srcPaths.make**: The Drush make file used to assemble the Drupal project.
This is only used for Drupal 7.x projects. Example is `src/project.make`.

**srcPaths.configDir**: The directory that should be used for loading
configurations. The files inside this directory will be loaded using
[load-grunt-configs](https://www.npmjs.com/package/load-grunt-configs)
and merged with the *Gruntconfig.json*.

**buildPaths.build**: The directory that should be used for miscellaneous build
artifacts. This can be the parent directory of the following build paths.

Expand Down
9 changes: 1 addition & 8 deletions example/Gruntconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
{
"srcPaths": {
"configDir": "config",
"make": "src/project.make",
"drupal": "src"
},
"domain": "project.vm",
"buildPaths": {
"packages": "build/packages"
},
"packages": {
"srcFiles": ["!sites/*/files/**", "!xmlrpc.php", "!modules/php/*"],
"projFiles": ["README*", "bin/**", "hooks/**", "src/*.make", "vendor/**"],
"dest": {
"docroot": "html",
"devResources": ""
}
},
"phpcs": true,
"phpmd": true,
"behat": {
Expand Down
14 changes: 14 additions & 0 deletions example/config/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
srcFiles:
- "!sites/*/files/**"
- "!xmlrpc.php"
- "!modules/php/*"
projFiles:
- "README*"
- "bin/**"
- "hooks/**"
- "src/*.make"
- "vendor/**"
dest:
docroot: "html"
devResources: ""
1 change: 1 addition & 0 deletions lib/drupal.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = function(grunt) {
module.drupalPath = function(type) {
switch (module.majorVersion()) {
case 8:
case 9:
return path.join(grunt.config('config.buildPaths.html'), type);
case 7:
default:
Expand Down
232 changes: 232 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"fs-extra": "~3.0.1",
"grunt": "^1.0.1",
"grunt-available-tasks": "~0.6.2",
"load-grunt-configs": "~1.0.0",
"grunt-composer": "~0.4.4",
"grunt-concurrent": "^2.1.0",
"grunt-contrib-clean": "^1.0.0",
Expand Down
9 changes: 7 additions & 2 deletions tasks/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ module.exports = function(grunt) {
}
});
tasks.push('composer:install');
grunt.config(['composer', 'drupal-scaffold'], {});
tasks.push('composer:drupal-scaffold');

// Add the drupal-scaffold task if it is defined in the `composer.json`.
var composer = JSON.parse(require('fs').readFileSync('./composer.json', 'utf8'));
if (typeof composer.scripts !== 'undefined' && 'drupal-scaffold' in composer.scripts) {
grunt.config(['composer', 'drupal-scaffold'], {});
tasks.push('composer:drupal-scaffold');
}
}

if (this.args[0] && this.args[0] === 'compress') {
Expand Down
5 changes: 1 addition & 4 deletions test/test_assets/Gruntconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"srcPaths": {
"configDir": "config",
"make": "src/project.make",
"drupal": "src"
},
"siteUrls": {
"default": "http://project.local"
},
"packages": {
"srcFiles": ["!sites/*/files/**", "!xmlrpc.php", "!modules/php/*"],
"projFiles": ["README*", "bin/**"]
},
"phpcs": true,
"phpmd": true,
"behat": {
Expand Down
8 changes: 8 additions & 0 deletions test/test_assets/config/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
srcFiles:
- "!sites/*/files/**"
- "!xmlrpc.php"
- "!modules/php/*"
projFiles:
- "README*"
- "bin/**"
9 changes: 1 addition & 8 deletions test/test_assets_d8/Gruntconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
{
"domain": "http://127.0.0.1:8080",
"srcPaths": {
"configDir": "config",
"drupal": "src"
},
"siteUrls": {
"default": "http://project.local"
},
"packages": {
"srcFiles": ["!sites/*/files/**", "!xmlrpc.php", "!modules/php/*"],
"projFiles": ["README*", "bin/**", "hooks/**", "src/*.make", "vendor/**", "composer.*"],
"dest": {
"docroot": "html",
"devResources": ""
}
},
"phpcs": true,
"phpmd": true,
"behat": {
Expand Down
Loading