Files
blockly/scripts/gulpfiles/docs_tasks.js
Beka Westberg 48228e47e3 chore: merge develop into v11 to fix CI (#7893)
* fix: destroy connection highlight when the connection is disposed (#7830)

* fix: fix reference docs toc generation (#7832)

* fix: insertion marker previewer finding wrong connection for different conn counts (#7833)

* feat: make grid options togglable (#7828)

* chore(deps): Bump prettier from 3.1.1 to 3.2.5 (#7831)

Bumps [prettier](https://github.com/prettier/prettier) from 3.1.1 to 3.2.5.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/3.1.1...3.2.5)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: disposing of connection previewer (#7834)

* fix: typo in Click event class docs

* chore: rollup of updates from translatewiki for 10.4.0 (#7856)

* chore: update metadata for v10.4.0 (#7857)

* release: update version number to 10.4.0

* fix: connection previewer disposing too early

* Merge pull request #7859 from BeksOmega/fix/previewer-disposing

fix: connection previewer disposing too early
(cherry picked from commit da3ec253bf)

* release: update version number to 10.4.1

* chore: move connection previewer out of subfolder (#7835)

* chore(deps-dev): Bump undici from 5.26.3 to 5.28.3 (#7862)

Bumps [undici](https://github.com/nodejs/undici) from 5.26.3 to 5.28.3.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v5.26.3...v5.28.3)

---
updated-dependencies:
- dependency-name: undici
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: update webdriverio to fix chrome endpoint issue (#7875)

* fix: insertion marker drag scaling (#7874)

* fix: insertion marker drag scaling

* chore: added docs for other params

* fix: restore respecting snap radius (#7873)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Maribeth Bottorff <maribethb@google.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Elvis Adomnica <elvis.adomnica@gmail.com>
Co-authored-by: Rachel Fenichel <fenichel@google.com>
2024-03-08 14:24:58 -08:00

148 lines
4.8 KiB
JavaScript

const {execSync} = require('child_process');
const {Extractor} = require('markdown-tables-to-json');
const fs = require('fs');
const gulp = require('gulp');
const header = require('gulp-header');
const replace = require('gulp-replace');
const DOCS_DIR = 'docs';
/**
* Run API Extractor to generate the intermediate json file.
*/
const generateApiJson = function(done) {
execSync('api-extractor run --local', {stdio: 'inherit'});
done();
}
/**
* API Extractor output spuriously renames some functions. Undo that.
* See https://github.com/microsoft/rushstack/issues/2534
*/
const removeRenames = function() {
return gulp.src('temp/blockly.api.json')
.pipe(replace('_2', ''))
.pipe(gulp.dest('temp/'));
}
/**
* Run API Documenter to generate the raw docs files.
*/
const generateDocs = function(done) {
if (!fs.existsSync(DOCS_DIR)) {
// Create the directory if it doesn't exist.
// If it already exists, the contents will be deleted by api-documenter.
fs.mkdirSync(DOCS_DIR);
}
execSync(
`api-documenter markdown --input-folder temp --output-folder ${DOCS_DIR}`,
{stdio: 'inherit'});
done();
}
/**
* Prepends the project and book metadata that devsite requires.
*/
const prependBook = function() {
return gulp.src('docs/*.md')
.pipe(header(
'Project: /blockly/_project.yaml\nBook: /blockly/_book.yaml\n\n'))
.pipe(gulp.dest(DOCS_DIR));
}
/**
* Creates a map of top-level pages to sub-pages, e.g. a mapping
* of `block_class` to every page associated with that class.
* This is needed to create an accurate table of contents.
* @param {string[]} allFiles All files in docs directory.
* @returns {Map<string, string[]>}
*/
const buildAlternatePathsMap = function(allFiles) {
let map = new Map();
for (let file of allFiles) {
// Get the name of the class/namespaces/variable/etc., i.e. the top-level
// page.
let filePieces = file.split('.');
let name = filePieces[1];
if (!map.has(name)) {
map.set(name, []);
}
if (filePieces[2] === 'md') {
// Don't add the top-level page to the map.
continue;
}
// Add all sub-pages to the array for the corresponding top-level page.
map.get(name).push(file);
}
return map;
}
/**
* Create the _toc.yaml file used by devsite to create the leftnav.
* This file is generated from the contents of `blockly.md` which contains links
* to the other top-level API pages (each class, namespace, etc.).
*
* The `alternate_paths` for each top-level page contains the path for
* each associated sub-page. All subpages must be linked to their top-level page
* in the TOC for the left nav bar to remain correct after drilling down into a
* sub-page.
*/
const createToc = function(done) {
const fileContent = fs.readFileSync(`${DOCS_DIR}/blockly.md`, 'utf8');
// Create the TOC file. The file should not yet exist; if it does, this
// operation will fail.
const toc = fs.openSync(`${DOCS_DIR}/_toc.yaml`, 'ax');
const files = fs.readdirSync(DOCS_DIR);
const map = buildAlternatePathsMap(files);
const referencePath = '/blockly/reference/js';
const tocHeader = `toc:
- title: Overview
path: /blockly/reference/js/blockly.md\n`;
fs.writeSync(toc, tocHeader);
// Generate a section of TOC for each section/heading in the overview file.
const sections = fileContent.split('##');
for (let section of sections) {
// This converts the md table in each section to a JS object
const table = Extractor.extractObject(section, 'rows', false);
if (!table) {
continue;
}
// Get the name of the section, i.e. the text immediately after the `##` in
// the source doc
const sectionName = section.split('\n')[0].trim();
fs.writeSync(toc, `- heading: ${sectionName}\n`);
for (let row in table) {
// After going through the Extractor, the markdown is now HTML.
// Each row in the table is now a link (anchor tag).
// Get the target of the link, excluding the first `.` since we don't want
// a relative path.
const path = /href="\.(.*?)"/.exec(row)?.[1];
// Get the name of the link (text in between the <a> and </a>)
const name = /">(.*?)</.exec(row)?.[1];
if (!path || !name) {
continue;
}
fs.writeSync(toc, `- title: ${name}\n path: ${referencePath}${path}\n`);
// Get the list of sub-pages for this page.
// Add each sub-page to the `alternate_paths` property.
let pages = map.get(path.split('.')[1]);
if (pages?.length) {
fs.writeSync(toc, ` alternate_paths:\n`);
for (let page of pages) {
fs.writeSync(toc, ` - ${referencePath}/${page}\n`);
}
}
}
}
done();
}
const docs = gulp.series(
generateApiJson, removeRenames, generateDocs,
gulp.parallel(prependBook, createToc));
module.exports = {docs};