Skip to content

Modify convert.js and finish standardizing parameters #7183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/events/acceleration.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ p5.prototype.setMoveThreshold = function (val) {
* the <a href="#/p5/deviceShaken">deviceShaken()</a> function. The default threshold is set to 30.
*
* @method setShakeThreshold
* @param {number} value The threshold value
* @param {Number} value The threshold value
* @example
* <div class="norender">
* <code>
Expand Down
4 changes: 2 additions & 2 deletions src/io/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -1273,8 +1273,8 @@ p5.prototype.httpPost = function (...args) {
* @param {Object} options Request object options as documented in the
* "fetch" API
* <a href="https://developer.mozilla.org/en/docs/Web/API/Fetch_API">reference</a>
* @param {function} [callback]
* @param {function} [errorCallback]
* @param {Function} [callback]
* @param {Function} [errorCallback]
* @return {Promise}
*/
p5.prototype.httpDo = function (...args) {
Expand Down
93 changes: 69 additions & 24 deletions utils/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,45 +462,90 @@ for (const key in constUsage) {
// parameterData.json
// ============================================================================

function buildParamDocs(docs) {
let newClassItems = {};
// the fields we need for the FES, discard everything else
let allowed = new Set(['name', 'class', 'module', 'params', 'overloads']);
for (let classitem of docs.classitems) {
if (classitem.name && classitem.class) {
for (let key in classitem) {
if (!allowed.has(key)) {
delete classitem[key];
}
function cleanUpClassItems(data) {
for (const classItem in data) {
if (typeof data[classItem] === 'object') {
if (data[classItem].overloads) {
delete data[classItem].name;
delete data[classItem].class;
}
if (classitem.hasOwnProperty('overloads')) {
for (let overload of classitem.overloads) {
// remove line number and return type
if (overload.line) {
delete overload.line;
}
cleanUpClassItems(data[classItem]);
}
}

if (overload.return) {
delete overload.return;
}
}
}
if (!newClassItems[classitem.class]) {
newClassItems[classitem.class] = {};
const flattenOverloads = funcObj => {
const result = {};

for (const [key, value] of Object.entries(funcObj)) {
if (value && typeof value === 'object' && value.overloads) {
result[key] = {
overloads: Object.values(value.overloads).map(overload => {
if (overload.params) {
return Object.values(overload.params).map(param => {
let type = param.type;
if (param.optional) {
type += '?';
}
return type;
});
}
return overload;
})
};
} else {
result[key] = value;
}
}

return result;
};

for (const classItem in data) {
if (typeof data[classItem] === 'object') {
data[classItem] = flattenOverloads(data[classItem]);
}
}

return data;
}

function buildParamDocs(docs) {
let newClassItems = {};
// the fields we need—note that `name` and `class` are needed at this step because it's used to group classitems together. They will be removed later in cleanUpClassItems.
let allowed = new Set(['name', 'class', 'params', 'overloads']);

for (let classitem of docs.classitems) {
// If `classitem` doesn't have overloads, then it's not a function—skip processing in this case
if (classitem.name && classitem.class && classitem.hasOwnProperty('overloads')) {
// Clean up fields that will not be used in each classitem's overloads
classitem.overloads?.forEach(overload => {
delete overload.line;
delete overload.return;
overload.params.forEach(param => {
delete param.description;
delete param.name;
});
});

Object.keys(classitem).forEach(key => {
if (!allowed.has(key)) delete classitem[key];
});

newClassItems[classitem.class] = newClassItems[classitem.class] || {};
newClassItems[classitem.class][classitem.name] = classitem;
}
}

const cleanedClassItems = cleanUpClassItems(newClassItems);

let out = fs.createWriteStream(
path.join(__dirname, '../docs/parameterData.json'),
{
flags: 'w',
mode: '0644'
}
);
out.write(JSON.stringify(newClassItems, null, 2));
out.write(JSON.stringify(cleanedClassItems, null, 2));
out.end();
}

Expand Down
Loading