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 8E50C18762 for ; Wed, 29 Apr 2015 19:29:50 +0000 (UTC) Received: (qmail 37519 invoked by uid 500); 29 Apr 2015 19:29:50 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 37481 invoked by uid 500); 29 Apr 2015 19:29:50 -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 37470 invoked by uid 99); 29 Apr 2015 19:29: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; Wed, 29 Apr 2015 19:29:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D2F63E0984; Wed, 29 Apr 2015 19:29:49 +0000 (UTC) From: robpaveza To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code. Content-Type: text/plain Message-Id: <20150429192949.D2F63E0984@git1-us-west.apache.org> Date: Wed, 29 Apr 2015 19:29:49 +0000 (UTC) Github user robpaveza commented on a diff in the pull request: https://github.com/apache/cordova-medic/pull/47#discussion_r29371466 --- Diff: bin/medic.js --- @@ -55,6 +181,210 @@ function exclusiveLs(lsPath, excludes) { }); } +function getConfigPath(appPath) { + return path.join(appPath, "config.xml"); +} + +function getCSPPath(appPath) { + return path.join(appPath, "www", "csp-incl.js"); +} + +function addURIToWhitelist(appPath, uri) { + + var configFile = getConfigPath(appPath); + var cspFile = getCSPPath(appPath); + + var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING); + var cspContent = fs.readFileSync(cspFile, DEFAULT_ENCODING); + + // add whitelisting rule allow access to couch server + medicLog("Adding whitelist rule for CouchDB host: " + uri); + var accessOriginTag = ""; + if (!contains(configContent, accessOriginTag)) { + configContent = configContent.split("").join(""); + configContent += " " + accessOriginTag + "\n\n"; + fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING); + } + + // add couchdb address to csp rules + medicLog("Adding CSP rule for CouchDB host: " + uri); + var cspRule = "connect-src " + uri; + if (!contains(cspContent, cspRule)) { + cspContent = cspContent.replace("connect-src", cspRule); + fs.writeFileSync(cspFile, cspContent, DEFAULT_ENCODING); + } +} + +function setEntryPoint(appPath, entryPoint) { + + var configFile = getConfigPath(appPath); + var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING); + + // replace/add start page preference + // check if config.xml already contains element + medicLog("Setting entry point to " + entryPoint + " in config.xml"); + + if (configContent.match(//gi)) { + configContent = configContent.replace( + //gi, + "" + ); + + } else { + + // add entry point to config + configContent = configContent.split("").join("") + + " \n"; + } + + // write the changes + fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING); +} + +function changeLoadTimeout(appPath, timeout) { + + medicLog("Increasing url loading timeout for android to " + timeout); + + var timeoutRegex = /)|(>.*?<\/\s*preference>))/i; + var timeoutTag = ""; + var timeoutTagWithPlatform = " \n \n \n"; + var platformRegex = //i; + var widgetRegex = /<\/s*widget\s*>/i; + + var configFile = getConfigPath(appPath); + var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING); + + if (timeoutRegex.test(configContent)) { + configContent = configContent.replace(timeoutRegex, timeoutTag); + medicLog("Found \"loadUrlTimeoutValue\" preference, replacing with desired value"); + } else if (platformRegex.test(configContent)) { + var oldPlatformTag = platformRegex.exec(configContent)[0]; + configContent = configContent.replace(platformRegex, oldPlatformTag + "\n " + timeoutTag); + medicLog("Found platform tag, appending \"loadUrlTimeoutValue\" preference"); + } else if (widgetRegex.test(configContent)) { + var oldWidgetTag = widgetRegex.exec(configContent)[0]; + configContent = configContent.replace(widgetRegex, timeoutTagWithPlatform + oldWidgetTag); + medicLog("Did not find platform tag, adding preference with platform tag"); + } else { + medicLog("Warning: could not modify config.xml for android: no tag found!"); + } + + // write the changes + fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING); +} + +function setWindowsTargetStoreVersion(appPath, version) { + + medicLog('setting target store version to ' + version); + + var configFile = getConfigPath(appPath); + var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING); + + var versionPreference = ' '; + configContent = configContent.replace('', versionPreference + '\r\n'); + + fs.writeFileSync(configFile, configContent, "utf8"); +} + +function androidSpecifics(argv) { --- End diff -- Your "(platform)Specifics" functions don't really indicate what it is they do by their names. --- 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