From c4c06612f9fc5c325125d433787b3c313d4195b4 Mon Sep 17 00:00:00 2001 From: Dylan Pinn Date: Tue, 12 Mar 2019 17:23:44 +1100 Subject: [PATCH] fix(build): Fix build issues caused by updated Google Maps docs commit by @thzinc from tomchentw/react-google-maps#952 --- src/tx/ClassDefinition.js | 27 +++++++++++++-------------- src/tx/MapChild.js | 4 ++-- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/tx/ClassDefinition.js b/src/tx/ClassDefinition.js index 705c8fa9..2b3c57e6 100644 --- a/src/tx/ClassDefinition.js +++ b/src/tx/ClassDefinition.js @@ -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($ => { @@ -33,11 +39,9 @@ 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"]` ) @@ -45,20 +49,15 @@ function contentToJS(KlassName, $, $content) { .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, } }) diff --git a/src/tx/MapChild.js b/src/tx/MapChild.js index 1ff79c03..216c6398 100644 --- a/src/tx/MapChild.js +++ b/src/tx/MapChild.js @@ -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( @@ -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(