forked from benkeen/generatedata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gruntfile.js
128 lines (112 loc) · 3.31 KB
/
gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
module.exports = function(grunt) {
"use strict";
var config = {
pkg: grunt.file.readJSON('package.json'),
uglify: {
coreJS: {
files: {
'cache/core.js': [
'resources/libs/codemirror/lib/codemirror.js',
'resources/scripts/libs/jquery.min.js',
'resources/scripts/libs/jquery-ui.min.js',
'resources/scripts/libs/jquery.json-2.2.min.js',
'resources/scripts/libs/chosen.jquery.min.js',
'resources/scripts/libs/spinners.js',
// pity, but now everyone gets them <!--[if lt IE 9]>
'resources/scripts/libs/html5shiv.js',
'resources/scripts/libs/excanvas.js'
]
},
options: {
report: "min",
compress: true
}
}
},
cssmin: {
target: {
files: {
// it would be VERY nice to bundle all the CSS, but the various image paths make it impossible
'cache/core.css': [
'resources/css/tablesorter.theme.css',
'resources/libs/codemirror/lib/codemirror.css'
]
}
}
},
requirejs: {
compile: {
options: {
name: "appStartGenerated",
baseUrl: "./", // necessary!
mainConfigFile: "resources/scripts/requireConfig.js",
out: "cache/appStartGenerated.bundled.js"
}
}
},
md5: {
prod: {
files: {
"cache/core.css": "cache/core.css",
"cache/core.js": "cache/core.js",
"cache/appStartGenerated.bundled.js": "cache/appStartGenerated.bundled.js"
},
options: {
after: function(fileChanges) {
if (fileChanges.length !== 3) {
return;
}
// now create the cache/minifiedResourcePaths.php that contains the new, unique filenames
var php = "<?php\n$MINIFIED = array();\n" +
"$MINIFIED['coreCSS'] = \"" + fileChanges[0].newPath + "\";\n" +
"$MINIFIED['coreJS'] = \"" + fileChanges[1].newPath + "\";\n" +
"$MINIFIED['appStart'] = \"" + fileChanges[2].newPath + "\";\n";
grunt.file.write("cache/minifiedResourcePaths.php", php);
}
}
}
},
search: {
short_tags: {
files: {
src: [
"resources/classes/**/*.php",
"plugins/**/*.php",
"*.php"
]
},
options: {
searchString: /(<\?[^p])|(<\?$)/,
logFile: "cache/short_tags.json",
logFormat: "json",
outputExaminedFiles: true,
failOnMatch: true
}
}
}
};
grunt.initConfig(config);
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-md5');
grunt.loadNpmTasks('grunt-template');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-search');
/**
* The default - and only - Grunt task simply recreates all the bundled resources. It doesn't alter the actual
* script at all. To use these bundled resources you need to add a $useMinifiedResources = true; var to your
* settings.php file.
*/
grunt.registerTask('default', [
// uglify the core CSS + JS
'uglify',
'cssmin',
// generate the requireJS bundle containing all modules + core. This relies on there being a
// /cache/appStartStatic file having been auto-generated by the script first. That file is generated every
// time you click the "Reset Plugins" link
'requirejs',
// now create md5 versions of the main minified file, which (re)-generates the /cache/minifiedResourcePaths.php file
// with the latest file mapping
'md5'
]);
};