forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1522992 - generate TOC's in READMEs
- Loading branch information
Showing
46 changed files
with
219 additions
and
67 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
TaskCluster Hooks | ||
================= | ||
# Hooks Service | ||
|
||
A hooks service for triggering tasks from events. | ||
|
||
|
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Taskcluster Infrastructure | ||
# Infrastructure | ||
|
||
Tools and packages that are used to run a deployment of Taskcluster. |
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
75 changes: 75 additions & 0 deletions
75
infrastructure/builder/src/generate/generators/readme-tocs.js
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,75 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const {gitLsFiles, readFile, writeFile} = require('../util'); | ||
|
||
exports.tasks = [{ | ||
title: 'README TOCs', | ||
provides: ['target-readme-tocs'], | ||
run: async (requirements, utils) => { | ||
utils.status({message: 'gathering READMEs'}); | ||
let readmes = (await gitLsFiles()) | ||
.filter(file => file.endsWith('README.md')) | ||
// ignore generated output | ||
.filter(file => !file.startsWith('generated/')) | ||
// some test directories have READMEs | ||
.filter(file => !file.match(/\/test\//)) | ||
.map(file => ({dir: path.dirname(file).replace(/^.$/, ''), children: []})); | ||
|
||
// read each README and extract titles where available | ||
const firstLine = /^# (.*)\n/; | ||
for (let readme of readmes) { | ||
readme.content = await readFile(path.join(readme.dir, 'README.md')); | ||
const match = firstLine.exec(readme.content); | ||
if (match) { | ||
readme.title = match[1]; | ||
} | ||
} | ||
|
||
// organize readmes into a hierarchy | ||
readmes.sort((a, b) => b.dir.length - a.dir.length); | ||
for (let readme of [...readmes]) { | ||
const remainder = []; | ||
for (let child of readmes) { | ||
if (child.dir.length > readme.dir.length && child.dir.startsWith(readme.dir)) { | ||
readme.children.push(child); | ||
} else { | ||
remainder.push(child); | ||
} | ||
} | ||
readmes = remainder; | ||
} | ||
|
||
// generate the lines of a table of contents for a particular README | ||
const tocLines = (lines, indent, dir, children) => { | ||
for (let child of children) { | ||
const relative = path.relative(dir, child.dir); | ||
const title = child.title || relative; | ||
lines.push(`${indent}* [${title}](${relative})`); | ||
tocLines(lines, `${indent} `, dir, child.children); | ||
} | ||
return lines; | ||
}; | ||
|
||
// recursively write out TOC's | ||
const rewrite = async ({content, dir, title, children}) => { | ||
const lines = tocLines([], '', dir, children); | ||
if (lines.length > 0) { | ||
utils.status({message: `rewriting ${path.join(dir, 'README.md')}`}); | ||
const newContent = content.replace( | ||
/(<!-- TOC BEGIN -->)(?:.|\n)*(<!-- TOC END -->)/m, | ||
`$1\n${lines.join('\n')}\n$2`); | ||
if (content !== newContent) { | ||
await writeFile(path.join(dir, 'README.md'), newContent); | ||
} | ||
} | ||
|
||
for (let child of children) { | ||
await rewrite(child); | ||
} | ||
}; | ||
|
||
for (let readme of readmes) { | ||
await rewrite(readme); | ||
} | ||
}, | ||
}]; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Taskcluster Terraform | ||
# Terraform | ||
|
||
A simple module to set up some requirements for a Taskcluster deployment. | ||
|
||
|
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 |
---|---|---|
@@ -1,3 +1,22 @@ | ||
# Taskcluster Libraries | ||
# Libraries | ||
|
||
These are any packages that are used by Taskcluster services that aren't intended to be used widely externally. | ||
|
||
## Table of Contents | ||
|
||
<!-- TOC BEGIN --> | ||
* [Typed-Env-Config Library](typed-env-config) | ||
* [References Library](references) | ||
* [Validate Library](validate) | ||
* [Testing Library](testing) | ||
* [Iterate Library](iterate) | ||
* [Monitor Library](monitor) | ||
* [Scopes Library](scopes) | ||
* [Taskcluster Client](client) | ||
* [Loader Library](loader) | ||
* [Azure Library](azure) | ||
* [Pulse Library](pulse) | ||
* [Docs Library](docs) | ||
* [API Library](api) | ||
* [App Library](app) | ||
<!-- TOC END --> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
Taskcluster-lib-testing | ||
======================= | ||
# Testing Library | ||
|
||
Support for testing TaskCluster components. | ||
|
||
|
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 |
---|---|---|
@@ -1,3 +1,20 @@ | ||
# Taskcluster Services | ||
# Services | ||
|
||
These are any packages that are run as part of a deployment of Taskcluster. | ||
|
||
## Table of Contents | ||
|
||
<!-- TOC BEGIN --> | ||
* [Built-In Workers Service](built-in-workers) | ||
* [Purge-Cache Service](purge-cache) | ||
* [Web-Server Service](web-server) | ||
* [Treeherder Service](treeherder) | ||
* [Secrets Service](secrets) | ||
* [Notify Service](notify) | ||
* [Github Service](github) | ||
* [Queue Service](queue) | ||
* [Login Service](login) | ||
* [Index Service](index) | ||
* [Hooks Service](hooks) | ||
* [Auth Service](auth) | ||
<!-- TOC END --> |
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.