|
|
@@ -5,10 +5,28 @@ const MarkdownIt = require('markdown-it')();
|
|
|
const basePath = path.resolve(__dirname, './../src/packages/__VUE');
|
|
|
const componentDirs = fs.readdirSync(basePath, 'utf8');
|
|
|
const config = require('../package.json');
|
|
|
+const cfg = require('./../src/config.json');
|
|
|
const TYPE_IDENTIFY_OPEN = 'tbody_open';
|
|
|
const TYPE_IDENTIFY_CLOSE = 'tbody_close';
|
|
|
const TR_TYPE_IDENTIFY_OPEN = 'tr_open';
|
|
|
const TR_TYPE_IDENTIFY_CLOSE = 'tr_close';
|
|
|
+const argv = process.argv[2];
|
|
|
+let packages = [];
|
|
|
+
|
|
|
+const kebabCase = (str) => {
|
|
|
+ str = str.replace(str.charAt(0), str.charAt(0).toLocaleLowerCase());
|
|
|
+ return str.replace(/([a-z])([A-Z])/g, (_, p1, p2) => p1 + '-' + p2.toLowerCase());
|
|
|
+};
|
|
|
+
|
|
|
+const getCompName = (name) => {
|
|
|
+ if(!packages.length) {
|
|
|
+ cfg.nav.forEach((item, index) => {
|
|
|
+ packages = packages.concat(item.packages);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const packageName = packages.find((item) => item.name.toLowerCase() === name.toLowerCase());
|
|
|
+ return packageName.name
|
|
|
+}
|
|
|
|
|
|
const getSubSources = (sources) => {
|
|
|
let sourcesMap = [];
|
|
|
@@ -24,61 +42,6 @@ const getSubSources = (sources) => {
|
|
|
return sourcesMap;
|
|
|
};
|
|
|
|
|
|
-const genaratorTags = () => {
|
|
|
- let componentTags = {};
|
|
|
- if (!componentDirs.length) return;
|
|
|
-
|
|
|
- for (let componentDir of componentDirs) {
|
|
|
- let stat = fs.lstatSync(`${basePath}/${componentDir}`);
|
|
|
- if (stat.isDirectory()) {
|
|
|
- const absolutePath = path.join(`${basePath}/${componentDir}`, 'doc.md');
|
|
|
- if (!fs.existsSync(absolutePath)) continue;
|
|
|
- const data = fs.readFileSync(absolutePath, 'utf8');
|
|
|
- let sources = MarkdownIt.parse(data, {});
|
|
|
- let sourcesMap = getSubSources(sources);
|
|
|
- componentTags[`nut-${componentDir}`] = { attributes: [] };
|
|
|
- for (let sourceMap of sourcesMap) {
|
|
|
- let propItem = sourceMap.filter((source) => source.type === 'inline').length
|
|
|
- ? `${sourceMap.filter((source) => source.type === 'inline')[0].content.replace(/`.*?`/g, '')}`
|
|
|
- : '';
|
|
|
- componentTags[`nut-${componentDir}`]['attributes'].push(propItem);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return componentTags;
|
|
|
-};
|
|
|
-
|
|
|
-const genaratorAttributes = () => {
|
|
|
- let componentTags = {};
|
|
|
- if (!componentDirs.length) return;
|
|
|
- for (let componentDir of componentDirs) {
|
|
|
- let stat = fs.lstatSync(`${basePath}/${componentDir}`);
|
|
|
- if (stat.isDirectory()) {
|
|
|
- const absolutePath = path.join(`${basePath}/${componentDir}`, 'doc.md');
|
|
|
- if (!fs.existsSync(absolutePath)) continue;
|
|
|
- const data = fs.readFileSync(absolutePath, 'utf8');
|
|
|
- let sources = MarkdownIt.parse(data, {});
|
|
|
- let sourcesMap = getSubSources(sources);
|
|
|
- for (let sourceMap of sourcesMap) {
|
|
|
- const inlineItem = sourceMap.filter((source) => source.type === 'inline').length
|
|
|
- ? sourceMap.filter((source) => source.type === 'inline')
|
|
|
- : [];
|
|
|
- const propItem = inlineItem.length ? `${inlineItem[0].content.replace(/`.*?`/g, '')}` : '';
|
|
|
- const infoItem = inlineItem.length ? `${inlineItem[1].content}` : '';
|
|
|
- const typeItem = inlineItem.length ? `${inlineItem[2].content.toLowerCase()}` : '';
|
|
|
- const defaultItem = inlineItem.length ? `${inlineItem[3].content}` : '';
|
|
|
- componentTags[`nut-${componentDir}/${propItem}`] = {
|
|
|
- type: `${typeItem}`,
|
|
|
- description: `属性说明:${infoItem},默认值:${defaultItem}`
|
|
|
- };
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return componentTags;
|
|
|
-};
|
|
|
-
|
|
|
const genaratorWebTypes = () => {
|
|
|
let typesData = {
|
|
|
$schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
|
|
|
@@ -99,7 +62,10 @@ const genaratorWebTypes = () => {
|
|
|
for (let componentDir of componentDirs) {
|
|
|
let stat = fs.lstatSync(`${basePath}/${componentDir}`);
|
|
|
if (stat.isDirectory()) {
|
|
|
- const absolutePath = path.join(`${basePath}/${componentDir}`, 'doc.md');
|
|
|
+ let absolutePath = path.join(`${basePath}/${componentDir}`, `doc.md`);
|
|
|
+ if(argv === 'taro') {
|
|
|
+ absolutePath = path.join(`${basePath}/${componentDir}`, `doc.taro.md`);
|
|
|
+ }
|
|
|
let attributes = [];
|
|
|
if (!fs.existsSync(absolutePath)) continue;
|
|
|
const data = fs.readFileSync(absolutePath, 'utf8');
|
|
|
@@ -123,8 +89,9 @@ const genaratorWebTypes = () => {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ let compoName = kebabCase(getCompName(componentDir));
|
|
|
typesData.contributions.html.tags.push({
|
|
|
- name: `nut-${componentDir}`,
|
|
|
+ name: `nut-${compoName}`,
|
|
|
slots: [],
|
|
|
events: [],
|
|
|
attributes: attributes.slice()
|
|
|
@@ -135,29 +102,6 @@ const genaratorWebTypes = () => {
|
|
|
return typesData;
|
|
|
};
|
|
|
|
|
|
-const writeTags = () => {
|
|
|
- const componentTags = genaratorTags();
|
|
|
- let innerText = `${JSON.stringify(componentTags, null, 2)}`;
|
|
|
- const distPath = path.resolve(__dirname, './../dist');
|
|
|
- const componentTagsPath = path.resolve(__dirname, './../dist/smartips/tags.json');
|
|
|
- if (!fs.existsSync(path.join(distPath + '/smartips'))) {
|
|
|
- fs.mkdirSync(path.join(distPath + '/smartips'));
|
|
|
- }
|
|
|
-
|
|
|
- fs.writeFileSync(componentTagsPath, innerText);
|
|
|
-};
|
|
|
-
|
|
|
-const writeAttributes = () => {
|
|
|
- const componentAttributes = genaratorAttributes();
|
|
|
- let innerText = `${JSON.stringify(componentAttributes, null, 2)}`;
|
|
|
- const distPath = path.resolve(__dirname, './../dist');
|
|
|
- const componentAttributespPath = path.resolve(__dirname, './../dist/smartips/attributes.json');
|
|
|
- if (!fs.existsSync(path.join(distPath + '/smartips'))) {
|
|
|
- fs.mkdirSync(path.join(distPath + '/smartips'));
|
|
|
- }
|
|
|
- fs.writeFileSync(componentAttributespPath, innerText);
|
|
|
-};
|
|
|
-
|
|
|
const writeWebTypes = () => {
|
|
|
const typesData = genaratorWebTypes();
|
|
|
let innerText = `${JSON.stringify(typesData, null, 2)}`;
|
|
|
@@ -169,6 +113,4 @@ const writeWebTypes = () => {
|
|
|
fs.writeFileSync(componentWebTypespPath, innerText);
|
|
|
};
|
|
|
|
|
|
-writeTags();
|
|
|
-writeAttributes();
|
|
|
writeWebTypes();
|