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


Generated: Thu Sep 24 01:03:44 2020 Cross-referenced by PHPXref 0.7.1