Skip to:
Content

BuddyPress.org

Ticket #6382: 6382.diff

File 6382.diff, 4.7 KB (added by netweb, 9 years ago)
  • Gruntfile.js

     
    11/* jshint node:true */
    22/* global module */
    33module.exports = function( grunt ) {
    4         var SOURCE_DIR = 'src/',
     4        var path   = require( 'path' ),
     5                SOURCE_DIR = 'src/',
    56                BUILD_DIR = 'build/',
    67
    78                BP_CSS = [
     
    1819                ],
    1920
    2021                BP_EXCLUDED_MISC = [
    21                         '!bp-forums/bbpress/**/*'
     22                        '!bp-forums/bbpress/**/*',
     23                        '!**/*.scss'
    2224                ];
    2325
    2426        require( 'matchdep' ).filterDev( ['grunt-*', '!grunt-legacy-util'] ).forEach( grunt.loadNpmTasks );
     
    7072                        }
    7173                },
    7274                sass: {
    73                         admin: {
     75                        styles: {
    7476                                cwd: SOURCE_DIR,
    7577                                extDot: 'last',
    7678                                expand: true,
     
    9294                                ext: '-rtl.css',
    9395                                src: BP_CSS.concat( BP_EXCLUDED_CSS, BP_EXCLUDED_MISC ),
    9496                                options: { generateExactDuplicates: true }
     97                        },
     98                        dynamic: {
     99                                expand: true,
     100                                cwd: SOURCE_DIR,
     101                                dest: SOURCE_DIR,
     102                                extDot: 'last',
     103                                ext: '-rtl.css',
     104                                src: [],
     105                                options: { generateExactDuplicates: true }
    95106                        }
    96107                },
     108
    97109                checktextdomain: {
    98110                        options: {
    99111                                correct_domain: false,
     
    146158                                dest: SOURCE_DIR
    147159                        }
    148160                },
     161
    149162                clean: {
    150                         all: [ BUILD_DIR ]
     163                        all: [ BUILD_DIR ],
     164                        dynamic: {
     165                                cwd: BUILD_DIR,
     166                                dot: true,
     167                                expand: true,
     168                                src: []
     169                        }
    151170                },
    152171                copy: {
    153172                        files: {
     
    160179                                                src: ['**', '!**/.{svn,git}/**'].concat( BP_EXCLUDED_MISC )
    161180                                        }
    162181                                ]
     182                        },
     183                        dynamic: {
     184                                cwd: SOURCE_DIR,
     185                                dest: BUILD_DIR,
     186                                dot: true,
     187                                expand: true,
     188                                src: []
    163189                        }
    164190                },
    165191                uglify: {
    166192                        core: {
    167                                 cwd: BUILD_DIR,
     193                                cwd: SOURCE_DIR,
    168194                                dest: BUILD_DIR,
    169                                 extDot: 'last',
    170195                                expand: true,
    171196                                ext: '.min.js',
    172197                                src: BP_JS
    173198                        },
     199                        dynamic: {
     200                                cwd: SOURCE_DIR,
     201                                dest: BUILD_DIR,
     202                                expand: true,
     203                                ext: '.min.js',
     204                                src: []
     205                        },
    174206                        options: {
    175207                                banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
    176208                                '<%= grunt.template.today("UTC:yyyy-mm-dd h:MM:ss TT Z") %> - ' +
     
    243275                        options: {
    244276                                tracUrl: 'buddypress.trac.wordpress.org'
    245277                        }
     278                },
     279                watch: {
     280                        all: {
     281                                files: [
     282                                        SOURCE_DIR + '**'
     283                                        // Ignore version control directories.
     284                        //              '!' + SOURCE_DIR + '**/.{svn,git}/**'
     285                                ],
     286                                tasks: [ 'clean:dynamic', 'copy:dynamic' ],
     287                                options: {
     288                                        dot: true,
     289                                        spawn: false
     290                                }
     291                        },
     292                        config: {
     293                                files: 'Gruntfile.js',
     294                                tasks: ['jshint:grunt'],
     295                                options: {
     296                                        spawn: false
     297                                }
     298                        },
     299                        js: {
     300                                files: BP_JS.map( function( path ) {
     301                                        return SOURCE_DIR + path;
     302                                } ),
     303                                tasks: [ 'uglify:dynamic' ],
     304                                options: {
     305                                        spawn: false
     306                                }
     307                        },
     308                        rtl: {
     309                                files: BP_CSS.map( function( path ) {
     310                                        return SOURCE_DIR + path;
     311                                } ),
     312                                tasks: [ 'cssjanus:dynamic' ],
     313                                options: {
     314                                        spawn: false
     315                                }
     316                        },
     317                        styles: {
     318                                files: [ SOURCE_DIR + 'bp-templates/bp-legacy/css/*.scss' ],
     319                                tasks: [ 'sass:styles' ]
     320                        }
    246321                }
    247322        });
    248323
     324        // Styles task for Twenty* themes.
     325        grunt.registerTask( 'styles', [ 'sass:styles' ] );
    249326
    250327        /**
    251328         * Register tasks.
     
    252329         */
    253330        grunt.registerTask( 'src',     ['jsvalidate:src', 'jshint', 'scsslint', 'sass', 'cssjanus'] );
    254331        grunt.registerTask( 'commit',  ['src', 'checktextdomain', 'imagemin'] );
    255         grunt.registerTask( 'build',   ['commit', 'clean:all', 'copy:files', 'uglify', 'jsvalidate:build', 'cssmin', 'makepot', 'exec:bpdefault'] );
     332        grunt.registerTask( 'build',   ['commit', 'clean:all', 'copy:files', 'uglify:core', 'jsvalidate:build', 'cssmin', 'makepot', 'exec:bpdefault'] );
    256333        grunt.registerTask( 'release', ['build', 'exec:bbpress'] );
    257334
    258335        // Testing tasks.
     
    276353
    277354        // Default task.
    278355        grunt.registerTask( 'default', ['src'] );
     356
     357
     358        /**
     359         * Add a listener to the watch task.
     360         *
     361         * On `watch:all`, automatically updates the `copy:dynamic` and `clean:dynamic` configurations so that only the changed files are updated.
     362         * On `watch:js`, automatically updates the `cssjanus:dynamic` configuration.
     363         * On `watch:rtl`, automatically updates the `cssjanus:dynamic` configuration.
     364         * On `watch:styles`, automatically updates the `cssjanus:dynamic` configuration.
     365         */
     366        grunt.event.on( 'watch', function( action, filepath, target ) {
     367                if ( target !== 'all' && target !== 'rtl' ) {
     368                        return;
     369                }
     370
     371                var relativePath = path.relative( SOURCE_DIR, filepath ),
     372                cleanSrc = ( action === 'deleted' ) ? [ relativePath ] : [],
     373                copySrc  = ( action === 'deleted' ) ? [] : [ relativePath ];
     374
     375                grunt.config( ['clean', 'dynamic', 'src'], cleanSrc );
     376                grunt.config( ['copy', 'dynamic', 'src'], copySrc );
     377                grunt.config( ['cssjanus', 'dynamic', 'src'], copySrc );
     378                grunt.config( [ 'uglify', 'dynamic', 'src' ], copySrc );
     379        });
    279380};