cpx icon indicating copy to clipboard operation
cpx copied to clipboard

Question: How to create a transform that change the file extension

Open mictian opened this issue 9 years ago • 3 comments

First of all, awesome tool!

I am trying to create a transform module that convert all '.tpl' files into '.js'. Could you please provide to me some guidelines or point me out with some documentation/examples?

Thanks in advance.

mictian avatar Apr 10 '16 19:04 mictian

I'm sorry for this late response.

Currently, we can check filenames inside conversion plugins. For example:

var path = require("path");
var PassThrough = require("stream").PassThrough;
var through = require("through");

module.exports = function convert(filename, args) {
    if (path.extname(filename) === ".tpl") {
        return through(
            function write(chunk) {
                this.queue(doSomeConvert(chunk));
            },
            function end() {
                this.queue(null);
            }
        );
    }
    return new PassThrough();
};

mysticatea avatar Apr 15 '16 12:04 mysticatea

Hi don't worry we all have to work.

First of all, thank you for your answer. Regarding your code. Does it actually change the file extension or only select those files that are '.tpl' ? Perhaps I'm doing something wrong but it doesn't work for me.

Thanks.

mictian avatar Apr 18 '16 22:04 mictian

Ah! Unfortunately, this tool does not provide the feature to change the file name in a copy, now. That's an interesting feature.

mysticatea avatar Apr 19 '16 00:04 mysticatea