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

Add config directory #330

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
11 changes: 11 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,16 @@ 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');
};

module.sitePath = function() {
return path.join(grunt.config('config.buildPaths.html'), 'sites');
};
Expand Down
21 changes: 19 additions & 2 deletions tasks/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ 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: [
Expand All @@ -33,6 +36,9 @@ module.exports = function(grunt) {
}
});

/**
* Symlink directories from 'src' to 'build/html'.
*/
grunt.config(['symlink', 'libraries'], {
expand: true,
cwd: '<%= config.srcPaths.drupal %>/libraries',
Expand Down Expand Up @@ -64,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 @@ -75,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
26 changes: 26 additions & 0 deletions test/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe strict equality is fine here based on what I'm seeing here:

Setting environment variables from .travis.yml
$ export NVM_NODE_VERSION="4"
$ export GDT_DRUPAL_CORE="7"

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() {
Expand Down