1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/big.boot-generator-jhipster

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
util.js 1.7 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
big.boot Отправлено 19.06.2014 09:20 ba67bda
'use strict';
var path = require('path');
var fs = require('fs');
module.exports = {
rewrite: rewrite,
rewriteFile: rewriteFile,
classify: classify
};
function rewriteFile(args) {
args.path = args.path || process.cwd();
var fullPath = path.join(args.path, args.file);
args.haystack = fs.readFileSync(fullPath, 'utf8');
var body = rewrite(args);
fs.writeFileSync(fullPath, body);
}
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}
function rewrite(args) {
// check if splicable is already in the body text
var re = new RegExp(args.splicable.map(function(line) {
return '\s*' + escapeRegExp(line);
})
.join('\n'));
if (re.test(args.haystack)) {
return args.haystack;
}
var lines = args.haystack.split('\n');
var otherwiseLineIndex = 0;
lines.forEach(function(line, i) {
if (line.indexOf(args.needle) !== -1) {
otherwiseLineIndex = i;
}
});
var spaces = 0;
while (lines[otherwiseLineIndex].charAt(spaces) === ' ') {
spaces += 1;
}
var spaceStr = '';
while ((spaces -= 1) >= 0) {
spaceStr += ' ';
}
lines.splice(otherwiseLineIndex, 0, args.splicable.map(function(line) {
return spaceStr + line;
})
.join('\n'));
return lines.join('\n');
}
// _.classify uses _.titleize which lowercase the string,
// so if the user chooses a proper ClassName it will not rename properly
function classify(string) {
string = string.replace(/[\W_](\w)/g, function (match) { return ' ' + match[1].toUpperCase(); }).replace(/\s/g, '');
return string.charAt(0).toUpperCase() + string.slice(1);
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/big.boot-generator-jhipster.git
git@api.gitlife.ru:oschina-mirror/big.boot-generator-jhipster.git
oschina-mirror
big.boot-generator-jhipster
big.boot-generator-jhipster
master