Skip to content

Commit 4e486b6

Browse files
committed
GDT-330 : Make sure we only try to symlink the config directory if one 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
1 parent 8428821 commit 4e486b6

File tree

6 files changed

+49
-8
lines changed

6 files changed

+49
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea
12
/node_modules
23
/test/working_copy
34
/build

docs/10_BUILD.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ package.json
7070
phpmd.xml
7171
```
7272

73+
If you are using Config Management in Drupal 8 you will want to place a
74+
`src/config` directory in your codebase. Scaffolding (scaffold.js) will not
75+
create a symlink to `build/html/config` if it does not exist. Please see the
76+
`example/src/config` directory.
77+
7378
### Setting up Source Code
7479

7580
- Place custom modules in **src/modules/**. When the project is built, the

example/src/config/.gitkeep

Whitespace-only changes.

lib/drupal.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var path = require('path');
2+
var fs = require('fs');
23

34
module.exports = function(grunt) {
45
var module = {};
@@ -51,6 +52,12 @@ module.exports = function(grunt) {
5152
return path.join(grunt.config('config.buildPaths.html'), 'profiles');
5253
};
5354

55+
// Confirms that a project has a `src/config` directory.
56+
module.sourceConfigExists = function() {
57+
var directoryPath = path.join(grunt.config('config.srcPaths.drupal'), 'config');
58+
return fs.existsSync(directoryPath);
59+
};
60+
5461
module.configPath = function() {
5562
return path.join(grunt.config('config.buildPaths.html'), 'config');
5663
};

tasks/scaffold.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,22 @@ module.exports = function(grunt) {
2323

2424
grunt.loadNpmTasks('grunt-contrib-symlink');
2525

26+
var createConfig = drupal.sourceConfigExists();
27+
28+
// Creates directories needed for the build.
2629
grunt.config.set('mkdir.drupal', {
2730
options: {
2831
create: [
2932
drupal.libraryPath(),
3033
drupal.modulePath(),
31-
drupal.profilePath(),
32-
drupal.configPath()
34+
drupal.profilePath()
3335
]
3436
}
3537
});
3638

39+
/**
40+
* Symlink directories from 'src' to 'build/html'.
41+
*/
3742
grunt.config(['symlink', 'libraries'], {
3843
expand: true,
3944
cwd: '<%= config.srcPaths.drupal %>/libraries',
@@ -51,10 +56,6 @@ module.exports = function(grunt) {
5156
dest: drupal.profilePath(),
5257
filter: 'isDirectory'
5358
});
54-
grunt.config(['symlink', 'config'], {
55-
src: '<%= config.srcPaths.drupal %>/config',
56-
dest: drupal.configPath()
57-
});
5859
grunt.config(['symlink', 'sites'], {
5960
expand: true,
6061
cwd: '<%= config.srcPaths.drupal %>/sites',
@@ -69,7 +70,7 @@ module.exports = function(grunt) {
6970
dest: path.join(drupal.themePath(), 'custom')
7071
});
7172

72-
grunt.task.run([
73+
var tasks = [
7374
'mkdir:drupal',
7475
'symlink:profiles',
7576
'symlink:libraries',
@@ -80,7 +81,18 @@ module.exports = function(grunt) {
8081
'symlink:sites',
8182
'mkdir:files',
8283
'copy:static'
83-
]);
84+
];
85+
86+
// We symlink the config directory if one exists.
87+
if (createConfig) {
88+
grunt.config(['symlink', 'config'], {
89+
src: '<%= config.srcPaths.drupal %>/config',
90+
dest: drupal.configPath()
91+
});
92+
tasks.push('symlink:config');
93+
}
94+
95+
grunt.task.run(tasks);
8496

8597
done();
8698
});

test/build.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ describe('grunt', function() {
139139
done();
140140
});
141141
});
142+
143+
// Ensure the build/html/config directory exists if it should.
144+
it('config directory should exist if provided ', function(done) {
145+
var src = fs.existsSync('src/config');
146+
var html = fs.existsSync('build/html/config');
147+
if (src && html) {
148+
assert.ok(true, 'Both src/config and build/html/config exist');
149+
done();
150+
} else if (src && !html) {
151+
assert.ok(false, 'Error: src/config exists but build/html/config does not');
152+
done();
153+
} else if (html && !src) {
154+
assert.ok(false, 'Error: build/html/config exists but src/config does not');
155+
done();
156+
}
157+
});
142158
});
143159

144160
describe('Script dispatching', function() {

0 commit comments

Comments
 (0)