Skip to content

Commit

Permalink
Merge branch 'master' into fix/app-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
mike12345567 authored Feb 12, 2025
2 parents e8ad728 + 68111de commit 30bb1f2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions packages/string-templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 26 additions & 24 deletions packages/string-templates/scripts/gen-collection-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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."
Expand All @@ -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)) {
Expand All @@ -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, " ")
Expand Down Expand Up @@ -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)) {
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]", "@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"
Expand Down

0 comments on commit 30bb1f2

Please sign in to comment.