[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/ -> Gruntfile.js (source)

   1  /* jshint node:true */
   2  /* global module */
   3  module.exports = function( grunt ) {
   4      var SOURCE_DIR = 'src/',
   5          BUILD_DIR = 'build/',
   6  
   7          BP_CSS = [
   8              '**/*.css'
   9          ],
  10  
  11          // CSS exclusions, for excluding files from certain tasks, e.g. rtlcss
  12          BP_EXCLUDED_CSS = [
  13              '!**/*-rtl.css'
  14          ],
  15  
  16          BP_JS = [
  17              '**/*.js'
  18          ],
  19  
  20          BP_EXCLUDED_JS = [
  21              '!**/js/blocks/*.js',
  22              '!**/js/blocks/**/*.js',
  23              '!**/js/block-*/*.js',
  24              '!**/js/block-*/**/*.js',
  25              '!**/js/block-*.js',
  26              '!**/js/friends.js',
  27              '!**/js/dynamic-members.js',
  28              '!**/js/dynamic-groups.js',
  29              '!**/js/dynamic-widget-block.js',
  30              '!**/js/sitewide-notices.js'
  31          ],
  32  
  33          BP_EXCLUDED_MISC = [
  34          ],
  35  
  36          // SASS generated "Twenty*"" CSS files
  37          BP_SCSS_CSS_FILES = [
  38              '!bp-templates/bp-legacy/css/twenty*.css',
  39              '!bp-templates/bp-nouveau/css/buddypress.css',
  40              '!bp-templates/bp-nouveau/css/twenty*.css',
  41              '!bp-templates/bp-nouveau/css/primary-nav.css',
  42              '!bp-core/admin/css/hello.css',
  43              '!bp-members/css/blocks/member.css',
  44              '!bp-groups/css/blocks/group.css',
  45              '!bp-members/css/blocks/members.css',
  46              '!bp-groups/css/blocks/groups.css',
  47              '!bp-core/css/blocks/login-form.css',
  48              '!bp-activity/css/blocks/latest-activities.css',
  49              '!bp-friends/css/blocks/friends.css',
  50              '!bp-members/css/blocks/dynamic-members.css',
  51              '!bp-groups/css/blocks/dynamic-groups.css',
  52              '!bp-messages/css/blocks/sitewide-notices.css',
  53              '!bp-blogs/css/blocks/recent-posts.css',
  54              '!bp-members/css/blocks/member-avatar-blocks.css'
  55          ],
  56  
  57          autoprefixer = require('autoprefixer');
  58  
  59      require( 'matchdep' ).filterDev( ['grunt-*', '!grunt-legacy-util'] ).forEach( grunt.loadNpmTasks );
  60      grunt.util = require( 'grunt-legacy-util' );
  61      require( 'phplint' ).gruntPlugin( grunt );
  62  
  63      grunt.initConfig( {
  64          pkg: grunt.file.readJSON( 'package.json' ),
  65          checkDependencies: {
  66              options: {
  67                  packageManager: 'npm'
  68              },
  69              src: {}
  70          },
  71          jshint: {
  72              options: grunt.file.readJSON( '.jshintrc' ),
  73              grunt: {
  74                  src: ['Gruntfile.js']
  75              },
  76              core: {
  77                  expand: true,
  78                  cwd: SOURCE_DIR,
  79                  src: BP_JS,
  80  
  81                  /**
  82                   * Limit JSHint's run to a single specified file:
  83                   *
  84                   * grunt jshint:core --file=filename.js
  85                   *
  86                   * Optionally, include the file path:
  87                   *
  88                   * grunt jshint:core --file=path/to/filename.js
  89                   *
  90                   * @param {String} filepath
  91                   * @returns {Bool}
  92                   */
  93                  filter: function( filepath ) {
  94                      var index, file = grunt.option( 'file' );
  95  
  96                      // Don't filter when no target file is specified
  97                      if ( ! file ) {
  98                          return true;
  99                      }
 100  
 101                      // Normalise filepath for Windows
 102                      filepath = filepath.replace( /\\/g, '/' );
 103                      index = filepath.lastIndexOf( '/' + file );
 104  
 105                      // Match only the filename passed from cli
 106                      if ( filepath === file || ( -1 !== index && index === filepath.length - ( file.length + 1 ) ) ) {
 107                          return true;
 108                      }
 109  
 110                      return false;
 111                  }
 112              }
 113          },
 114          sass: {
 115              options: {
 116                  outputStyle: 'expanded',
 117                  indentType: 'tab',
 118                  indentWidth: '1'
 119              },
 120              legacy: {
 121                  cwd: SOURCE_DIR,
 122                  extDot: 'last',
 123                  expand: true,
 124                  ext: '.css',
 125                  flatten: true,
 126                  src: ['bp-templates/bp-legacy/css/*.scss'],
 127                  dest: SOURCE_DIR + 'bp-templates/bp-legacy/css/'
 128              },
 129              nouveau: {
 130                  cwd: SOURCE_DIR,
 131                  extDot: 'last',
 132                  expand: true,
 133                  ext: '.css',
 134                  flatten: true,
 135                  src: ['bp-templates/bp-nouveau/sass/buddypress.scss', 'bp-templates/bp-nouveau/sass/twenty*.scss', 'bp-templates/bp-nouveau/sass/primary-nav.scss'],
 136                  dest: SOURCE_DIR + 'bp-templates/bp-nouveau/css/'
 137              },
 138              admin: {
 139                  cwd: SOURCE_DIR,
 140                  extDot: 'last',
 141                  expand: true,
 142                  ext: '.css',
 143                  flatten: true,
 144                  src: ['bp-core/admin/sass/*.scss'],
 145                  dest: SOURCE_DIR + 'bp-core/admin/css/'
 146              },
 147              members_blocks: {
 148                  cwd: SOURCE_DIR,
 149                  extDot: 'last',
 150                  expand: true,
 151                  ext: '.css',
 152                  flatten: true,
 153                  src: ['bp-members/sass/blocks/*.scss'],
 154                  dest: SOURCE_DIR + 'bp-members/css/blocks/'
 155              },
 156              groups_blocks: {
 157                  cwd: SOURCE_DIR,
 158                  extDot: 'last',
 159                  expand: true,
 160                  ext: '.css',
 161                  flatten: true,
 162                  src: ['bp-groups/sass/blocks/*.scss'],
 163                  dest: SOURCE_DIR + 'bp-groups/css/blocks/'
 164              },
 165              core_blocks: {
 166                  cwd: SOURCE_DIR,
 167                  extDot: 'last',
 168                  expand: true,
 169                  ext: '.css',
 170                  flatten: true,
 171                  src: ['bp-core/sass/blocks/*.scss'],
 172                  dest: SOURCE_DIR + 'bp-core/css/blocks/'
 173              },
 174              activity_blocks: {
 175                  cwd: SOURCE_DIR,
 176                  extDot: 'last',
 177                  expand: true,
 178                  ext: '.css',
 179                  flatten: true,
 180                  src: ['bp-activity/sass/blocks/*.scss'],
 181                  dest: SOURCE_DIR + 'bp-activity/css/blocks/'
 182              },
 183              friends_blocks: {
 184                  cwd: SOURCE_DIR,
 185                  extDot: 'last',
 186                  expand: true,
 187                  ext: '.css',
 188                  flatten: true,
 189                  src: ['bp-friends/sass/blocks/*.scss'],
 190                  dest: SOURCE_DIR + 'bp-friends/css/blocks/'
 191              },
 192              messages_blocks: {
 193                  cwd: SOURCE_DIR,
 194                  extDot: 'last',
 195                  expand: true,
 196                  ext: '.css',
 197                  flatten: true,
 198                  src: ['bp-messages/sass/blocks/*.scss'],
 199                  dest: SOURCE_DIR + 'bp-messages/css/blocks/'
 200              },
 201              blogs_blocks: {
 202                  cwd: SOURCE_DIR,
 203                  extDot: 'last',
 204                  expand: true,
 205                  ext: '.css',
 206                  flatten: true,
 207                  src: ['bp-blogs/sass/blocks/*.scss'],
 208                  dest: SOURCE_DIR + 'bp-blogs/css/blocks/'
 209              }
 210          },
 211          rtlcss: {
 212              options: {
 213                  opts: {
 214                      processUrls: false,
 215                      autoRename: false,
 216                      clean: true
 217                  },
 218                  saveUnmodified: true
 219              },
 220              core: {
 221                  expand: true,
 222                  cwd: SOURCE_DIR,
 223                  dest: SOURCE_DIR,
 224                  extDot: 'last',
 225                  ext: '-rtl.css',
 226                  src: BP_CSS.concat( BP_EXCLUDED_CSS, BP_EXCLUDED_MISC )
 227              }
 228          },
 229          checktextdomain: {
 230              options: {
 231                  correct_domain: false,
 232                  text_domain: 'buddypress',
 233                  keywords: [
 234                      '__:1,2d',
 235                      '_e:1,2d',
 236                      '_x:1,2c,3d',
 237                      '_n:1,2,4d',
 238                      '_ex:1,2c,3d',
 239                      '_nx:1,2,4c,5d',
 240                      'esc_attr__:1,2d',
 241                      'esc_attr_e:1,2d',
 242                      'esc_attr_x:1,2c,3d',
 243                      'esc_html__:1,2d',
 244                      'esc_html_e:1,2d',
 245                      'esc_html_x:1,2c,3d',
 246                      '_n_noop:1,2,3d',
 247                      '_nx_noop:1,2,3c,4d'
 248                  ]
 249              },
 250              files: {
 251                  cwd: SOURCE_DIR,
 252                  src: ['**/*.php'].concat( BP_EXCLUDED_MISC ),
 253                  expand: true
 254              }
 255          },
 256          imagemin: {
 257              core: {
 258                  expand: true,
 259                  cwd: SOURCE_DIR,
 260                  src: ['**/*.{gif,jpg,jpeg,png}'].concat( BP_EXCLUDED_MISC ),
 261                  dest: SOURCE_DIR
 262              }
 263          },
 264          clean: {
 265              all: [ BUILD_DIR ],
 266              bp_rest: [ BUILD_DIR + 'bp-rest/' ],
 267              cli: [
 268                  BUILD_DIR + 'cli/features/',
 269                  BUILD_DIR + 'cli/*.{yml,json,lock,xml,xml.dist,md}',
 270                  BUILD_DIR + 'cli/{.gitignore,.distignore,.editorconfig,.travis.yml}'
 271              ]
 272          },
 273          copy: {
 274              files: {
 275                  files: [
 276                      {
 277                          cwd: SOURCE_DIR,
 278                          dest: BUILD_DIR,
 279                          dot: true,
 280                          expand: true,
 281                          src: ['**', '!**/.{svn,git,cache}/**', '!js/**'].concat( BP_EXCLUDED_MISC )
 282                      },
 283                      {
 284                          dest: BUILD_DIR,
 285                          dot: true,
 286                          expand: true,
 287                          src: ['composer.json']
 288                      }
 289                  ]
 290              },
 291              bp_rest_components: {
 292                  cwd: BUILD_DIR + 'bp-rest/includes/',
 293                  dest: BUILD_DIR,
 294                  dot: true,
 295                  expand: true,
 296                  src: ['**/bp-activity/**', '**/bp-blogs/**', '**/bp-friends/**', '**/bp-groups/**', '**/bp-members/**', '**/bp-messages/**', '**/bp-notifications/**', '**/bp-settings/**', '**/bp-xprofile/**'],
 297                  options: {
 298                      process : function( content ) {
 299                          return content.replace( /\@since 0\.1\.0/g, '@since 5.0.0' );
 300                      }
 301                  }
 302              },
 303              bp_rest_core: {
 304                  cwd: BUILD_DIR + 'bp-rest/includes/',
 305                  dest: BUILD_DIR + 'bp-core/classes/',
 306                  dot: true,
 307                  expand: true,
 308                  flatten: true,
 309                  filter: 'isFile',
 310                  src: ['**', '!functions.php', '!**/bp-activity/**', '!**/bp-blogs/**', '!**/bp-friends/**', '!**/bp-groups/**', '!**/bp-members/**', '!**/bp-messages/**', '!**/bp-notifications/**', '!**/bp-settings/**', '!**/bp-xprofile/**'],
 311                  options: {
 312                      process : function( content ) {
 313                          return content.replace( /\@since 0\.1\.0/g, '@since 5.0.0' );
 314                      }
 315                  }
 316              }
 317          },
 318          uglify: {
 319              core: {
 320                  cwd: BUILD_DIR,
 321                  dest: BUILD_DIR,
 322                  extDot: 'last',
 323                  expand: true,
 324                  ext: '.min.js',
 325                  src: BP_JS.concat( BP_EXCLUDED_JS, BP_EXCLUDED_MISC )
 326              }
 327          },
 328          stylelint: {
 329              css: {
 330                  options: {
 331                      configFile: '.stylelintrc',
 332                      format: 'css'
 333                  },
 334                  expand: true,
 335                  cwd: SOURCE_DIR,
 336                  src: BP_CSS.concat( BP_EXCLUDED_CSS, BP_EXCLUDED_MISC, BP_SCSS_CSS_FILES )
 337              },
 338              scss: {
 339                  options: {
 340                      configFile: '.stylelintrc',
 341                      format: 'scss'
 342                  },
 343                  expand: true,
 344                  cwd: SOURCE_DIR,
 345                  src: [ '**/*.scss' ]
 346              }
 347          },
 348          phplint: {
 349              files: ['src/**/*.php'].concat( BP_EXCLUDED_MISC ),
 350              options: {
 351                  stdout: false,
 352                  stderr: true
 353              }
 354          },
 355          postcss: {
 356              options: {
 357                  map: false,
 358                  processors: [
 359                      autoprefixer({
 360                          browsers: ['extends @wordpress/browserslist-config'],
 361                          cascade: false
 362                      })
 363                  ],
 364                  failOnError: false
 365              },
 366              css: {
 367                  expand: true,
 368                  cwd: SOURCE_DIR,
 369                  dest: SOURCE_DIR,
 370                  src: BP_CSS.concat( BP_EXCLUDED_CSS, BP_EXCLUDED_MISC )
 371              }
 372          },
 373          cssmin: {
 374              minify: {
 375                  cwd: BUILD_DIR,
 376                  dest: BUILD_DIR,
 377                  extDot: 'last',
 378                  expand: true,
 379                  ext: '.min.css',
 380                  src: BP_CSS
 381              }
 382          },
 383          phpunit: {
 384              'default': {
 385                  cmd: './vendor/phpunit/phpunit/phpunit',
 386                  args: ['-c', 'phpunit.xml.dist']
 387              },
 388              'multisite': {
 389                  cmd: './vendor/phpunit/phpunit/phpunit',
 390                  args: ['-c', 'tests/phpunit/multisite.xml']
 391              },
 392              'codecoverage': {
 393                  cmd: './vendor/phpunit/phpunit/phpunit',
 394                  args: ['-c', 'tests/phpunit/codecoverage.xml' ]
 395              }
 396          },
 397          exec: {
 398              bpdefault: {
 399                  command: 'svn export --force https://github.com/buddypress/BP-Default.git/trunk bp-themes/bp-default',
 400                  cwd: BUILD_DIR,
 401                  stdout: false
 402              },
 403              cli: {
 404                  command: 'svn export --force https://github.com/buddypress/wp-cli-buddypress.git/tags/2.0.1 cli',
 405                  cwd: BUILD_DIR,
 406                  stdout: false
 407              },
 408              phpcompat: {
 409                  command: './vendor/bin/phpcs -p --standard=PHPCompatibilityWP --extensions=php --runtime-set testVersion 5.6- src tests',
 410                  stdout: true
 411              },
 412              rest_api: {
 413                  command: 'svn export --force https://github.com/buddypress/BP-REST.git/trunk bp-rest',
 414                  cwd: BUILD_DIR,
 415                  stdout: false
 416              },
 417              makepot: {
 418                  command: 'wp i18n make-pot build build/buddypress.pot --headers=\'{"Project-Id-Version": "BuddyPress", "Report-Msgid-Bugs-To": "https://buddypress.trac.wordpress.org", "Last-Translator": "JOHN JAMES JACOBY <jjj@buddypress.org>", "Language-Team": "ENGLISH <jjj@buddypress.org>"}\'',
 419                  stdout: true
 420              },
 421              blocks_src: {
 422                  command: 'npm run dev',
 423                  cwd: SOURCE_DIR,
 424                  stdout: true
 425              },
 426              blocks_build: {
 427                  command: 'npm run build',
 428                  cwd: SOURCE_DIR,
 429                  stdout: true
 430              }
 431          },
 432          jsvalidate:{
 433              options:{
 434                  globals: {},
 435                  esprimaOptions:{},
 436                  verbose: false
 437              },
 438              build: {
 439                  files: {
 440                      src: [BUILD_DIR + '/**/*.js'].concat( BP_EXCLUDED_JS, BP_EXCLUDED_MISC )
 441                  }
 442              },
 443              src: {
 444                  files: {
 445                      src: [SOURCE_DIR + '/**/*.js'].concat( BP_EXCLUDED_JS, BP_EXCLUDED_MISC )
 446                  }
 447              }
 448          },
 449          patch: {
 450              options: {
 451                  tracUrl: 'buddypress.trac.wordpress.org'
 452              }
 453          },
 454          upload_patch: {
 455              options: {
 456                  tracUrl: 'buddypress.trac.wordpress.org'
 457              }
 458          }
 459      });
 460  
 461      /**
 462       * Register tasks.
 463       */
 464      grunt.registerTask( 'src', ['checkDependencies', 'jsvalidate:src', 'jshint', 'stylelint', 'sass', 'postcss', 'rtlcss'] );
 465      grunt.registerTask( 'style', ['stylelint', 'sass', 'postcss', 'rtlcss'] );
 466      grunt.registerTask( 'makepot', ['exec:makepot'] );
 467      grunt.registerTask( 'commit', ['src', 'checktextdomain', 'imagemin', 'phplint', 'exec:phpcompat'] );
 468      grunt.registerTask( 'commit:blocks', ['commit', 'exec:blocks_src'] );
 469      grunt.registerTask( 'bp_rest', [ 'exec:rest_api', 'copy:bp_rest_components', 'copy:bp_rest_core', 'clean:bp_rest' ] );
 470      grunt.registerTask( 'build', ['commit', 'clean:all', 'copy:files', 'uglify:core', 'jsvalidate:build', 'exec:blocks_build', 'cssmin', 'bp_rest', 'makepot', 'exec:bpdefault', 'exec:cli', 'clean:cli'] );
 471      grunt.registerTask( 'release', ['build'] );
 472  
 473      // Testing tasks.
 474      grunt.registerMultiTask( 'phpunit', 'Runs PHPUnit tests, including the ajax and multisite tests.', function() {
 475          grunt.util.spawn( {
 476              args: this.data.args,
 477              cmd:  this.data.cmd,
 478              opts: { stdio: 'inherit' }
 479          }, this.async() );
 480      });
 481  
 482      grunt.registerTask( 'test', 'Run all unit test tasks.', ['phpunit:default', 'phpunit:multisite'] );
 483  
 484      grunt.registerTask( 'jstest', 'Runs all JavaScript tasks.', [ 'jsvalidate:src', 'jshint' ] );
 485  
 486      // Patch task.
 487      grunt.renameTask( 'patch_wordpress', 'patch' );
 488  
 489      // Default task.
 490      grunt.registerTask( 'default', ['src'] );
 491  };


Generated: Fri Jul 30 01:01:42 2021 Cross-referenced by PHPXref 0.7.1