ant-design/scripts/build-common.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-03-02 11:57:37 +08:00
'use strict';
const fs = require('fs');
const path = require('path');
2016-03-02 11:57:37 +08:00
const R = require('ramda');
const buildDemosList = require('./build-demos-list');
2016-03-03 17:23:08 +08:00
const devil = require('./devil');
2016-03-02 11:57:37 +08:00
const utils = require('./utils');
const isMeta = R.complement(R.propEq('type', 'hr'));
const getMeta = R.prop('meta');
const getOrder = R.compose(parseInt, R.path(['meta', 'order']));
2016-03-03 11:12:46 +08:00
const getMenuItems = R.compose(
R.groupBy(R.compose(R.defaultTo('topLevel'), R.prop('category'))),
R.map(getMeta)
);
2016-03-02 11:57:37 +08:00
const sortByOrder = R.sortBy(getOrder);
const parseDemos = function parseDemos(fileName) {
const demosPath = path.join(path.dirname(fileName), 'demo');
const demosMDFild = utils.findMDFile(demosPath);
return buildDemosList.parse(demosMDFild).docs; // TODO
};
2016-03-02 11:57:37 +08:00
const parse = function parse(fileName) {
const fileContent = utils.parseFileContent(fileName);
const meta = utils.parseMeta(fileContent);
2016-03-03 17:23:08 +08:00
const description = R.map(
(node) => {
if (node.type === 'code' && node.props.lang === '__react') {
2016-03-04 09:55:03 +08:00
return devil(node.children, ['React', 'antd']);
2016-03-03 17:23:08 +08:00
}
return node;
},
R.tail(R.dropWhile(isMeta, fileContent))
);
2016-03-02 11:57:37 +08:00
const demos = !utils.isIndex(fileName) ? null : parseDemos(fileName);
return { meta, description, demos };
2016-03-02 11:57:37 +08:00
};
2016-03-03 11:12:46 +08:00
module.exports = function buildCommon(inputDir, outputFile) {
const mds = utils.findMDFile(inputDir, true);
2016-03-02 11:57:37 +08:00
2016-03-04 15:19:23 +08:00
let content = 'module.exports = {';
mds.forEach((md) => {
content += `\n '${md}': require('antd-md!../../${md}'),`;
});
content += '\n};';
2016-03-02 11:57:37 +08:00
2016-03-03 11:12:46 +08:00
fs.writeFile(outputFile, content);
2016-03-02 11:57:37 +08:00
};