-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Apply border-radius in JS frame * Add border around every type of example * Adds height-data.json * Add missing exports in processor.js * Apply prettier on processor.js * Include height of the editors
- Loading branch information
1 parent
60341bf
commit b4f2d09
Showing
5 changed files
with
294 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
{ | ||
"editors": [ | ||
{ | ||
"name": "css", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 675 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 375 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "js-taller", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 723 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 654 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "js-standard", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 513 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 444 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "js-smaller", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 433 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 364 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "wat-taller", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 686 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 617 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "wat-standard", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 476 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 407 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "wat-smaller", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 406 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 337 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "tabbed-taller", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 774 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 630 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "tabbed-standard", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 549 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 420 | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "tabbed-shorter", | ||
"heights": [ | ||
{ | ||
"minFrameWidth": 0, | ||
"height": 487 | ||
}, | ||
{ | ||
"minFrameWidth": 590, | ||
"height": 350 | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import fse from "fs-extra"; | ||
import glob from "glob"; | ||
|
||
import getConfig from "./config.js"; | ||
import { getJSPageHeight, getWatPageHeight } from "./processor.js"; | ||
|
||
const config = getConfig(); | ||
|
||
function getEditorHeights() { | ||
return fse.readJsonSync(config.editorHeights); | ||
} | ||
|
||
/** | ||
* Converts content of meta.json to object containing path and editor name of every interactive example present in that file | ||
* | ||
* In case meta.json is missing required height property or it has unsupported value, exception is thrown | ||
* @param metaContent - Content of meta.json as an JS object | ||
*/ | ||
function getPagesEditorNames(metaContent) { | ||
const pages = Object.values(metaContent.pages); | ||
const editorNames = {}; | ||
|
||
for (const page of pages) { | ||
const height = getEditorName(page); | ||
if (height !== undefined) { | ||
const path = getPagePath(page); | ||
editorNames[path] = height; | ||
} | ||
} | ||
return editorNames; | ||
} | ||
|
||
function getPagePath(page) { | ||
return `pages/${page.type}/${page.fileName}`; | ||
} | ||
|
||
/** | ||
* Returns editor name for a given page, based on its height | ||
* Every editor name must have a record in editor-heights.json | ||
* @param page - Object describing single interactive example | ||
* @return {String} - editor name | ||
*/ | ||
function getEditorName(page) { | ||
switch (page.type) { | ||
case "css": | ||
return "css"; | ||
case "tabbed": | ||
case "webapi-tabbed": | ||
switch (page.height) { | ||
case "tabbed-taller": | ||
case "tabbed-standard": | ||
case "tabbed-shorter": | ||
return page.height; | ||
default: | ||
throw new Error( | ||
`MDN-BOB: (heightBuilder.js) Invalid height property for ${page.fileName}` | ||
); | ||
} | ||
case "js": { | ||
const height = getJSPageHeight(page.exampleCode); | ||
switch (height) { | ||
case "taller": | ||
return "js-taller"; | ||
case "": | ||
return "js-standard"; | ||
case "shorter": | ||
return "js-smaller"; | ||
default: | ||
throw new Error( | ||
`MDN-BOB: (heightBuilder.js) Height '${height}' calculated for JS example '${page.fileName}' is invalid` | ||
); | ||
} | ||
} | ||
case "wat": { | ||
const height = getWatPageHeight(page.watExampleCode); | ||
switch (height) { | ||
case "taller": | ||
return "wat-taller"; | ||
case "standard": | ||
return "wat-standard"; | ||
case "shorter": | ||
return "wat-smaller"; | ||
default: | ||
throw new Error( | ||
`MDN-BOB: (heightBuilder.js) Height '${height}' calculated for WAT example '${page.fileName}' is invalid` | ||
); | ||
} | ||
} | ||
default: | ||
throw new Error( | ||
`MDN-BOB: (heightBuilder.js) Unsupported page type ${page.type}` | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Builds height-data.json containing path and editor name of every interactive example in `examples` property, | ||
* together with content of editor-heights which contains name and the height of every editor type | ||
*/ | ||
export default function buildHeightData() { | ||
const metaJSONArray = glob.sync(config.metaGlob, {}); | ||
const heightData = { | ||
...getEditorHeights(), | ||
}; | ||
heightData.examples = {}; | ||
|
||
for (const metaJson of metaJSONArray) { | ||
const file = fse.readJsonSync(metaJson); | ||
|
||
const names = getPagesEditorNames(file); | ||
Object.assign(heightData.examples, names); | ||
} | ||
|
||
const jsonData = JSON.stringify(heightData, null, 4); | ||
fse.outputFileSync(config.heightData, jsonData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters