Skip to content

Commit

Permalink
Updated grunt
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed Apr 10, 2017
1 parent 1bde5fa commit eb2c6bc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 155 deletions.
196 changes: 52 additions & 144 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,72 @@
/* jshint node:true */
'use strict';

module.exports = function( grunt ) {
'use strict';

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

var pluginConfig = {
grunt.initConfig({

// gets the package vars
// Gets the package vars.
pkg: grunt.file.readJSON( 'package.json' ),

// plugin directories
// Setting folder templates
dirs: {
front: {
js: 'assets/js'
}
css: 'assets/css',
fonts: 'assets/fonts',
images: 'assets/images',
js: 'assets/js'
},

// svn settings
svn_settings: {
path: '../../../../wp_plugins/<%= pkg.name %>',
tag: '<%= svn_settings.path %>/tags/<%= pkg.version %>',
trunk: '<%= svn_settings.path %>/trunk',
exclude: [
'.editorconfig',
'.git/',
'.tx/',
'.gitignore',
'.jshintrc',
'node_modules/',
'Gruntfile.js',
'README.md',
'package.json',
'*.zip'
]
},

// javascript linting with jshint
// Javascript linting with jshint.
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= dirs.front.js %>/update-checkout.js'
'<%= dirs.js %>/*/*/*.js',
'!<%= dirs.js %>/*/*/*.min.js'
]
},

// uglify to concat and minify
// Minify .js files.
uglify: {
dist: {
files: {
'<%= dirs.front.js %>/update-checkout.min.js': ['<%= dirs.front.js %>/update-checkout.js']
}
options: {
preserveComments: /^!/
},
frontend: {
files: [{
expand: true,
cwd: '<%= dirs.js %>/frontend/',
src: [
'*.js',
'!*.min.js'
],
dest: '<%= dirs.js %>/frontend/',
ext: '.min.js'
}]
}
},

// watch for changes and trigger compass, jshint and uglify
// Watch changes for assets.
watch: {
js: {
files: [
'<%= jshint.all %>'
'<%= dirs.js %>/*js',
'!<%= dirs.js %>/*.min.js'
],
tasks: ['jshint', 'uglify']
}
},

// image optimization
imagemin: {
dist: {
options: {
optimizationLevel: 7,
progressive: true
},
files: [
{
expand: true,
cwd: './',
src: 'screenshot-*.png',
dest: './'
}
]
tasks: [ 'jshint', 'uglify' ]
}
},

// Make .pot files.
makepot: {
dist: {
options: {
type: 'wp-plugin',
potHeaders: {
'report-msgid-bugs-to': 'https://wordpress.org/plugins/woocommerce-payment-discounts/',
'language-team': 'LANGUAGE <EMAIL@ADDRESS>'
}
type: 'wp-plugin'
}
}
},

// Check text domain.
checktextdomain: {
options:{
text_domain: '<%= pkg.name %>',
Expand All @@ -119,100 +89,38 @@ module.exports = function( grunt ) {
},
files: {
src: [
'**/*.php', // Include all files
'!node_modules/**' // Exclude node_modules/
'**/*.php', // Include all files.
'!node_modules/**' // Exclude node_modules/.
],
expand: true
}
},

po2mo: {
files: {
src: 'languages/*.po',
expand: true
}
},

// rsync commands used to take the files to svn repository
rsync: {
// Create README.md for GitHub.
wp_readme_to_markdown: {
options: {
args: ['--verbose'],
exclude: '<%= svn_settings.exclude %>',
syncDest: true,
recursive: true
},
tag: {
options: {
src: './',
dest: '<%= svn_settings.tag %>'
}
},
trunk: {
options: {
src: './',
dest: '<%= svn_settings.trunk %>'
}
}
},

// shell command to commit the new version of the plugin
shell: {
// Remove delete files.
svn_remove: {
command: 'svn st | grep \'^!\' | awk \'{print $2}\' | xargs svn --force delete',
options: {
stdout: true,
stderr: true,
execOptions: {
cwd: '<%= svn_settings.path %>'
}
}
screenshot_url: 'http://ps.w.org/<%= pkg.name %>/assets/{screenshot}.png'
},
// Add new files.
svn_add: {
command: 'svn add --force * --auto-props --parents --depth infinity -q',
options: {
stdout: true,
stderr: true,
execOptions: {
cwd: '<%= svn_settings.path %>'
}
}
},
// Commit the changes.
svn_commit: {
command: 'svn commit -m "updated the plugin version to <%= pkg.version %>"',
options: {
stdout: true,
stderr: true,
execOptions: {
cwd: '<%= svn_settings.path %>'
}
dest: {
files: {
'README.md': 'readme.txt'
}
}
}
};
});

// initialize grunt config
// --------------------------
grunt.initConfig( pluginConfig );
// Load tasks.
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-checktextdomain' );
grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' );

// register tasks
// --------------------------

// default task
// Register tasks.
grunt.registerTask( 'default', [
'jshint',
'uglify'
] );

// deploy task
grunt.registerTask( 'deploy', [
'default',
'rsync:tag',
'rsync:trunk',
'shell:svn_remove',
'shell:svn_add',
'shell:svn_commit'
] );
]);
grunt.registerTask( 'readme', 'wp_readme_to_markdown' );
};
18 changes: 7 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
"version": "2.3.0",
"main": "Gruntfile.js",
"devDependencies": {
"grunt": "~0.4.1",
"load-grunt-tasks": "0.2.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-imagemin": "~0.4.0",
"grunt-rsync": "~0.2.1",
"grunt-shell": "~0.6.1",
"grunt-po2mo": "~0.1.2",
"grunt-checktextdomain": "~0.1.1",
"grunt-wp-i18n": "~0.5.0"
"grunt": "^1.0.1",
"grunt-checktextdomain": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-uglify": "^2.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-wp-i18n": "^1.0.0",
"grunt-wp-readme-to-markdown": "^2.0.1"
},
"engines": {
"node": ">=0.8.0",
Expand Down

0 comments on commit eb2c6bc

Please sign in to comment.