diff --git a/.gitignore b/.gitignore index c587911b..7201a22f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea /node_modules /test/working_copy /build diff --git a/docs/10_BUILD.md b/docs/10_BUILD.md index 6f765594..6a0d84cd 100644 --- a/docs/10_BUILD.md +++ b/docs/10_BUILD.md @@ -70,6 +70,11 @@ package.json phpmd.xml ``` +If you are using Config Management in Drupal 8 you will want to place a +`src/config` directory in your codebase. Scaffolding (scaffold.js) will not +create a symlink to `build/html/config` if it does not exist. Please see the +`example/src/config` directory. + ### Setting up Source Code - Place custom modules in **src/modules/**. When the project is built, the diff --git a/example/src/config/.gitkeep b/example/src/config/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/lib/drupal.js b/lib/drupal.js index 4d641a07..73f628b0 100644 --- a/lib/drupal.js +++ b/lib/drupal.js @@ -1,4 +1,5 @@ var path = require('path'); +var fs = require('fs'); module.exports = function(grunt) { var module = {}; @@ -51,6 +52,12 @@ module.exports = function(grunt) { return path.join(grunt.config('config.buildPaths.html'), 'profiles'); }; + // Confirms that a project has a `src/config` directory. + module.sourceConfigExists = function() { + var directoryPath = path.join(grunt.config('config.srcPaths.drupal'), 'config'); + return fs.existsSync(directoryPath); + }; + module.configPath = function() { return path.join(grunt.config('config.buildPaths.html'), 'config'); }; diff --git a/tasks/scaffold.js b/tasks/scaffold.js index 611e376a..37b9ce61 100644 --- a/tasks/scaffold.js +++ b/tasks/scaffold.js @@ -23,17 +23,22 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-symlink'); + var createConfig = drupal.sourceConfigExists(); + + // Creates directories needed for the build. grunt.config.set('mkdir.drupal', { options: { create: [ drupal.libraryPath(), drupal.modulePath(), - drupal.profilePath(), - drupal.configPath() + drupal.profilePath() ] } }); + /** + * Symlink directories from 'src' to 'build/html'. + */ grunt.config(['symlink', 'libraries'], { expand: true, cwd: '<%= config.srcPaths.drupal %>/libraries', @@ -51,10 +56,6 @@ module.exports = function(grunt) { dest: drupal.profilePath(), filter: 'isDirectory' }); - grunt.config(['symlink', 'config'], { - src: '<%= config.srcPaths.drupal %>/config', - dest: drupal.configPath() - }); grunt.config(['symlink', 'sites'], { expand: true, cwd: '<%= config.srcPaths.drupal %>/sites', @@ -69,7 +70,7 @@ module.exports = function(grunt) { dest: path.join(drupal.themePath(), 'custom') }); - grunt.task.run([ + var tasks = [ 'mkdir:drupal', 'symlink:profiles', 'symlink:libraries', @@ -80,7 +81,18 @@ module.exports = function(grunt) { 'symlink:sites', 'mkdir:files', 'copy:static' - ]); + ]; + + // We symlink the config directory if one exists. + if (createConfig) { + grunt.config(['symlink', 'config'], { + src: '<%= config.srcPaths.drupal %>/config', + dest: drupal.configPath() + }); + tasks.push('symlink:config'); + } + + grunt.task.run(tasks); done(); }); diff --git a/test/build.js b/test/build.js index ac47ec9a..0272c5d0 100644 --- a/test/build.js +++ b/test/build.js @@ -139,6 +139,32 @@ describe('grunt', function() { done(); }); }); + + // Ensure the build/html/config directory exists if it should. + it('config directory should exist if provided ', function(done) { + var src = fs.existsSync('src/config'); + var html = fs.existsSync('build/html/config'); + if (drupalCore === '8') { + if (src && html) { + assert.ok(true, 'Both src/config and build/html/config exist'); + done(); + } else if (src && !html) { + assert.ok(false, 'Error: src/config exists but build/html/config does not'); + done(); + } else if (html && !src) { + assert.ok(false, 'Error: build/html/config exists but src/config does not'); + done(); + } + } else if (drupalCore === '7') { + if (src || html) { + assert.ok(false, 'Error: The src/config or build/html/config directories should not exist'); + done(); + } else { + assert.ok(true, 'Neither src/config or build/html/config exist'); + done(); + } + } + }); }); describe('Script dispatching', function() {