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 d57e521..b2f56fb 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 @@ -10,7 +11,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 ./ @@ -18,9 +19,11 @@ 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 +mkdir -p dist/jest/docs/en node src/modifyDocsHTML.js # read the previously fetched doc site and parse it into sqlite @@ -29,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/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/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 { 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 diff --git a/src/modifyDocsHTML.js b/src/modifyDocsHTML.js index 2125eb2..73bcfd5 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(); @@ -18,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(''); @@ -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!');