Skip to content

Commit

Permalink
Fixed #1138 Fixed #962
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed May 12, 2021
1 parent 367d4a5 commit 8681911
Show file tree
Hide file tree
Showing 92 changed files with 7,793 additions and 2 deletions.
164 changes: 164 additions & 0 deletions api-generator/build-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
const fs = require("fs");
const path = require("path");

const rootDir = path.resolve(__dirname, "../");
const distDir = path.resolve(rootDir, "dist");
const componentPath = path.join(__dirname, "./components");

// Import project `package.json`
const pkg = require(path.resolve(rootDir, "package.json"));
const libraryName = "PrimeVue";
const libraryVersion = pkg.version;

const showcaseURL = "https://primefaces.org/primevue/showcase/#/";

const fileModules = {},
veturTags = {},
veturAttributes = {};

const files = fs.readdirSync(componentPath);
files.forEach(file => {
const { name } = path.parse(file);

fileModules[name] = require(`./components//${name}`);
});

const webTypes = {
$schema: "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
framework: "vue",
name: libraryName,
version: libraryVersion,
contributions: {
html: {
"types-syntax": "typescript",
"description-markup": "markdown",
tags: [],
attributes: []
}
}
};

const addURL = (attr, url, value) => {
const newArray = [];

attr.forEach(att => {
const newObj = {};

Object.keys(att).forEach(key => {
newObj[key] = att[key];
if (key === value) newObj["doc-url"] = url;
});

newArray.push(newObj);
});

return newArray;
};

const createWebTypes = component => {
const url = showcaseURL + `${component["doc-url"] ? component["doc-url"] : component.name.toLowerCase()}`;

// components
const tag = {
name: component.name,
source: {
module: libraryName,
symbol: component.name
},
"doc-url": url,
description: component.description
};

// directives
const attribute = {
name: component.name,
source: {
module: libraryName,
symbol: component.name
},
description: component.description,
"doc-url": url,
value: {
kind: "expression",
type: "function"
}
};

if (component.props) {
tag.attributes = addURL(component.props, url, "default");
tag.attributes.forEach(k => {
k["value"] = {
kind: "expression",
type: k["type"]
};

delete k["type"];
});
}

if (component.events) {
tag.events = addURL(component.events, url, "name");
tag.events.forEach(k => {
if (k.arguments) {
k.arguments = addURL(k.arguments, url, "name");
}
});
}

if (component.slots) {
tag.slots = addURL(component.slots, url, "name");
}

if (component["vue-modifiers"]) {
attribute.required = false;
attribute["vue-modifiers"] = addURL(component["vue-modifiers"], url, "name");

if (attribute["vue-modifiers"].length < 1)
delete attribute["vue-modifiers"];

webTypes.contributions.html.attributes.push(attribute);
}

webTypes.contributions.html.tags.push(tag);
};

const createVeturTags = component => {
const attributes = [];
if (component.props) {
component.props.forEach(comp => {
attributes.push(comp.name);
});
}
if (attributes.length > 0) {
veturTags[component.name] = {
description: component.description,
attributes
};
}
};

const createVeturAttributes = component => {
if (component.props) {
component.props.forEach(comp => {
veturAttributes[component.name.toLowerCase() + `/${comp.name}`] = {
description: comp.description,
type: comp.type
};
});
}
};

Object.keys(fileModules).forEach(p => {
createWebTypes(fileModules[p][p]);
createVeturTags(fileModules[p][p]);
createVeturAttributes(fileModules[p][p]);
});

const webTypesJson = JSON.stringify(webTypes, null, 2);
fs.writeFileSync(path.resolve(distDir, "web-types.json"), webTypesJson);

const veturTagsJson = JSON.stringify(veturTags, null, 2);
fs.writeFileSync(path.resolve(distDir, "vetur-tags.json"), veturTagsJson);

const veturAttributesJson = JSON.stringify(veturAttributes, null, 2);
fs.writeFileSync(path.resolve(distDir, "vetur-attributes.json"), veturAttributesJson);
58 changes: 58 additions & 0 deletions api-generator/components/accordion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const AccordionProps = [
{
name: "multiple",
type: "boolean",
default: "false",
description: "When enabled, multiple tabs can be activated at the same time."
},
{
name: "activeIndex",
type: "number|array",
default: "null",
description: "Index of the active tab or an array of indexes in multiple mode."
}
];

const AccordionEvents = [
{
name: "tab-open",
description: "Callback to invoke when a tab gets expanded.",
arguments: [
{
name: "originalEvent",
type: "object",
description: "Original event"
},
{
name: "index",
type: "number",
description: "Opened tab index"
}
]
},
{
name: "tab-close",
description: "Callback to invoke when an active tab is collapsed by clicking on the header.",
arguments: [
{
name: "originalEvent",
type: "object",
description: "Original event"
},
{
name: "index",
type: "number",
description: "Closed tab index"
}
]
}
];

module.exports = {
accordion: {
name: "Accordion",
description: "Accordion groups a collection of contents in tabs.",
props: AccordionProps,
events: AccordionEvents
}
};
28 changes: 28 additions & 0 deletions api-generator/components/accordiontab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const AccordionTabProps = [
{
name: "header",
type: "string",
default: "null",
description: "Orientation of tab headers."
},
{
name: "active",
type: "boolean",
default: "null",
description: "Visibility of the content."
},
{
name: "disabled",
type: "boolean",
default: "false",
description: "Whether the tab is disabled."
}
];

module.exports = {
accordiontab: {
name: "AccordionTab",
description: "Accordion element consists of one or more AccordionTab elements.",
props: AccordionTabProps
}
};
Loading

0 comments on commit 8681911

Please sign in to comment.