cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robpaveza <...@git.apache.org>
Subject [GitHub] cordova-medic pull request: [CB-8870] Consolidating medic code.
Date Wed, 29 Apr 2015 19:29:49 GMT
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 = "<access origin=\"" + uri + "\" />";
    +    if (!contains(configContent, accessOriginTag)) {
    +        configContent = configContent.split("</widget>").join("");
    +        configContent += "    " + accessOriginTag + "\n</widget>\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 <content /> element
    +    medicLog("Setting entry point to " + entryPoint + " in config.xml");
    +
    +    if (configContent.match(/<content\s*src=".*"\s*\/>/gi)) {
    +        configContent = configContent.replace(
    +            /<content\s*src=".*"\s*\/>/gi,
    +            "<content src=\"" + entryPoint + "\" />"
    +        );
    +
    +    } else {
    +
    +        // add entry point to config
    +        configContent = configContent.split("</widget>").join("") +
    +            "    <content src=\"" + entryPoint + "\" />\n</widget>";
    +    }
    +
    +    // write the changes
    +    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
    +}
    +
    +function changeLoadTimeout(appPath, timeout) {
    +
    +    medicLog("Increasing url loading timeout for android to " + timeout);
    +
    +    var timeoutRegex           = /<preference\s*name\s *= \s*"?loadUrlTimeoutValue"?.*?((\/>)|(>.*?<\/\s*preference>))/i;
    +    var timeoutTag             = "<preference name=\"loadUrlTimeoutValue\" value=\""
+ timeout + "\" />";
    +    var timeoutTagWithPlatform = "    <platform name=\"android\">\n        <preference
name=\"loadUrlTimeoutValue\" value=\"120000\" />\n    </platform>\n";
    +    var platformRegex          = /<platform\s*name\s *= \s*"android"\s*>/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 <widget>
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 = '    <preference name="windows-target-version" value="'
+ version + '" />';
    +    configContent = configContent.replace('</widget>', versionPreference + '\r\n</widget>');
    +
    +    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


Mime
View raw message