1111var JavaScriptObfuscator = require ( 'javascript-obfuscator' ) ;
1212
1313function concat ( grunt , paths ) {
14+ console . log ( "paths" , paths ) ;
15+
1416 if ( paths . length === 0 ) {
15- grunt . log . warn ( 'Source files don\'t exist' ) ;
16- return '' ;
17+ throw new Error ( 'Source files not found.' ) ;
1718 }
1819
19- return paths . filter ( function ( path ) {
20- // Warn on and remove invalid source files (if nonull was set).
21- if ( ! grunt . file . exists ( path ) ) {
22- grunt . log . warn ( 'Source file "' + path + '" not found.' ) ;
23- return false ;
24- } else {
25- return true ;
26- }
27- } ) . map ( function ( path ) {
20+ return paths . map ( function ( path ) {
21+
2822 // Read file source.
2923 return grunt . file . read ( path ) ;
3024 } ) . join ( grunt . util . normalizelf ( ';' ) ) ;
3125}
3226
3327module . exports = function ( grunt ) {
34-
35- // Please see the Grunt documentation for more information regarding task
36- // creation: http://gruntjs.com/creating-tasks
37-
3828 grunt . registerMultiTask ( 'javascript_obfuscator' , 'Obfuscates JavaScript files.' , function ( ) {
29+
3930 // Merge task-specific and/or target-specific options with these defaults.
4031 var options = this . options ( { } ) ;
4132
42- // Iterate over all specified file groups.
4333 this . files . forEach ( function ( f ) {
44- // Concat specified files.
34+ var src ;
4535
46- var src = concat ( grunt , f . src ) ;
36+ try {
37+ src = concat ( grunt , f . src ) ;
38+ } catch ( e ) {
39+ return grunt . fail . warn ( e ) ;
40+ }
4741
4842 src = JavaScriptObfuscator . obfuscate ( src , options ) . getObfuscatedCode ( ) ;
4943
@@ -54,5 +48,4 @@ module.exports = function(grunt) {
5448 grunt . log . writeln ( 'File "' + f . dest + '" created.' ) ;
5549 } ) ;
5650 } ) ;
57-
5851} ;
0 commit comments