mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-26 09:58:33 +08:00
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
/* eslint strict: 0 */
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const utils = require('./utils');
|
|
|
|
module.exports = function buildCommon(dirs, outputFile) {
|
|
const mds = utils.findMDFile(dirs, true)
|
|
.filter((file) => !/\/demo$/i.test(path.dirname(file)))
|
|
.filter((file) => !/install_en\.md$/gi.test(file)); // TODO
|
|
|
|
const addedMd = [];
|
|
let content = 'module.exports = {';
|
|
mds.forEach((fileName) => {
|
|
const localeId = path.basename(fileName, '.md').split('.')[1];
|
|
const simplifiedFileName = fileName.replace(`.${localeId}`, '');
|
|
if (addedMd.indexOf(simplifiedFileName) > -1) return;
|
|
|
|
const isLocalized = ['zh-CN', 'en-US'].indexOf(localeId) > -1;
|
|
if (isLocalized) {
|
|
content += `\n '${simplifiedFileName}': {` +
|
|
'\n localized: true,' +
|
|
`\n 'zh-CN': require('${path.relative(path.dirname(outputFile), fileName.replace(localeId, 'zh-CN'))}'),` +
|
|
`\n 'en-US': require('${path.relative(path.dirname(outputFile), fileName.replace(localeId, 'en-US'))}'),` +
|
|
'\n },';
|
|
addedMd.push(simplifiedFileName);
|
|
} else {
|
|
const requirePath = path.relative(path.dirname(outputFile), fileName);
|
|
content += `\n '${simplifiedFileName}': require('${requirePath}'),`;
|
|
}
|
|
});
|
|
content += '\n};';
|
|
|
|
fs.writeFile(outputFile, content);
|
|
};
|