woocommerce/Gruntfile.js

406 lines
11 KiB
JavaScript
Raw Normal View History

2014-02-02 19:20:52 +00:00
/* jshint node:true */
2014-08-01 12:53:31 +00:00
module.exports = function( grunt ) {
2014-02-02 19:20:52 +00:00
'use strict';
2014-01-30 16:11:02 +00:00
2014-02-02 19:22:05 +00:00
grunt.initConfig({
2014-10-23 21:42:07 +00:00
// Setting folder templates.
dirs: {
css: 'assets/css',
fonts: 'assets/fonts',
images: 'assets/images',
js: 'assets/js'
},
// JavaScript linting with JSHint.
2014-08-04 14:12:50 +00:00
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= dirs.js %>/admin/*.js',
'!<%= dirs.js %>/admin/*.min.js',
'<%= dirs.js %>/frontend/*.js',
'!<%= dirs.js %>/frontend/*.min.js',
'includes/gateways/simplify-commerce/assets/js/*.js',
'!includes/gateways/simplify-commerce/assets/js/*.min.js'
2014-08-04 14:12:50 +00:00
]
},
2016-08-08 19:32:39 +00:00
// Sass linting with Stylelint.
stylelint: {
options: {
2016-11-07 17:47:05 +00:00
configFile: '.stylelintrc'
2016-08-08 19:32:39 +00:00
},
all: [
2016-08-10 13:15:58 +00:00
'<%= dirs.css %>/*.scss',
'!<%= dirs.css %>/select2.scss'
2016-08-08 19:32:39 +00:00
]
},
// Minify .js files.
uglify: {
options: {
2017-06-19 11:49:27 +00:00
ie8: true,
parse: {
strict: false
},
output: {
comments : /@license|@preserve|^!/
}
},
admin: {
files: [{
expand: true,
cwd: '<%= dirs.js %>/admin/',
src: [
'*.js',
'!*.min.js'
],
dest: '<%= dirs.js %>/admin/',
ext: '.min.js'
}]
},
vendor: {
files: {
'<%= dirs.js %>/accounting/accounting.min.js': ['<%= dirs.js %>/accounting/accounting.js'],
2015-02-02 16:11:05 +00:00
'<%= dirs.js %>/jquery-blockui/jquery.blockUI.min.js': ['<%= dirs.js %>/jquery-blockui/jquery.blockUI.js'],
'<%= dirs.js %>/jquery-cookie/jquery.cookie.min.js': ['<%= dirs.js %>/jquery-cookie/jquery.cookie.js'],
2016-11-22 15:09:37 +00:00
'<%= dirs.js %>/js-cookie/js.cookie.min.js': ['<%= dirs.js %>/js-cookie/js.cookie.js'],
'<%= dirs.js %>/jquery-flot/jquery.flot.min.js': ['<%= dirs.js %>/jquery-flot/jquery.flot.js'],
'<%= dirs.js %>/jquery-flot/jquery.flot.pie.min.js': ['<%= dirs.js %>/jquery-flot/jquery.flot.pie.js'],
'<%= dirs.js %>/jquery-flot/jquery.flot.resize.min.js': ['<%= dirs.js %>/jquery-flot/jquery.flot.resize.js'],
'<%= dirs.js %>/jquery-flot/jquery.flot.stack.min.js': ['<%= dirs.js %>/jquery-flot/jquery.flot.stack.js'],
'<%= dirs.js %>/jquery-flot/jquery.flot.time.min.js': ['<%= dirs.js %>/jquery-flot/jquery.flot.time.js'],
'<%= dirs.js %>/jquery-payment/jquery.payment.min.js': ['<%= dirs.js %>/jquery-payment/jquery.payment.js'],
2015-06-08 21:31:19 +00:00
'<%= dirs.js %>/jquery-qrcode/jquery.qrcode.min.js': ['<%= dirs.js %>/jquery-qrcode/jquery.qrcode.js'],
2015-07-14 14:18:03 +00:00
'<%= dirs.js %>/jquery-serializejson/jquery.serializejson.min.js': ['<%= dirs.js %>/jquery-serializejson/jquery.serializejson.js'],
'<%= dirs.js %>/jquery-tiptip/jquery.tipTip.min.js': ['<%= dirs.js %>/jquery-tiptip/jquery.tipTip.js'],
'<%= dirs.js %>/jquery-ui-touch-punch/jquery-ui-touch-punch.min.js': ['<%= dirs.js %>/jquery-ui-touch-punch/jquery-ui-touch-punch.js'],
'<%= dirs.js %>/prettyPhoto/jquery.prettyPhoto.init.min.js': ['<%= dirs.js %>/prettyPhoto/jquery.prettyPhoto.init.js'],
'<%= dirs.js %>/prettyPhoto/jquery.prettyPhoto.min.js': ['<%= dirs.js %>/prettyPhoto/jquery.prettyPhoto.js'],
Add/product galleries (#11665) * register prettyPhoto but don't enqueue. #10721 * Remove lightbox option. #10721 Also registers the prettyPhoto styles instead of enqueueing * Stip all prettyPhoto related stuff from the templates and tidy up some logic. #10721 * Add flexslider assets #10721 * styling and re-adds `woocommerce_single_product_image_thumbnail_html`. #10721. * Add zoom functionality. #10721 * Move js to single-product.js. #10721 * styling of the gallery thumbnails when using the `product_page` shortcode. #10721 * Only enable the zoom if the image is large enough. #10721 * Use a 4 column layout by default. #10721 * Make the carousel options filterable. #10721 * rtl styles for gallery. #10721 * Don't zoom on handheld devices. #10721 * markup tweaks in prep for photoswipe * disable zoom for now * Add and enqueue photoswipe assets * add the photoswipe template * initialise photoswipe - it's alive! * tidy up js. add title. add separate trigger. #10721 * Move photoswipe functions to single-product.js. #10721 * reactivate the zoom! #10721 * style the photoswipe trigger. #10721 * disable flexslider animation loop. #10721 * js tidy up. #10721 * Fix jshint * Abstract the product gallery scripts * Minify * Fixed conflict with the admin bar * Photoswipe conflict with admin bar * Index. #10721 * photoswipe button styles. #10721 * Styling. #10721 * No animation on zoom * Image width on mobile * No shadows please. #10721 Looking at you, Twenty Twelve. * code tidy and add class to placeholder figure. #10721 * simplify rtl query * photoswipe button styles * Comma should not be here * zoom icon #10721 * gallery thumb styles. #10721 * trigger icon. #10721 * Image margins. #10721 * icon hover states. #10721 * Variation handling * Fix zoom and heights * Resize after timeout
2016-10-13 14:25:42 +00:00
'<%= dirs.js %>/flexslider/jquery.flexslider.min.js': ['<%= dirs.js %>/flexslider/jquery.flexslider.js'],
'<%= dirs.js %>/zoom/jquery.zoom.min.js': ['<%= dirs.js %>/zoom/jquery.zoom.js'],
'<%= dirs.js %>/photoswipe/photoswipe.min.js': ['<%= dirs.js %>/photoswipe/photoswipe.js'],
'<%= dirs.js %>/photoswipe/photoswipe-ui-default.min.js': ['<%= dirs.js %>/photoswipe/photoswipe-ui-default.js'],
'<%= dirs.js %>/round/round.min.js': ['<%= dirs.js %>/round/round.js'],
'<%= dirs.js %>/stupidtable/stupidtable.min.js': ['<%= dirs.js %>/stupidtable/stupidtable.js'],
'<%= dirs.js %>/zeroclipboard/jquery.zeroclipboard.min.js': ['<%= dirs.js %>/zeroclipboard/jquery.zeroclipboard.js']
}
},
frontend: {
files: [{
expand: true,
cwd: '<%= dirs.js %>/frontend/',
src: [
'*.js',
'!*.min.js'
],
dest: '<%= dirs.js %>/frontend/',
ext: '.min.js'
}]
},
2018-05-31 09:44:52 +00:00
flexslider: {
files: [{
2018-05-31 09:44:52 +00:00
'<%= dirs.js %>/flexslider/jquery.flexslider.min.js': ['<%= dirs.js %>/flexslider/jquery.flexslider.js']
}]
2014-09-22 16:55:53 +00:00
}
},
// Compile all .scss files.
sass: {
compile: {
options: {
2017-06-26 17:16:46 +00:00
sourceMap: 'none'
},
2014-09-22 16:55:53 +00:00
files: [{
expand: true,
cwd: '<%= dirs.css %>/',
src: ['*.scss'],
dest: '<%= dirs.css %>/',
ext: '.css'
}]
}
},
// Generate RTL .css files.
rtlcss: {
woocommerce: {
expand: true,
cwd: '<%= dirs.css %>',
src: [
'*.css',
2017-02-10 19:39:28 +00:00
'!select2.css',
'!*-rtl.css'
],
dest: '<%= dirs.css %>/',
ext: '-rtl.css'
}
},
2014-08-04 14:12:50 +00:00
// Minify all .css files.
cssmin: {
minify: {
expand: true,
cwd: '<%= dirs.css %>/',
src: ['*.css'],
dest: '<%= dirs.css %>/',
ext: '.css'
}
},
// Concatenate select2.css onto the admin.css files.
concat: {
admin: {
files: {
'<%= dirs.css %>/admin.css' : ['<%= dirs.css %>/select2.css', '<%= dirs.css %>/admin.css'],
'<%= dirs.css %>/admin-rtl.css' : ['<%= dirs.css %>/select2.css', '<%= dirs.css %>/admin-rtl.css']
}
2017-02-16 10:44:43 +00:00
}
},
// Watch changes for assets.
2014-02-02 21:33:20 +00:00
watch: {
2014-09-22 16:55:53 +00:00
css: {
files: ['<%= dirs.css %>/*.scss'],
tasks: ['sass', 'rtlcss', 'postcss', 'cssmin', 'concat']
2014-02-02 21:33:20 +00:00
},
js: {
files: [
'<%= dirs.js %>/admin/*js',
'<%= dirs.js %>/frontend/*js',
2014-02-19 19:53:00 +00:00
'!<%= dirs.js %>/admin/*.min.js',
'!<%= dirs.js %>/frontend/*.min.js'
2014-02-02 21:33:20 +00:00
],
tasks: ['jshint', 'uglify']
2014-02-02 21:33:20 +00:00
}
},
// Generate POT files.
2014-08-01 12:53:31 +00:00
makepot: {
options: {
type: 'wp-plugin',
domainPath: 'i18n/languages',
potHeaders: {
'report-msgid-bugs-to': 'https://github.com/woocommerce/woocommerce/issues',
2014-08-01 12:53:31 +00:00
'language-team': 'LANGUAGE <EMAIL@ADDRESS>'
}
},
dist: {
2014-08-01 12:53:31 +00:00
options: {
potFilename: 'woocommerce.pot',
exclude: [
2015-01-16 16:06:58 +00:00
'apigen/.*',
'vendor/.*',
'tests/.*',
'tmp/.*'
]
2014-08-01 12:53:31 +00:00
}
}
},
// Check textdomain errors.
2014-08-01 12:53:31 +00:00
checktextdomain: {
options:{
text_domain: 'woocommerce',
keywords: [
'__:1,2d',
'_e:1,2d',
'_x:1,2c,3d',
'esc_html__:1,2d',
'esc_html_e:1,2d',
'esc_html_x:1,2c,3d',
'esc_attr__:1,2d',
'esc_attr_e:1,2d',
'esc_attr_x:1,2c,3d',
'_ex:1,2c,3d',
'_n:1,2,4d',
'_nx:1,2,4c,5d',
'_n_noop:1,2,3d',
'_nx_noop:1,2,3c,4d'
2014-08-01 21:05:30 +00:00
]
2014-08-01 12:53:31 +00:00
},
files: {
src: [
2018-02-02 11:42:13 +00:00
'**/*.php', // Include all files
'!apigen/**', // Exclude apigen/
'!includes/libraries/**', // Exclude libraries/
'!node_modules/**', // Exclude node_modules/
'!tests/**', // Exclude tests/
'!vendor/**', // Exclude vendor/
'!tmp/**' // Exclude tmp/
2014-08-01 12:53:31 +00:00
],
2014-08-01 21:05:30 +00:00
expand: true
}
2014-08-01 12:53:31 +00:00
},
// Exec shell commands.
2014-02-02 19:22:05 +00:00
shell: {
options: {
stdout: true,
stderr: true
},
2018-02-02 13:20:16 +00:00
apidocs: {
2014-02-14 14:29:30 +00:00
command: [
2018-02-02 13:20:16 +00:00
'vendor/bin/apigen generate -q',
2015-02-23 14:40:16 +00:00
'cd apigen',
'php hook-docs.php'
2014-02-14 14:29:30 +00:00
].join( '&&' )
2017-02-28 20:00:12 +00:00
},
2017-03-20 18:51:21 +00:00
e2e_test: {
command: 'npm run --silent test:single tests/e2e-tests/' + grunt.option( 'file' )
2017-03-10 21:41:40 +00:00
},
2017-03-20 18:51:21 +00:00
e2e_tests: {
command: 'npm run --silent test'
},
e2e_tests_grep: {
command: 'npm run --silent test:grep "' + grunt.option( 'grep' ) + '"'
2018-05-21 14:28:32 +00:00
},
contributors: {
command: [
'echo "Generating contributor list since <%= fromDate %>"',
'./node_modules/.bin/githubcontrib --owner woocommerce --repo woocommerce --fromDate <%= fromDate %> --authToken <%= authToken %> --cols 6 --sortBy contributions --format md --sortOrder desc --showlogin true > contributors.md'
].join( '&&' )
2014-02-02 19:22:05 +00:00
}
2014-02-10 12:52:41 +00:00
},
2018-05-21 14:28:32 +00:00
prompt: {
contributors: {
options: {
questions: [
{
config: 'fromDate',
type: 'input',
message: 'What date (YYYY-MM-DD) should we get contributions since?'
},
{
config: 'authToken',
type: 'input',
2018-05-31 09:44:52 +00:00
message: '(optional) Provide a personal access token. This will allow 5000 requests per hour rather than 60 - use if nothing is generated.'
}
]
}
2018-05-31 09:44:52 +00:00
}
},
2018-05-21 14:28:32 +00:00
// Clean the directory.
2014-02-10 12:52:41 +00:00
clean: {
2018-02-02 13:20:16 +00:00
apidocs: {
2014-02-14 15:09:35 +00:00
src: [ 'wc-apidocs' ]
}
2016-09-13 21:24:01 +00:00
},
// PHP Code Sniffer.
phpcs: {
options: {
2017-10-10 16:08:23 +00:00
bin: 'vendor/bin/phpcs'
2016-09-13 21:24:01 +00:00
},
dist: {
src: [
'**/*.php', // Include all files
'!apigen/**', // Exclude apigen/
'!includes/api/legacy/**', // Exclude legacy REST API
'!includes/gateways/simplify-commerce/includes/Simplify/**', // Exclude simplify commerce SDK
'!includes/libraries/**', // Exclude libraries/
'!node_modules/**', // Exclude node_modules/
2016-12-15 17:11:08 +00:00
'!tests/cli/**', // Exclude tests/cli/
2016-09-13 21:24:01 +00:00
'!tmp/**', // Exclude tmp/
'!vendor/**' // Exclude vendor/
]
}
2017-04-29 15:23:01 +00:00
},
2017-05-04 22:29:40 +00:00
// Autoprefixer.
postcss: {
2017-04-29 15:23:01 +00:00
options: {
processors: [
2017-05-04 22:29:40 +00:00
require( 'autoprefixer' )({
browsers: [
'> 0.1%',
'ie 8',
'ie 9'
]
})
2017-04-29 15:23:01 +00:00
]
},
dist: {
src: [
'<%= dirs.css %>/*.css'
]
}
2014-02-10 14:29:41 +00:00
}
2014-02-02 19:22:05 +00:00
});
2014-01-30 16:11:02 +00:00
// Load NPM tasks to be used here.
2017-06-26 17:16:46 +00:00
grunt.loadNpmTasks( 'grunt-sass' );
2014-02-02 19:22:05 +00:00
grunt.loadNpmTasks( 'grunt-shell' );
2017-06-26 17:16:46 +00:00
grunt.loadNpmTasks( 'grunt-phpcs' );
grunt.loadNpmTasks( 'grunt-rtlcss' );
2017-06-26 17:16:46 +00:00
grunt.loadNpmTasks( 'grunt-postcss' );
grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.loadNpmTasks( 'grunt-checktextdomain' );
2014-08-04 14:12:50 +00:00
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
2014-09-22 16:55:53 +00:00
grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
grunt.loadNpmTasks( 'grunt-contrib-concat' );
2014-02-02 21:33:20 +00:00
grunt.loadNpmTasks( 'grunt-contrib-watch' );
2014-02-10 12:52:41 +00:00
grunt.loadNpmTasks( 'grunt-contrib-clean' );
grunt.loadNpmTasks( 'grunt-prompt' );
// Register tasks.
grunt.registerTask( 'default', [
'js',
'css',
2017-11-21 00:18:07 +00:00
'i18n'
]);
2016-01-22 19:42:05 +00:00
grunt.registerTask( 'js', [
'jshint',
'uglify:admin',
2018-05-31 09:44:52 +00:00
'uglify:frontend',
'uglify:flexslider'
2016-01-22 19:42:05 +00:00
]);
grunt.registerTask( 'css', [
'sass',
'rtlcss',
2017-05-04 22:29:40 +00:00
'postcss',
'cssmin',
2017-05-04 22:29:40 +00:00
'concat'
]);
2014-02-14 14:29:30 +00:00
grunt.registerTask( 'docs', [
2018-02-02 13:20:16 +00:00
'clean:apidocs',
'shell:apidocs'
2014-02-14 14:29:30 +00:00
]);
2018-05-21 14:28:32 +00:00
grunt.registerTask( 'contributors', [
'prompt:contributors',
'shell:contributors'
]);
// Only an alias to 'default' task.
grunt.registerTask( 'dev', [
'default'
]);
grunt.registerTask( 'i18n', [
'checktextdomain',
2014-08-01 12:53:31 +00:00
'makepot'
]);
2017-02-28 20:00:12 +00:00
2017-03-20 18:51:21 +00:00
grunt.registerTask( 'e2e-tests', [
'shell:e2e_tests'
2017-02-28 20:00:12 +00:00
]);
2017-03-10 21:41:40 +00:00
grunt.registerTask( 'e2e-tests-grep', [
'shell:e2e_tests_grep'
]);
2017-03-20 18:51:21 +00:00
grunt.registerTask( 'e2e-test', [
'shell:e2e_test'
2017-03-10 21:41:40 +00:00
]);
};