[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/ -> Gruntfile.js (source)

   1  /* jshint node:true */
   2  /* global module */
   3  module.exports = function( grunt ) {
   4      var path = require( 'path' ),
   5          SOURCE_DIR = 'src/',
   6          BUILD_DIR = 'build/',
   7  
   8          BBP_RTL_CSS = [
   9              'includes/admin/assets/css/admin-rtl.css',
  10              'includes/admin/styles/*/colors-rtl.css',
  11              'templates/default/css/bbpress-rtl.css'
  12          ],
  13  
  14          BBP_LTR_CSS = [
  15              'includes/admin/assets/css/admin.css',
  16              'includes/admin/styles/*/colors.css',
  17              'templates/default/css/bbpress.css'
  18          ],
  19  
  20          BBP_JS = [
  21              'includes/admin/assets/js/*.js',
  22              'templates/default/js/*.js'
  23          ],
  24  
  25          BBP_EXCLUDED_FILES = [
  26  
  27              // Ignore these
  28              '!**/.{svn,git}/**',
  29              '!.editorconfig',
  30              '!.gitignore',
  31              '!.jshintrc',
  32              '!.travis.yml',
  33              '!build/**',
  34              '!Gruntfile.js',
  35              '!node_modules/**',
  36              '!npm-debug.log',
  37              '!package.json',
  38  
  39              // bbPress SCSS CSS source files
  40              '!**/*.scss',
  41  
  42              // bbPress PHPUnit tests
  43              '!tests/**',
  44              '!phpunit.xml',
  45              '!phpunit.xml.dist'
  46          ],
  47  
  48          // PostCSS
  49          autoprefixer = require('autoprefixer'),
  50          configCss    = require('stylelint-config-wordpress/index.js'),
  51          configScss   = require('stylelint-config-wordpress/scss.js');
  52  
  53      // Load tasks.
  54      require( 'matchdep' ).filterDev([ 'grunt-*', '!grunt-legacy-util' ]).forEach( grunt.loadNpmTasks );
  55  
  56      // Load legacy utils
  57      grunt.util = require( 'grunt-legacy-util' );
  58  
  59      // Project configuration.
  60      grunt.initConfig({
  61          pkg: grunt.file.readJSON( 'package.json' ),
  62          checktextdomain: {
  63              options: {
  64                  text_domain: 'bbpress',
  65                  correct_domain: false,
  66                  keywords: [
  67                      '__:1,2d',
  68                      '_e:1,2d',
  69                      '_x:1,2c,3d',
  70                      '_n:1,2,4d',
  71                      '_ex:1,2c,3d',
  72                      '_nx:1,2,4c,5d',
  73                      'esc_attr__:1,2d',
  74                      'esc_attr_e:1,2d',
  75                      'esc_attr_x:1,2c,3d',
  76                      'esc_html__:1,2d',
  77                      'esc_html_e:1,2d',
  78                      'esc_html_x:1,2c,3d',
  79                      '_n_noop:1,2,3d',
  80                      '_nx_noop:1,2,3c,4d'
  81                  ]
  82              },
  83              files: {
  84                  src: SOURCE_DIR + '**/*.php',
  85                  expand: true
  86              }
  87          },
  88          clean: {
  89              all: [ BUILD_DIR ],
  90              dynamic: {
  91                  cwd: BUILD_DIR,
  92                  dot: true,
  93                  expand: true,
  94                  src: []
  95              }
  96          },
  97          checkDependencies: {
  98              options: {
  99                  packageManager: 'npm'
 100              },
 101              src: {}
 102          },
 103          copy: {
 104              files: {
 105                  files: [
 106                      {
 107                          cwd: SOURCE_DIR,
 108                          dest: BUILD_DIR,
 109                          dot: true,
 110                          expand: true,
 111                          src: [ '!**/.{svn,git}/**', '**', [ BBP_EXCLUDED_FILES ] ]
 112                      }
 113                  ]
 114              },
 115              dynamic: {
 116                  cwd: SOURCE_DIR,
 117                  dest: BUILD_DIR,
 118                  dot: true,
 119                  expand: true,
 120                  src: []
 121              }
 122          },
 123          cssmin: {
 124              ltr: {
 125                  cwd: BUILD_DIR,
 126                  dest: BUILD_DIR,
 127                  expand: true,
 128                  ext: '.min.css',
 129                  src: BBP_LTR_CSS
 130              },
 131              rtl: {
 132                  cwd: BUILD_DIR,
 133                  dest: BUILD_DIR,
 134                  expand: true,
 135                  ext: '.min.css',
 136                  src: BBP_RTL_CSS
 137              }
 138          },
 139          jshint: {
 140              options: grunt.file.readJSON( '.jshintrc' ),
 141              grunt: {
 142                  src: [ 'Gruntfile.js' ]
 143              },
 144              core: {
 145                  expand: true,
 146                  cwd: SOURCE_DIR,
 147                  src: BBP_JS,
 148  
 149                  /**
 150                   * Limit JSHint's run to a single specified file:
 151                   *
 152                   * grunt jshint:core --file=filename.js
 153                   *
 154                   * Optionally, include the file path:
 155                   *
 156                   * grunt jshint:core --file=path/to/filename.js
 157                   *
 158                   * @param {String} filepath
 159                   * @returns {Bool}
 160                   */
 161                  filter: function( filepath ) {
 162                      var index, file = grunt.option( 'file' );
 163  
 164                      // Don't filter when no target file is specified
 165                      if ( ! file ) {
 166                          return true;
 167                      }
 168  
 169                      // Normalise filepath for Windows
 170                      filepath = filepath.replace( /\\/g, '/' );
 171                      index = filepath.lastIndexOf( '/' + file );
 172  
 173                      // Match only the filename passed from cli
 174                      if ( filepath === file || ( -1 !== index && index === filepath.length - ( file.length + 1 ) ) ) {
 175                          return true;
 176                      }
 177  
 178                      return false;
 179                  }
 180              }
 181          },
 182          jsvalidate:{
 183              options:{
 184                  globals: {},
 185                  esprimaOptions:{},
 186                  verbose: false
 187              },
 188              build: {
 189                  files: {
 190                      src: BUILD_DIR + '/**/*.js'
 191                  }
 192              },
 193              src: {
 194                  files: {
 195                      src: SOURCE_DIR + '/**/*.js'
 196                  }
 197              }
 198          },
 199          makepot: {
 200              target: {
 201                  options: {
 202                      cwd: BUILD_DIR,
 203                      domainPath: '.',
 204                      mainFile: 'bbpress.php',
 205                      potFilename: 'bbpress.pot',
 206                      processPot: function( pot ) {
 207                          pot.headers['report-msgid-bugs-to'] = 'https://bbpress.trac.wordpress.org';
 208                          pot.headers['last-translator'] = 'JOHN JAMES JACOBY <jjj@bbpress.org>';
 209                          pot.headers['language-team'] = 'ENGLISH <jjj@bbpress.org>';
 210                          return pot;
 211                      },
 212                      type: 'wp-plugin'
 213                  }
 214              }
 215          },
 216          patch: {
 217              options: {
 218                  tracUrl: 'bbpress.trac.wordpress.org'
 219              }
 220          },
 221          upload_patch: {
 222              options: {
 223                  tracUrl: 'bbpress.trac.wordpress.org'
 224              }
 225          },
 226          phpunit: {
 227              'default': {
 228                  cmd: 'phpunit',
 229                  args: [ '-c', 'phpunit.xml.dist' ]
 230              },
 231              buddypress: {
 232                  cmd: 'phpunit',
 233                  args: [ '-c', 'tests/phpunit/buddypress.xml' ]
 234              },
 235              multisite: {
 236                  cmd: 'phpunit',
 237                  args: [ '-c', 'tests/phpunit/multisite.xml' ]
 238              }
 239          },
 240          postcss: {
 241              options: {
 242                  map: false,
 243                  processors: [
 244                      autoprefixer({
 245                          browsers: ['extends @wordpress/browserslist-config'],
 246                          cascade: false
 247                      })
 248                  ],
 249                  failOnError: false
 250              },
 251              core: {
 252                  expand: true,
 253                  cwd: SOURCE_DIR,
 254                  dest: SOURCE_DIR,
 255                  src: [ [ BBP_LTR_CSS ], 'includes/admin/styles/*/colors.scss' ]
 256              },
 257              colors: {
 258                  expand: true,
 259                  cwd: BUILD_DIR,
 260                  dest: BUILD_DIR,
 261                  src: [ 'includes/admin/styles/*/colors.css' ]
 262              }
 263          },
 264          rtlcss: {
 265              options: {
 266                  opts: {
 267                      processUrls: false,
 268                      autoRename: false,
 269                      clean: true
 270                  },
 271                  saveUnmodified: false
 272              },
 273              core: {
 274                  expand: true,
 275                  cwd: BUILD_DIR,
 276                  dest: BUILD_DIR,
 277                  ext: '-rtl.css',
 278                  src: BBP_LTR_CSS
 279              },
 280              dynamic: {
 281                  expand: true,
 282                  cwd: BUILD_DIR,
 283                  dest: BUILD_DIR,
 284                  ext: '-rtl.css',
 285                  src: []
 286              }
 287          },
 288          sass: {
 289              colors: {
 290                  expand: true,
 291                  cwd: SOURCE_DIR,
 292                  dest: BUILD_DIR,
 293                  ext: '.css',
 294                  src: [ 'includes/admin/styles/*/colors.scss' ],
 295                  options: {
 296                      implementation: require('node-sass'),
 297                      outputStyle: 'expanded'
 298                  }
 299              }
 300          },
 301          stylelint: {
 302              css: {
 303                  options: {
 304                      config: configCss,
 305                      format: 'css'
 306                  },
 307                  expand: true,
 308                  cwd: SOURCE_DIR,
 309                  src: BBP_LTR_CSS
 310              },
 311              scss: {
 312                  options: {
 313                      config: configScss,
 314                      format: 'scss'
 315                  },
 316                  expand: true,
 317                  cwd: SOURCE_DIR,
 318                  src: [ 'includes/admin/styles/*/colors.scss' ]
 319              }
 320          },
 321          uglify: {
 322              core: {
 323                  cwd: SOURCE_DIR,
 324                  dest: BUILD_DIR,
 325                  expand: true,
 326                  ext: '.min.js',
 327                  src: BBP_JS
 328              },
 329              dynamic: {
 330                  cwd: SOURCE_DIR,
 331                  dest: BUILD_DIR,
 332                  expand: true,
 333                  ext: '.min.js',
 334                  src: []
 335              },
 336              options: {
 337                  banner: '/*! This file is automatically generated. */\n'
 338              }
 339          },
 340          watch: {
 341              all: {
 342                  files: [
 343                      SOURCE_DIR + '**',
 344  
 345                      // Ignore version control directories.
 346                      '!' + SOURCE_DIR + '**/.{svn,git}/**'
 347                  ],
 348                  tasks: [ 'clean:dynamic', 'copy:dynamic' ],
 349                  options: {
 350                      dot: true,
 351                      interval: 2000,
 352                      spawn: false
 353                  }
 354              },
 355              colors: {
 356                  files: [ SOURCE_DIR + 'includes/admin/styles/*/colors.scss' ],
 357                  tasks: [ 'sass:colors', 'rtlcss:core', 'cssmin:ltr', 'cssmin:rtl' ]
 358              },
 359              config: {
 360                  files: 'Gruntfile.js'
 361              },
 362              js: {
 363                  files: BBP_JS.map( function( path ) {
 364                      return SOURCE_DIR + path;
 365                  } ),
 366                  tasks: [ 'uglify:dynamic' ],
 367                  options: {
 368                      interval: 2000,
 369                      spawn: false
 370                  }
 371              },
 372              rtl: {
 373                  files: BBP_LTR_CSS.map( function( path ) {
 374                      return SOURCE_DIR + path;
 375                  } ),
 376                  tasks: [ 'rtlcss:dynamic', 'cssmin:ltr', 'cssmin:rtl' ],
 377                  options: {
 378                      interval: 2000,
 379                      spawn: false
 380                  }
 381              }
 382          }
 383      });
 384  
 385      // Register tasks.
 386  
 387      // Color schemes task.
 388      grunt.registerTask( 'colors', [ 'sass:colors', 'postcss:colors' ] );
 389  
 390      // Build tasks.
 391      grunt.registerTask( 'src',     [ 'checkDependencies', 'jsvalidate:src', 'jshint', 'stylelint' ] );
 392      grunt.registerTask( 'commit',  [ 'src', 'checktextdomain', 'postcss:core' ] );
 393      grunt.registerTask( 'build',   [ 'commit', 'clean:all', 'copy:files', 'colors', 'rtlcss:core', 'cssmin:ltr', 'cssmin:rtl', 'uglify:core', 'jsvalidate:build', 'makepot' ] );
 394      grunt.registerTask( 'release', [ 'build' ] );
 395  
 396      // PHPUnit test task.
 397      grunt.registerMultiTask( 'phpunit', 'Runs PHPUnit tests, including the BuddyPress and multisite tests.', function() {
 398          grunt.util.spawn( {
 399              cmd:  this.data.cmd,
 400              args: this.data.args,
 401              opts: { stdio: 'inherit' }
 402          }, this.async() );
 403      } );
 404  
 405      // PHPUnit test task.
 406      grunt.registerTask( 'test:buddypress', 'Run the BuddyPress PHPUnit test tasks.', [ 'phpunit:buddypress' ] );
 407      grunt.registerTask( 'test:wordpress', 'Run the single and multisite WordPress PHPUnit test tasks.', [ 'phpunit:default', 'phpunit:multisite' ] );
 408  
 409  
 410  
 411  
 412      // JavaScript test task.
 413      grunt.registerTask( 'jstest', 'Runs all JavaScript tasks.', [ 'jsvalidate:src', 'jshint' ] );
 414  
 415      // Travis CI Task
 416      grunt.registerTask( 'travis', [ 'jsvalidate:src', 'jshint', 'checktextdomain', 'test:wordpress' ] );
 417  
 418      // Patch task.
 419      grunt.renameTask( 'patch_wordpress', 'patch' );
 420  
 421      // Default task.
 422      grunt.registerTask( 'default', [ 'src' ] );
 423  
 424      // Add a listener to the watch task.
 425      //
 426      // On `watch:all`, automatically updates the `copy:dynamic` and `clean:dynamic` configurations so that only the changed files are updated.
 427      // On `watch:rtl`, automatically updates the `rtlcss:dynamic` configuration.
 428      grunt.event.on( 'watch', function( action, filepath, target ) {
 429          if ( target !== 'all' && target !== 'rtl' ) {
 430              return;
 431          }
 432  
 433          var relativePath = path.relative( SOURCE_DIR, filepath ),
 434          cleanSrc = ( action === 'deleted' ) ? [ relativePath ] : [],
 435          copySrc  = ( action === 'deleted' ) ? [] : [ relativePath ];
 436  
 437          grunt.config( [ 'clean', 'dynamic', 'src' ], cleanSrc );
 438          grunt.config( [ 'copy', 'dynamic', 'src' ], copySrc );
 439          grunt.config( [ 'rtlcss', 'dynamic', 'src' ], copySrc );
 440          grunt.config( [ 'uglify', 'dynamic', 'src' ], copySrc );
 441      });
 442  };


Generated: Sat Dec 15 01:01:40 2018 Cross-referenced by PHPXref 0.7.1