2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-21 18:50:37 +03:00

refactor: 3.0

This commit is contained in:
mengxiong10
2019-11-10 17:47:30 +08:00
parent 72024440d7
commit 4875dc6b3d
165 changed files with 23248 additions and 21723 deletions
+52
View File
@@ -0,0 +1,52 @@
const path = require('path');
const fs = require('fs');
const libLocales = path.resolve(__dirname, '../../node_modules/date-format-parse/lib/locale');
const localLocalePath = path.resolve(__dirname, '../../src/locale');
const yearBeforeMonth = ['hu', 'ja', 'ko', 'lv', 'vi', 'zh-cn', 'zh-tw'];
const yearFormatMap = {
'zh-cn': 'YYYY年',
'zh-tw': 'YYYY年',
};
const getTemplate = locale => {
const formatLocale = locale.replace(/-(\w+)/, (m, p1) => p1.toLocaleUpperCase());
const yearFormat = yearFormatMap[locale] || 'YYYY';
const template = `
${locale === 'en' ? '' : "import DatePicker from 'vue2-datepicker';"}
import ${formatLocale} from 'date-format-parse/lib/locale/${locale}';
const lang = {
formatLocale: ${formatLocale},
yearFormat: '${yearFormat}',
monthFormat: 'MMM',
monthBeforeYear: ${yearBeforeMonth.indexOf(locale) === -1},
};
${locale === 'en' ? '' : `DatePicker.locale('${locale}', lang);`}
export default lang;
`;
return template.trim();
};
function generateLocales() {
fs.readdirSync(libLocales).forEach(filename => {
if (!/\.js$/.test(filename)) {
return;
}
const name = filename.replace(/\.js$/, '');
const data = getTemplate(name);
fs.writeFile(path.join(localLocalePath, filename), data, err => {
if (err) {
throw err;
}
});
});
}
generateLocales();