Merge branch 'fix/app-preview' of github.com:Budibase/budibase into fix/app-preview

This commit is contained in:
mike12345567 2025-02-12 17:06:18 +00:00
commit 8e791bdcb8
3 changed files with 32 additions and 24 deletions

View File

@ -33,6 +33,7 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "8.3.0",
"@types/doctrine": "^0.0.9",
"doctrine": "^3.0.0",
"jest": "29.7.0",
"marked": "^4.0.10",

View File

@ -7,18 +7,30 @@ import { marked } from "marked"
import { join, dirname } from "path"
const helpers = require("@budibase/handlebars-helpers")
const doctrine = require("doctrine")
import doctrine, { Annotation } from "doctrine"
type HelperInfo = {
type BudibaseAnnotation = Annotation & {
example?: string
acceptsInline?: boolean
acceptsBlock?: boolean
}
type Helper = {
args: string[]
numArgs: number
example?: string
description: string
tags?: any[]
requiresBlock?: boolean
}
type Manifest = {
[category: string]: {
[helper: string]: Helper
}
}
const FILENAME = join(__dirname, "..", "src", "manifest.json")
const outputJSON: any = {}
const outputJSON: Manifest = {}
const ADDED_HELPERS = {
date: {
date: {
@ -38,11 +50,10 @@ const ADDED_HELPERS = {
},
}
function fixSpecialCases(name: string, obj: any) {
const args = obj.args
function fixSpecialCases(name: string, obj: Helper) {
if (name === "ifNth") {
args[0] = "a"
args[1] = "b"
obj.args = ["a", "b", "options"]
obj.numArgs = 3
}
if (name === "eachIndex") {
obj.description = "Iterates the array, listing an item and the index of it."
@ -66,10 +77,10 @@ function lookForward(lines: string[], funcLines: string[], idx: number) {
return true
}
function getCommentInfo(file: string, func: string): HelperInfo {
function getCommentInfo(file: string, func: string): BudibaseAnnotation {
const lines = file.split("\n")
const funcLines = func.split("\n")
let comment = null
let comment: string | null = null
for (let idx = 0; idx < lines.length; ++idx) {
// from here work back until we have the comment
if (lookForward(lines, funcLines, idx)) {
@ -91,15 +102,9 @@ function getCommentInfo(file: string, func: string): HelperInfo {
}
}
if (comment == null) {
return { description: "" }
return { description: "", tags: [] }
}
const docs: {
acceptsInline?: boolean
acceptsBlock?: boolean
example: string
description: string
tags: any[]
} = doctrine.parse(comment, { unwrap: true })
const docs: BudibaseAnnotation = doctrine.parse(comment, { unwrap: true })
// some hacky fixes
docs.description = docs.description.replace(/\n/g, " ")
docs.description = docs.description.replace(/[ ]{2,}/g, " ")
@ -135,7 +140,7 @@ function run() {
)}/lib/${collection}.js`,
"utf8"
)
const collectionInfo: any = {}
const collectionInfo: { [name: string]: Helper } = {}
// collect information about helper
let hbsHelperInfo = helpers[collection]()
for (let entry of Object.entries(hbsHelperInfo)) {
@ -154,11 +159,8 @@ function run() {
const jsDocInfo = getCommentInfo(collectionFile, fnc)
let args = jsDocInfo.tags
.filter(tag => tag.title === "param")
.map(
tag =>
tag.description &&
tag.description.replace(/`/g, "").split(" ")[0].trim()
)
.filter(tag => tag.description)
.map(tag => tag.description!.replace(/`/g, "").split(" ")[0].trim())
collectionInfo[name] = fixSpecialCases(name, {
args,
numArgs: args.length,

View File

@ -6456,6 +6456,11 @@
"@types/node" "*"
"@types/ssh2" "*"
"@types/doctrine@^0.0.9":
version "0.0.9"
resolved "https://registry.yarnpkg.com/@types/doctrine/-/doctrine-0.0.9.tgz#d86a5f452a15e3e3113b99e39616a9baa0f9863f"
integrity sha512-eOIHzCUSH7SMfonMG1LsC2f8vxBFtho6NGBznK41R84YzPuvSBzrhEps33IsQiOW9+VL6NQ9DbjQJznk/S4uRA==
"@types/estree@*", "@types/estree@1.0.5", "@types/estree@^1.0.0", "@types/estree@^1.0.1":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"