You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
const globby = require('globby');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const matter = require('gray-matter');
|
|
const { ESLint } = require('eslint');
|
|
|
|
(async () => {
|
|
const paths = await globby('components/*/index.*.md');
|
|
const components = {};
|
|
|
|
paths.forEach(path => {
|
|
const content = fs.readFileSync(path).toString();
|
|
const componentName = path.split('/')[1];
|
|
|
|
const { data } = matter(content);
|
|
components[componentName] = { ...components[componentName], ...data };
|
|
});
|
|
const TEMPLATE = `
|
|
export default [
|
|
${Object.keys(components).map(
|
|
component => `
|
|
{
|
|
path: '${component}:lang(-cn)?',
|
|
meta: ${JSON.stringify(components[component])},
|
|
component: () => import('../../../components/${component}/demo/index.vue'),
|
|
}`,
|
|
)}
|
|
];`;
|
|
|
|
const engine = new ESLint({
|
|
fix: true,
|
|
useEslintrc: false,
|
|
baseConfig: require(path.join(process.cwd(), '.eslintrc.js')),
|
|
});
|
|
|
|
const report = await engine.lintText(TEMPLATE);
|
|
|
|
fs.writeFileSync('site/src/router/demoRoutes.js', report[0].output);
|
|
})();
|