Make WordPress Core

source: tags/3.7.40/Gruntfile.js

Last change on this file was 50224, checked in by desrosj, 5 years ago

Build/Test Tools: Support NodeJS 14.x in the 3.7 branch.

This updates the 3.7 branch to support the latest LTS version of NodeJS (currently 14.x), allowing the same version to be used across all WordPress branches that receive security updates as a courtesy.

Because older branches use (really) old versions of NodeJS, the local Docker environment cannot be backported since the needed dependencies will not run on these older versions (see #48301). This also blocks the ability to move automated testing over to GitHub Actions (see #50401).

This change also introduces a packager-lock.json file to the branch.

In addition to backporting the package updates that happened after branching 3.7, dependencies that were removed in future releases have also been updated to their latest versions.

Props desrosj, dd32, netweb, jorbin.
Merges [27053,27299,27721,27848,28796,29270,30060,30062-30063,30066,31557,31650,32356,32988,33726,35513,35521,35538,35540-35541,36861-36865,37019-37020,37212,37612,38111,39113,39115-39117,39478,42460-42461,42887,42989,43320,43323,43977,44219,45446,45765,46408-46409,47867,47872,48705,49636,49933,49939,50185] to the 3.7 branch.
See #52341.

File size: 6.3 KB
Line 
1/*global module:false*/
2module.exports = function(grunt) {
3        var path = require('path');
4        var SOURCE_DIR = 'src/';
5        var BUILD_DIR = 'build/';
6
7        // Load tasks.
8        require('matchdep').filterDev(['grunt-*', '!grunt-legacy-util']).forEach( grunt.loadNpmTasks );
9        // Load legacy utils
10        grunt.util = require('grunt-legacy-util');
11
12        // Project configuration.
13        grunt.initConfig({
14                clean: {
15                        all: [BUILD_DIR],
16                        dynamic: {
17                                dot: true,
18                                expand: true,
19                                cwd: BUILD_DIR,
20                                src: []
21                        },
22                        tinymce: {
23                                src: [
24                                        '<%= concat.tinymce.dest %>',
25                                        BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce-schema.min.js',
26                                        BUILD_DIR + 'wp-includes/js/tinymce/mark_loaded.js'
27                                ]
28                        }
29                },
30                copy: {
31                        files: {
32                                files: [
33                                        {
34                                                dot: true,
35                                                expand: true,
36                                                cwd: SOURCE_DIR,
37                                                src: [
38                                                        '**',
39                                                        '!**/.{svn,git}/**', // Ignore version control directories.
40                                                        '!wp-includes/version.php' // Exclude version.php
41                                                ],
42                                                dest: BUILD_DIR
43                                        },
44                                        {
45                                                src: 'wp-config-sample.php',
46                                                dest: BUILD_DIR
47                                        }
48                                ]
49                        },
50                        version: {
51                                options: {
52                                        processContent: function( src, filepath ) {
53                                                return src.replace( /^(\$wp_version.+?)-src';/m, "$1';" );
54                                        }
55                                },
56                                files: [
57                                        {
58                                                src: SOURCE_DIR + 'wp-includes/version.php',
59                                                dest: BUILD_DIR + 'wp-includes/version.php'
60                                        }
61                                ]
62                        },
63                        dynamic: {
64                                dot: true,
65                                expand: true,
66                                cwd: SOURCE_DIR,
67                                dest: BUILD_DIR,
68                                src: []
69                        },
70                        qunit: {
71                                src: 'tests/qunit/index.html',
72                                dest: 'tests/qunit/compiled.html',
73                                options: {
74                                        processContent: function( src ) {
75                                                return src.replace( /([^\.])*\.\.\/src/ig , '/../build' );
76                                        }
77                                }
78                        }
79                },
80                cssmin: {
81                        core: {
82                                expand: true,
83                                cwd: SOURCE_DIR,
84                                dest: BUILD_DIR,
85                                ext: '.min.css',
86                                src: [
87                                        'wp-admin/css/*.css',
88                                        'wp-includes/css/*.css',
89                                        // Exceptions
90                                        '!wp-admin/css/farbtastic.css'
91                                ]
92                        }
93                },
94                qunit: {
95                        files: ['tests/qunit/**/*.html']
96                },
97                phpunit: {
98                        'default': {
99                                cmd: 'phpunit',
100                                args: ['-c', 'phpunit.xml.dist']
101                        },
102                        ajax: {
103                                cmd: 'phpunit',
104                                args: ['-c', 'phpunit.xml.dist', '--group', 'ajax']
105                        },
106                        multisite: {
107                                cmd: 'phpunit',
108                                args: ['-c', 'tests/phpunit/multisite.xml']
109                        }
110                },
111                uglify: {
112                        options: {
113                                '!ie8': false
114                        },
115                        core: {
116                                expand: true,
117                                cwd: SOURCE_DIR,
118                                dest: BUILD_DIR,
119                                ext: '.min.js',
120                                src: [
121                                        'wp-admin/js/*.js',
122                                        'wp-includes/js/*.js',
123                                        'wp-includes/js/plupload/handlers.js',
124                                        'wp-includes/js/plupload/wp-plupload.js',
125                                        'wp-includes/js/tinymce/plugins/wp*/js/*.js',
126                                        'wp-includes/js/tinymce/wp-tinymce-schema.js',
127                                        // Exceptions
128                                        '!wp-admin/js/custom-header.js', // Why? We should minify this.
129                                        '!wp-admin/js/farbtastic.js',
130                                        '!wp-admin/js/iris.min.js',
131                                        '!wp-includes/js/backbone.min.js',
132                                        '!wp-includes/js/swfobject.js',
133                                        '!wp-includes/js/underscore.min.js',
134                                        '!wp-includes/js/zxcvbn.min.js',
135                                        // Hard-coded in editimage.html
136                                        '!wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.js'
137                                ]
138                        },
139                        tinymce: {
140                                expand: true,
141                                cwd: SOURCE_DIR,
142                                dest: BUILD_DIR,
143                                src: [
144                                        'wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js',
145                                        'wp-includes/js/tinymce/plugins/wp*/editor_plugin_src.js',
146                                        'wp-includes/js/tinymce/mark_loaded_src.js'
147                                ],
148                                // TinyMCE plugins use a nonstandard naming scheme: plugin files are named
149                                // `editor_plugin_src.js`, and are compressed into `editor_plugin.js`.
150                                rename: function(destBase, destPath) {
151                                        destPath = destPath.replace(/_src.js$/, '.js');
152                                        return path.join(destBase || '', destPath);
153                                }
154                        }
155                },
156                concat: {
157                        tinymce: {
158                                options: {
159                                        separator: '\n',
160                                        process: function( src, filepath ) {
161                                                return '// Source: ' + filepath.replace( BUILD_DIR, '' ) + '\n' + src;
162                                        }
163                                },
164                                src: [
165                                        BUILD_DIR + 'wp-includes/js/tinymce/tiny_mce.js',
166                                        BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce-schema.min.js',
167                                        BUILD_DIR + 'wp-includes/js/tinymce/themes/advanced/editor_template.js',
168                                        BUILD_DIR + 'wp-includes/js/tinymce/plugins/*/editor_plugin.js',
169                                        BUILD_DIR + 'wp-includes/js/tinymce/mark_loaded.js'
170                                ],
171                                dest: BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce.js'
172                        }
173                },
174                compress: {
175                        tinymce: {
176                                options: {
177                                        mode: 'gzip',
178                                        level: 9
179                                },
180                                src: '<%= concat.tinymce.dest %>',
181                                dest: BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce.js.gz'
182                        }
183                },
184                watch: {
185                        all: {
186                                files: [
187                                        SOURCE_DIR + '**',
188                                        // Ignore version control directories.
189                                        '!' + SOURCE_DIR + '**/.{svn,git}/**'
190                                ],
191                                tasks: ['clean:dynamic', 'copy:dynamic'],
192                                options: {
193                                        dot: true,
194                                        spawn: false,
195                                        interval: 2000
196                                }
197                        },
198                        test: {
199                                files: ['tests/qunit/**'],
200                                tasks: ['qunit']
201                        }
202                }
203        });
204
205        // Register tasks.
206
207        // Copy task.
208        grunt.registerTask('copy:all', ['copy:files', 'copy:version']);
209       
210        // Build task.
211        grunt.registerTask('build', ['clean:all', 'copy:all', 'cssmin:core', 'uglify:core',
212                'uglify:tinymce', 'concat:tinymce', 'compress:tinymce', 'clean:tinymce']);
213
214        // Testing tasks.
215        grunt.registerMultiTask('phpunit', 'Runs PHPUnit tests, including the ajax and multisite tests.', function() {
216                grunt.util.spawn({
217                        cmd: this.data.cmd,
218                        args: this.data.args,
219                        opts: {stdio: 'inherit'}
220                }, this.async());
221        });
222
223        grunt.registerTask('qunit:compiled', 'Runs QUnit tests on compiled as well as uncompiled scripts.',
224                ['build', 'copy:qunit', 'qunit']);
225
226        grunt.registerTask('test', 'Runs all QUnit and PHPUnit tasks.', ['qunit:compiled', 'phpunit']);
227
228        // Travis CI tasks.
229        grunt.registerTask('travis:phpunit', 'Runs PHPUnit Travis CI tasks.', 'phpunit');
230
231        // Patch task.
232        grunt.renameTask('patch_wordpress', 'patch');
233
234        // Default task.
235        grunt.registerTask('default', ['build']);
236
237        // Add a listener to the watch task.
238        //
239        // On `watch:all`, automatically updates the `copy:dynamic` and `clean:dynamic`
240        // configurations so that only the changed files are updated.
241        grunt.event.on('watch', function( action, filepath, target ) {
242                if ( target != 'all' )
243                        return;
244
245                var relativePath = path.relative( SOURCE_DIR, filepath );
246                var cleanSrc = ( action == 'deleted' ) ? [relativePath] : [];
247                var copySrc = ( action == 'deleted' ) ? [] : [relativePath];
248
249                grunt.config(['clean', 'dynamic', 'src'], cleanSrc);
250                grunt.config(['copy', 'dynamic', 'src'], copySrc);
251        });
252};
Note: See TracBrowser for help on using the repository browser.