build: migrate widget doc generation script, ungit widget reference
This commit is contained in:
parent
6b68237f41
commit
4c98442fed
7 changed files with 1615 additions and 1479 deletions
|
|
@ -1,120 +0,0 @@
|
|||
// import './client-shim'
|
||||
import widgets from '../src/client/widgets/index.js'
|
||||
import baseClass from '../src/client/widgets/common/widget.js'
|
||||
|
||||
// Here we go
|
||||
var base = baseClass.defaults(),
|
||||
doc = ['<!-- This file is generated automatically from the widget class declarations. See scripts/build-widget-reference.js -->']
|
||||
|
||||
|
||||
doc.push(`
|
||||
|
||||
## Common
|
||||
|
||||
??? api "<div id="generic_properties">Generic properties<a class="headerlink" href="#generic_properties" title="Permanent link">#</a></div>"
|
||||
Properties shared by all widgets
|
||||
|
||||
`
|
||||
)
|
||||
|
||||
for (var categoryName in base) {
|
||||
doc.push(`\n
|
||||
|
||||
=== "${categoryName}"
|
||||
|
||||
| property | type |default | description |
|
||||
| --- | --- | --- | --- |`
|
||||
)
|
||||
var notEmpty = false
|
||||
|
||||
for (var propName in base[categoryName]) {
|
||||
|
||||
var prop = base[categoryName][propName],
|
||||
permalink = propName
|
||||
|
||||
if (propName === '_props' || propName[0] === '_') continue
|
||||
|
||||
var help = Array.isArray(prop.help) ? prop.help.join('<br/><br/>').replace(/<br\/>-/g, '-') : prop.help || '',
|
||||
dynamic = baseClass.dynamicProps.includes(propName) ? '<sup><i class="fas fa-bolt" title="dynamic"></i></sup>' : ''
|
||||
|
||||
if (prop.choices) {
|
||||
if (help) help += '<br/><br/>'
|
||||
help += 'Choices: ' + prop.choices.map(x=>'`' + x + '`').join(', ')
|
||||
}
|
||||
|
||||
doc.push(`
|
||||
| <h6 id="${permalink}">${propName}${dynamic}<a class="headerlink" href="#${permalink}" title="Permanent link">#</a></h6> | \`${prop.type.replace(/\|/g,'\`|<br/>\`')}\` | <code>${(JSON.stringify(prop.value, null, ' ') || '').replace(/\n/g,'<br/>').replace('{','\\{')}</code> | ${help} |`
|
||||
)
|
||||
notEmpty = true
|
||||
|
||||
}
|
||||
if (!notEmpty) doc.pop()
|
||||
|
||||
}
|
||||
|
||||
for (var k in widgets.categories) {
|
||||
var category = widgets.categories[k]
|
||||
if (k == 'Containers') {
|
||||
category.push('root')
|
||||
category.push('tab')
|
||||
}
|
||||
|
||||
doc.push(`
|
||||
## ${k}`
|
||||
)
|
||||
|
||||
for (var kk in category) {
|
||||
var type = category[kk],
|
||||
defaults = widgets.widgets[type].defaults(),
|
||||
description = widgets.widgets[type].description()
|
||||
|
||||
doc.push(`
|
||||
|
||||
??? api "<div id="${type}">${type}<a class="headerlink" href="#${type}" title="Permanent link">#</a></div>"
|
||||
${description}`
|
||||
|
||||
)
|
||||
|
||||
for (var categoryName in defaults) {
|
||||
doc.push(`\n
|
||||
=== "${categoryName == 'class_specific' ? type : categoryName}"
|
||||
|
||||
| property | type |default | description |
|
||||
| --- | --- | --- | --- |`
|
||||
)
|
||||
var notEmpty = false
|
||||
|
||||
for (var propName in defaults[categoryName]) {
|
||||
|
||||
var prop = defaults[categoryName][propName],
|
||||
permalink = type + '_' + propName
|
||||
|
||||
|
||||
if (propName === '_props' || propName[0] === '_' || JSON.stringify(prop) == JSON.stringify((base[categoryName]||{})[propName])) continue
|
||||
|
||||
var help = Array.isArray(prop.help) ? prop.help.join('<br/><br/>').replace(/<br\/>-/g, '-') : prop.help || '',
|
||||
dynamic = widgets.widgets[type].dynamicProps.includes(propName) ? '<sup><i class="fas fa-bolt" title="dynamic"></i></sup>' : ''
|
||||
|
||||
if (prop.choices) {
|
||||
if (help) help += '<br/><br/>'
|
||||
help += 'Choices: ' + prop.choices.map(x=>'`' + x + '`').join(', ')
|
||||
}
|
||||
doc.push(`
|
||||
| <h6 id="${permalink}">${propName}${dynamic}<a class="headerlink" href="#${permalink}" title="Permanent link">#</a></h6> | \`${prop.type.replace(/\|/g,'\`|<br/>\`')}\` | <code>${(JSON.stringify(prop.value, null, ' ') || '').replace(/\n/g,'<br/>').replace('{','\\{')}</code> | ${help} |`
|
||||
)
|
||||
notEmpty = true
|
||||
}
|
||||
|
||||
if (!notEmpty) doc.pop()
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
console.log(doc.join(''))
|
||||
|
||||
process.exit(0) // avoid setTimeout errors in required modules
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
// Dirty browser window shim
|
||||
|
||||
document = {
|
||||
createElement: x=>({
|
||||
ownerDocument: document,
|
||||
style: {},
|
||||
contentWindow: {},
|
||||
nodeName: '',
|
||||
childNodes: [],
|
||||
setAttribute: ()=>{},
|
||||
appendChild: ()=>{},
|
||||
lastChild: {},
|
||||
toString: ()=>' ',
|
||||
removeChild: ()=>{},
|
||||
contentWindow: {
|
||||
document: {
|
||||
open: ()=>{},
|
||||
close: ()=>{},
|
||||
write: ()=>{},
|
||||
}
|
||||
}
|
||||
}),
|
||||
createTextNode: x=>({
|
||||
nodeValue: '',
|
||||
nodeName: '',
|
||||
childNodes: [],
|
||||
setAttribute: ()=>{},
|
||||
appendChild: ()=>{},
|
||||
lastChild: {},
|
||||
toString: ()=>' '
|
||||
}),
|
||||
createElementNS: x=>[],
|
||||
addEventListener: ()=>{},
|
||||
createRange: ()=>{
|
||||
return {
|
||||
createContextualFragment:()=>{return {
|
||||
firstChild: {
|
||||
querySelectorAll: x=>[]
|
||||
}
|
||||
}},
|
||||
selectNode: ()=>{}
|
||||
}
|
||||
},
|
||||
body: {
|
||||
appendChild: ()=>{},
|
||||
addEventListener: ()=>{}
|
||||
},
|
||||
location: {},
|
||||
documentElement: {
|
||||
appendChild: ()=>{},
|
||||
removeChild: ()=>{}
|
||||
}
|
||||
}
|
||||
|
||||
window = {
|
||||
screen: {width: 800, height: 600},
|
||||
addEventListener: ()=>{},
|
||||
location: {},
|
||||
Image: Function,
|
||||
document: document,
|
||||
navigator: {
|
||||
platform:'',
|
||||
userAgent: ''
|
||||
},
|
||||
NodeList: Array,
|
||||
WebSocket: Object,
|
||||
localStorage: {
|
||||
getItem(){return null}
|
||||
},
|
||||
sessionStorage: {
|
||||
getItem(){return null},
|
||||
setItem(){},
|
||||
},
|
||||
MutationObserver: class MutationObserver{}
|
||||
}
|
||||
|
||||
Object.assign(global, window)
|
||||
|
||||
// Required globals
|
||||
|
||||
ELECTRON_NOGPU = false
|
||||
CANVAS_FRAMERATE = 1
|
||||
LANG = 'en'
|
||||
ENV = {id: ''}
|
||||
IP = ''
|
||||
25
scripts/docs.rollup.config.js
Normal file
25
scripts/docs.rollup.config.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
var commonjs = require('@rollup/plugin-commonjs'),
|
||||
nodeResolve = require('@rollup/plugin-node-resolve'),
|
||||
json = require('@rollup/plugin-json')
|
||||
|
||||
module.exports = {
|
||||
input: 'src/docs/widgets-reference.mjs',
|
||||
output: [
|
||||
{
|
||||
file: 'src/docs/widgets-reference.js',
|
||||
inlineDynamicImports: true,
|
||||
format: 'commonjs',
|
||||
sourcemap: false,
|
||||
strict: false,
|
||||
indent: false,
|
||||
name: '_'
|
||||
},
|
||||
],
|
||||
plugins: [
|
||||
json(),
|
||||
nodeResolve({
|
||||
browser: true
|
||||
}),
|
||||
commonjs()
|
||||
]
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue