File grunt将文件树注入javascript对象
有没有一种方法可以使用Grunt将文件树的结构读取到JSON对象中,然后将其注入javascript文件中 例如,假设我的项目有一个结构为File grunt将文件树注入javascript对象,file,tree,gruntjs,inject,File,Tree,Gruntjs,Inject,有没有一种方法可以使用Grunt将文件树的结构读取到JSON对象中,然后将其注入javascript文件中 例如,假设我的项目有一个结构为 Assets ├╴docs │ └╴doc1.txt │ └╴doc2.txt │ ├╴effects │ └╴sound.mp3 我将能够注入一些.js文件 Assets = { docs : ['doc1.txt', 'd
Assets
├╴docs
│ └╴doc1.txt
│ └╴doc2.txt
│
├╴effects
│ └╴sound.mp3
我将能够注入一些.js文件
Assets = {
docs : ['doc1.txt', 'doc2.txt.'],
effects: [sound.mp3]
}
其中初始资产等于一些while卡,如“此处”。确定。我把这个过程分为两步 首先,我使用grunt tree模块构建文件系统的JSON表示。我将JSON文件保存到.tmp文件夹中的临时文件中
tree: {
options: {
},
soundFileTree: {
files: [
{
src: ['<%= yeoman.client %>/assets/audio/'],
dest: '.tmp/soundTree.json',
}
],
},
},
injector: {
// Inject JSON file into client and server files
soundFileTree: {
options: {
transform: function(filePath) {
var soundTreeJSONString = require(filePath); //you might have to adjust the files path
return JSON.stringify(soundTreeJSONString);
},
starttag: '/* injector:soundFileTree */',
endtag: '/* endinjector */',
},
files: {
'<%= yeoman.client %>/treeTarget.js': ['.tmp/soundTree.json'],
},
},
...
}
var myVar=
/* injector:soundFileTree */
{"boxing":{"bell":"boxing/bell.wav","warning":"boxing/warning.wav"}}
/* endinjector */
;