javascript - Dynamic file mapping with relative destination -
this generic question dynamic file mapping grunt.js, example purpose, i'll trying build coffee files in project dynamic structure :
here, can have multiple (dynamic) target folders different depth. finding coffee files remain easy, match **/coffee/*.coffee
anytime.
what i'm trying achieve, making dest property relative matched coffee file :
- find
**/coffee/*.coffee
- compile
../js/*.js
instead of making relative project folder (gruntfile).
coffee: { compile: { files: [ { expand: true, src: ['**/coffee/*.coffee'], dest: '../js/', // won't work ! wish :) ext: '.js' } ] } }
how achieve ?
i don't think that's idea. sounds each target should perhaps repository of own. if ignore that, you'll have other problems, such difficulty telling target , non-target folders apart. example, current pattern potentially match coffeescript files in node_modules/
directory.
i find weird targets have differing folder structures (i.e. coffee/
, js/
not on same level). again, sounds they're different projects, , should have own repos.
that being said, if really, have that, there few ways accomplish this.
first, "normal" way specify multiple targets manually. i'll using gruntfile.coffee
syntax here:
coffee: target1: expand: true cwd: 'target1/coffee' src: '**/*.coffee' dest: 'target1/js' ext: '.js' targetx: expand: true cwd: 'targetx/some-folder/coffee' src: '**/*.coffee' dest: 'targetx/some-folder/js' ext: '.js'
however if you're need have dynamic targets, , don't mind blacklisting unwanted folders, perhaps try this:
coffee: -> targets = {} target in grunt.file.expand '**/coffee', '!node_modules/**' targets[target.split('/', 1)[0]] = expand: true cwd: target src: '**/*.coffee' dest: target + '/../js' ext: '.js' targets
this same previous snippet, added uncertainty. perhaps rid of blacklist having targets/
folder contain targets, , using targets/**/coffee
pattern.
alternatively use grunt.file.expandmapping
:
coffee: compile: files: grunt.file.expandmapping ['**/coffee/**/*.coffee', '!node_modules/**'], '', expand: true ext: '.js' rename: (base, src) -> src.replace '/coffee/', '/js/'
while may kind of simple (and ugly), it's slowest option , feels wrong.
so there. it's possible, not want.
Comments
Post a Comment