|
2 | 2 |
|
3 | 3 | module.exports = function( grunt ) {
|
4 | 4 |
|
5 |
| -var |
6 |
| - glob = require( "glob" ), |
7 |
| - |
8 |
| - // files |
9 |
| - coreFiles = [ |
10 |
| - "core.js", |
11 |
| - "widget.js", |
12 |
| - "widgets/mouse.js", |
13 |
| - "widgets/draggable.js", |
14 |
| - "widgets/droppable.js", |
15 |
| - "widgets/resizable.js", |
16 |
| - "widgets/selectable.js", |
17 |
| - "widgets/sortable.js", |
18 |
| - "effect.js" |
19 |
| - ], |
20 |
| - |
21 |
| - uiFiles = coreFiles.map( function( file ) { |
22 |
| - return "ui/" + file; |
23 |
| - } ).concat( expandFiles( "ui/**/*.js" ).filter( function( file ) { |
24 |
| - return coreFiles.indexOf( file.substring( 3 ) ) === -1; |
25 |
| - } ) ), |
26 |
| - |
27 |
| - allI18nFiles = expandFiles( "ui/i18n/*.js" ), |
28 |
| - |
29 |
| - cssFiles = [ |
30 |
| - "core", |
31 |
| - "accordion", |
32 |
| - "autocomplete", |
33 |
| - "button", |
34 |
| - "checkboxradio", |
35 |
| - "controlgroup", |
36 |
| - "datepicker", |
37 |
| - "dialog", |
38 |
| - "draggable", |
39 |
| - "menu", |
40 |
| - "progressbar", |
41 |
| - "resizable", |
42 |
| - "selectable", |
43 |
| - "selectmenu", |
44 |
| - "sortable", |
45 |
| - "slider", |
46 |
| - "spinner", |
47 |
| - "tabs", |
48 |
| - "tooltip", |
49 |
| - "theme" |
50 |
| - ].map( function( component ) { |
51 |
| - return "themes/base/" + component + ".css"; |
52 |
| - } ), |
53 |
| - |
54 |
| - // minified files |
55 |
| - minify = { |
| 5 | +// files |
| 6 | +const coreFiles = [ |
| 7 | + "core.js", |
| 8 | + "widget.js", |
| 9 | + "widgets/mouse.js", |
| 10 | + "widgets/draggable.js", |
| 11 | + "widgets/droppable.js", |
| 12 | + "widgets/resizable.js", |
| 13 | + "widgets/selectable.js", |
| 14 | + "widgets/sortable.js", |
| 15 | + "effect.js" |
| 16 | +]; |
| 17 | + |
| 18 | +const uiFiles = coreFiles.map( function( file ) { |
| 19 | + return "ui/" + file; |
| 20 | +} ).concat( expandFiles( "ui/**/*.js" ).filter( function( file ) { |
| 21 | + return coreFiles.indexOf( file.substring( 3 ) ) === -1; |
| 22 | +} ) ); |
| 23 | + |
| 24 | +const allI18nFiles = expandFiles( "ui/i18n/*.js" ); |
| 25 | + |
| 26 | +const cssFiles = [ |
| 27 | + "core", |
| 28 | + "accordion", |
| 29 | + "autocomplete", |
| 30 | + "button", |
| 31 | + "checkboxradio", |
| 32 | + "controlgroup", |
| 33 | + "datepicker", |
| 34 | + "dialog", |
| 35 | + "draggable", |
| 36 | + "menu", |
| 37 | + "progressbar", |
| 38 | + "resizable", |
| 39 | + "selectable", |
| 40 | + "selectmenu", |
| 41 | + "sortable", |
| 42 | + "slider", |
| 43 | + "spinner", |
| 44 | + "tabs", |
| 45 | + "tooltip", |
| 46 | + "theme" |
| 47 | +].map( function( component ) { |
| 48 | + return "themes/base/" + component + ".css"; |
| 49 | +} ); |
| 50 | + |
| 51 | +// minified files |
| 52 | +const minify = { |
| 53 | + options: { |
| 54 | + preserveComments: false |
| 55 | + }, |
| 56 | + main: { |
56 | 57 | options: {
|
57 |
| - preserveComments: false |
| 58 | + banner: createBanner( uiFiles ) |
58 | 59 | },
|
59 |
| - main: { |
60 |
| - options: { |
61 |
| - banner: createBanner( uiFiles ) |
62 |
| - }, |
63 |
| - files: { |
64 |
| - "dist/jquery-ui.min.js": "dist/jquery-ui.js" |
65 |
| - } |
66 |
| - }, |
67 |
| - i18n: { |
68 |
| - options: { |
69 |
| - banner: createBanner( allI18nFiles ) |
70 |
| - }, |
71 |
| - files: { |
72 |
| - "dist/i18n/jquery-ui-i18n.min.js": "dist/i18n/jquery-ui-i18n.js" |
73 |
| - } |
| 60 | + files: { |
| 61 | + "dist/jquery-ui.min.js": "dist/jquery-ui.js" |
74 | 62 | }
|
75 | 63 | },
|
| 64 | + i18n: { |
| 65 | + options: { |
| 66 | + banner: createBanner( allI18nFiles ) |
| 67 | + }, |
| 68 | + files: { |
| 69 | + "dist/i18n/jquery-ui-i18n.min.js": "dist/i18n/jquery-ui-i18n.js" |
| 70 | + } |
| 71 | + } |
| 72 | +}; |
76 | 73 |
|
77 |
| - compareFiles = { |
78 |
| - all: [ |
79 |
| - "dist/jquery-ui.js", |
80 |
| - "dist/jquery-ui.min.js" |
81 |
| - ] |
82 |
| - }, |
83 |
| - component = grunt.option( "component" ) || "**", |
84 |
| - |
85 |
| - htmllintBad = [ |
86 |
| - "demos/tabs/ajax/content*.html", |
87 |
| - "demos/tooltip/ajax/content*.html", |
88 |
| - "tests/unit/core/core.html", |
89 |
| - "tests/unit/tabs/data/test.html" |
90 |
| - ]; |
| 74 | +const compareFiles = { |
| 75 | + all: [ |
| 76 | + "dist/jquery-ui.js", |
| 77 | + "dist/jquery-ui.min.js" |
| 78 | + ] |
| 79 | +}; |
| 80 | +const component = grunt.option( "component" ) || "**"; |
| 81 | + |
| 82 | +const htmllintBad = [ |
| 83 | + "demos/tabs/ajax/content*.html", |
| 84 | + "demos/tooltip/ajax/content*.html", |
| 85 | + "tests/unit/core/core.html", |
| 86 | + "tests/unit/tabs/data/test.html" |
| 87 | +]; |
| 88 | + |
| 89 | +const nodeV16OrNewer = !/^v1[0-5]\./.test( process.version ); |
| 90 | + |
| 91 | +// Support: Node.js <16 |
| 92 | +// Skip running tasks that dropped support for Node.js 10-15 |
| 93 | +// in this Node version. |
| 94 | +function runIfNewNode( task ) { |
| 95 | + return nodeV16OrNewer ? task : "print_old_node_message:" + task; |
| 96 | +} |
91 | 97 |
|
92 | 98 | function mapMinFile( file ) {
|
93 | 99 | return "dist/" + file.replace( /ui\//, "minified/" );
|
@@ -115,20 +121,14 @@ uiFiles.forEach( function( file ) {
|
115 | 121 | compareFiles[ file ] = [ file, mapMinFile( file ) ];
|
116 | 122 | } );
|
117 | 123 |
|
118 |
| -// grunt plugins |
119 |
| -require( "load-grunt-tasks" )( grunt ); |
120 |
| - |
121 |
| -// local testswarm and build tasks |
122 |
| -grunt.loadTasks( "build/tasks" ); |
123 |
| - |
124 | 124 | function stripDirectory( file ) {
|
125 | 125 | return file.replace( /.+\/(.+?)>?$/, "$1" );
|
126 | 126 | }
|
127 | 127 |
|
128 | 128 | function createBanner( files ) {
|
129 | 129 |
|
130 | 130 | // strip folders
|
131 |
| - var fileNames = files && files.map( stripDirectory ); |
| 131 | + const fileNames = files && files.map( stripDirectory ); |
132 | 132 | return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
|
133 | 133 | "<%= grunt.template.today('isoDate') %>\n" +
|
134 | 134 | "<%= pkg.homepage ? '* ' + pkg.homepage + '\\n' : '' %>" +
|
@@ -184,9 +184,10 @@ grunt.initConfig( {
|
184 | 184 | ignore: [
|
185 | 185 | /The text content of element “script” was not in the required format: Expected space, tab, newline, or slash but found “.” instead/
|
186 | 186 | ] },
|
187 |
| - src: glob.sync( "{demos,tests}/**/*.html", { |
188 |
| - ignore: htmllintBad |
189 |
| - } ) |
| 187 | + src: [ |
| 188 | + "{demos,tests}/**/*.html", |
| 189 | + ...htmllintBad.map( pattern => `!${ pattern }` ) |
| 190 | + ] |
190 | 191 | },
|
191 | 192 | bad: {
|
192 | 193 | options: {
|
@@ -469,9 +470,22 @@ grunt.initConfig( {
|
469 | 470 | }
|
470 | 471 | } );
|
471 | 472 |
|
| 473 | +// grunt plugins |
| 474 | +require( "load-grunt-tasks" )( grunt, { |
| 475 | + pattern: nodeV16OrNewer ? [ "grunt-*" ] : [ |
| 476 | + "grunt-*", |
| 477 | + "!grunt-contrib-qunit", |
| 478 | + "!grunt-eslint", |
| 479 | + "!grunt-html" |
| 480 | + ] |
| 481 | +} ); |
| 482 | + |
| 483 | +// local testswarm and build tasks |
| 484 | +grunt.loadTasks( "build/tasks" ); |
| 485 | + |
472 | 486 | grunt.registerTask( "update-authors", function() {
|
473 |
| - var getAuthors = require( "grunt-git-authors" ).getAuthors, |
474 |
| - done = this.async(); |
| 487 | + const getAuthors = require( "grunt-git-authors" ).getAuthors; |
| 488 | + const done = this.async(); |
475 | 489 |
|
476 | 490 | getAuthors( {
|
477 | 491 | priorAuthors: grunt.config( "authors.prior" )
|
@@ -499,11 +513,21 @@ grunt.registerTask( "update-authors", function() {
|
499 | 513 | } );
|
500 | 514 | } );
|
501 | 515 |
|
| 516 | +grunt.registerTask( "print_old_node_message", ( ...args ) => { |
| 517 | + const task = args.join( ":" ); |
| 518 | + grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." ); |
| 519 | +} ); |
| 520 | + |
502 | 521 | // Keep this task list in sync with the testing steps in our GitHub action test workflow file!
|
503 | 522 | grunt.registerTask( "default", [ "lint", "requirejs", "test" ] );
|
504 | 523 | grunt.registerTask( "jenkins", [ "default", "concat" ] );
|
505 |
| -grunt.registerTask( "lint", [ "asciilint", "eslint", "csslint", "htmllint" ] ); |
506 |
| -grunt.registerTask( "test", [ "qunit" ] ); |
| 524 | +grunt.registerTask( "lint", [ |
| 525 | + "asciilint", |
| 526 | + runIfNewNode( "eslint" ), |
| 527 | + "csslint", |
| 528 | + runIfNewNode( "htmllint" ) |
| 529 | +] ); |
| 530 | +grunt.registerTask( "test", [ runIfNewNode( "qunit" ) ] ); |
507 | 531 | grunt.registerTask( "sizer", [ "requirejs:js", "uglify:main", "compare_size:all" ] );
|
508 | 532 | grunt.registerTask( "sizer_all", [ "requirejs:js", "uglify", "compare_size" ] );
|
509 | 533 |
|
|
0 commit comments