|
@@ -4,6 +4,7 @@ const MarkdownIt = require('markdown-it')();
|
|
|
|
|
|
|
|
const basePath = path.resolve(__dirname, './../src/packages/__VUE');
|
|
const basePath = path.resolve(__dirname, './../src/packages/__VUE');
|
|
|
const componentDirs = fs.readdirSync(basePath, 'utf8');
|
|
const componentDirs = fs.readdirSync(basePath, 'utf8');
|
|
|
|
|
+const config = require('./../package.json');
|
|
|
const TYPE_IDENTIFY_OPEN = 'tbody_open';
|
|
const TYPE_IDENTIFY_OPEN = 'tbody_open';
|
|
|
const TYPE_IDENTIFY_CLOSE = 'tbody_close';
|
|
const TYPE_IDENTIFY_CLOSE = 'tbody_close';
|
|
|
const TR_TYPE_IDENTIFY_OPEN = 'tr_open';
|
|
const TR_TYPE_IDENTIFY_OPEN = 'tr_open';
|
|
@@ -78,6 +79,62 @@ const genaratorAttributes = () => {
|
|
|
return componentTags;
|
|
return componentTags;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+const genaratorWebTypes = () => {
|
|
|
|
|
+ let typesData = {
|
|
|
|
|
+ $schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
|
|
|
|
|
+ framework: 'vue',
|
|
|
|
|
+ name: 'NutUI',
|
|
|
|
|
+ version: config.version,
|
|
|
|
|
+ contributions: {
|
|
|
|
|
+ html: {
|
|
|
|
|
+ tags: [],
|
|
|
|
|
+ attributes: [],
|
|
|
|
|
+ 'types-syntax': 'typescript'
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ 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');
|
|
|
|
|
+ let attributes = [];
|
|
|
|
|
+ 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}` : '';
|
|
|
|
|
+ const infoItem = inlineItem.length ? `${inlineItem[1].content}` : '';
|
|
|
|
|
+ const typeItem = inlineItem.length ? `${inlineItem[2].content.toLowerCase()}` : '';
|
|
|
|
|
+ const defaultItem = inlineItem.length ? `${inlineItem[3].content}` : '';
|
|
|
|
|
+ attributes.push({
|
|
|
|
|
+ name: propItem,
|
|
|
|
|
+ default: defaultItem,
|
|
|
|
|
+ description: infoItem,
|
|
|
|
|
+ value: {
|
|
|
|
|
+ type: typeItem,
|
|
|
|
|
+ kind: 'expression'
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ typesData.contributions.html.tags.push({
|
|
|
|
|
+ name: `nut-${componentDir}`,
|
|
|
|
|
+ slots: [],
|
|
|
|
|
+ events: [],
|
|
|
|
|
+ attributes: attributes.slice()
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return typesData;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
const writeTags = () => {
|
|
const writeTags = () => {
|
|
|
const componentTags = genaratorTags();
|
|
const componentTags = genaratorTags();
|
|
|
let innerText = `${JSON.stringify(componentTags, null, 2)}`;
|
|
let innerText = `${JSON.stringify(componentTags, null, 2)}`;
|
|
@@ -101,5 +158,17 @@ const writeAttributes = () => {
|
|
|
fs.writeFileSync(componentAttributespPath, innerText);
|
|
fs.writeFileSync(componentAttributespPath, innerText);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+const writeWebTypes = () => {
|
|
|
|
|
+ const typesData = genaratorWebTypes();
|
|
|
|
|
+ let innerText = `${JSON.stringify(typesData, null, 2)}`;
|
|
|
|
|
+ const distPath = path.resolve(__dirname, './../dist');
|
|
|
|
|
+ const componentWebTypespPath = path.resolve(__dirname, './../dist/smartips/web-types.json');
|
|
|
|
|
+ if (!fs.existsSync(path.join(distPath + '/smartips'))) {
|
|
|
|
|
+ fs.mkdirSync(path.join(distPath + '/smartips'));
|
|
|
|
|
+ }
|
|
|
|
|
+ fs.writeFileSync(componentWebTypespPath, innerText);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
writeTags();
|
|
writeTags();
|
|
|
writeAttributes();
|
|
writeAttributes();
|
|
|
|
|
+writeWebTypes();
|