0

Javascript is restricted from accessing the user's folders, as it should be, but I am working on a plugin for Docsify that will allow dynamic creation of documentation from comments in application *.js files -- I would like to extend this to HTML files but I need to accomplish this first.

I have two problems:

  1. How do I read a folder from my root and turn the filenames therein into strings?
  2. How do I read a file from the folder mentioned above and turn that into a string so I can process it?

From my scouring of Mozilla MDN it looks like all of the file APIs are for users uploading files for processing.

My Folder Structure

So pretending objects are folders and files are contents of arrays.

root:{
  docs:[
     docsifyFilesAndFolders.ext
  ],
  targetJSFolder:[
    target1.js,
    target2.js
  ],
  rootFiles: [
    applicationRootFiles.ext
  ]
}

My Goal

So what I would like to do is something like this:

const Functions: {
  folderProcessor: (folderPath) => { 

    var files = [
      ./target1.js, 
      ./target2.js
    ];

    forEach( file in Files ){
      Functions.extractTaggedComments();
    }
    
 },
  extractTaggedComments: (filePath) => { 
    var comments = TurnCommentsIntoArrays();
    var result = new Object();

    forEach(comment in comments){

       findTag();
       createStringInMarkdownFormat();

       result.tagAndReference = comment;
    }

    return result;
  },
  createMDFile= (extractedComments) => {
    var formattedMDText = actions();

    return formattedMDText;
  }
}

Eventually, I will be creating ./docs/options.html where the user will be able to see the files and folders inside ./ and decide which ones to present in the documentation with checkboxes.

I think eventually I might have to store the ${fileContents} into a server of some sort, but I would prefer to avoid that if possible.

  • You could write a browser extension, which could access the file system. – GabeRAMturn Jul 24 '22 at 03:15
  • I'm not sure that is going to work. Ideally, we want to be able to set up our file system, pick the features we want to have documentation for, and let it update as the developers commit their code to GitHub. Is there something that could be done with NodeJS perhaps? – The Jaded George Jul 24 '22 at 06:58

0 Answers0