comparison vakata-jstree-3.3.5/gruntfile.js @ 0:803f4888f36a draft

planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
author mingchen0919
date Thu, 13 Dec 2018 22:46:23 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:803f4888f36a
1 /*global module:false, require:false, __dirname:false*/
2
3 module.exports = function(grunt) {
4 grunt.util.linefeed = "\n";
5
6 // Project configuration.
7 grunt.initConfig({
8 pkg: grunt.file.readJSON('package.json'),
9 concat: {
10 options : {
11 separator : "\n"
12 },
13 dist: {
14 src: ['src/<%= pkg.name %>.js', 'src/<%= pkg.name %>.*.js', 'src/vakata-jstree.js'],
15 dest: 'dist/<%= pkg.name %>.js'
16 }
17 },
18 copy: {
19 libs : {
20 files : [
21 { expand: true, cwd : 'libs/', src: ['*'], dest: 'dist/libs/' }
22 ]
23 },
24 docs : {
25 files : [
26 { expand: true, cwd : 'dist/', src: ['**/*'], dest: 'docs/assets/dist/' }
27 ]
28 }
29 },
30 uglify: {
31 options: {
32 banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> - (<%= _.pluck(pkg.licenses, "type").join(", ") %>) */\n',
33 preserveComments: false,
34 //sourceMap: "dist/jstree.min.map",
35 //sourceMappingURL: "jstree.min.map",
36 report: "min",
37 beautify: {
38 ascii_only: true
39 },
40 compress: {
41 hoist_funs: false,
42 loops: false,
43 unused: false
44 }
45 },
46 dist: {
47 src: ['<%= concat.dist.dest %>'],
48 dest: 'dist/<%= pkg.name %>.min.js'
49 }
50 },
51 qunit: {
52 files: ['test/unit/**/*.html']
53 },
54 jshint: {
55 options: {
56 'curly' : true,
57 'eqeqeq' : true,
58 'latedef' : true,
59 'newcap' : true,
60 'noarg' : true,
61 'sub' : true,
62 'undef' : true,
63 'boss' : true,
64 'eqnull' : true,
65 'browser' : true,
66 'trailing' : true,
67 'globals' : {
68 'console' : true,
69 'jQuery' : true,
70 'browser' : true,
71 'XSLTProcessor' : true,
72 'ActiveXObject' : true
73 }
74 },
75 beforeconcat: ['src/<%= pkg.name %>.js', 'src/<%= pkg.name %>.*.js'],
76 afterconcat: ['dist/<%= pkg.name %>.js']
77 },
78 dox: {
79 files: {
80 src: ['src/*.js'],
81 dest: 'docs'
82 }
83 },
84 amd : {
85 files: {
86 src: ['dist/jstree.js'],
87 dest: 'dist/jstree.js'
88 }
89 },
90 less: {
91 production: {
92 options : {
93 cleancss : true,
94 compress : true
95 },
96 files: {
97 "dist/themes/default/style.min.css" : "src/themes/default/style.less",
98 "dist/themes/default-dark/style.min.css" : "src/themes/default-dark/style.less"
99 }
100 },
101 development: {
102 files: {
103 "src/themes/default/style.css" : "src/themes/default/style.less",
104 "dist/themes/default/style.css" : "src/themes/default/style.less",
105 "src/themes/default-dark/style.css" : "src/themes/default-dark/style.less",
106 "dist/themes/default-dark/style.css" : "src/themes/default-dark/style.less"
107 }
108 }
109 },
110 watch: {
111 js : {
112 files: ['src/**/*.js'],
113 tasks: ['js'],
114 options : {
115 atBegin : true
116 }
117 },
118 css : {
119 files: ['src/**/*.less','src/**/*.png','src/**/*.gif'],
120 tasks: ['css'],
121 options : {
122 atBegin : true
123 }
124 },
125 },
126 resemble: {
127 options: {
128 screenshotRoot: 'test/visual/screenshots/',
129 url: 'http://127.0.0.1/jstree/test/visual/',
130 gm: false
131 },
132 desktop: {
133 options: {
134 width: 1280,
135 },
136 src: ['desktop'],
137 dest: 'desktop',
138 },
139 mobile: {
140 options: {
141 width: 360,
142 },
143 src: ['mobile'],
144 dest: 'mobile'
145 }
146 },
147 imagemin: {
148 dynamic: {
149 options: { // Target options
150 optimizationLevel: 7,
151 pngquant : true
152 },
153 files: [{
154 expand: true, // Enable dynamic expansion
155 cwd: 'src/themes/default/', // Src matches are relative to this path
156 src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
157 dest: 'dist/themes/default/' // Destination path prefix
158 },{
159 expand: true, // Enable dynamic expansion
160 cwd: 'src/themes/default-dark/', // Src matches are relative to this path
161 src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
162 dest: 'dist/themes/default-dark/' // Destination path prefix
163 }]
164 }
165 },
166 replace: {
167 files: {
168 src: ['dist/*.js', 'bower.json', 'component.json', 'jstree.jquery.json'],
169 overwrite: true,
170 replacements: [
171 {
172 from: '{{VERSION}}',
173 to: "<%= pkg.version %>"
174 },
175 {
176 from: /"version": "[^"]+"/g,
177 to: "\"version\": \"<%= pkg.version %>\""
178 },
179 ]
180 }
181 }
182 });
183
184 grunt.loadNpmTasks('grunt-contrib-jshint');
185 grunt.loadNpmTasks('grunt-contrib-concat');
186 grunt.loadNpmTasks('grunt-contrib-copy');
187 grunt.loadNpmTasks('grunt-contrib-uglify');
188 grunt.loadNpmTasks('grunt-contrib-less');
189 grunt.loadNpmTasks('grunt-contrib-qunit');
190 grunt.loadNpmTasks('grunt-resemble-cli');
191 grunt.loadNpmTasks('grunt-contrib-watch');
192 grunt.loadNpmTasks('grunt-contrib-imagemin');
193 grunt.loadNpmTasks('grunt-text-replace');
194
195 grunt.registerMultiTask('amd', 'Clean up AMD', function () {
196 var s, d;
197 this.files.forEach(function (f) {
198 s = f.src;
199 d = f.dest;
200 });
201 grunt.file.copy(s, d, {
202 process: function (contents) {
203 contents = contents.replace(/\s*if\(\$\.jstree\.plugins\.[a-z]+\)\s*\{\s*return;\s*\}/ig, '');
204 contents = contents.replace(/\/\*globals[^\/]+\//ig, '');
205 //contents = contents.replace(/\(function \(factory[\s\S]*?undefined/mig, '(function ($, undefined');
206 //contents = contents.replace(/\}\)\);/g, '}(jQuery));');
207 contents = contents.replace(/\(function \(factory[\s\S]*?undefined\s*\)[^\n]+/mig, '');
208 contents = contents.replace(/\}\)\);/g, '');
209 contents = contents.replace(/\s*("|')use strict("|');/g, '');
210 contents = contents.replace(/\s*return \$\.fn\.jstree;/g, '');
211 return grunt.file.read('src/intro.js') + contents + grunt.file.read('src/outro.js');
212 }
213 });
214 });
215
216 grunt.registerMultiTask('dox', 'Generate dox output ', function() {
217 var exec = require('child_process').exec,
218 path = require('path'),
219 done = this.async(),
220 doxPath = path.resolve(__dirname),
221 formatter = [doxPath, 'node_modules', '.bin', 'dox'].join(path.sep);
222 exec(formatter + ' < "dist/jstree.js" > "docs/jstree.json"', {maxBuffer: 5000*1024}, function(error, stout, sterr){
223 if (error) {
224 grunt.log.error(formatter);
225 grunt.log.error("WARN: "+ error);
226 }
227 if (!error) {
228 grunt.log.writeln('dist/jstree.js doxxed.');
229 done();
230 }
231 });
232 });
233
234 grunt.util.linefeed = "\n";
235
236 // Default task.
237 grunt.registerTask('default', ['jshint:beforeconcat','concat','amd','jshint:afterconcat','copy:libs','uglify','less','imagemin','replace','copy:docs','qunit','resemble','dox']);
238 grunt.registerTask('js', ['concat','amd','uglify']);
239 grunt.registerTask('css', ['copy','less']);
240
241 };