@@ -13,7 +13,9 @@ const fs = require('fs'),
1313
1414function findJS ( searchDir , options = { } ) {
1515
16- const exampleCall = 'findJS(\'assets/js\', { verbose: false, dotFolders: true })' ;
16+ const docURL = 'https://docs.minify-js.org/#findjssearchdir-options' ,
17+ exampleCall = 'findJS(\'assets/js\', { verbose: false, dotFoldes: true })' ;
18+
1719 const defaultOptions = {
1820 recursive : true , // recursively search for nested files in searchDir passed
1921 verbose : true , // enable logging
@@ -22,13 +24,16 @@ function findJS(searchDir, options = {}) {
2224 } ;
2325
2426 // Validate searchDir
25- if ( typeof searchDir !== 'string' )
26- return console . error ( 'findJS() » ERROR: 1st arg <searchDir> must be a string.' ) ;
27- else { // verify searchDir path existence
27+ if ( typeof searchDir !== 'string' ) {
28+ console . error ( 'findJS() » ERROR: 1st arg <searchDir> must be a string.' ) ;
29+ console . info ( 'findJS() » For more help, please visit ' + docURL ) ;
30+ return ;
31+ } else { // verify searchDir path existence
2832 const searchPath = path . resolve ( process . cwd ( ) , searchDir ) ;
2933 if ( ! fs . existsSync ( searchPath ) ) {
3034 console . error ( 'findJS() » ERROR: 1st arg <searchDir> must be an existing directory.' ) ;
31- console . error ( `findJS() » ${ searchPath } does not exist.` ) ;
35+ console . error ( `findJS() » ${ searchPath } does not exist.` ) ;
36+ console . info ( 'findJS() » For more help, please visit ' + docURL ) ;
3237 return ;
3338 } }
3439
@@ -64,7 +69,9 @@ function findJS(searchDir, options = {}) {
6469
6570function minify ( input , options = { } ) {
6671
67- const exampleCall = 'minify(\'assets/js\', { recursive: false, mangle: false })' ;
72+ const docURL = 'https://docs.minify-js.org/#minifyinput-options' ,
73+ exampleCall = 'minify(\'assets/js\', { recursive: false, mangle: false })' ;
74+
6875 const defaultOptions = {
6976 recursive : true , // recursively search for nested files if dir path passed
7077 verbose : true , // enable logging
@@ -75,8 +82,11 @@ function minify(input, options = {}) {
7582 } ;
7683
7784 // Validate input
78- if ( typeof input !== 'string' ) return console . error (
79- 'minify() » ERROR: 1st arg <input> must be a string.' ) ;
85+ if ( typeof input !== 'string' ) {
86+ console . error ( 'minify() » ERROR: 1st arg <input> must be a string.' ) ;
87+ console . info ( 'minify() » For more help, please visit ' + docURL ) ;
88+ return ;
89+ }
8090
8191 // Validate/init options
8292 if ( ! validateOptions ( options , defaultOptions , exampleCall ) ) return ;
@@ -127,37 +137,47 @@ function minify(input, options = {}) {
127137// Define INTERNAL validation function
128138
129139function validateOptions ( options , defaultOptions , exampleCall ) {
130- const logPrefix = ( validateOptions . caller ?. name || 'validateOptions' ) + '() » ' ;
140+
141+ const docURL = 'https://docs.minify-js.org/#-api-usage' ;
142+
143+ // Init option strings/types
131144 const strDefaultOptions = JSON . stringify ( defaultOptions , null , 2 )
132145 . replace ( / " ( [ ^ " ] + ) " : / g, '$1:' ) // strip quotes from keys
133146 . replace ( / " / g, '\'' ) // replace double quotes w/ single quotes
134147 . replace ( / \n \s * / g, ' ' ) ; // condense to single line
135148 const strValidOptions = Object . keys ( defaultOptions ) . join ( ', ' ) ,
136149 booleanOptions = Object . keys ( defaultOptions ) . filter ( key => typeof defaultOptions [ key ] === 'boolean' ) ,
137150 integerOptions = Object . keys ( defaultOptions ) . filter ( key => Number . isInteger ( defaultOptions [ key ] ) ) ;
151+
152+ // Define print functions
153+ const logPrefix = ( validateOptions . caller ?. name || 'validateOptions' ) + '() » ' ;
138154 const printValidOptions = ( ) => {
139155 console . info ( `${ logPrefix } Valid options: [ ${ strValidOptions } ]` ) ;
140156 console . info ( `${ logPrefix } If omitted, default settings are: ${ strDefaultOptions } ` ) ;
141157 } ;
158+ const printDocURL = ( ) => {
159+ console . info ( `${ logPrefix } For more help, please visit ${ docURL } ` ) ; } ;
160+
161+ // Validate options
142162 if ( typeof options != 'object' ) { // validate as obj
143163 console . error ( `${ logPrefix } ERROR: [options] can only be an object of key/values.` ) ;
144164 console . info ( `${ logPrefix } Example valid call: ${ exampleCall } ` ) ;
145- printValidOptions ( ) ; return false ;
165+ printValidOptions ( ) ; printDocURL ( ) ; return false ;
146166 }
147167 for ( const key in options ) { // validate each key
148168 if ( key != 'isRecursing' && ! Object . prototype . hasOwnProperty . call ( defaultOptions , key ) ) {
149169 console . error (
150170 `${ logPrefix } ERROR: \`${ key } \` is an invalid option.` ) ;
151- printValidOptions ( ) ; return false ;
171+ printValidOptions ( ) ; printDocURL ( ) ; return false ;
152172 } else if ( booleanOptions . includes ( key ) && typeof options [ key ] !== 'boolean' ) {
153173 console . error (
154174 `${ logPrefix } ERROR: [${ key } ] option can only be \`true\` or \`false\`.` ) ;
155- return false ;
175+ printDocURL ( ) ; return false ;
156176 } else if ( integerOptions . includes ( key ) ) {
157177 options [ key ] = parseInt ( options [ key ] , 10 ) ;
158178 if ( isNaN ( options [ key ] ) || options [ key ] < 1 ) {
159179 console . error ( `${ logPrefix } ERROR: [${ key } ] option can only be an integer > 0.` ) ;
160- return false ;
180+ printDocURL ( ) ; return false ;
161181 }
162182 }
163183 }
0 commit comments