diff --git a/bootstrap/index.js b/bootstrap/index.js index 031bbb2..5bce5f8 100644 --- a/bootstrap/index.js +++ b/bootstrap/index.js @@ -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 diff --git a/create/index.js b/create/index.js index ba6043a..6ef8c4f 100644 --- a/create/index.js +++ b/create/index.js @@ -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 diff --git a/output/output.js b/output/output.js index 31d2dae..5ea7298 100644 --- a/output/output.js +++ b/output/output.js @@ -55,7 +55,20 @@ 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/options/_wordpressdeploy.js', 'tasks/options/wordpressdeploy.js'); + + + this.template('tasks/_vagrant_commands_task.js', 'tasks/vagrant_commands_task.js'); } function scripts() { @@ -121,6 +134,7 @@ module.exports = { config: config, src: src, node: node, + tasks: tasks, scripts: scripts, findSQL: findSQL, sql: sql diff --git a/package.json b/package.json index 7cff045..19a2a1e 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,8 @@ "chalk": "~0.4.0" }, "devDependencies": { + "grunt": "^0.4.5", + "grunt-wordpress-deploy": "0.0.6", "mocha": "*" }, "peerDependencies": { diff --git a/templates/_Gruntfile.js b/templates/_Gruntfile.js index a572f77..26e61c9 100644 --- a/templates/_Gruntfile.js +++ b/templates/_Gruntfile.js @@ -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'; }; diff --git a/templates/_package.json b/templates/_package.json index c96eee4..67702b9 100644 --- a/templates/_package.json +++ b/templates/_package.json @@ -3,10 +3,11 @@ "version": "0.0.1", "repository": "none", "devDependencies": { + "glob": "^4.3.2", "grunt": "^0.4.5", "grunt-gitpull": "^0.1.6", "grunt-svn-checkout": "^0.1.1", - "grunt-http": "^1.4.0", + "grunt-http": "^1.4.0", "grunt-vagrant-commands": "^0.0.3", "load-grunt-tasks": "^0.5.0" } diff --git a/templates/_wp-constants b/templates/_wp-constants index 980406b..8ae7fef 100644 --- a/templates/_wp-constants +++ b/templates/_wp-constants @@ -1,10 +1,32 @@ -/* Debug */ -define( 'WP_DEBUG', true ); -define( 'WP_DEBUG_DISPLAY', true ); -define( 'WP_DEBUG_LOG', false ); -define( 'SCRIPT_DEBUG', true ); -define( 'SAVEQUERIES', true ); -define( 'JETPACK_DEV_DEBUG', true ); - /*Caching*/ define( 'WP_CACHE_KEY_SALT', '<%= site.id %>' ); + +<% if (wordpress.constants) { +%>/* Constants */ +<% _.each(wordpress.constants, function(value, key, field){ + if(!_.contains([true,false],value)){ + value = "'" + value + "'"; + } + %>define( '<%= key %>', <%= value %> ); +<% }) +} %> + +/* Debug Defaults*/ +if( !defined('WP_DEBUG') ) { + define( 'WP_DEBUG', true ); +} +if( !defined('WP_DEBUG_DISPLAY') ) { + define( 'WP_DEBUG_DISPLAY', true ); +} +if( !defined('WP_DEBUG_LOG') ) { + define( 'WP_DEBUG_LOG', false ); +} +if( !defined('SCRIPT_DEBUG') ) { + define( 'SCRIPT_DEBUG', true ); +} +if( !defined('SAVEQUERIES') ) { + define( 'SAVEQUERIES', true ); +} +if( !defined('JETPACK_DEV_DEBUG') ) { + define( 'JETPACK_DEV_DEBUG', true ); +} diff --git a/templates/scripts/src.sh b/templates/scripts/src.sh index 3a04731..0973639 100644 --- a/templates/scripts/src.sh +++ b/templates/scripts/src.sh @@ -3,10 +3,10 @@ source config/site-vars.sh # Plugins echo "Linking working directory pluins" -find src/plugins/ -maxdepth 1 -mindepth 1 \( ! -regex '.*/\..*' \) -exec ln -s $PWD/{} $PWD/htdocs/wp-content/plugins/ \; +find src/plugins/ -maxdepth 1 -mindepth 1 \( ! -regex '.*/\..*' \) -exec ln -sf ../../../{} $PWD/htdocs/wp-content/plugins/ \; # Themes echo "Linking working directory themes" -find src/themes/ -maxdepth 1 -mindepth 1 \( ! -regex '.*/\..*' \) -exec ln -s $PWD/{} $PWD/htdocs/wp-content/themes/ \; +find src/themes/ -maxdepth 1 -mindepth 1 \( ! -regex '.*/\..*' \) -exec ln -sf ../../../{} $PWD/htdocs/wp-content/themes/ \; # Dropins echo "Linking any available drop-ins" -find src/dropins/ -maxdepth 1 -mindepth 1 \( ! -regex '.*/\..*' \) -exec ln -s $PWD/{} $PWD/htdocs/wp-content/ \; +find src/dropins/ -maxdepth 1 -mindepth 1 \( ! -regex '.*/\..*' \) -exec ln -sf ../../../{} $PWD/htdocs/wp-content/ \; diff --git a/templates/tasks/_vagrant_commands_task.js b/templates/tasks/_vagrant_commands_task.js new file mode 100644 index 0000000..1cb8b1a --- /dev/null +++ b/templates/tasks/_vagrant_commands_task.js @@ -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']); +} \ No newline at end of file diff --git a/templates/tasks/options/_gitPull.js b/templates/tasks/options/_gitPull.js new file mode 100644 index 0000000..0eaea8a --- /dev/null +++ b/templates/tasks/options/_gitPull.js @@ -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) { %>,<% } %> +<% } } +%> ] + }<% } %> + } \ No newline at end of file diff --git a/templates/tasks/options/_http.js b/templates/tasks/options/_http.js new file mode 100644 index 0000000..69aff15 --- /dev/null +++ b/templates/tasks/options/_http.js @@ -0,0 +1,8 @@ +module.exports = { + remoteDatabases: { + options: { + url: '<%= remoteDatabase.url %>' + }, + dest: 'config/data/<%= remoteDatabase.url.match(/([^\/]*)$/)[0] %>' + } +} \ No newline at end of file diff --git a/templates/tasks/options/_svn_checkout.js b/templates/tasks/options/_svn_checkout.js new file mode 100644 index 0000000..ad9fe2a --- /dev/null +++ b/templates/tasks/options/_svn_checkout.js @@ -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) { %>,<% } %> +<% } } +%> ] + }<% } %> + } \ No newline at end of file diff --git a/templates/tasks/options/_vagrant_commands.js b/templates/tasks/options/_vagrant_commands.js new file mode 100644 index 0000000..bc3ae23 --- /dev/null +++ b/templates/tasks/options/_vagrant_commands.js @@ -0,0 +1,50 @@ +module.exports = { + 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'] + ] + } + } \ No newline at end of file diff --git a/templates/tasks/options/_wordpressdeploy.js b/templates/tasks/options/_wordpressdeploy.js new file mode 100644 index 0000000..1313775 --- /dev/null +++ b/templates/tasks/options/_wordpressdeploy.js @@ -0,0 +1,37 @@ +module.exports = { + options: { + backup_dir: "backups/", + rsync_args: ['--verbose', '--progress', '-rlpt', '--compress', '--omit-dir-times', '--delete'], + exclusions: ['Gruntfile.js', '.git/', 'tmp/*', 'backups/', 'wp-config.php', 'composer.json', 'composer.lock', 'README.md', '.gitignore', 'package.json', 'node_modules'] + }, + local: { + "title": "local", + "database": '<%= site.db_name %>', //Needs implemented + "user": '<%= site.db_user %>', + "pass": '<%= site.db_pass %>', + "host": '<%= site.db_host %>', + "url": '<%= site.url %>', + "path": process.cwd() + '/htdocs' + }, + staging: { + "title": "staging", + "database": '<%= deploy.staging.db_name %>', + "user": '<%= deploy.staging.db_user %>', + "pass": '<%= deploy.staging.db_pass %>', + "host": '<%= deploy.staging.db_host %>', + "url": '<%= deploy.staging.url %>', + "path": '<%= deploy.staging.path %>', + "ssh_host": '<%= deploy.staging.ssh_host %>' + }, + production: { + "title": "prod", + "database": '<%= deploy.production.db_name %>', + "user": '<%= deploy.production.db_user %>', + "pass": '<%= deploy.production.db_pass %>', + "host": '<%= deploy.production.db_host %>', + "url": '<%= deploy.production.url %>', + "path": '<%= deploy.production.path %>', + "ssh_host": '<%= deploy.production.ssh_host %>' + } + + } \ No newline at end of file