cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nikhilkh <...@git.apache.org>
Subject [GitHub] cordova-docs pull request: Docs fetching improvements
Date Tue, 23 Feb 2016 17:14:52 GMT
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-docs/pull/514#discussion_r53814215
  
    --- 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'");
    +        return;
    +    }
    +
    +    if (!srcConfig.repoName) {
    +        console.error("entry '" + entry.toString() + "' missing 'repoName' in 'src'");
    +        return;
    +    }
    +
    +    if (!destConfig) {
    +        console.error("entry '" + entry.toString() + "' missing 'dest'");
    +        return;
    +    }
    +
    +    // complete src config
    +    if (!srcConfig.packageName) {
    +        srcConfig.packageName = packageNameFromRepoName(srcConfig.repoName);
    --- End diff --
    
    Nit: The JS way of writing this is: `srcConfig.packageName = srcConfig.packageName ||
packageNameFromRepoName(srcConfig.repoName);`
    I like it because it's more compact too. This method seems long with a lot of whitespaces
making it hard to eyeball - but all of this is just stylistic and not a big deal IMO.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message