This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Puppeteer to /web/tools/ (#5644)
* Add Puppeteer to /web/tools * Make tests pass * Support {% includecode github_path="..." regex="..."} * Use real path * better nav * Build scripts for puppeteer docs * make eslint happy * fix build error * Add ppptr docs build to travis * Fix travis? * update desc * feedback * remove _project.yaml for now * remove footer
- Loading branch information
Showing
22 changed files
with
352 additions
and
16 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
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
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,128 @@ | ||
/** | ||
* @fileoverview Generates the Puppeteer docs at /web/tools/puppeteer/ | ||
* | ||
* @author Eric Bidelman <e.bidelman@google.com> | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const gulp = require('gulp'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
const jsYaml = require('js-yaml'); | ||
const {promisify} = require('util'); | ||
const semver = require('semver'); | ||
|
||
const checkoutRepoAtTag = require('../reference-docs/get-source-code'); | ||
const wfHelper = require('../wfHelper'); | ||
|
||
const readFile = promisify(fs.readFile); | ||
const ensureDir = promisify(fs.ensureDir); | ||
const writeFile = promisify(fs.writeFile); | ||
|
||
const ORG = 'GoogleChrome'; | ||
const USER = 'puppeteer'; | ||
const GITHUB_PROJECT_URL = `https://github.com/${ORG}/${USER}`; | ||
const GIT_URL = `${GITHUB_PROJECT_URL}.git`; | ||
const NUM_RELEASES_TO_INCLUDE = 3; | ||
|
||
const DOC_FILES = [ | ||
'README.md', | ||
'docs/troubleshooting.md', | ||
'examples/README.md', | ||
]; | ||
|
||
const PPTR_FOLDER_PATH = path.join( | ||
__dirname, '..', '..', 'src', 'content', 'en', 'tools', 'puppeteer' | ||
); | ||
|
||
/** | ||
* Writes a file to disk. | ||
* @param {string} outputFile Path to output file | ||
* @param {string} content File content to write. | ||
*/ | ||
async function saveFile(outputFile, content) { | ||
const filePath = path.join(PPTR_FOLDER_PATH, '_src', outputFile); | ||
await ensureDir(path.dirname(filePath)); | ||
await writeFile(filePath, content); | ||
} | ||
|
||
/** | ||
* Updates _toc.yaml file with latest releases and saves file to disk. | ||
* @param {string} tocYaml Path to toc yaml file. | ||
* @param {!Array<string>} tags | ||
*/ | ||
async function generateTOC(tocYaml, tags) { | ||
const items = tags.map((tag, i) => { | ||
const obj = { | ||
title: tag, | ||
section: [{ | ||
title: 'Docs', | ||
path: `${GITHUB_PROJECT_URL}/blob/${tag}/docs/api.md`, | ||
status: 'external', | ||
}, { | ||
title: 'Release Notes', | ||
path: `${GITHUB_PROJECT_URL}/releases/tag/${tag}`, | ||
status: 'external', | ||
}], | ||
}; | ||
// Latest release. | ||
if (i === 0) { | ||
obj.status = 'new'; | ||
} | ||
return obj; | ||
}); | ||
|
||
items.push({ | ||
title: 'Old releases', | ||
path: `${GITHUB_PROJECT_URL}/releases`, | ||
status: 'external', | ||
}); | ||
|
||
const filePath = path.join(PPTR_FOLDER_PATH, '_src', 'api_section.yaml'); | ||
await writeFile(filePath, jsYaml.safeDump({toc: items})); | ||
} | ||
|
||
/** | ||
* Extracts a devsite START/END region from file. | ||
* @param {string} content | ||
* @param {string} region Name of region to pull out. | ||
* @return {string|null} | ||
*/ | ||
function extractRegion(content, region) { | ||
const re = new RegExp( | ||
`<!-- \\[START ${region}\\] -->([\\s\\S]*)<!-- \\[END ${region}\\] -->`); | ||
const m = content.match(re); | ||
return m && m[0] || null; | ||
} | ||
|
||
gulp.task('puppeteer:build', async () => { | ||
const result = await wfHelper.promisedExec( | ||
`git ls-remote --tags ${GITHUB_PROJECT_URL}`, '.'); | ||
const refs = result.split('\n'); | ||
const tags = refs.map((ref) => ref.split('refs/tags/')[1]) | ||
.sort(semver.rcompare).slice(0, NUM_RELEASES_TO_INCLUDE); | ||
const latestTag = tags[0]; | ||
|
||
const tmpDir = path.join(os.tmpdir(), Date.now().toString(), latestTag); | ||
await checkoutRepoAtTag(GIT_URL, latestTag, tmpDir); | ||
|
||
// Extract sections from README and create separate .md files for them. | ||
const readme = DOC_FILES.shift(); | ||
let content = await readFile(path.join(tmpDir, readme), {encoding: 'utf-8'}); | ||
await saveFile('_index/badges.md', extractRegion(content, 'badges')); | ||
await saveFile('_index/usecases.md', extractRegion(content, 'usecases')); | ||
await saveFile('_index/getstarted.md', extractRegion(content, 'getstarted')); | ||
await saveFile('_index/debugging.md', extractRegion(content, 'debugging')); | ||
await saveFile( | ||
'_index/runtimesettings.md', extractRegion(content, 'runtimesettings')); | ||
await saveFile('_index/faq.md', extractRegion(content, 'faq')); | ||
|
||
for (const iFile of DOC_FILES) { | ||
let content = await readFile(path.join(tmpDir, iFile), {encoding: 'utf-8'}); | ||
await saveFile(iFile, content); | ||
} | ||
|
||
await generateTOC(path.join(PPTR_FOLDER_PATH, '_toc.yaml'), tags); | ||
}); |
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
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,5 @@ | ||
<style> | ||
.page-title { | ||
display: none; | ||
} | ||
</style> |
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,50 @@ | ||
toc: | ||
- heading: Get Started | ||
- title: Overview | ||
path: /web/tools/puppeteer/ | ||
- title: Get Started | ||
path: /web/tools/puppeteer/get-started | ||
- title: API Reference | ||
style: accordion | ||
section: | ||
- include: /web/tools/puppeteer/_src/api_section.yaml | ||
- title: Examples | ||
path: /web/tools/puppeteer/examples | ||
|
||
- heading: Resources | ||
- title: Debugging tips | ||
path: /web/tools/puppeteer/debugging | ||
- title: Troubleshooting | ||
path: /web/tools/puppeteer/troubleshooting | ||
- title: Headless Chrome | ||
style: accordian | ||
section: | ||
- title: Getting Started with Headless Chrome | ||
path: /web/updates/2017/04/headless-chrome | ||
- title: Automated testing with Headless Chrome | ||
path: /web/updates/2017/06/headless-karma-mocha-chai | ||
- title: DevTools Protocol APIs | ||
path: 'https://chromedevtools.github.io/devtools-protocol/' | ||
status: external | ||
- title: Try Puppeteer! | ||
path: 'https://try-puppeteer.appspot.com/' | ||
status: external | ||
|
||
- heading: Project | ||
- title: NPM | ||
path: 'https://www.npmjs.com/package/puppeteer' | ||
status: external | ||
- title: Github | ||
path: 'https://github.com/GoogleChrome/puppeteer' | ||
status: external | ||
- title: Report an issue | ||
path: 'https://github.com/GoogleChrome/puppeteer/issues/new' | ||
status: external | ||
- title: Releases | ||
path: 'https://github.com/GoogleChrome/puppeteer/releases' | ||
status: external | ||
- title: How to Contribute | ||
path: 'https://github.com/GoogleChrome/puppeteer/blob/master/CONTRIBUTING.md' | ||
status: external | ||
- title: FAQ | ||
path: /web/tools/puppeteer/faq |
Oops, something went wrong.