Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

Commit

Permalink
fix(build): Fix build issues caused by updated Google Maps docs
Browse files Browse the repository at this point in the history
commit by @thzinc
from tomchentw#952
  • Loading branch information
Dylan Pinn committed Mar 12, 2019
1 parent 93c9bae commit c4c0661
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
27 changes: 13 additions & 14 deletions src/tx/ClassDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const KlassName = process.argv[2]
fetch(
"https://developers.google.com/maps/documentation/javascript/3.exp/reference"
)
.then(it => it.text())
.then(it => cheerio.load(it))
.then($ => {
const href = $(`#${KlassName} a`).attr("href")
return fetch(href)
})
.then(it => it.text())
.then(it => cheerio.load(it))
.then($ => {
Expand All @@ -33,32 +39,25 @@ function contentToJS(KlassName, $, $content) {
const $constructorTable = $content.find(
`[summary="class ${KlassName} - Constructor"]`
)
const [, constructorArgs] = $constructorTable
.find(`tr > td > code`)
const constructorArgs = $constructorTable
.find(`tbody .desc li code:first-child`)
.text()
.match(/\S+\((.*)\)/)

const $methodsTable = $content.find(
`[summary="class ${KlassName} - Methods"]`
)
const methods = $methodsTable
.find("tbody > tr")
.map((i, tr) => {
const $tr = $(tr)
const [, name, args] = $tr
.find("td:first-child")
.text()
.replace("\n", "")
.match(/(\S+)\((.*)\)/)

const returnsDesc = toMarkdown(
$tr.find("td:nth-child(2) > div.desc").html()
)
const name = $tr.find('[itemprop="property"]').text()
const args = $tr.find('.desc:contains("Parameters") li').text()
const returns = $tr.find('.desc:contains("Return Value") code').text()
const returnsDesc = toMarkdown($tr.find(".desc:last-child").html())

return {
name,
args,
returns: $tr.find("td:nth-child(2) > div > code").text(),
returns,
returnsDesc,
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/tx/MapChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default function transformer(file, api) {
return [
...methodAsProps.map(({ name, args, desc }) => {
const [, prop] = name.match(/^set(\S+)/)
const [, maybeType] = args.match(/\S+:(\S+)/)
const [, maybeType] = args.match(/\S+:\s*(\S+)/)

return Object.assign(
j.objectProperty(
Expand All @@ -136,7 +136,7 @@ export default function transformer(file, api) {
}),
...methodAsProps.map(({ name, args, desc }) => {
const [, prop] = name.match(/^set(\S+)/)
const [, maybeType] = args.match(/\S+:(\S+)/)
const [, maybeType] = args.match(/\S+:\s*(\S+)/)

return Object.assign(
j.objectProperty(
Expand Down

0 comments on commit c4c0661

Please sign in to comment.