From 5242e9cb3fadda7ffe16bfe59dee2a7f6dc26ff0 Mon Sep 17 00:00:00 2001 From: Anatoly Ostrovsky Date: Wed, 22 Nov 2023 01:41:24 +0200 Subject: [PATCH] Clean up --- generator.js | 14 -------------- generator/global-attributes.js | 23 +++++------------------ 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/generator.js b/generator.js index d1e97e3..7be5a4a 100644 --- a/generator.js +++ b/generator.js @@ -19,16 +19,9 @@ const fs = require("fs"); "wbr", ]; - // Launch the Chromium browser const browser = await chromium.launch(); - - // Create a new browser context const context = await browser.newContext(); - - // Create an array to store the extracted elements const extractedElements = []; - - // Create a page and navigate to the URL const page = await context.newPage(); await page.goto("https://html.spec.whatwg.org/multipage/indices.html"); @@ -37,13 +30,9 @@ const fs = require("fs"); if (rows.length > 0) { console.log("Number of rows in the table:", rows.length); - - // You can iterate through each row if needed for (const row of rows) { - // Select the first element within the row's const codeElements = await row.$$("th code a"); if (codeElements.length > 0) { - // Loop through each code element and extract its text content for (const codeElement of codeElements) { const elementText = await codeElement.textContent(); console.log("Element in the row:", elementText); @@ -56,10 +45,7 @@ const fs = require("fs"); } else { console.log("No rows found in the table."); } - - // Write the extracted elements to a text file const outputFilePath = "lib/nitroux/html_tags.ex"; - // Wrap the element with some text (e.g., "Element: ") const wrappedElement = ` defmodule Nitroux.HtmlTags do diff --git a/generator/global-attributes.js b/generator/global-attributes.js index 49b0527..1cf154b 100644 --- a/generator/global-attributes.js +++ b/generator/global-attributes.js @@ -2,14 +2,12 @@ const fs = require("fs"); /** - * Represents global attribute. * @typedef {Object} GlobalAttribute * @property {string} name - The name of the attribute ('translate'). * @property {string} description - A description of the attribute's purpose and usage. * @property {string} ty - Bool or String. */ -// Specify the path to your JSON file const filePath = "html/resources/manual/global_attributes.json"; /** @@ -17,18 +15,10 @@ const filePath = "html/resources/manual/global_attributes.json"; */ let attributeList = []; -// Read the JSON file -fs.readFile(filePath, "utf8", (err, data) => { - if (err) { - console.error(`Error reading file: ${err}`); - return; - } - try { - attributeList = JSON.parse(data); - // Write the extracted elements to a text file - const outputFilePath = "lib/nitroux/types/global_attributes.ex"; - // Wrap the element with some text (e.g., "Element: ") - const wrappedElement = ` +fs.readFile(filePath, "utf8", (_err, data) => { + attributeList = JSON.parse(data); + const outputFilePath = "lib/nitroux/types/global_attributes.ex"; + const wrappedElement = ` defmodule Nitroux.Types.GlobalAttributes do # AUTO GENERATED DO NOT EDIT @@ -55,8 +45,5 @@ fs.readFile(filePath, "utf8", (err, data) => { .join("\n")} end `; - fs.writeFileSync(outputFilePath, wrappedElement); - } catch (error) { - console.error(`Error parsing JSON: ${error}`); - } + fs.writeFileSync(outputFilePath, wrappedElement); });