From 147f7b08eacfcb0ef9a5e6107c66a7b171423764 Mon Sep 17 00:00:00 2001 From: Anadian Date: Sun, 28 Jun 2020 22:09:34 -0400 Subject: [PATCH] chore: Real final commit before release. --- .gitignore | 1 + file.txt | 0 source/main.js | 89 +++++++++++++++++++++++++++----------------------- test.js | 19 ----------- 4 files changed, 49 insertions(+), 60 deletions(-) create mode 100644 file.txt delete mode 100755 test.js diff --git a/.gitignore b/.gitignore index ace58497..a267cae8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .nyc_output node_modules/ +temp_docs/ diff --git a/file.txt b/file.txt new file mode 100644 index 00000000..e69de29b diff --git a/source/main.js b/source/main.js index e9df1cf7..9f0e2a28 100755 --- a/source/main.js +++ b/source/main.js @@ -166,7 +166,7 @@ function getDocumentationStringFromSourceString( source_string, options = {} ){ documentation += (matches_array[index][1])+'\n'; //Crude and will be polished up soon. } _return = documentation; - /**regex = new RegExp(/\/\*\*[\W\w\s\r\n*]*?\*\//, 'gs'); + /*regex = new RegExp(/\/\*\*[\W\w\s\r\n*]*?\*\//, 'gs'); matches_iterator = source_string.matchAll(regex); Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `matches: ${matches_array}`}); _return = Array.from(matches_iterator).join('\n').replace(/\/\*\*|\*\/|(?:\r?\n|\r){2,}/g, '')*/ @@ -690,7 +690,7 @@ async function main_Async( options = {} ){ var arguments_array = Array.from(arguments); var return_error = null; const FUNCTION_NAME = 'main_Async'; - Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `received: ${arguments_array}`}); + Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `received: ${Utility.inspect( arguments_array, true, null, true )}`}); //Variables var input_string = ''; var output_string = ''; @@ -704,52 +704,71 @@ async function main_Async( options = {} ){ //Parametre checks //Function //Multi-file mode - if( options.input != null && Array.isArray(options.input) === true ){ - Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `options.input: ${options.input.toString('utf8')}`}); - Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'note', message: 'Multi-file mode activated.'}); - if( options.output != null && typeof(options.output) === 'string' ){ - for( var i = 0; i < options.input.length; i++ ){ - report_file_object = { - path: options.input[i], - success: false, - error: null - }; - try{ - output_string = getDocumentationStringFromFilePathSync( options.input[i], options ); + if( options.input != null && typeof(options.input) === 'object' && Array.isArray(options.input) === true ){ + if( options.input.length > 1 ){ + Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `options.input: ${options.input.toString('utf8')}`}); + Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'note', message: 'Multi-file mode activated.'}); + if( options.output != null && typeof(options.output) === 'string' ){ + for( var i = 0; i < options.input.length; i++ ){ + report_file_object = { + path: options.input[i], + success: false, + error: null + }; try{ - output_path = Path.join( options.output, options.input[i] ); + output_string = getDocumentationStringFromFilePathSync( options.input[i], options ); try{ - output_directory = Path.dirname( output_path ); + output_path = Path.join( options.output, options.input[i] ); try{ - MakeDir.sync( output_directory ); + output_directory = Path.dirname( output_path ); try{ - FileSystem.writeFileSync( output_path, output_string, 'utf8' ); - report_file_object.success = true; - report.files.push( report_file_object ); + MakeDir.sync( output_directory ); + try{ + FileSystem.writeFileSync( output_path, output_string, 'utf8' ); + report_file_object.success = true; + report.files.push( report_file_object ); + } catch(error){ + report_file_object.error = new Error(`FileSystem.writeFileSync threw an error: ${error}`); + report.files.push( report_file_object ); + } } catch(error){ - report_file_object.error = new Error(`FileSystem.writeFileSync threw an error: ${error}`); + report_file_object.error = new Error(`MakeDir.sync threw an error: ${error}`); report.files.push( report_file_object ); } } catch(error){ - report_file_object.error = new Error(`MakeDir.sync threw an error: ${error}`); + report_file_object.error = new Error(`Path.dirname threw an error: ${error}`); report.files.push( report_file_object ); } } catch(error){ - report_file_object.error = new Error(`Path.dirname threw an error: ${error}`); + report_file_object.error = new Error(`Path.join threw an error: ${error}`); report.files.push( report_file_object ); } } catch(error){ - report_file_object.error = new Error(`Path.join threw an error: ${error}`); + report_file_object.error = new Error(`getDocumentationStringFromFilePathSync threw an error: ${error}`); report.files.push( report_file_object ); } + } + Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `Multi-file report: ${Utility.inspect( report, false, null, true )}`}); + } else{ + return_error = new Error('"options.output" (`--output`) must be specified when using multi-file mode.'); + Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message}); + } + } else if( options.input.length === 1 ){ + Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'info', message: 'Reading input from a file.'}); + if( typeof(options.input[0]) === 'string' ){ + Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `options.input: '${options.input}'`}); + try{ + input_string = FileSystem.readFileSync( options.input[0], 'utf8' ); } catch(error){ - report_file_object.error = new Error(`getDocumentationStringFromFilePathSync threw an error: ${error}`); - report.files.push( report_file_object ); + return_error = new Error(`FileSystem.readFileSync threw an error: ${error}`); + Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message}); } + } else{ + return_error = new Error('"options.input" is not a string.'); + Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message}); } - Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `Multi-file report: ${Utility.inspect( report, false, null, true )}`}); } else{ - return_error = new Error('"options.output" (`--output`) must be specified when using multi-file mode.'); + return_error = new Error('"options.input" is an empty array?'); Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message}); } } else{ //Single-file mode @@ -764,19 +783,6 @@ async function main_Async( options = {} ){ Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message}); } } else if( options.input != null ){ - Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'info', message: 'Reading input from a file.'}); - if( typeof(options.input) === 'string' ){ - Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `options.input: '${options.input}'`}); - try{ - input_string = FileSystem.readFileSync( options.input, 'utf8' ); - } catch(error){ - return_error = new Error(`FileSystem.readFileSync threw an error: ${error}`); - Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message}); - } - } else{ - return_error = new Error('"options.input" is not a string.'); - Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message}); - } } else{ return_error = new Error('No input options specified.'); Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message}); @@ -977,5 +983,6 @@ if(require.main === module){ exports.setLogger = setLogger; exports.getDocumentationStringFromSourceString = getDocumentationStringFromSourceString; exports.getDocumentationStringFromSourceBuffer = getDocumentationStringFromSourceBuffer; + exports.getDocumentationStringFromFilePathSync = getDocumentationStringFromFilePathSync; } diff --git a/test.js b/test.js deleted file mode 100755 index 9d843b81..00000000 --- a/test.js +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/local/bin/node -const ChildProcess = require('child_process'); - -async function Test(){ - var process_object = ChildProcess.exec('bash -c \'node --version\'', { detached: true }); - process_object.stdio[1].on('data', function( chunk ){ - console.log(`stdout chunk: ${chunk.toString('utf8')}`); - }); - process_object.stdio[2].on('data', function( chunk ){ - console.log(`stderr chunk: ${chunk.toString('utf8')}`); - }); - process_object.on('exit', function( code, signal ){ - console.log(`code: ${code} signal: ${signal}`); - }); - /*function(error, stdout, stderr){ - console.log(`error: ${error} stdout: ${stdout} stderr: ${stderr}`); - }*/ -} -Test();