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


Generated: Sat Dec 21 01:00:58 2024 Cross-referenced by PHPXref 0.7.1