Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2D3F718A01 for ; Tue, 23 Feb 2016 20:06:50 +0000 (UTC) Received: (qmail 33599 invoked by uid 500); 23 Feb 2016 20:06:49 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 33559 invoked by uid 500); 23 Feb 2016 20:06:49 -0000 Mailing-List: contact dev-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list dev@cordova.apache.org Received: (qmail 33548 invoked by uid 99); 23 Feb 2016 20:06:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Feb 2016 20:06:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 610C0E8E74; Tue, 23 Feb 2016 20:06:49 +0000 (UTC) From: dblotsky To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-docs pull request: Docs fetching improvements Content-Type: text/plain Message-Id: <20160223200649.610C0E8E74@git1-us-west.apache.org> Date: Tue, 23 Feb 2016 20:06:49 +0000 (UTC) Github user dblotsky commented on a diff in the pull request: https://github.com/apache/cordova-docs/pull/514#discussion_r53841393 --- 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 -- I opted for the "callee prints error and returns null, caller checks for null" instead of the "callee throws exception, caller catches it" pattern. Is one more advantageous than the other? --- 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