From 9e6a65f06ae94f718acb7a7975aabf9f8fc4fcc9 Mon Sep 17 00:00:00 2001 From: claudiosmweb Date: Wed, 15 Jan 2014 23:51:36 -0200 Subject: [PATCH] added grunt --- .gitignore | 3 + .jshintrc | 24 ++++ Gruntfile.js | 170 ++++++++++++++++++++++++++ package.json | 20 +++ public/class-wc-payment-discounts.php | 2 +- 5 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 Gruntfile.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6baf9dc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +node_modules/ +public/assets/js/*.min.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..2b49bbb --- /dev/null +++ b/.jshintrc @@ -0,0 +1,24 @@ +{ + "boss": true, + "curly": true, + "eqeqeq": true, + "eqnull": true, + "es3": true, + "expr": true, + "immed": true, + "noarg": true, + "onevar": true, + "quotmark": "single", + "trailing": true, + "undef": true, + "unused": true, + + "browser": true, + + "globals": { + "_": false, + "Backbone": false, + "jQuery": false, + "wp": false + } +} \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..a42f88f --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,170 @@ +/* jshint node:true */ +'use strict'; + +module.exports = function( grunt ) { + + // auto load grunt tasks + require( 'load-grunt-tasks' )( grunt ); + + var pluginConfig = { + + // gets the package vars + pkg: grunt.file.readJSON( 'package.json' ), + + // plugin directories + dirs: { + front: { + js: 'public/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/', + '.gitignore', + '.jshintrc', + 'node_modules/', + 'public/assets/js/update-checkout.js', + 'Gruntfile.js', + 'README.md', + 'package.json', + '*.zip' + ] + }, + + // javascript linting with jshint + jshint: { + options: { + jshintrc: '.jshintrc' + }, + all: [ + 'Gruntfile.js', + '<%= dirs.front.js %>/update-checkout.js' + ] + }, + + // uglify to concat and minify + uglify: { + dist: { + files: { + '<%= dirs.front.js %>/update-checkout.min.js': ['<%= dirs.front.js %>/update-checkout.js'] + } + } + }, + + // watch for changes and trigger compass, jshint and uglify + watch: { + js: { + files: [ + '<%= jshint.all %>' + ], + tasks: ['jshint', 'uglify'] + } + }, + + // image optimization + imagemin: { + dist: { + options: { + optimizationLevel: 7, + progressive: true + }, + files: [ + { + expand: true, + cwd: './', + src: 'screenshot-*.png', + dest: './' + } + ] + } + }, + + // rsync commands used to take the files to svn repository + rsync: { + 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 %>' + } + } + }, + // 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 %>' + } + } + } + } + }; + + // initialize grunt config + // -------------------------- + grunt.initConfig( pluginConfig ); + + // register tasks + // -------------------------- + + // default task + grunt.registerTask( 'default', [ + 'jshint', + 'uglify' + ] ); + + // deploy task + grunt.registerTask( 'deploy', [ + 'default', + 'rsync:tag', + 'rsync:trunk', + 'shell:svn_remove', + 'shell:svn_add', + 'shell:svn_commit' + ] ); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..d5b69ca --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "woocommerce-payment-discounts", + "description": "WooCommerce Discounts Per Payment Method", + "version": "2.0.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" + }, + "engines": { + "node": ">=0.8.0", + "npm": ">=1.1.0" + } +} \ No newline at end of file diff --git a/public/class-wc-payment-discounts.php b/public/class-wc-payment-discounts.php index f1231b9..3598d2d 100644 --- a/public/class-wc-payment-discounts.php +++ b/public/class-wc-payment-discounts.php @@ -289,7 +289,7 @@ public function load_plugin_textdomain() { */ public function enqueue_scripts() { if ( is_checkout() ) { - wp_enqueue_script( self::$plugin_slug, plugins_url( 'assets/js/update-checkout.js', __FILE__ ), array( 'wc-checkout' ), self::VERSION ); + wp_enqueue_script( self::$plugin_slug, plugins_url( 'assets/js/update-checkout.min.js', __FILE__ ), array( 'wc-checkout' ), self::VERSION ); } }