function cleanupOldFiles(generator, javaDir, testDir) { if (generator.isJhipsterVersionLessThan('3.2.0')) { // removeFile and removeFolder methods should be called here for files and folders to cleanup generator.removeFile(`${ANGULAR_DIR}components/form/uib-pager.config.js`); generator.removeFile(`${ANGULAR_DIR}components/form/uib-pagination.config.js`); } }
n/a
function cleanupOldServerFiles(generator, javaDir, testDir) { if (generator.isJhipsterVersionLessThan('3.5.0')) { generator.removeFile(`${javaDir}domain/util/JSR310DateTimeSerializer.java`); generator.removeFile(`${javaDir}domain/util/JSR310LocalDateDeserializer.java`); } if (generator.isJhipsterVersionLessThan('3.6.0')) { generator.removeFile(`${javaDir}config/HerokuDatabaseConfiguration.java`); } if (generator.isJhipsterVersionLessThan('3.8.1')) { generator.removeFile(`${javaDir}config/JacksonConfiguration.java`); } if (generator.isJhipsterVersionLessThan('3.10.0')) { generator.removeFile(`${javaDir}config/CloudMongoDbConfiguration.java`); generator.removeFile(`${javaDir}security/CustomAccessDeniedHandler.java`); generator.removeFile(`${javaDir}web/filter/CsrfCookieGeneratorFilter.java`); } if (generator.isJhipsterVersionLessThan('3.11.0')) { generator.removeFile(`${CLIENT_MAIN_SRC_DIR}app/layouts/navbar/active-link.directive.js`); } if (generator.isJhipsterVersionLessThan('3.12.0')) { generator.removeFile(`${javaDir}config/hazelcast/HazelcastCacheRegionFactory.java`); generator.removeFile(`${javaDir}config/hazelcast/package-info.java`); } if (generator.isJhipsterVersionLessThan('4.0.0')) { generator.removeFile(`${javaDir}async/ExceptionHandlingAsyncTaskExecutor.java`); generator.removeFile(`${javaDir}async/package-info.java`); generator.removeFile(`${javaDir}config/jHipsterProperties.java`); generator.removeFile(`${javaDir}config/LoadBalancedResourceDetails.java`); generator.removeFile(`${javaDir}config/ElasticSearchConfiguration.java`); generator.removeFile(`${javaDir}config/apidoc/package-info.java`); generator.removeFile(`${javaDir}config/apidoc/PageableParameterBuilderPlugin.java`); generator.removeFile(`${javaDir}config/apidoc/SwaggerConfiguration.java`); generator.removeFile(`${javaDir}config/jcache/SpringCacheRegionFactory.java`); generator.removeFile(`${javaDir}config/jcache/SpringCacheRegionFactory.java`); generator.removeFile(`${javaDir}config/liquibase/AsyncSpringLiquibase.java`); generator.removeFile(`${javaDir}config/liquibase/package-info.java`); generator.removeFile(`${javaDir}config/locale/AngularCookieLocaleResolver.java`); generator.removeFile(`${javaDir}config/locale/package-info.java`); generator.removeFile(`${javaDir}domain/util/FixedH2Dialect.java`); generator.removeFile(`${javaDir}domain/util/FixedPostgreSQL82Dialect`); generator.removeFile(`${javaDir}domain/util/JSR310DateConverters.java`); generator.removeFile(`${javaDir}domain/util/JSR310PersistenceConverters.java`); generator.removeFile(`${javaDir}security/AjaxAuthenticationFailureHandler.java`); generator.removeFile(`${javaDir}security/AjaxAuthenticationSuccessHandler.java`); generator.removeFile(`${javaDir}security/AjaxLogoutSuccessHandler.java`); generator.removeFile(`${javaDir}security/CustomPersistentRememberMeServices.java`); generator.removeFile(`${javaDir}security/Http401UnauthorizedEntryPoint.java`); generator.removeFile(`${javaDir}security/UserDetailsService.java`); generator.removeFile(`${javaDir}web/filter/CachingHttpHeadersFilter.java`); generator.removeFile(`${javaDir}web/filter/package-info.java`); } }
n/a
function classify(string) { string = string.replace(/[\W_](\w)/g, match => ` ${match[1].toUpperCase()}`).replace(/\s/g, ''); return string.charAt(0).toUpperCase() + string.slice(1); }
n/a
function copyWebResource(source, dest, regex, type, generator, opt = {}, template) { if (generator.enableTranslation) { generator.template(source, dest, generator, opt); } else { renderContent(source, generator, generator, opt, (body) => { body = body.replace(regex, ''); switch (type) { case 'html' : body = replacePlaceholders(body, generator); break; case 'js' : body = replaceTitle(body, generator); break; default: break; } generator.fs.write(dest, body); }); } }
...
regex = new RegExp([
/( (data-t|jhiT)ranslate="([a-zA-Z0-9 +{}'](\.)?)+")/, // data-translate or jhiTranslate
/( translate(-v|V)alues="\{([a-zA-Z]|\d|:|\{|\}|\[|\]|-|'|\s|\.)*?\}")/, // translate-values or translateValues
/( translate-compile)/, // translate-compile
/( translate-value-max="[0-9{}()|]*")/, // translate-value-max
].map(r => r.source).join('|'), 'g');
jhipsterUtils.copyWebResource(source, dest, regex, 'html', _this, opt,
template);
break;
case 'stripJs' :
regex = new RegExp([
/(,[\s]*(resolve):[\s]*[{][\s]*(translatePartialLoader)['a-zA-Z0-9$,(){.<%=\->;\s:[\]]*(;[\s]*\}\][\s]*\}))/, //
ng1 resolve block
/([\s]import\s\{\s?JhiLanguageService\s?\}\sfrom\s["|']ng-jhipster["|'];)/, // ng2 import jhiLanguageService
/(,?\s?JhiLanguageService,?\s?)/, // ng2 import jhiLanguageService
/(private\s[a-zA-Z0-9]*(L|l)anguageService\s?:\s?JhiLanguageService\s?,*[\s]*)/, // ng2 jhiLanguageService constructor
argument
...
function deepFind(obj, path, placeholder) { const paths = path.split('.'); let current = obj; if (placeholder) { // dirty fix for placeholders, the json files needs to be corrected paths[paths.length - 2] = `${paths[paths.length - 2]}.${paths[paths.length - 1]}`; paths.pop(); } for (let i = 0; i < paths.length; ++i) { if (current[paths[i]] === undefined) { return undefined; } current = current[paths[i]]; } return current; }
n/a
function getJavadoc(text, indentSize) { let javadoc = `${_.repeat(' ', indentSize)}/**`; const rows = text.split('\n'); for (let i = 0; i < rows.length; i++) { javadoc = `${javadoc}\n${_.repeat(' ', indentSize)} * ${rows[i]}`; } javadoc = `${javadoc}\n${_.repeat(' ', indentSize)} */`; return javadoc; }
...
}
getDefaultAppName() {
return (/^[a-zA-Z0-9_]+$/.test(path.basename(process.cwd()))) ? path.basename(process.cwd()) : 'jhipster';
}
formatAsClassJavadoc(text) {
return jhipsterUtils.getJavadoc(text, 0);
}
formatAsFieldJavadoc(text) {
return jhipsterUtils.getJavadoc(text, 4);
}
formatAsApiDescription(text) {
...
function renderContent(source, generator, context, options, cb) { ejs.renderFile(generator.templatePath(source), context, options, (err, res) => { if (!err) { cb(res); } else { generator.error(`Copying template ${source} failed. [${err}]`); } }); }
...
* @param {*} generator
* @param {*} options
* @param {*} context
*/
template(source, destination, generator, options = {}, context) {
const _this = generator || this;
const _context = context || _this;
jhipsterUtils.renderContent(source, _this, _context, options, (res) => {
_this.fs.write(_this.destinationPath(destination), res);
});
}
/**
* Utility function to copy files.
*
...
function replaceContent(args, generator) { args.path = args.path || process.cwd(); const fullPath = path.join(args.path, args.file); const re = args.regex ? new RegExp(args.pattern, 'g') : args.pattern; let body = generator.fs.read(fullPath); body = body.replace(re, args.content); generator.fs.write(fullPath, body); }
...
* @param {string} fullPath - path of the source file to rewrite
* @param {string} pattern - pattern to look for where content will be replaced
* @param {string} content - content to be written
* @param {string} regex - true if pattern is regex
*/
replaceContent(filePath, pattern, content, regex) {
try {
jhipsterUtils.replaceContent({
file: filePath,
pattern,
content,
regex
}, this);
} catch (e) {
this.log(chalk.yellow('\nUnable to find ') + filePath + chalk.yellow(' or missing required pattern. File
rewrite failed.\n') + e);
...
function rewrite(args) { // check if splicable is already in the body text const re = new RegExp(args.splicable.map(line => `\\s*${escapeRegExp(line)}`).join('\n')); if (re.test(args.haystack)) { return args.haystack; } const lines = args.haystack.split('\n'); let otherwiseLineIndex = -1; lines.forEach((line, i) => { if (line.indexOf(args.needle) !== -1) { otherwiseLineIndex = i; } }); let spaces = 0; while (lines[otherwiseLineIndex].charAt(spaces) === ' ') { spaces += 1; } let spaceStr = ''; while ((spaces -= 1) >= 0) { // eslint-disable-line no-cond-assign spaceStr += ' '; } lines.splice(otherwiseLineIndex, 0, args.splicable.map(line => spaceStr + line).join('\n')); return lines.join('\n'); }
n/a
function rewriteFile(args, generator) { args.path = args.path || process.cwd(); const fullPath = path.join(args.path, args.file); args.haystack = generator.fs.read(fullPath); const body = rewrite(args); generator.fs.write(fullPath, body); }
...
* @param {string} clientFramework - The name of the client framework
*/
addElementToMenu(routerName, glyphiconName, enableTranslation, clientFramework) {
let navbarPath;
try {
if (clientFramework === 'angular1') {
navbarPath = `${CLIENT_MAIN_SRC_DIR}app/layouts/navbar/navbar.html`;
jhipsterUtils.rewriteFile({
file: navbarPath,
needle: 'jhipster-needle-add-element-to-menu',
splicable: [`<li ui-sref-active="active">
<a ui-sref="${routerName}" ng-click="vm.collapseNavbar()">
<span class="glyphicon glyphicon-${glyphiconName}"></span> 
;
<span ${enableTranslation ? `data-translate="global.menu.${routerName}"` : '
x27;}>${_.startCase(routerName)}</span>
</a>
...
function rewriteJSONFile(filePath, rewriteFile, generator) { const jsonObj = generator.fs.readJSON(filePath); rewriteFile(jsonObj, generator); generator.fs.writeJSON(filePath, jsonObj, null, 4); }
...
* @param {string} key - Key for the entry
* @param {string} value - Default translated value or object with multiple key and translated value
* @param {string} language - The language to which this translation should be added
*/
addGlobalTranslationKey(key, value, language) {
const fullPath = `${CLIENT_MAIN_SRC_DIR}i18n/${language}/global.json`;
try {
jhipsterUtils.rewriteJSONFile(fullPath, (jsonObj) => {
jsonObj[key] = value;
}, this);
} catch (e) {
this.log(`${chalk.yellow('\nUnable to find ') + fullPath + chalk.yellow('. Reference to ')}(key: ${key
}, value:${value})${chalk.yellow(' not added to global translations.\n')}`);
}
}
...