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.
# This is a combination of 27 commits.
# This is the 1st commit message: Adding start of Workbox v3 alpha docs # This is the commit message #2: Adding v3 alpha # This is the commit message #3: Adding configuration guide # This is the commit message #4: Adding workbox-precaching and fixing nested parameters # This is the commit message #5: Setting up namespaced docs on WF # This is the commit message #6: Adding ref and module docs for precaching # This is the commit message #7: Adding ref and module docs for precaching # This is the commit message #8: Routing Docs and module guide # This is the commit message #9: Routing Docs and module guide # This is the commit message #10: Adding workbox-cache-expiration guide and reference docs # This is the commit message #11: Adding routing docs # This is the commit message #12: Changing menu name # This is the commit message #13: Adding ability to use custom project yaml # This is the commit message #14: Adding workbox pages # This is the commit message #15: Getting it to work on devsite staging # This is the commit message #16: Adding some headings instead of sections but need to stage # This is the commit message #17: Moving to heading # This is the commit message #18: Adding heading support for navigation # This is the commit message #19: Adding contributor list # This is the commit message #20: Adding more content for docs # This is the commit message #21: Adding in company logos # This is the commit message #22: Adding in company logos # This is the commit message #23: Adding logos # This is the commit message #24: Adding some fixes for left nav # This is the commit message #25: Renaming strategies # This is the commit message #26: Fixng ref doc bug and add missing module pages # This is the commit message #27: Adding Guides etc
- Loading branch information
Matt Gaunt
committed
Nov 15, 2017
1 parent
2f5de32
commit 3c205d7
Showing
161 changed files
with
22,456 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
const gulp = require('gulp'); | ||
const remoteGitTags = require('remote-git-tags'); | ||
const semver = require('semver'); | ||
const fse = require('fs-extra'); | ||
const path = require('path'); | ||
const os = require('os'); | ||
const spawn = require('child_process').spawn; | ||
const glob = require('glob'); | ||
|
||
const PREVIOUS_RELEASES = 0; | ||
|
||
const buildJSDocs = (srcCodePath, docOutputPath, jsdocConfPath) => { | ||
console.log(`\n\n Building JSDocs to '${path.relative(process.cwd(), docOutputPath)}'.`); | ||
|
||
try { | ||
fse.accessSync(jsdocConfPath, fse.F_OK); | ||
} catch (err) { | ||
console.warn(`Unable to find jsdoc Config File @ '${jsdocConfPath}'`); | ||
console.warn(err); | ||
return; | ||
} | ||
|
||
const contentPath = path.join(__dirname, '..', 'src', 'content', 'en'); | ||
const templateBasePath = path.join( | ||
path.posix.sep, | ||
'web', | ||
path.relative(contentPath, docOutputPath) | ||
); | ||
console.log(`\n\n Using JSDoc basepath=${templateBasePath}.`); | ||
|
||
const jsdocConfigContents = fse.readFileSync(jsdocConfPath); | ||
const jsdocConfig = JSON.parse(jsdocConfigContents); | ||
if (!jsdocConfig.webFundamentals) { | ||
console.warn(`In your JSDoc config file you MUST provide a 'webFundamentals' property with:`); | ||
console.warn(` projectRoot`); | ||
console.warn(` productName`); | ||
return; | ||
} | ||
|
||
const queryString = [ | ||
`projectRoot=${jsdocConfig.webFundamentals.projectRoot}`, | ||
`basepath=${templateBasePath}`, | ||
`productName=${jsdocConfig.webFundamentals.productName}`, | ||
].join('&'); | ||
|
||
const jsDocParams = [ | ||
'--template', path.join( | ||
__dirname, '..', 'src', 'templates', 'reference-docs', 'jsdoc' | ||
), | ||
'-c', jsdocConfPath, | ||
'-d', docOutputPath, | ||
'--query', queryString, | ||
]; | ||
|
||
console.log(` JSDoc Params: `, jsDocParams); | ||
|
||
const jsdocPath = path.join(__dirname, '..', 'node_modules', 'jsdoc', 'jsdoc.js'); | ||
|
||
return new Promise((resolve, reject) => { | ||
const jsdocProcess = spawn(jsdocPath, jsDocParams, { | ||
cwd: srcCodePath, | ||
stdio: 'inherit', | ||
}); | ||
|
||
jsdocProcess.on('error', (err) => { | ||
console.error('\n\nUnable to run jsdoc.'); | ||
console.error(err); | ||
}); | ||
|
||
jsdocProcess.on('close', (code) => { | ||
if (code === 0) { | ||
resolve(docOutputPath); | ||
} else { | ||
reject(`Error code: ${code}`); | ||
} | ||
}); | ||
}) | ||
.then((docOutputPath) => { | ||
// jsdoc-baseline copies over these files for it's own template | ||
// but we don't use them for devsite - so remove these files. | ||
fse.removeSync(path.join(docOutputPath, 'css')); | ||
fse.removeSync(path.join(docOutputPath, 'scripts')); | ||
|
||
return docOutputPath; | ||
}) | ||
.then((docOutputPath) => { | ||
// Web Fundamentals linting errors on developers.google.com | ||
const allFiles = glob.sync(path.join(docOutputPath, '**', '*'), { | ||
absolute: true, | ||
}); | ||
allFiles.forEach((filePath) => { | ||
const fileContents = fse.readFileSync(filePath).toString(); | ||
const cleanContents = fileContents | ||
.split('https://developers.google.com/').join('/'); | ||
fse.writeFileSync(filePath, cleanContents); | ||
}); | ||
|
||
return docOutputPath; | ||
}) | ||
.catch((err) => { | ||
// If we error'd, make sure we didn't create a directory that will stop | ||
// future doc builds. | ||
fse.removeSync(docOutputPath); | ||
|
||
console.error(`\n\nUnable to build docs for: '${path.relative(process.cwd(), docOutputPath)}'`); | ||
console.error(err); | ||
|
||
return null; | ||
}); | ||
}; | ||
|
||
const getSourceCode = (gitUrl, tag, tmpPath) => { | ||
fse.ensureDirSync(tmpPath); | ||
|
||
return new Promise((resolve, reject) => { | ||
const gitDownload = spawn('git', [ | ||
'clone', | ||
'--branch', tag, | ||
'--depth', '1', | ||
'--config', 'advice.detachedHead=false', | ||
gitUrl, | ||
tmpPath, | ||
], { | ||
stdio: 'inherit', | ||
}); | ||
|
||
gitDownload.on('error', (err) => { | ||
console.error(`\n\nUnable to retrieve tag '${tag}' from Git.`); | ||
console.error(err); | ||
reject(`Unable to retrieve tag '${tag}' from Git.`); | ||
}); | ||
|
||
gitDownload.on('close', (code) => { | ||
if (code === 0) { | ||
resolve(tmpPath); | ||
} else { | ||
reject(`Error ${code} returned by command: 'git ${params.join(' ')}'`); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
const generateRefDocs = (projectName, gitUrl, docPath, tag, jsdocConfPath, isLatest) => { | ||
// 1. Check if current tag exists, if so return | ||
const outputPath = path.join(docPath, tag); | ||
if (fse.pathExistsSync(outputPath)) { | ||
return; | ||
} | ||
|
||
console.log(`\n\nNeed to build docs for '${projectName}: ${tag}'`); | ||
|
||
const tmpDirectory = path.join(os.tmpdir(), Date.now().toString()); | ||
const tmpSrCodePath = path.join(tmpDirectory, tag); | ||
return getSourceCode(gitUrl, tag, tmpSrCodePath) | ||
.then(() => { | ||
if (isLatest) { | ||
const outputPath = path.join(docPath, 'latest'); | ||
return buildJSDocs(tmpSrCodePath, outputPath, jsdocConfPath); | ||
} | ||
}) | ||
.then(() => { | ||
if (PREVIOUS_RELEASES > 0) { | ||
return buildJSDocs(tmpSrCodePath, outputPath, jsdocConfPath); | ||
} | ||
}) | ||
.then(() => { | ||
fse.removeSync(tmpDirectory); | ||
}, (err) => { | ||
fse.removeSync(tmpDirectory); | ||
throw err; | ||
}); | ||
}; | ||
|
||
const buildReferenceDocs = (projectName, gitUrl, localPath, jsdocConfPath) => { | ||
fse.removeSync(path.join(localPath, 'latest')); | ||
|
||
return generateRefDocs( | ||
projectName, | ||
gitUrl, | ||
localPath, | ||
'v3', | ||
jsdocConfPath, | ||
true, | ||
); | ||
}; | ||
|
||
gulp.task('reference-docs:workbox-v3', () => { | ||
return buildReferenceDocs( | ||
'Workbox', | ||
'https://github.com/GoogleChrome/workbox.git', | ||
path.join(__dirname, '..', 'src/content/en/tools/workbox/v3/reference-docs/'), | ||
path.join(__dirname, '..', 'src/content/en/tools/workbox/v3/_jsdoc.conf') | ||
); | ||
}); |
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,94 @@ | ||
const GitHubApi = require('github'); | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const gulp = require('gulp'); | ||
|
||
const MAX_COLLABORATORS = 20; | ||
|
||
function getContributorHTML(contributorStats) { | ||
const contributor = contributorStats.author; | ||
let html = ` | ||
<div class="wb-contrib"> | ||
<a class="wb-contrib__img-link" href="${contributor.url}" target="_blank"> | ||
<img class="wb-contrib__image" src="${contributor.avatar_url}"> | ||
</a> | ||
<br /> | ||
<a class="wb-contrib__link" href="${contributor.url}" target="_blank"> | ||
${contributor.login} | ||
</a> | ||
</div> | ||
`; | ||
return html; | ||
} | ||
|
||
gulp.task(`workbox:generate-contributors`, function() { | ||
if (!process.env.GITHUB_TOKEN) { | ||
console.warn(`Unable to build Workbox contributors due to no ` + | ||
`GITHUB_TOKEN existing on the current Path.`); | ||
|
||
// Return a promise so gulp is happy and thinks the task completed | ||
return Promise.resolve(); | ||
} | ||
|
||
const github = new GitHubApi(); | ||
github.authenticate({ | ||
type: 'token', | ||
token: process.env.GITHUB_TOKEN | ||
}); | ||
|
||
return github.repos.getStatsContributors({ | ||
owner: 'googlechrome', | ||
repo: 'workbox', | ||
}) | ||
.then((contributorStats) => { | ||
contributorStats.sort((a, b) => b.total - a.total); | ||
if (contributorStats.length > MAX_COLLABORATORS) { | ||
contributorStats = contributorStats.splice(0, MAX_COLLABORATORS); | ||
} | ||
return contributorStats.map(getContributorHTML).join(''); | ||
}) | ||
.then((html) => { | ||
const finalHtml = `{% framebox height="auto" %} | ||
<!-- This file is auto-generated by 'gulp workbox:generate-contributors' --> | ||
<style> | ||
.workbox-contributors-container { | ||
display: flex; | ||
flex-direction: row; | ||
flex-wrap: wrap; | ||
justify-content: space-around; | ||
} | ||
.wb-contrib { | ||
text-align: center; | ||
margin: 10px; | ||
} | ||
.wb-contrib a { | ||
color: inherit; | ||
} | ||
.wb-contrib__image { | ||
width: 80px; | ||
height: 80px; | ||
border-radius: 100%; | ||
box-shadow: 0 4px 6px #616161; | ||
background-color: white; | ||
} | ||
</style> | ||
<div class="workbox-contributors-container"> | ||
${html} | ||
</div> | ||
{% endframebox %}`; | ||
const templatePath = path.join(__dirname, '..', 'src', 'content', | ||
'en', 'tools', 'workbox', 'templates', 'contributors.html'); | ||
return fs.ensureDir(path.dirname(templatePath)) | ||
.then(() => fs.writeFile(templatePath, finalHtml)) | ||
.catch((err) => { | ||
console.warn(`An error occured when generating the Workbox ` + | ||
`collaborators.`); | ||
console.warn(`This is not a vital error.`); | ||
console.warn(err); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.