Skip to content

Instantly share code, notes, and snippets.

@ekoneko
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekoneko/04961fe28fd9345bb784 to your computer and use it in GitHub Desktop.
Save ekoneko/04961fe28fd9345bb784 to your computer and use it in GitHub Desktop.
grunt任务
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