[ 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          },
 195          copy: {
 196              files: {
 197                  files: [
 198                      {
 199                          cwd: SOURCE_DIR,
 200                          dest: BUILD_DIR,
 201                          dot: true,
 202                          expand: true,
 203                          src: ['**', '!**/.{svn,git}/**'].concat( BP_EXCLUDED_MISC )
 204                      },
 205                      {
 206                          dest: BUILD_DIR,
 207                          dot: true,
 208                          expand: true,
 209                          src: ['composer.json']
 210                      }
 211                  ]
 212              }
 213          },
 214          uglify: {
 215              core: {
 216                  cwd: BUILD_DIR,
 217                  dest: BUILD_DIR,
 218                  extDot: 'last',
 219                  expand: true,
 220                  ext: '.min.js',
 221                  src: BP_JS
 222              }
 223          },
 224          stylelint: {
 225              css: {
 226                  options: {
 227                      config: stylelintConfigCss,
 228                      format: 'css'
 229                  },
 230                  expand: true,
 231                  cwd: SOURCE_DIR,
 232                  src: BP_CSS.concat( BP_EXCLUDED_CSS, BP_EXCLUDED_MISC, BP_SCSS_CSS_FILES )
 233              },
 234              scss: {
 235                  options: {
 236                      config: stylelintConfigScss,
 237                      format: 'scss'
 238                  },
 239                  expand: true,
 240                  cwd: SOURCE_DIR,
 241                  src: [ '**/*.scss' ]
 242              }
 243          },
 244          postcss: {
 245              options: {
 246                  map: false,
 247                  processors: [
 248                      autoprefixer({
 249                          browsers: ['extends @wordpress/browserslist-config'],
 250                          cascade: false
 251                      })
 252                  ],
 253                  failOnError: false
 254              },
 255              css: {
 256                  expand: true,
 257                  cwd: SOURCE_DIR,
 258                  dest: SOURCE_DIR,
 259                  src: BP_CSS.concat( BP_EXCLUDED_CSS, BP_EXCLUDED_MISC )
 260              }
 261          },
 262          cssmin: {
 263              minify: {
 264                  cwd: BUILD_DIR,
 265                  dest: BUILD_DIR,
 266                  extDot: 'last',
 267                  expand: true,
 268                  ext: '.min.css',
 269                  src: BP_CSS
 270              }
 271          },
 272          phpunit: {
 273              'default': {
 274                  cmd: 'phpunit',
 275                  args: ['-c', 'phpunit.xml.dist']
 276              },
 277              'multisite': {
 278                  cmd: 'phpunit',
 279                  args: ['-c', 'tests/phpunit/multisite.xml']
 280              },
 281              'codecoverage': {
 282                  cmd: 'phpunit',
 283                  args: ['-c', 'tests/phpunit/codecoverage.xml' ]
 284              }
 285          },
 286          exec: {
 287              bpdefault: {
 288                  command: 'svn export --force https://github.com/buddypress/BP-Default.git/trunk bp-themes/bp-default',
 289                  cwd: BUILD_DIR,
 290                  stdout: false
 291              },
 292              cli: {
 293                  command: 'svn export --force https://github.com/buddypress/wp-cli-buddypress.git/tags/1.8 cli',
 294                  cwd: BUILD_DIR,
 295                  stdout: false
 296              },
 297              phpcompat: {
 298                  command: './vendor/bin/phpcs -p --standard=PHPCompatibilityWP --extensions=php --runtime-set testVersion 5.3- src tests',
 299                  stdout: true
 300              }
 301          },
 302          jsvalidate:{
 303              options:{
 304                  globals: {},
 305                  esprimaOptions:{},
 306                  verbose: false
 307              },
 308              build: {
 309                  files: {
 310                      src: [BUILD_DIR + '/**/*.js']
 311                  }
 312              },
 313              src: {
 314                  files: {
 315                      src: [SOURCE_DIR + '/**/*.js'].concat( BP_EXCLUDED_MISC )
 316                  }
 317              }
 318          },
 319          patch: {
 320              options: {
 321                  tracUrl: 'buddypress.trac.wordpress.org'
 322              }
 323          },
 324          upload_patch: {
 325              options: {
 326                  tracUrl: 'buddypress.trac.wordpress.org'
 327              }
 328          }
 329      });
 330  
 331  
 332      /**
 333       * Register tasks.
 334       */
 335      grunt.registerTask( 'src',     ['checkDependencies', 'jsvalidate:src', 'jshint', 'stylelint', 'sass', 'postcss', 'rtlcss'] );
 336      grunt.registerTask( 'commit',  ['src', 'checktextdomain', 'imagemin','exec:phpcompat'] );
 337      grunt.registerTask( 'build',   ['commit', 'clean:all', 'copy:files', 'uglify', 'jsvalidate:build', 'cssmin', 'makepot', 'exec:bpdefault', 'exec:cli'] );
 338      grunt.registerTask( 'release', ['build'] );
 339  
 340      // Testing tasks.
 341      grunt.registerMultiTask( 'phpunit', 'Runs PHPUnit tests, including the ajax and multisite tests.', function() {
 342          grunt.util.spawn( {
 343              args: this.data.args,
 344              cmd:  this.data.cmd,
 345              opts: { stdio: 'inherit' }
 346          }, this.async() );
 347      });
 348  
 349      grunt.registerTask( 'test', 'Run all unit test tasks.', ['phpunit:default', 'phpunit:multisite'] );
 350  
 351      grunt.registerTask( 'jstest', 'Runs all JavaScript tasks.', [ 'jsvalidate:src', 'jshint' ] );
 352  
 353      // Travis CI Tasks.
 354      grunt.registerTask( 'travis:grunt', 'Runs Grunt build task.', [ 'build' ]);
 355      grunt.registerTask( 'travis:phpunit', ['jsvalidate:src', 'jshint', 'checktextdomain', 'test'] );
 356      grunt.registerTask( 'travis:codecoverage', 'Runs PHPUnit tasks with code-coverage generation.', ['phpunit:codecoverage'] );
 357      grunt.registerTask( 'travis:phpcompat', 'Runs PHP compatibility scan.', ['exec:phpcompat'] );
 358  
 359      // Patch task.
 360      grunt.renameTask( 'patch_wordpress', 'patch' );
 361  
 362      // Default task.
 363      grunt.registerTask( 'default', ['src'] );
 364  };


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