Skip to content

Commit

Permalink
Modularized grunt tasks to later improve extensibility of grunt tasks…
Browse files Browse the repository at this point in the history
… per project.

Fixes: 	Case sensitive filename change.
		Typo in hosts.
  • Loading branch information
EHLOVader committed Jan 6, 2015
1 parent 16e2da7 commit bbbf299
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 167 deletions.
1 change: 1 addition & 0 deletions bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var BootstrapVVV = yeoman.generators.Base.extend({
config: output.config,
src: output.src,
node: output.node,
tasks: output.tasks,
scripts: output.scripts,
findSQL: output.findSQL,
sql: output.sql
Expand Down
1 change: 1 addition & 0 deletions create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var VVVCreate = yeoman.generators.Base.extend({
config: output.config,
src: output.src,
node: output.node,
tasks: output.tasks,
scripts: output.scripts,
findSQL: output.findSQL,
sql: output.sql
Expand Down
13 changes: 13 additions & 0 deletions output/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ function src() {

function node() {
this.template('_package.json', 'package.json');
}

function tasks() {
this.template('_Gruntfile.js', 'Gruntfile.js');
if ( this.remoteDatabase ) {
this.template('tasks/options/_http.js', 'tasks/options/http.js');
}
this.template('tasks/options/_gitPull.js', 'tasks/options/gitPull.js');
this.template('tasks/options/_svn_checkout.js', 'tasks/options/svn_checkout.js');
this.template('tasks/options/_vagrant_commands.js', 'tasks/options/vagrant_commands.js');


this.template('tasks/_vagrant_commands_task.js', 'tasks/vagrant_commands_task.js');
}

function scripts() {
Expand Down Expand Up @@ -121,6 +133,7 @@ module.exports = {
config: config,
src: src,
node: node,
tasks: tasks,
scripts: scripts,
findSQL: findSQL,
sql: sql
Expand Down
191 changes: 24 additions & 167 deletions templates/_Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,179 +1,36 @@
function loadConfig(path) {
var glob = require('glob');
var object = {};
var key;

glob.sync('*', {cwd: path}).forEach(function(option) {
key = option.replace(/\.js$/,'');
object[key] = require(path + option);
});

return object;
}

module.exports = function (grunt) {
'use strict';
// Project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),<% if ( remoteDatabase ) { %>
http: {
remoteDatabases: {
options: {
url: '<%= remoteDatabase.url %>'
},
dest: 'config/data/<%= remoteDatabase.url.match(/([^\/]*)$/)[0] %>'
}
},<% } if ( repos || dependencies ) { %>
gitPull: {<% if ( dependencies ) { %>
dependencies: {
repos: [
{
path: [],
dir: 'deps',
repo: '<%= dependencies %>'
}
]
}<% if ( repos && dependencies ) { %>,
<% } }
if ( repos ) {
%> themes: {
repos: [
<% var i, length;
for (i = 0, length = repos.theme.length; i < length; i++) {
if ( 'object' === typeof repos.theme[i] ) {
%> {
path: ['src', 'themes'],
dir: '<%= repos.theme[i].dir %>',
repo: '<%= repos.theme[i].repo %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } else {
%> {
path: ['src', 'themes'],
repo: '<%= repos.theme[i] %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } }
%> ]
},
plugins: {
repos: [
<% for (i = 0, length = repos.plugin.length; i < length; i++) {
if ( 'object' === typeof repos.plugin[i] ) {
%> {
path: ['src', 'plugins'],
dir: '<%= repos.plugin[i].dir %>',
repo: '<%= repos.plugin[i].repo %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } else {
%> {
path: ['src', 'plugins'],
repo: '<%= repos.plugin[i] %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } }
%> ]
}<% } %>
},<% } if ( svn_repos || svn_dependencies ) { %>
svn_checkout: {<% if ( svn_dependencies ) { %>
dependencies: {
repos: [
{
path: [],
dir: 'deps',
repo: '<%= svn_dependencies %>'
}
]
}<% } if ( svn_repos && svn_dependencies ) { %>,
<% }
if ( svn_repos ) { %>
themes: {
repos: [
<% var i, length;
for (i = 0, length = svn_repos.theme.length; i < length; i++) {
if ( 'object' === typeof svn_repos.theme[i] ) {
%> {
path: ['src', 'themes'],
dir: '<%= svn_repos.theme[i].dir %>',
repo: '<%= svn_repos.theme[i].repo %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } else {
%> {
path: ['src', 'themes'],
repo: '<%= svn_repos.theme[i] %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } }
%> ]
},
plugins: {
repos: [
<% for (i = 0, length = svn_repos.plugin.length; i < length; i++) {
if ( 'object' === typeof svn_repos.plugin[i] ) {
%> {
path: ['src', 'plugins'],
dir: '<%= svn_repos.plugin[i].dir %>',
repo: '<%= svn_repos.plugin[i].repo %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } else {
%> {
path: ['src', 'plugins'],
repo: '<%= svn_repos.plugin[i] %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } }
%> ]
}<% } %>
},<% } %>
vagrant_commands: {
restart: {
commands: [
['up'],
['provision']
]
},<% if ( 'trunk' === wordpress.version ) { %>
svn_up: {
commands: [
['ssh', '--command=cd /var/sites/<%= site.id %>/htdocs && svn up']
]
},
<% } %> import_db: {
commands: [
['ssh', '--command=cd /var/sites/<%= site.id %> && bash scripts/import-sql.sh']
]
},
install_plugins: {
commands: [
['ssh', '--command=cd /var/sites/<%= site.id %> && bash scripts/plugins.sh']
]
},
install_themes: {
commands: [
['ssh', '--command=cd /var/sites/<%= site.id %> && bash scripts/themes.sh']
]
},
symlinks: {
commands: [
['ssh', '--command=cd /var/sites/<%= site.id %> && bash scripts/clear-links.sh'],
['ssh', '--command=cd /var/sites/<%= site.id %> && bash scripts/dependencies.sh'],
['ssh', '--command=cd /var/sites/<%= site.id %> && bash scripts/src.sh']
]
},
proxy_on: {
commands: [
['ssh', '--command=cd /var/sites/<%= site.id %> && bash scripts/proxy_on.sh']
]
},
proxy_off: {
commands: [
['ssh', '--command=cd /var/sites/<%= site.id %> && bash scripts/proxy_off.sh']
]
},
cleanup: {
commands: [
['ssh', '--command=cd /var/sites/<%= site.id %> && bash scripts/cleanup.sh']
]
}
}
});

var config = {
pkg: grunt.file.readJSON('package.json'),
env: process.env
};

grunt.util._.extend(config, loadConfig('./tasks/options/'));

grunt.initConfig(config);

// Load tasks
require('load-grunt-tasks')(grunt);

// Register tasks
grunt.registerTask('default', [<% if ( remoteDatabase ) { %>'http', <% } %><% if ( repos || dependencies ) { %>'gitPull', <% } %><% if ( svn_repos || svn_dependencies ) { %>'svn_checkout', <% } %>'vagrant_commands:restart']);
<% if ( 'trunk' === wordpress.version ) { %> grunt.registerTask('trunk', ['vagrant_commands:svn_up']);<% }
%> grunt.registerTask('provision', ['vagrant_commands:restart']);
grunt.registerTask('db', ['vagrant_commands:import_db']);<% if ( remoteDatabase ) { %>
grunt.registerTask('remoteDB', ['http:remoteDatabases', 'vagrant_commands:import_db']);<% } %>
grunt.registerTask('plugins', ['vagrant_commands:install_plugins']);
grunt.registerTask('themes', ['vagrant_commands:install_themes']);
grunt.registerTask('relink', [<% if ( dependencies ) { %>'gitPull:dependencies', <% } %><% if ( svn_dependencies ) { %>'svn_checkout:dependencies', <% } %>'vagrant_commands:symlinks']);
grunt.registerTask('proxy_on', ['vagrant_commands:proxy_on']);
grunt.registerTask('proxy_off', ['vagrant_commands:proxy_off']);
grunt.registerTask('cleanup', ['vagrant_commands:cleanup']);

grunt.loadTasks('tasks');

grunt.util.linefeed = '\n';
};
12 changes: 12 additions & 0 deletions templates/tasks/_vagrant_commands_task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = function (grunt){
<% if ( 'trunk' === wordpress.version ) { %> grunt.registerTask('trunk', ['vagrant_commands:svn_up']);<% }
%> grunt.registerTask('provision', ['vagrant_commands:restart']);
grunt.registerTask('db', ['vagrant_commands:import_db']);<% if ( remoteDatabase ) { %>
grunt.registerTask('remoteDB', ['http:remoteDatabases', 'vagrant_commands:import_db']);<% } %>
grunt.registerTask('plugins', ['vagrant_commands:install_plugins']);
grunt.registerTask('themes', ['vagrant_commands:install_themes']);
grunt.registerTask('relink', [<% if ( dependencies ) { %>'gitPull:dependencies', <% } %><% if ( svn_dependencies ) { %>'svn_checkout:dependencies', <% } %>'vagrant_commands:symlinks']);
grunt.registerTask('proxy_on', ['vagrant_commands:proxy_on']);
grunt.registerTask('proxy_off', ['vagrant_commands:proxy_off']);
grunt.registerTask('cleanup', ['vagrant_commands:cleanup']);
}
48 changes: 48 additions & 0 deletions templates/tasks/options/_gitPull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {<% if ( dependencies ) { %>
dependencies: {
repos: [
{
path: [],
dir: 'deps',
repo: '<%= dependencies %>'
}
]
}<% if ( repos && dependencies ) { %>,
<% } }
if ( repos ) {
%> themes: {
repos: [
<% var i, length;
for (i = 0, length = repos.theme.length; i < length; i++) {
if ( 'object' === typeof repos.theme[i] ) {
%> {
path: ['src', 'themes'],
dir: '<%= repos.theme[i].dir %>',
repo: '<%= repos.theme[i].repo %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } else {
%> {
path: ['src', 'themes'],
repo: '<%= repos.theme[i] %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } }
%> ]
},
plugins: {
repos: [
<% for (i = 0, length = repos.plugin.length; i < length; i++) {
if ( 'object' === typeof repos.plugin[i] ) {
%> {
path: ['src', 'plugins'],
dir: '<%= repos.plugin[i].dir %>',
repo: '<%= repos.plugin[i].repo %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } else {
%> {
path: ['src', 'plugins'],
repo: '<%= repos.plugin[i] %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } }
%> ]
}<% } %>
}
8 changes: 8 additions & 0 deletions templates/tasks/options/_http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
remoteDatabases: {
options: {
url: '<%= remoteDatabase.url %>'
},
dest: 'config/data/<%= remoteDatabase.url.match(/([^\/]*)$/)[0] %>'
}
}
48 changes: 48 additions & 0 deletions templates/tasks/options/_svn_checkout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {<% if ( svn_dependencies ) { %>
dependencies: {
repos: [
{
path: [],
dir: 'deps',
repo: '<%= svn_dependencies %>'
}
]
}<% } if ( svn_repos && svn_dependencies ) { %>,
<% }
if ( svn_repos ) { %>
themes: {
repos: [
<% var i, length;
for (i = 0, length = svn_repos.theme.length; i < length; i++) {
if ( 'object' === typeof svn_repos.theme[i] ) {
%> {
path: ['src', 'themes'],
dir: '<%= svn_repos.theme[i].dir %>',
repo: '<%= svn_repos.theme[i].repo %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } else {
%> {
path: ['src', 'themes'],
repo: '<%= svn_repos.theme[i] %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } }
%> ]
},
plugins: {
repos: [
<% for (i = 0, length = svn_repos.plugin.length; i < length; i++) {
if ( 'object' === typeof svn_repos.plugin[i] ) {
%> {
path: ['src', 'plugins'],
dir: '<%= svn_repos.plugin[i].dir %>',
repo: '<%= svn_repos.plugin[i].repo %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } else {
%> {
path: ['src', 'plugins'],
repo: '<%= svn_repos.plugin[i] %>'
}<% if((i + 1) !== length) { %>,<% } %>
<% } }
%> ]
}<% } %>
}
Loading

0 comments on commit bbbf299

Please sign in to comment.