qwc2
Version:
QGIS Web Client
159 lines (157 loc) • 6.78 kB
JavaScript
/**
* Copyright 2024 Sourcepole AG
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
var fs = require("fs");
var path = require("path");
var reactDocs = require("react-docgen");
var qwcPluginDir = __dirname + '/../plugins';
var pluginData = [];
fs.readdirSync(qwcPluginDir).forEach(function (entry) {
if (entry.endsWith(".jsx")) {
var file = path.resolve(qwcPluginDir, entry);
var contents = fs.readFileSync(file);
pluginData.push(reactDocs.parse(contents, reactDocs.resolver.findAllComponentDefinitions));
}
});
pluginData = pluginData.flat();
var mapToolPluginData = [];
fs.readdirSync(qwcPluginDir + "/map").forEach(function (entry) {
if (entry.endsWith(".jsx")) {
var file = path.resolve(qwcPluginDir, "map", entry);
var contents = fs.readFileSync(file);
mapToolPluginData.push(reactDocs.parse(contents, reactDocs.resolver.findAllComponentDefinitions));
}
});
mapToolPluginData = mapToolPluginData.flat();
var plugin3dData = [];
fs.readdirSync(qwcPluginDir + "/map3d").forEach(function (entry) {
if (entry.endsWith(".jsx")) {
var file = path.resolve(qwcPluginDir, "map3d", entry);
var contents = fs.readFileSync(file);
plugin3dData.push(reactDocs.parse(contents, reactDocs.resolver.findAllComponentDefinitions));
}
});
plugin3dData = plugin3dData.flat();
function parsePropType(type) {
if (type.name === 'shape') {
return '{\n' + Object.entries(type.value).map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return ' ' + key + ": " + parsePropType(value) + ',\n';
}).join('') + '}';
} else if (type.name === 'arrayOf') {
return '[' + parsePropType(type.value) + "]";
} else if (type.name === 'union') {
return '{' + type.value.map(function (entry) {
return parsePropType(entry);
}).join(", ") + '}';
} else {
return type.name;
}
}
function genPluginDoc(plugin) {
var output = "";
if (!plugin.description) {
return "";
}
output += "".concat(plugin.displayName, "<a name=\"").concat(plugin.displayName.toLowerCase(), "\"></a>\n");
output += "----------------------------------------------------------------\n";
output += plugin.description + "\n\n";
var props = Object.entries(plugin.props || {}).filter(function (entry) {
return entry[1].description;
});
if (props.length > 0) {
output += "| Property | Type | Description | Default value |\n";
output += "|----------|------|-------------|---------------|\n";
props.forEach(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
name = _ref4[0],
prop = _ref4[1];
if (!prop.description) {
return;
}
var defaultValue = prop.defaultValue ? prop.defaultValue.value.split("\n").map(function (x) {
return '`' + x.replace(' ', ' ') + '`';
}).join("<br />") : "`undefined`";
var type = "`" + parsePropType(prop.type).replaceAll(' ', ' ').replaceAll("\n", "`<br />`") + "`";
output += "| ".concat(name, " | ").concat(type, " | ").concat(prop.description.replaceAll("\n", "<br />"), " | ").concat(defaultValue, " |\n");
});
output += "\n";
}
plugin.methods.forEach(function (method) {
if (method.docblock) {
var params = method.params.map(function (param) {
return param.name;
}).join(",");
output += "**".concat(method.name, "(").concat(params, ")**\n\n");
output += (method.docblock || "") + "\n";
output += "\n";
}
});
return output;
}
// Write markdown output
var output = "";
output += "Plugin reference\n";
output += "================\n";
output += "\n";
pluginData.forEach(function (plugin) {
if (!plugin.description) {
return;
}
output += "* [".concat(plugin.displayName, "](#").concat(plugin.displayName.toLowerCase(), ")\n");
});
output += "\n";
output += "Map support plugins\n";
output += "\n";
mapToolPluginData.forEach(function (plugin) {
if (!plugin.description) {
return;
}
output += "* [".concat(plugin.displayName, "](#").concat(plugin.displayName.toLowerCase(), ")\n");
});
output += "\n";
output += "3D Plugins\n";
output += "\n";
plugin3dData.forEach(function (plugin) {
if (!plugin.description) {
return;
}
output += "* [".concat(plugin.displayName, "](#").concat(plugin.displayName.toLowerCase(), ")\n");
});
output += "\n";
output += "---\n";
pluginData.forEach(function (plugin) {
output += genPluginDoc(plugin);
});
output += "---\n";
output += "# Map support plugins<a name=\"mapSupportPlugins\"></a>\n";
output += "\n";
output += "These plugins must be listed as children of the [Map](#map) plugin.";
output += "\n";
mapToolPluginData.forEach(function (plugin) {
output += genPluginDoc(plugin);
});
output += "---\n";
output += "# 3D Plugins<a name=\"plugins3d\"></a>\n";
output += "\n";
output += "These plugins must be listed as children of the [View3D](#view3d) plugin.";
output += "\n";
plugin3dData.forEach(function (plugin) {
output += genPluginDoc(plugin);
});
fs.writeFileSync(__dirname + '/../doc/plugins.md', output);
/* eslint-disable-next-line */
console.log("Plugin documentation written to doc/plugins.md!");