diff --git a/.github/scripts/extract-classnames.js b/.github/scripts/extract-classnames.js new file mode 100644 index 00000000..af2b709a --- /dev/null +++ b/.github/scripts/extract-classnames.js @@ -0,0 +1,32 @@ +const fs = require("fs"); +const path = require("path"); + +const rootDir = path.resolve(__dirname, "../../features"); +const outputFile = path.resolve(__dirname, "../../class-names.json"); + +let collected = new Set(); + +function traverseDir(dir) { + const files = fs.readdirSync(dir); + for (const file of files) { + const fullPath = path.join(dir, file); + const stat = fs.statSync(fullPath); + + if (stat.isDirectory()) { + traverseDir(fullPath); + } else if (stat.isFile() && file.endsWith(".js")) { + const content = fs.readFileSync(fullPath, "utf-8"); + const regex = /className\(["'`](.*?)["'`]\)/g; + let match; + while ((match = regex.exec(content)) !== null) { + collected.add("ste-" + match[1].replaceAll(" ", "-")); + } + } + } +} + +traverseDir(rootDir); + +// Write results +fs.writeFileSync(outputFile, JSON.stringify([...collected], null, 2)); +console.log(`✅ Extracted ${collected.size} class names to ${outputFile}`); diff --git a/.github/workflows/extract-classnames.yml b/.github/workflows/extract-classnames.yml new file mode 100644 index 00000000..e904b8f1 --- /dev/null +++ b/.github/workflows/extract-classnames.yml @@ -0,0 +1,30 @@ +name: Extract Class Names + +on: + push: + paths: + - "features/**.js" + workflow_dispatch: + +jobs: + extract: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Run extraction script + run: node .github/scripts/extract-classnames.js + + - name: Commit and push updated class-names.json + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add class-names.json + git commit -m "Update class-names.json" || echo "No changes" + git push diff --git a/api/module.js b/api/module.js index 041bd33d..71dcf878 100644 --- a/api/module.js +++ b/api/module.js @@ -21,6 +21,10 @@ function scratchClass(name) { } } +function className(name) { + return "ste-" + name.toLowerCase().replaceAll(" ", "-") +} + ScratchTools.modules.forEach(async function (script) { var feature = await import(ScratchTools.dir + "/api/feature/index.js"); var shouldBeRun = true; @@ -41,6 +45,7 @@ ScratchTools.modules.forEach(async function (script) { fun.default({ feature: featureGenerated, scratchClass, + className, console: { log: function (content) { ste.console.log(content, script.feature.id); @@ -78,6 +83,7 @@ ScratchTools.injectModule = async function (script) { fun.default({ feature: featureGenerated, scratchClass, + className, console: { log: function (content) { ste.console.log(content, script.feature.id); diff --git a/class-names.json b/class-names.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/class-names.json @@ -0,0 +1 @@ +[] \ No newline at end of file