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


Generated: Tue May 18 01:01:42 2021 Cross-referenced by PHPXref 0.7.1