Skip to content

Commit

Permalink
GDT-330 : Make sure we only try to symlink the config directory if on…
Browse files Browse the repository at this point in the history
…e exists at 'src/config'

 * Adding documentation to  10_BUILD.md in reference to the config directory.
 * Updating the test (build.js) to use fs.existsSync for my test
 * Reorder task/definition, Rewrite the test for the config directories
  • Loading branch information
scottalan committed Oct 27, 2017
1 parent 8428821 commit 4e486b6
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
/node_modules
/test/working_copy
/build
Expand Down
5 changes: 5 additions & 0 deletions docs/10_BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added example/src/config/.gitkeep
Empty file.
7 changes: 7 additions & 0 deletions lib/drupal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var path = require('path');
var fs = require('fs');

module.exports = function(grunt) {
var module = {};
Expand Down Expand Up @@ -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');
};
Expand Down
28 changes: 20 additions & 8 deletions tasks/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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();
});
Expand Down
16 changes: 16 additions & 0 deletions test/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ 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 (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();
}
});
});

describe('Script dispatching', function() {
Expand Down

0 comments on commit 4e486b6

Please sign in to comment.