UNPKG

gen-jhipster

Version:

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

15 lines (14 loc) 915 B
/** * Update DayJS Locales. * * @param application * @param configurationFile * @param commonjs */ export function updateLanguagesInDayjsConfigurationTask({ application, control = {} }, { configurationFile, commonjs = false }) { const { languagesDefinition = [] } = application; const { ignoreNeedlesError: ignoreNonExisting } = control; const uniqueDayjsLocales = [...new Map(languagesDefinition.map(v => [v.dayjsLocale, v])).values()]; const newContent = uniqueDayjsLocales.reduce((content, language) => `${content}import 'dayjs/${commonjs ? '' : 'esm/'}locale/${language.dayjsLocale}'\n`, '// jhipster-needle-i18n-language-dayjs-imports - JHipster will import languages from dayjs here\n'); this.editFile(configurationFile, { ignoreNonExisting }, content => content.replace(/\/\/ jhipster-needle-i18n-language-dayjs-imports[\s\S]+?(?=\/\/ DAYJS CONFIGURATION)/g, `${newContent}\n`)); }