[Templates] Create variable names by template URL

This commit is contained in:
Victor Woeltjen 2016-02-26 12:17:57 -08:00
parent 4666292907
commit 930fed83e8

View File

@ -29,18 +29,29 @@ var glob = require('glob'),
path = require('path'), path = require('path'),
_ = require('lodash'); _ = require('lodash');
function toTemplateName(templateUrl) {
var parts = templateUrl.split('/');
return _.camelCase(parts[parts.length - 1].replace(".html", "")) +
"Template";
}
function findTemplateURLs(sourceCode) { function findTemplateURLs(sourceCode) {
return sourceCode.split('\n') return sourceCode.split('\n')
.map(_.trim) .map(_.trim)
.filter(function (line) { .filter(function (line) {
return line.indexOf("templateUrl") !== -1; return line.indexOf("templateUrl") !== -1;
})
.map(function (line) {
return _.trim(line.split(":")[1], "\", ");
}); });
} }
function migrate(file) { function migrate(file) {
var sourceCode = fs.readFileSync(file, 'utf8'), var sourceCode = fs.readFileSync(file, 'utf8'),
templateUrls = findTemplateURLs(sourceCode); templateUrls = findTemplateURLs(sourceCode);
console.log(templateUrls); templateUrls.forEach(function (templateUrl) {
console.log(templateUrl, toTemplateName(templateUrl));
});
} }
glob('platform/**/bundle.js', {}, function (err, files) { glob('platform/**/bundle.js', {}, function (err, files) {