How to use the generator-jhipster/generators/utils.replaceContent function in generator-jhipster

To help you get started, we’ve selected a few generator-jhipster examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jhipster / jhipster-vuejs / generators / utils.js View on Github external
function updateLanguagesInTranslationStore(generator) {
    const fullPath = `${CLIENT_MAIN_SRC_DIR}app/shared/config/store/translation-store.ts`;
    try {
        let content = 'languages: {\n';
        if (generator.enableTranslation) {
            generator.generateLanguageOptions(generator.languages, generator.clientFramework).forEach((ln, i) => {
                content += `        ${ln}${i !== generator.languages.length - 1 ? ',' : ''}\n`;
            });
        }
        content += '        // jhipster-needle-i18n-language-key-pipe - JHipster will add/remove languages in this object\n      }';
        jhipsterUtils.replaceContent(
            {
                file: fullPath,
                pattern: /languages:.*\{([^\]]*jhipster-needle-i18n-language-key-pipe[^}]*)}/g,
                content
            },
            generator
        );
    } catch (e) {
        generator.log(
            chalk.yellow('\nUnable to find ')
            + fullPath
            + chalk.yellow(' or missing required jhipster-needle. Language pipe not updated with languages: ')
            + generator.languages
            + chalk.yellow(' since block was not found. Check if you have enabled translation support.\n')
        );
        generator.debug('Error:', e);
github jhipster / jhipster-vuejs / generators / utils.js View on Github external
function replaceTranslation(generator, files) {
    for (let i = 0; i < files.length; i++) {
        const filePath = `${CLIENT_MAIN_SRC_DIR}${files[i]}`;
        // Match the below attributes and the $t() method
        const regexp = ['v-text', 'v-bind:placeholder', 'v-html', 'v-bind:title', 'v-bind:label', 'v-bind:value', 'v-bind:html']
            .map(s => `${s}="\\$t\\(.*?\\)"`)
            .join(')|(');
        jhipsterUtils.replaceContent(
            {
                file: filePath,
                pattern: new RegExp(` ?(${regexp})`, 'g'),
                content: ''
            },
            generator
        );
    }
}
github jhipster / jhipster-vuejs / generators / utils.js View on Github external
function updateLanguagesInWebpack(generator) {
    const fullPath = `${CLIENT_WEBPACK_DIR}webpack.common.js`;
    try {
        let content = 'groupBy: [\n';
        generator.languages.forEach((language, i) => {
            content += `          { pattern: './src/main/webapp/i18n/${language}/*.json', fileName: './i18n/${language}.json' }${
                i !== generator.languages.length - 1 ? ',' : ''
            }\n`;
        });
        content += '          // jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array\n'
            + '        ]';

        jhipsterUtils.replaceContent(
            {
                file: fullPath,
                pattern: /groupBy:.*\[([^\]]*jhipster-needle-i18n-language-webpack[^\]]*)\]/g,
                content
            },
            generator
        );
    } catch (e) {
        generator.log(
            chalk.yellow('\nUnable to find ')
                + fullPath
                + chalk.yellow(' or missing required jhipster-needle. Webpack language task not updated with languages: ')
                + generator.languages
                + chalk.yellow(' since block was not found. Check if you have enabled translation support.\n')
        );
        generator.debug('Error:', e);
github jhipster / jhipster-vuejs / generators / utils.js View on Github external
function updateI18nConfig(generator) {
    const fullPath = `${CLIENT_MAIN_SRC_DIR}app/shared/config/config.ts`;

    try {
        // Add i18n config snippets for all languages
        let i18nConfig = 'const dateTimeFormats = {\n';
        if (generator.enableTranslation) {
            generator.languages.forEach((ln, i) => {
                i18nConfig += generateDateTimeFormat(ln, i, generator.languages.length);
            });
        }
        i18nConfig += '  // jhipster-needle-i18n-language-date-time-format - JHipster will add/remove format options in this object\n';
        i18nConfig += '}';

        jhipsterUtils.replaceContent(
            {
                file: fullPath,
                pattern: /const dateTimeFormats.*\{([^\]]*jhipster-needle-i18n-language-date-time-format[^}]*)}/g,
                content: i18nConfig
            },
            generator
        );
    } catch (e) {
        generator.log(
            chalk.yellow('\nUnable to find ')
            + fullPath
            + chalk.yellow(' or missing required jhipster-needle. Language pipe not updated with languages: ')
            + generator.languages
            + chalk.yellow(' since block was not found. Check if you have enabled translation support.\n')
        );
        generator.debug('Error:', e);

generator-jhipster

Spring Boot + Angular/React/Vue in one handy generator

Apache-2.0
Latest version published 23 days ago

Package Health Score

98 / 100
Full package analysis