Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-docs/pull/514#discussion_r53848104
  
    --- Diff: tools/bin/fetch_docs.js ---
    @@ -25,42 +25,103 @@ var child_process = require("child_process");
     var yaml          = require("js-yaml");
     
     // constants
    -var DEFAULT_REPO_PATH = "README.md";
    +var DEFAULT_REPO_PATH        = "README.md";
    +var DEFAULT_PERMALINK_PREFIX = "/gen/";
     
    -function generateFrontMatter (useDirectSrcURI, filePath, name, version) {
    -    var obj                 = {};
    +function generateFrontMatter(fetchedFile) {
     
    -    if(useDirectSrcURI) {
    -        var p               = 
/https:\/\/raw.githubusercontent.com\/([^\/]+)\/([^\/]+)\/([^\/]+)\/(.+)/;
    -        var filePathSplit   = filePath.match(p);
    -        name                = filePathSplit[1] + "/" + filePathSplit[2];
    -        version             = filePathSplit[3];
    -        filePath            = filePathSplit.slice(4).join("/");
    +    var frontMatterConfig = {};
    +
    +    frontMatterConfig.edit_link = fetchedFile.editLink;
    +    frontMatterConfig.permalink = fetchedFile.permalink;
    +
    +    // set special values for plugins
    +    if (isPluginName(fetchedFile.packageName)) {
    +        frontMatterConfig.plugin_name    = fetchedFile.packageName;
    +        frontMatterConfig.plugin_version = fetchedFile.version;
         }
     
    -    obj.edit_link           = getRepoURIForFrontMatter(name, version, 
filePath);
    -    obj.plugin_name         = name;
    -    obj.plugin_version      = version;
    +    // return front matter as a string
    +    var frontMatterString = "---\n" + yaml.dump(frontMatterConfig) + 
"---\n\n";
    +    return frontMatterString;
    +}
     
    -    var frontMatter         = "---\n" + yaml.dump(obj) + "\n---\n\n";
    -    return frontMatter;
    +function isPluginName(packageName) {
    +    return packageName.match(/cordova-plugin-.*/);
     }
     
    -function getRepoFileURI (name, version, filePath) {
    -    return "https://raw.githubusercontent.com/"; + name + "/" + version + 
"/" + filePath;
    +function getRepoFileURI(repoName, commit, filePath) {
    +    return "https://raw.githubusercontent.com/"; + repoName + "/" + commit 
+ "/" + filePath;
     }
     
    -function getRepoURIForFrontMatter (name, version, filePath) {
    -    return "https://github.com/"; + name + "/blob/" + version + "/"+ 
filePath
    +function getRepoEditURI(repoName, commit, filePath) {
    +    return "https://github.com/"; + repoName + "/blob/" + commit + "/"+ 
filePath
     }
     
    -function getLatestRelease (packageName) {
    +function getLatestRelease(packageName) {
         var latestRelease = child_process.execSync("npm info " + packageName + 
" dist-tags.latest");
         return latestRelease.toString().trim();
     }
     
    -function getPackageName (fileConfigSrc) {
    -    return fileConfigSrc.packageName || 
fileConfigSrc.repoName.split('/')[1];
    +function packageNameFromRepoName(repoName) {
    +    var repoSplit      = repoName.split('/');
    +    var repoOwner      = repoSplit[0];
    +    var actualRepoName = repoSplit[1];
    +    return actualRepoName;
    +}
    +
    +function getFetchedFile(entry) {
    +
    +    // get entry components
    +    var srcConfig  = entry.src;
    +    var destConfig = entry.dest;
    +
    +    // validate entry
    +    if (!srcConfig) {
    +        console.error("entry '" + entry.toString() + "' missing 'src'");
    --- End diff --
    
    In this case you would not catch - it's a truly exceptional case and you 
can't handle it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org
For additional commands, e-mail: dev-h...@cordova.apache.org

Reply via email to