futurechan / gulp-asset-transform

13 stars 3 forks source link

TypeError: undefined is not a function #13

Open danilo-valente opened 9 years ago

danilo-valente commented 9 years ago

AT will throw a TypeError: undefined is not a function when none of tagTemplate and tag are not defined and the block is missing the filename:

<!-- at:js -->
<script src="js/js1.js"></script>
<script src="js/js2.js"></script>
<!-- at:end -->
at({
    js: {
        tasks: ['concat']
    }
});
futurechan commented 9 years ago

This looks good, but from #12 I think we should support a scenario that does not use an output file name or tag template.

danilo-valente commented 9 years ago

No problem. How should AT work on this scenario?

futurechan commented 9 years ago

I'm not quite sure, but here are a few ideas:

1) => if no output destination specified, use relative path from asset 2) => if a directory is specified, use that output folder instead of relative path from asset 3) => if a full path is specified, rename file to new name

Potentially, this will allow one or more assets within a directive to be processed and output correctly when concat is not used. There are still a couple of weird cases though:

1) If scenario 1) or 2) occur with concat and no output filename is specified, this could be a problem. Perhaps we should use a hash as the default output filename, and replace it with whatever name they provide.

2) If scenario 3) were to occur with multiple assets and without concat, we could use the hash too.

Otherwise, I guess we need to throw an exception. Thoughts?

danilo-valente commented 9 years ago

I like the idea of hashing the file contents, we could change the getTagTemplate to calculate and return it. Also, what should be the tag template if neither of tagTemplate or tag options are provided? Should we infer it from the file extension?

futurechan commented 9 years ago

Yeah, I think so. That's how the "implicit tag" works today. I'm open to suggestions though.

danilo-valente commented 9 years ago

Well, I can't think of a better solution. Are you going to implement it yourself, or can I take it?

futurechan commented 9 years ago

Go for it!

danilo-valente commented 9 years ago

@futurechan I'm sorry, I've been busy these days and I can't find some time to implement these features. Can you do that?

futurechan commented 9 years ago

@danilo-valente no worries. I've been slammed lately too. I'll try to get to it.