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


Generated: Wed Oct 23 01:01:50 2019 Cross-referenced by PHPXref 0.7.1