From 493b65ec93c89c840809b827a392edda341adb0e Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Fri, 1 Jun 2018 18:06:06 +0800 Subject: [PATCH 1/5] Set retry times, timeout and new url --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index d57e521..71ef312 100755 --- a/build.sh +++ b/build.sh @@ -10,7 +10,7 @@ sqlite3 docSet.dsidx 'CREATE UNIQUE INDEX anchor ON searchIndex (name, type, pat # fetch the whole doc site cd Documents -wget -m -p -E -k -np http://facebook.github.io/jest/ +wget -m -p -E -k -np -t 3 -T 10 https://facebook.github.io/jest/ # move it around a bit mv facebook.github.io/jest ./ From 64538ac0bab8438dd734bc2ca64c86744bff2a01 Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Fri, 1 Jun 2018 18:30:59 +0800 Subject: [PATCH 2/5] Fix createSectionJSON.js and generate to dist folder --- .gitignore | 2 +- build.sh | 2 + src/createSectionJSON.js | 20 +++++----- src/indexedFiles.js | 84 ---------------------------------------- 4 files changed, 14 insertions(+), 94 deletions(-) delete mode 100644 src/indexedFiles.js diff --git a/.gitignore b/.gitignore index 58c7119..a627cc2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .DS_Store node_modules Contents/Resources -src/docs +dist/ *.docset *.tgz diff --git a/build.sh b/build.sh index 71ef312..5162e69 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,7 @@ # clean up previous remains, if any rm -rf Contents/Resources rm -rf Jest.docset +rm -rf dist mkdir -p Contents/Resources/Documents # create a fresh sqlite db @@ -18,6 +19,7 @@ rm -rf facebook.github.io cd ../../../ # create data file from base index page +mkdir dist node src/createSectionJSON.js # change the documentation markup layout a bit to fit dash's small window diff --git a/src/createSectionJSON.js b/src/createSectionJSON.js index 53d0dd3..d13f71a 100644 --- a/src/createSectionJSON.js +++ b/src/createSectionJSON.js @@ -1,38 +1,38 @@ var cheerio = require('cheerio'); var fs = require('fs'); +var path = require('path'); var config = require('./config'); // get base file to itterate over -var basePath = __dirname + '/../Contents/Resources/Documents/' + config.name + '/docs/' + config.index; +var basePath = __dirname + '/../Contents/Resources/Documents/' + config.name + '/docs/en/' + config.index; var baseSrc = fs.readFileSync(basePath, 'utf8'); var $ = cheerio.load(baseSrc); var pageNamesArray = []; var $section = $('.' + config.sectionClass); -var path = __dirname + '/../src/indexedFiles.js'; +var outputPath = __dirname + '/../dist/indexedFiles.js'; $section.each(function(i, elem){ // TODO: create a better config pointer - var $sectionHeader = $(this).children(config.headerTag).text(); + var sectionHeader = $(this).children(config.headerTag).text(); var $sectionLink = $(this).children('ul').children('li').children('a'); + console.log(`Found section ${sectionHeader}...`); $sectionLink.each(function(i, elem){ var page = {}; - if(config.ignoreSection.sectionsArray.indexOf($sectionHeader) !== -1) { + if(config.ignoreSection.sectionsArray.indexOf(sectionHeader) !== -1) { return; } - // $(this).attr('href') returns ie.(guides-containers.html#content) - // substring removes last 13 characters '.html#content' from href. - page.name = $(this).attr('href').substring(0, $(this).attr('href').length - 13); + page.name = path.basename($(this).attr('href'), '.html'); if(config.ignorePage.pagesArray.indexOf(page.name) !== -1) { return; } // set the Dash types based on the doc headers. - switch ($sectionHeader) { + switch (sectionHeader) { case 'Core Concepts': page.type = 'Library'; page.toc = 'Property'; @@ -46,7 +46,9 @@ $section.each(function(i, elem){ page.toc = config.defaultPageTOC; }; pageNamesArray.push(page); + console.log(`Found page ${page.name}...`); }); }); -fs.writeFile(path, 'var indexedFiles = ' + JSON.stringify(pageNamesArray, null, 4) + ';\n\nmodule.exports = indexedFiles;', 'utf8'); +fs.writeFileSync(outputPath, 'var indexedFiles = ' + JSON.stringify(pageNamesArray, null, 4) + ';\n\nmodule.exports = indexedFiles;', 'utf8'); +console.log('...indexedFiles.js generated!'); diff --git a/src/indexedFiles.js b/src/indexedFiles.js deleted file mode 100644 index b51b6e1..0000000 --- a/src/indexedFiles.js +++ /dev/null @@ -1,84 +0,0 @@ -var indexedFiles = [ - { - "name": "getting-started", - "type": "Guides", - "toc": "Section" - }, - { - "name": "using-matchers", - "type": "Guides", - "toc": "Section" - }, - { - "name": "asynchronous", - "type": "Guides", - "toc": "Section" - }, - { - "name": "setup-teardown", - "type": "Guides", - "toc": "Section" - }, - { - "name": "mock-functions", - "type": "Guides", - "toc": "Section" - }, - { - "name": "more-resources", - "type": "Guides", - "toc": "Section" - }, - { - "name": "snapshot-testing", - "type": "Guides", - "toc": "Section" - }, - { - "name": "tutorial-react", - "type": "Guides", - "toc": "Section" - }, - { - "name": "tutorial-react-native", - "type": "Guides", - "toc": "Section" - }, - { - "name": "tutorial-async", - "type": "Guides", - "toc": "Section" - }, - { - "name": "timer-mocks", - "type": "Guides", - "toc": "Section" - }, - { - "name": "manual-mocks", - "type": "Guides", - "toc": "Section" - }, - { - "name": "webpack", - "type": "Guides", - "toc": "Section" - }, - { - "name": "migration-guide", - "type": "Guides", - "toc": "Section" - }, - { - "name": "testing-frameworks", - "type": "Guides", - "toc": "Section" - }, - { - "name": "troubleshooting", - "type": "Guides", - "toc": "Section" - } -]; - -module.exports = indexedFiles; \ No newline at end of file From bc2ac096c045175ab635cf260e692138469628a7 Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Fri, 1 Jun 2018 18:44:48 +0800 Subject: [PATCH 3/5] Update modifiyDocsHTML.js --- build.sh | 1 + src/modifyDocsHTML.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index 5162e69..0deaca9 100755 --- a/build.sh +++ b/build.sh @@ -23,6 +23,7 @@ mkdir dist node src/createSectionJSON.js # change the documentation markup layout a bit to fit dash's small window +mkdir -p dist/jest/docs/en node src/modifyDocsHTML.js # read the previously fetched doc site and parse it into sqlite diff --git a/src/modifyDocsHTML.js b/src/modifyDocsHTML.js index 2125eb2..998ac13 100644 --- a/src/modifyDocsHTML.js +++ b/src/modifyDocsHTML.js @@ -1,14 +1,16 @@ var cheerio = require('cheerio'); var fs = require('fs'); var config = require('./config'); -var indexedFiles = require('./indexedFiles'); +var indexedFiles = require('../dist/indexedFiles'); // remove the left column and the nav bar so that it fits dash's usually small // browser screen indexedFiles.forEach(function(array, index) { - //console.log(array); - var path = __dirname + '/../Contents/Resources/Documents/' + config.name + '/docs/' + array.name + '.html'; - var src = fs.readFileSync(path, 'utf8'); + var inputBaseDir = __dirname + '/../Contents/Resources/Documents/' + config.name; + var outputBaseDir = __dirname + '/../dist/' + config.name; + var commonPath = '/docs/en/' + array.name + '.html'; + + var src = fs.readFileSync(inputBaseDir + commonPath, 'utf8'); var $ = cheerio.load(src); var headerClasses = config.pageSubHeaders.toString(); @@ -36,5 +38,7 @@ indexedFiles.forEach(function(array, index) { $('.docMainWrapper').attr('style', 'width:inherit;'); $('.post').attr('style', 'float:none;margin:auto;'); - fs.writeFileSync(path, $.html(), 'utf8'); + fs.writeFileSync(outputBaseDir + commonPath, $.html(), 'utf8'); + console.log(`Done ${commonPath}...`); }); +console.log('...modifyDocsHTML done!'); From 64e6f29ca8e0d87a35a2eab86ed308951281411a Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Fri, 1 Jun 2018 18:51:08 +0800 Subject: [PATCH 4/5] Update index.js --- build.sh | 1 + src/getData.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index 0deaca9..b2f56fb 100755 --- a/build.sh +++ b/build.sh @@ -32,6 +32,7 @@ node src/index.js # bundle up! mkdir Jest.docset cp -r Contents Jest.docset +cp -r dist/jest Jest.docSet/Contents/Resources/Documents/ cp src/icon* Jest.docset # Create gzip bundle for Dash Contribution diff --git a/src/getData.js b/src/getData.js index e317e89..d3bd3b3 100644 --- a/src/getData.js +++ b/src/getData.js @@ -2,13 +2,13 @@ var cheerio = require('cheerio'); var fs = require('fs'); var flatten = require('lodash.flatten'); var config = require('./config'); -var indexedFiles = require('./indexedFiles'); +var indexedFiles = require('../dist/indexedFiles'); // this assumes build.sh has been run, and the jest docs fetched into // Contents/Resources/Documents/jest function getData() { var res = indexedFiles.map(function(array) { - var path = __dirname + '/../Contents/Resources/Documents/' + config.name + '/docs/' + array.name + '.html'; + var path = __dirname + '/../dist/' + config.name + '/docs/en/' + array.name + '.html'; var src = fs.readFileSync(path, 'utf-8'); var $ = cheerio.load(src); @@ -22,7 +22,7 @@ function getData() { names.push(name.trim()); }); - var url = config.name + '/docs/' + array.name + '.html'; + var url = config.name + '/docs/en/' + array.name + '.html'; var res = names.map(function(n, i) { return { From 077e8951adf396fec81a9da24fac0199cd772d6e Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Fri, 1 Jun 2018 22:25:25 +0800 Subject: [PATCH 5/5] Fix dashAnchor name --- src/modifyDocsHTML.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modifyDocsHTML.js b/src/modifyDocsHTML.js index 998ac13..73bcfd5 100644 --- a/src/modifyDocsHTML.js +++ b/src/modifyDocsHTML.js @@ -20,7 +20,7 @@ indexedFiles.forEach(function(array, index) { // Remove "Edit this Page" Button $('.edit-page-link').remove(); - var name = $($(elem).contents().get(1)).text(); + var name = $(elem).text(); // TODO: Change "array.toc to somehting more relevant on a page-by-page basis in indexedFiles.js" $(elem).prepend('');