diff --git a/scripts/create-docs.js b/scripts/create-docs.js index 1d7f50a6fe..f7b27ad0be 100644 --- a/scripts/create-docs.js +++ b/scripts/create-docs.js @@ -12,6 +12,18 @@ const supertags = ['TimeSeries']; const currentTagsUrl = 'https://api.github.com/repos/heartexlabs/label-studio/contents/docs/source/tags'; +/** + * Conver jsdoc parser type to simple actual type or list of possible values + * @param {{ names: string[] }} type type from jsdoc + * @returns string[] | string + */ +const attrType = ({ names } = {}) => { + if (!names) return undefined; + // boolean values are actually string literals "true" or "false" in config + if (names[0] === 'boolean') return ['true', 'false']; + return names.length > 1 ? names : names[0]; +}; + // header with tag info and autogenerated order // don't touch whitespaces const infoHeader = (name, group, isNew = false, meta = {}) => @@ -32,6 +44,9 @@ const infoHeader = (name, group, isNew = false, meta = {}) => const outputDir = path.resolve(__dirname + '/../docs'); +// schema for CodeMirror autocomplete +const schema = {}; + fs.mkdirSync(outputDir, { recursive: true }); // get list of already exsting tags if possible to set `is_new` flag @@ -55,6 +70,22 @@ fetch(currentTagsUrl) : {}; const header = supertag ? `## ${t.name}\n\n` : infoHeader(t.name, dir, isNew, meta); + // generate tag details + all attributes + schema[t.name] = { + name: t.name, + description: t.description, + attrs: Object.fromEntries(t.params?.map(p => [ + p.name, + { + name: p.name, + description: p.description, + type: attrType(p.type), + required: !p.optional, + default: p.defaultvalue, + }, + ]) ?? []), + }; + // we can use comma-separated list of @regions used by tag const regions = t.customTags && t.customTags.find(desc => desc.tag === 'regions'); // sample regions result and description @@ -147,5 +178,10 @@ fetch(currentTagsUrl) fs.writeFileSync(path.resolve(outputDir, `${name}.md`), str); } } + + // for now only hardcoded list of all tags for View + schema.View.children = Object.keys(schema).filter(name => name !== '!top'); + // @todo proper place + fs.writeFileSync(path.resolve(__dirname, 'tags-schema.json'), JSON.stringify(schema, null, 2)); }) .catch(console.error);