Skip to content

Commit c2d6d46

Browse files
committed
dev: update scripts
1 parent 6052353 commit c2d6d46

File tree

3 files changed

+71
-23
lines changed

3 files changed

+71
-23
lines changed

scripts/checkDocs.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/node
2+
3+
/**
4+
* @file Checks If documentation data is up to date
5+
*/
6+
7+
import crypto from "crypto"
8+
import {dirname} from "path"
9+
import {fileURLToPath} from "url"
10+
import {promises as fs} from "fs"
11+
import yaml from "yaml"
12+
import getDocs from "./helpers/fetchDocs.mjs"
13+
14+
export const hash = (algo, contents, format = "hex") =>
15+
crypto.createHash(algo).update(contents).digest(format)
16+
17+
const __dirname = dirname(fileURLToPath(import.meta.url))
18+
19+
const newDocs = await getDocs()
20+
const newDocsString = `# THIS IS AN AUTOGENERATED FILE; DO NOT EDIT DIRECTLY\n\n${yaml.stringify(
21+
newDocs,
22+
{
23+
sortMapEntries: true,
24+
},
25+
)}`.trim()
26+
27+
const oldDocsString = (
28+
await fs.readFile(`${__dirname}/../data/documentation-data.yml`, "utf-8")
29+
).trim()
30+
31+
if (hash("sha256", newDocsString) === hash("sha256", oldDocsString)) {
32+
console.log("Documentation data is up to date")
33+
} else {
34+
throw new Error("Documentation is out of date")
35+
}
Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
#!/bin/node
22

3-
/**
4-
* @file gets Documentation from https://processing.org/reference and dumps it into
5-
* `src/documentation-data.json` with some bootleg webscraping
6-
*/
7-
83
import {JSDOM} from "jsdom"
9-
import {dirname} from "path"
104
import fetch from "node-fetch"
11-
import {fileURLToPath} from "url"
12-
import {promises as fs} from "fs"
13-
import yaml from "yaml"
145

15-
const __dirname = dirname(fileURLToPath(import.meta.url))
166
const docsUrl = "https://processing.org/reference"
177

188
// Processing global variables
@@ -115,7 +105,7 @@ const escapeHTML = (html) =>
115105
* Gets the documentation for a single link
116106
*
117107
* @param {string} link - Link to get doc from
118-
* @returns {Promise<import("../src/types").DocumentationVariable>}
108+
* @returns {Promise<import("../../src/types").DocumentationVariable>}
119109
*/
120110
const documentVariable = async (link) => {
121111
const documentation = {
@@ -177,7 +167,7 @@ const documentVariable = async (link) => {
177167
* Gets the documentation for a single link
178168
*
179169
* @param {string} link - Link to get doc from
180-
* @returns {Promise<import("../src/types").DocumentationFunction>}
170+
* @returns {Promise<import("../../src/types").DocumentationFunction>}
181171
*/
182172
const documentFunction = async (link) => {
183173
const documentation = {
@@ -246,7 +236,7 @@ const documentFunction = async (link) => {
246236
* Gets the documentation for a single link
247237
*
248238
* @param {string} link - Link to get doc from
249-
* @returns {Promise<import("../src/types").DocumentationClass>}
239+
* @returns {Promise<import("../../src/types").DocumentationClass>}
250240
*/
251241
const documentClass = async (link) => {
252242
const documentation = {
@@ -328,7 +318,7 @@ const documentLinks = async ({classLinks, functionLinks, variableLinks}) => {
328318
/**
329319
* All documentation (final object dumped to JSON)
330320
*
331-
* @type {import("../src/types").Documentation}
321+
* @type {import("../../src/types").Documentation}
332322
*/
333323
const documentation = {}
334324

@@ -390,7 +380,10 @@ const documentLinks = async ({classLinks, functionLinks, variableLinks}) => {
390380
return documentation
391381
}
392382

393-
;(async () => {
383+
/**
384+
* @returns Documentation from https://processing.org/reference
385+
*/
386+
export const getDocs = async () => {
394387
const links = await getDocLinks()
395388

396389
if (!links) {
@@ -405,11 +398,7 @@ const documentLinks = async ({classLinks, functionLinks, variableLinks}) => {
405398

406399
const docs = await documentLinks(links)
407400

408-
await fs.writeFile(
409-
`${__dirname}/../data/documentation-data.yml`,
410-
`# THIS IS AN AUTOGENERATED FILE; DO NOT EDIT DIRECTLY\n\n${yaml.stringify(docs, {
411-
sortMapEntries: true,
412-
})}`,
413-
"utf8",
414-
)
415-
})()
401+
return docs
402+
}
403+
404+
export default getDocs

scripts/writeDocs.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/node
2+
3+
/**
4+
* @file gets Documentation from https://processing.org/reference and dumps it into
5+
* `src/documentation-data.json` with some bootleg webscraping
6+
*/
7+
8+
import {dirname} from "path"
9+
import {fileURLToPath} from "url"
10+
import {promises as fs} from "fs"
11+
import yaml from "yaml"
12+
import getDocs from "./helpers/fetchDocs.mjs"
13+
14+
const __dirname = dirname(fileURLToPath(import.meta.url))
15+
16+
const docs = await getDocs()
17+
18+
await fs.writeFile(
19+
`${__dirname}/../data/documentation-data.yml`,
20+
`# THIS IS AN AUTOGENERATED FILE; DO NOT EDIT DIRECTLY\n\n${yaml.stringify(docs, {
21+
sortMapEntries: true,
22+
})}`,
23+
"utf8",
24+
)

0 commit comments

Comments
 (0)