2019-07-24 10:34:55 +08:00
|
|
|
/* eslint-disable no-console */
|
2020-12-28 15:30:18 +08:00
|
|
|
/** Generate legacy locale file as shadow of `/locale` to `/locale-provider`. */
|
2019-07-24 10:34:55 +08:00
|
|
|
|
|
|
|
const glob = require('glob');
|
|
|
|
const fs = require('fs');
|
|
|
|
const chalk = require('chalk');
|
|
|
|
|
|
|
|
glob('components/locale/@(*_*|default).tsx', (er, files) => {
|
|
|
|
files.forEach(filePath => {
|
|
|
|
const modulePath = filePath.replace(/^components/, '..').replace('.tsx', '');
|
|
|
|
const legacyModulePath = filePath.replace('locale', 'locale-provider');
|
|
|
|
|
|
|
|
const template = `import locale from '${modulePath}';
|
|
|
|
|
|
|
|
export default locale;
|
|
|
|
`.trim();
|
|
|
|
|
|
|
|
console.log(modulePath, '=>', legacyModulePath);
|
|
|
|
fs.writeFileSync(legacyModulePath, template, 'utf8');
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(chalk.green('✨ Locale generate success!'));
|
|
|
|
});
|