Github user dblotsky commented on a diff in the pull request: https://github.com/apache/cordova-docs/pull/514#discussion_r53841732 --- 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 -- I prefer very clear `if` statements because with long method/variable names sometimes the `||` is possible to miss. I opted for the former in this case because the names here are quite long.
--- 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