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-
83import { JSDOM } from "jsdom"
9- import { dirname } from "path"
104import 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 ) )
166const 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 */
120110const 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 */
182172const 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 */
251241const 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
0 commit comments