[ Index ] |
PHP Cross Reference of BBPress |
[Summary view] [Print] [Text view]
1 /* jshint node:true */ 2 /* global module */ 3 module.exports = function( grunt ) { 4 var path = require( 'path' ), 5 SOURCE_DIR = 'src/', 6 BUILD_DIR = 'build/', 7 8 BBP_RTL_CSS = [ 9 'includes/admin/assets/css/admin-rtl.css', 10 'includes/admin/styles/*/colors-rtl.css', 11 'templates/default/css/bbpress-rtl.css' 12 ], 13 14 BBP_LTR_CSS = [ 15 'includes/admin/assets/css/admin.css', 16 'includes/admin/styles/*/colors.css', 17 'templates/default/css/bbpress.css' 18 ], 19 20 BBP_JS = [ 21 'includes/admin/assets/js/*.js', 22 'templates/default/js/*.js' 23 ], 24 25 BBP_EXCLUDED_FILES = [ 26 27 // Ignore these 28 '!**/.{svn,git}/**', 29 '!.editorconfig', 30 '!.gitignore', 31 '!.jshintrc', 32 '!.travis.yml', 33 '!build/**', 34 '!Gruntfile.js', 35 '!node_modules/**', 36 '!npm-debug.log', 37 '!package.json', 38 39 // bbPress SCSS CSS source files 40 '!**/*.scss', 41 42 // bbPress PHPUnit tests 43 '!tests/**', 44 '!phpunit.xml', 45 '!phpunit.xml.dist' 46 ], 47 48 // PostCSS 49 autoprefixer = require('autoprefixer'); 50 51 // Load tasks. 52 require( 'matchdep' ).filterDev([ 'grunt-*', '!grunt-legacy-util' ]).forEach( grunt.loadNpmTasks ); 53 54 // Load legacy utils 55 grunt.util = require( 'grunt-legacy-util' ); 56 57 // Project configuration. 58 grunt.initConfig({ 59 pkg: grunt.file.readJSON( 'package.json' ), 60 checktextdomain: { 61 options: { 62 text_domain: 'bbpress', 63 correct_domain: false, 64 keywords: [ 65 '__:1,2d', 66 '_e:1,2d', 67 '_x:1,2c,3d', 68 '_n:1,2,4d', 69 '_ex:1,2c,3d', 70 '_nx:1,2,4c,5d', 71 'esc_attr__:1,2d', 72 'esc_attr_e:1,2d', 73 'esc_attr_x:1,2c,3d', 74 'esc_html__:1,2d', 75 'esc_html_e:1,2d', 76 'esc_html_x:1,2c,3d', 77 '_n_noop:1,2,3d', 78 '_nx_noop:1,2,3c,4d' 79 ] 80 }, 81 files: { 82 src: SOURCE_DIR + '**/*.php', 83 expand: true 84 } 85 }, 86 clean: { 87 all: [ BUILD_DIR ], 88 dynamic: { 89 cwd: BUILD_DIR, 90 dot: true, 91 expand: true, 92 src: [] 93 } 94 }, 95 checkDependencies: { 96 options: { 97 packageManager: 'npm' 98 }, 99 src: {} 100 }, 101 copy: { 102 files: { 103 files: [ 104 { 105 cwd: SOURCE_DIR, 106 dest: BUILD_DIR, 107 dot: true, 108 expand: true, 109 src: [ '!**/.{svn,git}/**', '**', [ BBP_EXCLUDED_FILES ] ] 110 } 111 ] 112 }, 113 dynamic: { 114 cwd: SOURCE_DIR, 115 dest: BUILD_DIR, 116 dot: true, 117 expand: true, 118 src: [] 119 } 120 }, 121 cssmin: { 122 ltr: { 123 cwd: BUILD_DIR, 124 dest: BUILD_DIR, 125 expand: true, 126 ext: '.min.css', 127 src: BBP_LTR_CSS 128 }, 129 rtl: { 130 cwd: BUILD_DIR, 131 dest: BUILD_DIR, 132 expand: true, 133 ext: '.min.css', 134 src: BBP_RTL_CSS 135 } 136 }, 137 jshint: { 138 options: grunt.file.readJSON( '.jshintrc' ), 139 grunt: { 140 src: [ 'Gruntfile.js' ] 141 }, 142 core: { 143 expand: true, 144 cwd: SOURCE_DIR, 145 src: BBP_JS, 146 147 /** 148 * Limit JSHint's run to a single specified file: 149 * 150 * grunt jshint:core --file=filename.js 151 * 152 * Optionally, include the file path: 153 * 154 * grunt jshint:core --file=path/to/filename.js 155 * 156 * @param {String} filepath 157 * @returns {Bool} 158 */ 159 filter: function( filepath ) { 160 var index, file = grunt.option( 'file' ); 161 162 // Don't filter when no target file is specified 163 if ( ! file ) { 164 return true; 165 } 166 167 // Normalise filepath for Windows 168 filepath = filepath.replace( /\\/g, '/' ); 169 index = filepath.lastIndexOf( '/' + file ); 170 171 // Match only the filename passed from cli 172 if ( filepath === file || ( -1 !== index && index === filepath.length - ( file.length + 1 ) ) ) { 173 return true; 174 } 175 176 return false; 177 } 178 } 179 }, 180 jsvalidate:{ 181 options:{ 182 globals: {}, 183 esprimaOptions:{}, 184 verbose: false 185 }, 186 build: { 187 files: { 188 src: BUILD_DIR + '/**/*.js' 189 } 190 }, 191 src: { 192 files: { 193 src: SOURCE_DIR + '/**/*.js' 194 } 195 } 196 }, 197 makepot: { 198 target: { 199 options: { 200 cwd: BUILD_DIR, 201 domainPath: '.', 202 mainFile: 'bbpress.php', 203 potFilename: 'bbpress.pot', 204 processPot: function( pot ) { 205 pot.headers['report-msgid-bugs-to'] = 'https://bbpress.trac.wordpress.org'; 206 pot.headers['last-translator'] = 'JOHN JAMES JACOBY <jjj@bbpress.org>'; 207 pot.headers['language-team'] = 'ENGLISH <jjj@bbpress.org>'; 208 return pot; 209 }, 210 type: 'wp-plugin' 211 } 212 } 213 }, 214 patch: { 215 options: { 216 tracUrl: 'bbpress.trac.wordpress.org' 217 } 218 }, 219 upload_patch: { 220 options: { 221 tracUrl: 'bbpress.trac.wordpress.org' 222 } 223 }, 224 phpcs: { 225 'default': { 226 cmd: 'phpcs', 227 args: [ '--report-summary', '--report-source', '--cache=.phpcscache' ] 228 } 229 }, 230 phpunit: { 231 'default': { 232 cmd: 'phpunit', 233 args: [ '-c', 'phpunit.xml.dist' ] 234 }, 235 buddypress: { 236 cmd: 'phpunit', 237 args: [ '-c', 'tests/phpunit/buddypress.xml' ] 238 }, 239 multisite: { 240 cmd: 'phpunit', 241 args: [ '-c', 'tests/phpunit/multisite.xml' ] 242 } 243 }, 244 postcss: { 245 options: { 246 map: false, 247 processors: [ 248 autoprefixer({ 249 browsers: ['extends @wordpress/browserslist-config'], 250 cascade: false 251 }) 252 ], 253 failOnError: false 254 }, 255 core: { 256 expand: true, 257 cwd: SOURCE_DIR, 258 dest: SOURCE_DIR, 259 src: [ [ BBP_LTR_CSS ], 'includes/admin/styles/*/colors.scss' ] 260 }, 261 colors: { 262 expand: true, 263 cwd: BUILD_DIR, 264 dest: BUILD_DIR, 265 src: [ 'includes/admin/styles/*/colors.css' ] 266 } 267 }, 268 rtlcss: { 269 options: { 270 opts: { 271 processUrls: false, 272 autoRename: false, 273 clean: true 274 }, 275 saveUnmodified: false 276 }, 277 core: { 278 expand: true, 279 cwd: BUILD_DIR, 280 dest: BUILD_DIR, 281 ext: '-rtl.css', 282 src: BBP_LTR_CSS 283 }, 284 dynamic: { 285 expand: true, 286 cwd: BUILD_DIR, 287 dest: BUILD_DIR, 288 ext: '-rtl.css', 289 src: [] 290 } 291 }, 292 sass: { 293 colors: { 294 expand: true, 295 cwd: SOURCE_DIR, 296 dest: BUILD_DIR, 297 ext: '.css', 298 src: [ 'includes/admin/styles/*/colors.scss' ], 299 options: { 300 implementation: require('node-sass'), 301 outputStyle: 'expanded' 302 } 303 } 304 }, 305 stylelint: { 306 css: { 307 options: { 308 format: 'css' 309 }, 310 expand: true, 311 cwd: SOURCE_DIR, 312 src: BBP_LTR_CSS 313 }, 314 scss: { 315 options: { 316 format: 'scss' 317 }, 318 expand: true, 319 cwd: SOURCE_DIR, 320 src: [ 'includes/admin/styles/*/colors.scss' ] 321 } 322 }, 323 uglify: { 324 core: { 325 cwd: SOURCE_DIR, 326 dest: BUILD_DIR, 327 expand: true, 328 ext: '.min.js', 329 src: BBP_JS 330 }, 331 dynamic: { 332 cwd: SOURCE_DIR, 333 dest: BUILD_DIR, 334 expand: true, 335 ext: '.min.js', 336 src: [] 337 }, 338 options: { 339 banner: '/*! This file is automatically generated. */\n' 340 } 341 }, 342 watch: { 343 all: { 344 files: [ 345 SOURCE_DIR + '**', 346 347 // Ignore version control directories. 348 '!' + SOURCE_DIR + '**/.{svn,git}/**' 349 ], 350 tasks: [ 'clean:dynamic', 'copy:dynamic' ], 351 options: { 352 dot: true, 353 interval: 2000, 354 spawn: false 355 } 356 }, 357 colors: { 358 files: [ SOURCE_DIR + 'includes/admin/styles/*/colors.scss' ], 359 tasks: [ 'sass:colors', 'rtlcss:core', 'cssmin:ltr', 'cssmin:rtl' ] 360 }, 361 config: { 362 files: 'Gruntfile.js' 363 }, 364 js: { 365 files: BBP_JS.map( function( path ) { 366 return SOURCE_DIR + path; 367 } ), 368 tasks: [ 'uglify:dynamic' ], 369 options: { 370 interval: 2000, 371 spawn: false 372 } 373 }, 374 rtl: { 375 files: BBP_LTR_CSS.map( function( path ) { 376 return SOURCE_DIR + path; 377 } ), 378 tasks: [ 'rtlcss:dynamic', 'cssmin:ltr', 'cssmin:rtl' ], 379 options: { 380 interval: 2000, 381 spawn: false 382 } 383 } 384 } 385 }); 386 387 // Register tasks. 388 389 // Color schemes task. 390 grunt.registerTask( 'colors', [ 'sass:colors', 'postcss:colors' ] ); 391 392 // Build tasks. 393 grunt.registerTask( 'src', [ 'checkDependencies', 'jsvalidate:src', 'jshint', 'stylelint' ] ); 394 grunt.registerTask( 'commit', [ 'src', 'checktextdomain', 'postcss:core' ] ); 395 grunt.registerTask( 'build', [ 'commit', 'clean:all', 'copy:files', 'colors', 'rtlcss:core', 'cssmin:ltr', 'cssmin:rtl', 'uglify:core', 'jsvalidate:build', 'makepot' ] ); 396 grunt.registerTask( 'release', [ 'build' ] ); 397 398 // PHPCS test task. 399 grunt.registerMultiTask( 'phpcs', 'Runs PHPCS tests.', function() { 400 grunt.util.spawn( { 401 cmd: this.data.cmd, 402 args: this.data.args, 403 opts: { stdio: 'inherit' } 404 }, this.async() ); 405 } ); 406 407 // PHPUnit test task. 408 grunt.registerMultiTask( 'phpunit', 'Runs PHPUnit tests, including the BuddyPress and multisite tests.', function() { 409 grunt.util.spawn( { 410 cmd: this.data.cmd, 411 args: this.data.args, 412 opts: { stdio: 'inherit' } 413 }, this.async() ); 414 } ); 415 416 // JavaScript test task. 417 grunt.registerTask( 'jstest', 'Runs all JavaScript tasks.', [ 'jsvalidate:src', 'jshint' ] ); 418 419 // Travis CI Task 420 grunt.registerTask( 'travis', [ 'jsvalidate:src', 'jshint', 'checktextdomain', 'phpunit' ] ); 421 422 // Patch task. 423 grunt.renameTask( 'patch_wordpress', 'patch' ); 424 425 // Default task. 426 grunt.registerTask( 'default', [ 'src' ] ); 427 428 // Add a listener to the watch task. 429 // 430 // On `watch:all`, automatically updates the `copy:dynamic` and `clean:dynamic` configurations so that only the changed files are updated. 431 // On `watch:rtl`, automatically updates the `rtlcss:dynamic` configuration. 432 grunt.event.on( 'watch', function( action, filepath, target ) { 433 if ( target !== 'all' && target !== 'rtl' ) { 434 return; 435 } 436 437 var relativePath = path.relative( SOURCE_DIR, filepath ), 438 cleanSrc = ( action === 'deleted' ) ? [ relativePath ] : [], 439 copySrc = ( action === 'deleted' ) ? [] : [ relativePath ]; 440 441 grunt.config( [ 'clean', 'dynamic', 'src' ], cleanSrc ); 442 grunt.config( [ 'copy', 'dynamic', 'src' ], copySrc ); 443 grunt.config( [ 'rtlcss', 'dynamic', 'src' ], copySrc ); 444 grunt.config( [ 'uglify', 'dynamic', 'src' ], copySrc ); 445 }); 446 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Nov 12 01:00:49 2024 | Cross-referenced by PHPXref 0.7.1 |