Example #1
0
    addReference:function(relPath,src) {

        events.emit('verbose','addReference::' + relPath);

        relPath = this.isUniversalWindowsApp ? '$(MSBuildThisFileDirectory)' + relPath : relPath;

        var item = new et.Element('ItemGroup');
        var extName = path.extname(relPath);

        var elem = new et.Element('Reference');
        // add file name
        elem.attrib.Include = path.basename(relPath, extName);

        // add hint path with full path
        var hint_path = new et.Element('HintPath');
        hint_path.text = relPath;

        elem.append(hint_path);

        if(extName == ".winmd") {
            var mdFileTag = new et.Element("IsWinMDFile");
            mdFileTag.text = "true";
            elem.append(mdFileTag);
        }

        item.append(elem);
        this.xml.getroot().append(item);
    },
Example #2
0
    addReference:function(relPath) {
        require('../../plugman').emit('verbose','addReference::' + relPath);

        var item = new et.Element('ItemGroup');
        var extName = path.extname(relPath);

        var elem = new et.Element('Reference');
        // add file name
        elem.attrib.Include = path.basename(relPath, extName);

        // add hint path with full path
        var hint_path = new et.Element('HintPath');
            hint_path.text = relPath;

        elem.append(hint_path);

        if(extName == ".winmd") {
            var mdFileTag = new et.Element("IsWinMDFile");
                mdFileTag.text = "true";
            elem.append(mdFileTag);
        }

        item.append(elem);
        this.xml.getroot().append(item);
    },
Example #3
0
    update_csproj:function() {
        console.log('csproj');
        console.log(this.csproj_path);
        var csproj_xml = xml.parseElementtreeSync(this.csproj_path);
        // remove any previous references to the www files
        var item_groups = csproj_xml.findall('ItemGroup');
        for (var i = 0, l = item_groups.length; i < l; i++) {
            var group = item_groups[i];
            var files = group.findall('Content');
            for (var j = 0, k = files.length; j < k; j++) {
                var file = files[j];
                if (file.attrib.Include.substr(0, 3) == 'www') {
                    // remove file reference
                    group.remove(0, file);
                    // remove ItemGroup if empty
                    var new_group = group.findall('Content');
                    if(new_group.length < 1) {
                        csproj_xml.getroot().remove(0, group);
                    }
                }
            }
        }

        // now add all www references back in from the wp www folder
        var www_files = this.folder_contents('www', this.www_dir());
        for(file in www_files) {
            var item = new et.Element('ItemGroup');
            var content = new et.Element('Content');
            content.attrib.Include = www_files[file];
            item.append(content);
            csproj_xml.getroot().append(item);
        }
        // save file
        fs.writeFileSync(this.csproj_path, csproj_xml.write({indent:4}), 'utf-8');
    },
Example #4
0
    addProjectReference: function (relative_path) {
        events.emit('verbose', 'adding project reference to ' + relative_path);

        relative_path = relative_path.split('/').join('\\');

        var pluginProjectXML = xml_helpers.parseElementtreeSync(relative_path);

        // find the guid + name of the referenced project
        var projectGuid = pluginProjectXML.find("PropertyGroup/ProjectGuid").text;
        var projName = pluginProjectXML.find("PropertyGroup/ProjectName").text;

        // get the project type
        var projectTypeGuid = getProjectTypeGuid(relative_path);
        if (!projectTypeGuid) {
            throw new Error("unrecognized project type");
        }

        var preInsertText = "\tProjectSection(ProjectDependencies) = postProject\r\n" +
            "\t\t" + projectGuid + "=" + projectGuid + "\r\n" +
            "\tEndProjectSection\r\n";
        var postInsertText = '\r\nProject("' + projectTypeGuid + '") = "' +
            projName + '", "' + relative_path + '", ' +
            '"' + projectGuid + '"\r\nEndProject';

        // There may be multiple solutions (for different VS versions) - process them all
        getSolutionPaths(this.location).forEach(function (solutionPath) {
            var solText = fs.readFileSync(solutionPath, {encoding: "utf8"});

            // Insert a project dependency into each jsproj in the solution.
            var jsProjectFound = false;
            solText = solText.replace(JsProjectRegEx, function (match) {
                jsProjectFound = true;
                return match + preInsertText;
            });

            if (!jsProjectFound) {
                throw new Error("no jsproj found in solution");
            }

            // Add the project after existing projects. Note that this fairly simplistic check should be fine, since the last
            // EndProject in the file should actually be an EndProject (and not an EndProjectSection, for example).
            var pos = solText.lastIndexOf("EndProject");
            if (pos === -1) {
                throw new Error("no EndProject found in solution");
            }
            pos += 10; // Move pos to the end of EndProject text
            solText = solText.slice(0, pos) + postInsertText + solText.slice(pos);

            fs.writeFileSync(solutionPath, solText, {encoding: "utf8"});
        });

        // Add the ItemGroup/ProjectReference to the cordova project :
        // <ItemGroup><ProjectReference Include="blahblah.csproj"/></ItemGroup>
        var item = new et.Element('ItemGroup');
        var projRef = new et.Element('ProjectReference');
        projRef.attrib.Include = relative_path;
        item.append(projRef);
        this.xml.getroot().append(item);
    },
Example #5
0
    addSDKRef:function(incText) {
        var item_group = new et.Element('ItemGroup');
        var elem = new et.Element('SDKReference');
        elem.attrib.Include = incText;

        item_group.append(elem);
        this.xml.getroot().append(item_group);
    },
Example #6
0
        self.sharedStrings.forEach(function(string) {
            var si = new etree.Element("si"),
                t  = new etree.Element("t");

            t.text = string;
            si.append(t);
            root.append(si);
        });
Example #7
0
    addProjectReference:function(relative_path) {
        events.emit('verbose','adding project reference to ' + relative_path);

        relative_path = relative_path.split('/').join('\\');
        // read the solution path from the base directory
        var solutionPath = shell.ls(path.join(path.dirname(this.location),"*.sln"))[0];// TODO:error handling
        // note we may not have a solution, in which case just add a project reference, I guess ..
        // get the project extension to figure out project type
        var projectExt = path.extname(relative_path);

        var pluginProjectXML = xml_helpers.parseElementtreeSync(relative_path);
        // find the guid + name of the referenced project
        var projectGuid = pluginProjectXML.find("PropertyGroup/ProjectGuid").text;
        var projName = pluginProjectXML.find("PropertyGroup/ProjectName").text;

        var preInsertText = "ProjectSection(ProjectDependencies) = postProject\n\r" +
                             projectGuid + "=" + projectGuid + "\n\r" +
                            "EndProjectSection\n\r";

        // read in the solution file
        var solText = fs.readFileSync(solutionPath,{encoding:"utf8"});
        var splitText = solText.split("EndProject");
        if(splitText.length != 2) {
            throw new Error("too many projects in solution.");
        }

        var projectTypeGuid = null;
        if(projectExt == ".vcxproj") {
            projectTypeGuid = WinCplusplusProjectTypeGUID;
        }
        else if(projectExt == ".csproj") {
            projectTypeGuid = WinCSharpProjectTypeGUID;
        }

        if(!projectTypeGuid) {
            throw new Error("unrecognized project type");
        }

        var postInsertText = 'Project("' + projectTypeGuid + '") = "' +
                         projName + '", "' + relative_path + '",' +
                        '"' + projectGuid + '"\n\r EndProject\n\r';

        solText = splitText[0] + preInsertText + "EndProject\n\r" + postInsertText + splitText[1];
        fs.writeFileSync(solutionPath,solText,{encoding:"utf8"});


        // Add the ItemGroup/ProjectReference to the cordova project :
        // <ItemGroup><ProjectReference Include="blahblah.csproj"/></ItemGroup>
        var item = new et.Element('ItemGroup');

        var projRef = new et.Element('ProjectReference');
            projRef.attrib.Include = relative_path;
            item.append(projRef);
        this.xml.getroot().append(item);

    },
Example #8
0
    addSourceFile:function(relative_path) {
        relative_path = relative_path.split('/').join('\\');
        // make ItemGroup to hold file.
        var item = new et.Element('ItemGroup');

        var content = new et.Element('Content');
            content.attrib.Include = relative_path;
            item.append(content);
        this.xml.getroot().append(item);
    },
Example #9
0
function cloneNode(original, deep) {
    var newOne = new ET.Element(original.tag, original.attrib);
    if (deep) {
        for (var i = 0,ch = original._children,l = ch.length; i < l; i++) {
            newOne.append(cloneNode(ch[i], true));
        }
    }
    else {
        newOne.text = original.text;
    }
    return newOne;
}
Example #10
0
function replaceWithChildren(who, whoparent, index, datas) {
    var replacer = new ET.Element("xsl:done"),
        ch = who._children;
    for (var i = 0; i < ch.length; i++) {
        var child = ch[i];
        var clone = cloneNode(child, true);
        replacer.append(clone);
        build(replacer, clone, i, datas);

    }
    whoparent.remove(null, who);
    whoparent.setSlice(0,1, replacer._children);
}
Example #11
0
        relative_path.forEach(function(filePath) {
            filePath = filePath.split('/').join('\\');

            var content = new et.Element('Content');
            content.attrib.Include = filePath;
            item.append(content);
        });
Example #12
0
        relative_path.forEach(function(filePath) {
            filePath = filePath.split('/').join('\\');
            filePath = this.isUniversalWindowsApp ? '$(MSBuildThisFileDirectory)' + filePath : filePath;

            var content = new et.Element('Content');
            content.attrib.Include = filePath;
            item.append(content);
        });
Example #13
0
module.exports.updateBuildConfig = function (buildConfig) {
    var projectRoot = path.join(__dirname, '../..');
    var config = new ConfigParser(path.join(projectRoot, 'config.xml'));

    // if no buildConfig is provided dont do anything
    buildConfig = buildConfig || {};

    // Merge buildConfig with config
    for (var attr in buildConfig) {
        config[attr] = buildConfig[attr];
    }

    var root = new et.Element('Project');
    root.set('xmlns', 'http://schemas.microsoft.com/developer/msbuild/2003');
    var buildConfigXML = new et.ElementTree(root);
    var propertyGroup = new et.Element('PropertyGroup');
    var itemGroup = new et.Element('ItemGroup');

    // Append PropertyGroup and ItemGroup
    buildConfigXML.getroot().append(propertyGroup);
    buildConfigXML.getroot().append(itemGroup);

    // packageCertificateKeyFile - defaults to 'CordovaApp_TemporaryKey.pfx'
    var packageCertificateKeyFile = config.packageCertificateKeyFile || 'CordovaApp_TemporaryKey.pfx';

    if (config.packageCertificateKeyFile) {
        // Convert packageCertificateKeyFile from absolute to relative path
        packageCertificateKeyFile = path.relative(projectRoot, packageCertificateKeyFile);
    }

    var certificatePropertyElement = new et.Element('PackageCertificateKeyFile');
    certificatePropertyElement.text = packageCertificateKeyFile;
    propertyGroup.append(certificatePropertyElement);

    var certificateItemElement = new et.Element('None', { 'Include': packageCertificateKeyFile });
    itemGroup.append(certificateItemElement);

    // packageThumbprint
    if (config.packageThumbprint) {
        var thumbprintElement = new et.Element('PackageCertificateThumbprint');
        thumbprintElement.text = config.packageThumbprint;
        propertyGroup.append(thumbprintElement);
    }

    // DefaultLanguage - defaults to 'en-US'
    var defaultLocale = config.defaultLocale() || 'en-US';
    var defaultLocaleElement = new et.Element('DefaultLanguage');
    defaultLocaleElement.text = defaultLocale;
    propertyGroup.append(defaultLocaleElement);

    var buildConfigFileName = buildConfig.buildType === 'release' ?
        path.join(projectRoot, 'CordovaAppRelease.projitems') :
        path.join(projectRoot, 'CordovaAppDebug.projitems');

    fs.writeFileSync(buildConfigFileName, TEMPLATE + buildConfigXML.write({indent: 2, xml_declaration: false}), 'utf-8');
};
Example #14
0
        relative_path.forEach(function (filePath) {
            // filePath is never used to find the actual file - it determines what we write to the project file, and so
            // should always be in Windows format.
            filePath = filePath.split('/').join('\\');

            var content = new et.Element('Content');
            content.attrib.Include = filePath;
            item.append(content);
        });
Example #15
0
    addSourceFile:function(relative_path) {
        // we allow multiple paths to be passed at once as array so that
        // we don't create separate ItemGroup for each source file, CB-6874
        if (!(relative_path instanceof Array)) {
            relative_path = [relative_path];
        }
        var compile;
        // make ItemGroup to hold file.
        var item = new et.Element('ItemGroup');
        var me = this;
        relative_path.forEach(function(filePath) {

            filePath = filePath.split('/').join('\\');
            var extName = path.extname(filePath);
            // check if it's a .xaml page
            if(extName == '.xaml') {
                var page = new et.Element('Page');
                var sub_type = new et.Element('SubType');

                sub_type.text = 'Designer';
                page.append(sub_type);
                page.attrib.Include = filePath;

                var gen = new et.Element('Generator');
                gen.text = 'MSBuild:Compile';
                page.append(gen);
                var item_groups = me.xml.findall('ItemGroup');
                if(item_groups.length === 0) {
                    item.append(page);
                } else {
                    item_groups[0].append(page);
                }

            }
            else if (extName == '.cs') {
                compile = new et.Element('Compile');
                compile.attrib.Include = filePath;
                // check if it's a .xaml.cs page that would depend on a .xaml of the same name
                if (filePath.indexOf('.xaml.cs', filePath.length - 8) > -1) {
                    var dep = new et.Element('DependentUpon');
                    var parts = filePath.split('\\');
                    var xaml_file = parts[parts.length - 1].substr(0, parts[parts.length - 1].length - 3); // Benn, really !?
                    dep.text = xaml_file;
                    compile.append(dep);
                }
                item.append(compile);
            }
            else { // otherwise add it normally
                compile = new et.Element('Content');
                compile.attrib.Include = filePath;
                item.append(compile);
            }
        });
        this.xml.getroot().append(item);
    },
Example #16
0
    path.forEach(function (elementName) {
        var element = new et.Element(elementName);
        if (lastElement) {
            element.append(lastElement);
        } else {
            element.attrib.Include = incText;

            var condition = createConditionAttrib(targetConditions);
            if (condition) {
                element.attrib.Condition = condition;
            }

            if (children) {
                children.forEach(function (child) {
                    element.append(child);
                });
            }
        }
        lastElement = element;
    });
Example #17
0
    addSourceFile:function(relative_path) {
        relative_path = relative_path.split('/').join('\\');
        // make ItemGroup to hold file.
        var item = new et.Element('ItemGroup');

        var extName = path.extname(relative_path);
        // check if it's a .xaml page
        if(extName == ".xaml") {
            var page = new et.Element('Page');
            var sub_type = new et.Element('SubType');

            sub_type.text = "Designer";
            page.append(sub_type);
            page.attrib.Include = relative_path;

            var gen = new et.Element('Generator');
            gen.text = "MSBuild:Compile";
            page.append(gen);

            var item_groups = this.xml.findall('ItemGroup');
            if(item_groups.length == 0) {
                item.append(page);
            } else {
                item_groups[0].append(page);
            }
        }
        else if (extName == ".cs") {
            var compile = new et.Element('Compile');
            compile.attrib.Include = relative_path;
            // check if it's a .xaml.cs page that would depend on a .xaml of the same name
            if (relative_path.indexOf('.xaml.cs', relative_path.length - 8) > -1) {
                var dep = new et.Element('DependentUpon');
                var parts = relative_path.split('\\');
                var xaml_file = parts[parts.length - 1].substr(0, parts[parts.length - 1].length - 3); // Benn, really !?
                dep.text = xaml_file;
                compile.append(dep);
            }
            item.append(compile);
        }
        else { // otherwise add it normally
            var compile = new et.Element('Content');
            compile.attrib.Include = relative_path;
            item.append(compile);
        }
        this.xml.getroot().append(item);
    },
Example #18
0
    addReference:function(relPath) {
        var item = new et.Element('ItemGroup');
        var extName = path.extname(relPath);

        var elem = new et.Element('Reference');
        // add dll file name
        elem.attrib.Include = path.basename(relPath, extName);
        // add hint path with full path
        var hint_path = new et.Element('HintPath');
        hint_path.text = relPath;
        elem.append(hint_path);

        if(extName == '.winmd') {
            var mdFileTag = new et.Element('IsWinMDFile');
            mdFileTag.text = 'true';
            elem.append(mdFileTag);
        }

        item.append(elem);

        this.xml.getroot().append(item);
    },
Example #19
0
 addFeature: function (name, params){
   var el = new et.Element('feature');
     el.attrib.name = name;
     if(params){
       params.forEach(function(param){
         var p = new et.Element('param');
         p.attrib.name = param.name;
         p.attrib.value = param.value;
         el.append(p);
       });
     }
     this.doc.getroot().append(el);
 },
Example #20
0
    update_csproj:function() {
        var raw = fs.readFileSync(this.csproj_path, 'utf-8');
        var cleaned = raw.replace(/^\uFEFF/i, '');
        var csproj_xml = new et.ElementTree(et.XML(cleaned));
        // remove any previous references to the www files
        var item_groups = csproj_xml.findall('ItemGroup');
        for (var i = 0, l = item_groups.length; i < l; i++) {
            var group = item_groups[i];
            var files = group.findall('Content');
            for (var j = 0, k = files.length; j < k; j++) {
                var file = files[j];
                if (file.attrib.Include.substr(0, 3) == 'www' && file.attrib.Include.indexOf('cordova.js') < 0) {
                    // remove file reference
                    group.remove(0, file);
                    // remove ItemGroup if empty
                    var new_group = group.findall('Content');
                    if(new_group.length < 1) {
                        csproj_xml.getroot().remove(0, group);
                    }
                }
            }
        }

        // now add all www references back in from the root www folder
        var project_root = util.isCordova(this.wp7_proj_dir);
        var www_files = this.folder_contents('www', util.projectWww(project_root));
        for(file in www_files) {
            var item = new et.Element('ItemGroup');
            var content = new et.Element('Content');
            content.attrib.Include = www_files[file];
            item.append(content);
            csproj_xml.getroot().append(item);
        }
        // save file
        fs.writeFileSync(this.csproj_path, csproj_xml.write({indent:4}), 'utf-8');
    },
Example #21
0
 addPlugin: function (attributes, variables) {
     if (!attributes && !attributes.name) return;
     var el = new et.Element('plugin');
     el.attrib.name = attributes.name;
     if (attributes.spec) {
         el.attrib.spec = attributes.spec;
     }
     if (variables) {
         variables.forEach(function (variable) {
             var v = new et.Element('variable');
             v.attrib.name = variable.name;
             v.attrib.value = variable.value;
             el.append(v);
         });
     }
     this.doc.getroot().append(el);
 },
Example #22
0
        relative_path.forEach(function(filePath) {

            filePath = filePath.split('/').join('\\');
            var extName = path.extname(filePath);
            // check if it's a .xaml page
            if(extName == '.xaml') {
                var page = new et.Element('Page');
                var sub_type = new et.Element('SubType');

                sub_type.text = 'Designer';
                page.append(sub_type);
                page.attrib.Include = filePath;

                var gen = new et.Element('Generator');
                gen.text = 'MSBuild:Compile';
                page.append(gen);
                var item_groups = me.xml.findall('ItemGroup');
                if(item_groups.length === 0) {
                    item.append(page);
                } else {
                    item_groups[0].append(page);
                }

            }
            else if (extName == '.cs') {
                compile = new et.Element('Compile');
                compile.attrib.Include = filePath;
                // check if it's a .xaml.cs page that would depend on a .xaml of the same name
                if (filePath.indexOf('.xaml.cs', filePath.length - 8) > -1) {
                    var dep = new et.Element('DependentUpon');
                    var parts = filePath.split('\\');
                    var xaml_file = parts[parts.length - 1].substr(0, parts[parts.length - 1].length - 3); // Benn, really !?
                    dep.text = xaml_file;
                    compile.append(dep);
                }
                item.append(compile);
            }
            else { // otherwise add it normally
                compile = new et.Element('Content');
                compile.attrib.Include = filePath;
                item.append(compile);
            }
        });
Example #23
0
    addSourceFile:function(relative_path) {
        // we allow multiple paths to be passed at once as array so that
        // we don't create separate ItemGroup for each source file, CB-6874
        if (!(relative_path instanceof Array)) {
            relative_path = [relative_path];
        }
        // make ItemGroup to hold file.
        var item = new et.Element('ItemGroup');

        relative_path.forEach(function(filePath) {
            filePath = filePath.split('/').join('\\');

            var content = new et.Element('Content');
            content.attrib.Include = filePath;
            item.append(content);
        });
        this.xml.getroot().append(item);
    },
    result.setAccessRules = function (rules) {
        var appUriRules = application.find('./uap:ApplicationContentUriRules');
        if (appUriRules) {
            application.remove(appUriRules);
        }

        // No rules defined
        if (!rules || rules.length === 0) {
            return;
        }

        appUriRules = new et.Element('uap:ApplicationContentUriRules');
        application.append(appUriRules);

        rules.forEach(function(rule) {
            appUriRules.append(new et.Element('uap:Rule', { Match: rule, Type: 'include', WindowsRuntimeAccess: 'all' }));
        });

        return this;
    };
        setAccessRules: function (rules) {
            var appUriRules = application.find('ApplicationContentUriRules');
            if (appUriRules) {
                application.remove(appUriRules);
            }

            // No rules defined
            if (!rules || rules.length === 0) {
                return;
            }

            appUriRules = new et.Element('ApplicationContentUriRules');
            application.append(appUriRules);

            rules.forEach(function(rule) {
                appUriRules.append(new et.Element('Rule', {Match: rule, Type: 'include'}));
            });

            return this;
        }
Example #26
0
    addSourceFile: function (relative_path) {
        // we allow multiple paths to be passed at once as array so that
        // we don't create separate ItemGroup for each source file, CB-6874
        if (!(relative_path instanceof Array)) {
            relative_path = [relative_path];
        }

        // make ItemGroup to hold file.
        var item = new et.Element('ItemGroup');

        relative_path.forEach(function (filePath) {
            // filePath is never used to find the actual file - it determines what we write to the project file, and so
            // should always be in Windows format.
            filePath = filePath.split('/').join('\\');

            var content = new et.Element('Content');
            content.attrib.Include = filePath;
            item.append(content);
        });

        this.appendToRoot(item);
    },
Example #27
0
    addPlugin: function (attributes, variables) {
        if (!attributes && !attributes.name) return;
        var el = new et.Element('plugin');
        el.attrib.name = attributes.name;
        if (attributes.spec) {
            el.attrib.spec = attributes.spec;
        }

        // support arbitrary object as variables source
        if (variables && typeof variables === 'object' && !Array.isArray(variables)) {
            variables = Object.keys(variables)
            .map(function (variableName) {
                return {name: variableName, value: variables[variableName]};
            });
        }

        if (variables) {
            variables.forEach(function (variable) {
                el.append(new et.Element('variable', { name: variable.name, value: variable.value }));
            });
        }
        this.doc.getroot().append(el);
    },
Example #28
0
 variables.forEach(function (variable) {
     el.append(new et.Element('variable', { name: variable.name, value: variable.value }));
 });
Example #29
0
 children.forEach(function (child) {
     element.append(child);
 });
Example #30
0
 params.forEach(function(param){
   var p = new et.Element('param');
   p.attrib.name = param.name;
   p.attrib.value = param.value;
   el.append(p);
 });