Thanks to visit codestin.com
Credit goes to github.com

Skip to content

REQUEST: Allow custom output filenames in process #18

@phun-ky

Description

@phun-ky

Currently, according to the documentation, I can only produce one '.md-file for all files that's given to markdox.

I am creating a multitask with grunt to take a set of files, create a *.md-file for each *.js-file, but it seems that I have to loop over each file in the set to produce a unique md file..

Current implementation

grunt.registerMultiTask('documentit', 'Create markdown documentation from JavaScript files with markdox', function(){

  var options = this.options({
      dest : 'docs/'
    });

  // Iterate over all src-dest file pairs.
  this.files.forEach(function(f) {

    var src = f.src.filter(function(filepath) {
      // Warn on and remove invalid source files (if nonull was set).
      if (!grunt.file.exists(filepath)) {
        grunt.log.warn('Source file "' + filepath + '" not found.');
        return false;
      } else {
        return true;
      }
    });

    if (src.length === 0) {
      grunt.log.warn('Destination (' + f.dest + ') not written because src files were empty.');
      return;
    }

    var _markdox_options = {
      output : ''
    };

    src.forEach(function(_f){

      var _dir_name =  path.dirname(_f),
      _new_name = path.basename(_dir_name);

      markdox.process(_f, options.dest + '' + _new_name + '-api.md', function(err){

        if(err){
          grunt.log.fatal(err);
        }

        grunt.log.success('Documentation generated to' + options.dest + '' + _new_name + '-api.md');

      });

    });

  });

});

Desired implementation

grunt.registerMultiTask('documentit', 'Create markdown documentation from JavaScript files with markdox', function(){

  var options = this.options({
      dest : 'docs/'
    });

  // Iterate over all src-dest file pairs.
  this.files.forEach(function(f) {

    var src = f.src.filter(function(filepath) {
      // Warn on and remove invalid source files (if nonull was set).
      if (!grunt.file.exists(filepath)) {
        grunt.log.warn('Source file "' + filepath + '" not found.');
        return false;
      } else {
        return true;
      }
    });

    if (src.length === 0) {
      grunt.log.warn('Destination (' + f.dest + ') not written because src files were empty.');
      return;
    }

    var _markdox_options = {
      // Use the filename of the processed file
      use_filename : true,
      // Prefix for the filename
      prefix : '',
      // Postfix for the filename
      postfix : '-api'
    };



    markdox.process(src, options, function(err){

      if(err){
        grunt.log.fatal(err);
      }

      grunt.log.success('Documentation generated');

    });

  });

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions