Skip to content

Preparations for Jest@23 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
node_modules
Contents/Resources
src/docs
dist/
*.docset
*.tgz
6 changes: 5 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,17 +11,19 @@ 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 ./
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
Expand All @@ -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
Expand Down
20 changes: 11 additions & 9 deletions src/createSectionJSON.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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!');
6 changes: 3 additions & 3 deletions src/getData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 {
Expand Down
84 changes: 0 additions & 84 deletions src/indexedFiles.js

This file was deleted.

16 changes: 10 additions & 6 deletions src/modifyDocsHTML.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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('<a name="//apple_ref/cpp/' + array.toc + '/' + encodeURIComponent(name) + '" class="dashAnchor"></a>');
Expand All @@ -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!');