Last active
August 29, 2015 14:06
-
-
Save ekoneko/04961fe28fd9345bb784 to your computer and use it in GitHub Desktop.
grunt任务
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (function () { | |
var fs = require('fs'), | |
tplReplace, | |
stateTpl = " .state('{{stateName}}', {url: '/{{stateRoute}}',templateUrl: 'tpl/{{stateFile}}'})"; | |
tplReplace = function (template, data) { | |
return template.replace(/\{\{(\w+)\}\}/g, function () { | |
return data[arguments[1]]; | |
}); | |
}; | |
return { | |
app: { | |
src: ['./assets/js/init/app.js'], | |
dest: './assets/js/app.js', | |
options: { | |
process: function (content) { | |
var stateData, tpls; | |
tpls = fs.readdirSync('./assets/tpl').filter(function (s) { | |
return s.match(/.html/); | |
}); | |
stateData = []; | |
tpls.forEach(function (tpl) { | |
var stateName, stateRoute; | |
stateName = tpl.split('.')[0].replace(/_/g, '.'); | |
stateRoute = stateName.split('.').pop(); | |
stateData.push(tplReplace(stateTpl, { | |
stateName: stateName, | |
stateRoute: stateRoute, | |
stateFile: tpl | |
})); | |
}); | |
return tplReplace(content, {state: stateData.join("\n")}); | |
} | |
} | |
}, | |
prod: { | |
files: [{ | |
expand: true, | |
cwd: './assets', | |
src: ['**/*.!(coffee|less)'], | |
dest: '.tmp/public' | |
}] | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment