javascript - copy JSON files from one dir to another -


in web project have following directory structure

|- target |- foo |- bar |- baz 

i'm trying write grunt task copy json files target directory directory name matches parameter provided build

grunt.registertask('flavor', function(srcdir) {   var = './' + srcdir + '/*.json';   var dest = './target/';    grunt.file.expand(from).foreach(function(src) {     grunt.file.copy(src, dest);   });    }); 

but when call

grunt flavor:foo 

i error

warning: unable write "./target/" file (error code: eisdir). use --force continue.

as @danielapt mentioned, should use grunt-contrib-copy. build on answer regarding on comment build-parameters, can them task via grunt-option.

way one: running different target

 grunt.initconfig({     copy: {         foo: {             files: [                 {                     'expand': 'true',                     'cwd': 'foo/',                     'src': [**],                     'dest': 'dist/en'                 }              ]           },         bar: {             files: [/**/]         },         baz: {             files: [/**/]         }     } });  var target = grunt.option("target") || "foo";  grunt.registertask("default", ["copy:" + target]);  // run grunt --target=foo 

way 2: arbituary folder templating:

var target = grunt.option("target") || "foo";  grunt.initconfig({     target: target,     copy: {         default_target: {             files: [                 {                     'expand': 'true',                     'cwd': '<%= target %>/',                     'src': [**],                     'dest': 'dist/en'                 }              ]         },     } });  grunt.registertask("default", ["copy"]);  // run grunt --target=anyfolderhere 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -