From 7341343534b685a0b7ad0cfa3ce005ca3af6fbb5 Mon Sep 17 00:00:00 2001 From: cswimr Date: Sun, 29 Dec 2024 17:32:32 -0500 Subject: [PATCH] build(repo): simplify generation --- generate.js | 30 ++++++++++++++++++++++++++++++ package.json | 5 +---- src/tailwindcss/generator/index.js | 10 ++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 generate.js diff --git a/generate.js b/generate.js new file mode 100644 index 0000000..405140a --- /dev/null +++ b/generate.js @@ -0,0 +1,30 @@ +import { readdirSync, statSync, existsSync } from "fs"; +import { join } from "path"; +import { execSync } from "child_process"; +import { fileURLToPath } from "url"; +import path from "path"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const srcDir = join(__dirname, "src"); + +try { + const directories = readdirSync(srcDir).filter((file) => + statSync(join(srcDir, file)).isDirectory() + ); + + directories.forEach((dir) => { + const generatorPath = join(srcDir, dir, "generator", "index.js"); + if (existsSync(generatorPath)) { + console.log(`Running generator for ${dir}...`); + try { + execSync(`node "${generatorPath}"`, { stdio: "inherit" }); + } catch (error) { + console.error(`Error running generator for ${dir}:`, error); + } + console.log(`Generator for ${dir} completed.`); + } + }); +} catch (error) { + console.error("Error reading directories:", error); +} diff --git a/package.json b/package.json index e897990..15f07e0 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,7 @@ "build": "yarn generate && gauntlet build", "dev": "gauntlet dev", "format": "eslint --fix .", - "generate": "yarn run generate:tailwindcss", - "generate:tailwindcss:css": "yarn dlx tailwindcss -i ./src/tailwindcss/generator/input.css -o ./assets/tailwindcss/generated/output.css", - "generate:tailwindcss:classes": "node ./src/tailwindcss/generator/index.js", - "generate:tailwindcss": "yarn run generate:tailwindcss:css && yarn run generate:tailwindcss:classes" + "generate": "node ./generate.js" }, "dependencies": { "@project-gauntlet/api": "0.12.0", diff --git a/src/tailwindcss/generator/index.js b/src/tailwindcss/generator/index.js index 94801ef..c7aa9ae 100644 --- a/src/tailwindcss/generator/index.js +++ b/src/tailwindcss/generator/index.js @@ -2,6 +2,16 @@ import fs from "fs"; import css from "css"; import path from "path"; import { fileURLToPath } from "url"; +import { execSync } from "child_process"; + +try { + execSync( + "yarn dlx tailwindcss -i ./src/tailwindcss/generator/input.css -o ./assets/tailwindcss/generated/output.css", + { stdio: "inherit" } + ); +} catch (error) { + console.error("Error running tailwindcss: ", error); +} const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename);