Skip to content

Commit 49b6000

Browse files
committed
Replace docs scripts with javascript code
1 parent dff60b0 commit 49b6000

File tree

6 files changed

+428
-463
lines changed

6 files changed

+428
-463
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
node_modules
22
*.js
3-
!eslint.config.js
43

54
# docs
65
!docs/jsdoc/templates/**/*.js

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
"format:ci": "prettier --list-different \"src/**/*.{ts,tsx}\"",
5959
"test": "jest",
6060
"test-coverage": "jest --coverage",
61-
"docs": "yarn jsdoc && yarn autocomplete",
62-
"jsdoc": "./scripts/jsdoc.sh",
63-
"autocomplete": "node ./scripts/updateAutocompleteDocs.js",
61+
"docs": "node ./scripts/docs.mjs docs",
62+
"jsdoc": "node ./scripts/docs.mjs",
63+
"autocomplete": "node ./scripts/docs.mjs autocomplete",
6464
"build_sicp_package": "./scripts/build_sicp_package.sh",
6565
"publish_sicp_package": "./scripts/publish_sicp_package.sh",
6666
"benchmark": "jest --runInBand --testPathPattern='.*benchmark.*' --testPathIgnorePatterns='/dist/'",

scripts/updateAutocompleteDocs.js renamed to scripts/autocomplete.mjs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const jsdom = require('jsdom');
4-
const { JSDOM } = jsdom;
1+
// @ts-check
2+
3+
import fs from 'fs/promises';
4+
import pathlib from 'path';
5+
import { JSDOM } from 'jsdom';
56

67
const CONST_DECL = "const";
78
const FUNC_DECL = "func";
@@ -74,11 +75,11 @@ function processFunction(namespace, element, document) {
7475
namespace[name] = { title, description: html, meta: FUNC_DECL };
7576
}
7677

77-
function processDirGlobals(target) {
78-
const inFile = path.join(BASE_DIR, target, SRC_FILENAME);
78+
async function processDirGlobals(target) {
79+
const inFile = pathlib.join(BASE_DIR, target, SRC_FILENAME);
7980
let document;
8081
try {
81-
const contents = fs.readFileSync(inFile);
82+
const contents = await fs.readFile(inFile);
8283
document = new JSDOM(contents.toString()).window.document;
8384
} catch (err) {
8485
console.error(inFile, "failed", err);
@@ -93,17 +94,26 @@ function processDirGlobals(target) {
9394
const functions = document.getElementsByClassName('function-entry')
9495
Array.prototype.forEach.call(functions, ele => processFunction(names, ele, document));
9596

96-
fs.mkdirSync(OUT_DIR, { recursive: true })
97-
98-
const outFile = path.join(OUT_DIR, target + '.json');
99-
fs.writeFileSync(outFile, JSON.stringify(names, null, 2), 'utf-8');
97+
const outFile = pathlib.join(OUT_DIR, target + '.json');
98+
await fs.writeFile(outFile, JSON.stringify(names, null, 2), 'utf-8')
10099
}
101100

102-
if (fs.existsSync(BASE_DIR)) {
103-
TARGETS.forEach(processDirGlobals);
104-
} else {
105-
console.error(`
106-
Error: path to jsdoc html is invalid.
107-
Ensure that this script is run from the project root and documentation has been generated\
108-
`);
101+
export default async function autocomplete() {
102+
try {
103+
await fs.access(BASE_DIR, fs.constants.R_OK)
104+
} catch (error) {
105+
if (error.code === 'ENOENT') {
106+
console.error(`
107+
Error: path to jsdoc html is invalid.
108+
Ensure that this script is run from the project root and documentation has been generated\
109+
`);
110+
} else {
111+
console.error(error)
112+
}
113+
}
114+
115+
await fs.mkdir(OUT_DIR, { recursive: true })
116+
await Promise.all(TARGETS.map(processDirGlobals))
117+
console.log('Finished processing autocomplete documentation')
109118
}
119+

scripts/autocomplete.sh

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)