forked from vakata/jstree
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gruntfile.js
187 lines (180 loc) · 5.47 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*global module:false, require:false, __dirname:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: ['src/<%= pkg.name %>.js', 'src/<%= pkg.name %>.*.js'],
dest: 'dist/<%= pkg.name %>.js'
}
},
copy: {
libs : {
files : [
{ expand: true, cwd : 'libs/', src: ['*'], dest: 'dist/libs/' }
]
},
docs : {
files : [
{ expand: true, cwd : 'dist/', src: ['**/*'], dest: 'docs/assets/dist/' }
]
}
},
uglify: {
options: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> - (<%= _.pluck(pkg.licenses, "type").join(", ") %>) */\n',
preserveComments: false,
//sourceMap: "dist/jstree.min.map",
//sourceMappingURL: "jstree.min.map",
report: "min",
beautify: {
ascii_only: true
},
compress: {
hoist_funs: false,
loops: false,
unused: false
}
},
dist: {
src: ['<%= concat.dist.dest %>'],
dest: 'dist/<%= pkg.name %>.min.js'
}
},
qunit: {
files: ['test/**/*.html']
},
jshint: {
options: {
'curly' : true,
'eqeqeq' : true,
'latedef' : true,
'newcap' : true,
'noarg' : true,
'sub' : true,
'undef' : true,
'boss' : true,
'eqnull' : true,
'browser' : true,
'trailing' : true,
'globals' : {
'console' : true,
'jQuery' : true,
'browser' : true,
'XSLTProcessor' : true,
'ActiveXObject' : true
}
},
beforeconcat: ['src/<%= pkg.name %>.js', 'src/<%= pkg.name %>.*.js'],
afterconcat: ['dist/<%= pkg.name %>.js']
},
dox: {
files: {
src: ['src/*.js'],
dest: 'docs'
}
},
amd : {
files: {
src: ['dist/jstree.js'],
dest: 'dist/jstree.js'
}
},
less: {
production: {
options : {
cleancss : true,
compress : true
},
files: {
"dist/themes/default/style.min.css" : "src/themes/default/style.less"
}
},
development: {
files: {
"src/themes/default/style.css" : "src/themes/default/style.less",
"dist/themes/default/style.css" : "src/themes/default/style.less"
}
}
},
watch: {
js : {
files: ['src/**/*.js'],
tasks: ['js'],
options : {
atBegin : true
}
},
css : {
files: ['src/**/*.less','src/**/*.png','src/**/*.gif'],
tasks: ['css'],
options : {
atBegin : true
}
},
},
imagemin: {
dynamic: {
options: { // Target options
optimizationLevel: 7,
pngquant : true
},
files: [{
expand: true, // Enable dynamic expansion
cwd: 'src/themes/default/', // Src matches are relative to this path
src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest: 'dist/themes/default/' // Destination path prefix
}]
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.registerMultiTask('amd', 'Clean up AMD', function () {
var s, d;
this.files.forEach(function (f) {
s = f.src;
d = f.dest;
});
grunt.file.copy(s, d, {
process: function (contents) {
contents = contents.replace(/\s*if\(\$\.jstree\.plugins\.[a-z]+\)\s*\{\s*return;\s*\}/ig, '');
contents = contents.replace(/\/\*globals[^\/]+\//ig, '');
//contents = contents.replace(/\(function \(factory[\s\S]*?undefined/mig, '(function ($, undefined');
//contents = contents.replace(/\}\)\);/g, '}(jQuery));');
contents = contents.replace(/\(function \(factory[\s\S]*?undefined[^\n]+/mig, '');
contents = contents.replace(/\}\)\);/g, '');
contents = contents.replace(/\s*("|')use strict("|');/g, '');
return grunt.file.read('src/intro.js') + contents + grunt.file.read('src/outro.js');
}
});
});
grunt.registerMultiTask('dox', 'Generate dox output ', function() {
var exec = require('child_process').exec,
path = require('path'),
done = this.async(),
doxPath = path.resolve(__dirname),
formatter = [doxPath, 'node_modules', '.bin', 'dox'].join(path.sep);
exec(formatter + ' < "dist/jstree.js" > "docs/jstree.json"', {maxBuffer: 5000*1024}, function(error, stout, sterr){
if (error) {
grunt.log.error(formatter);
grunt.log.error("WARN: "+ error);
}
if (!error) {
grunt.log.writeln('dist/jstree.js doxxed.');
done();
}
});
});
// Default task.
grunt.registerTask('default', ['jshint:beforeconcat','concat','amd','jshint:afterconcat','copy:libs','uglify','less','imagemin','copy:docs','qunit','dox']);
grunt.registerTask('js', ['concat','amd','uglify']);
grunt.registerTask('css', ['copy','less']);
};