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


Generated: Fri Nov 15 01:01:26 2019 Cross-referenced by PHPXref 0.7.1