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


Generated: Thu Dec 3 01:01:38 2020 Cross-referenced by PHPXref 0.7.1