A
A
Andrey Khokhlov2015-03-31 08:17:36
XML
Andrey Khokhlov, 2015-03-31 08:17:36

How to create xml using grunt/gulp?

The xml file contains the ide config (paths for ftp deployment).
It lies in the .idea folder, which has no place in the repository.
For each project, it's too lazy to set up paths every time.
Since grunt is used, the idea arose to generate this file with its help.
Just copying is not suitable, since several values ​​need to be changed (the server name in the main).
Is there a plugin for grunt (or gulp) that allows you to create an xml file according to a certain template, substituting the values ​​of variables from the config?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-03-31
@andrhohlov

For grunt you can write your own , it has a templating engine .
Something like this (not tested):

grunt.registerTask('createXml', 'Creates XML by template', function () {
    var template = grunt.file.read(this.data.tpl);
    var xml = grunt.template.process(template, this.data.vars);
    grunt.file.write(this.target, xml);
});

// пример конфига
grunt.initConfig({
    deployPath: 'ftp://example.ftp/',
    
    createXml: {
        '.idea/conf.xml': {
            tpl: 'path/to/template.xml',
            vars: {
                var1: '<%= deployPath %>'
            }
        }
    }
});

For gulp, judging by how it's being praised, it should be even easier :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question