Skip to content

Commit bdc241e

Browse files
authored
Merge pull request #1018 from rgantzos/main
Class Names API
2 parents f30f83f + f319c9b commit bdc241e

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const rootDir = path.resolve(__dirname, "../../features");
5+
const outputFile = path.resolve(__dirname, "../../class-names.json");
6+
7+
let collected = new Set();
8+
9+
function traverseDir(dir) {
10+
const files = fs.readdirSync(dir);
11+
for (const file of files) {
12+
const fullPath = path.join(dir, file);
13+
const stat = fs.statSync(fullPath);
14+
15+
if (stat.isDirectory()) {
16+
traverseDir(fullPath);
17+
} else if (stat.isFile() && file.endsWith(".js")) {
18+
const content = fs.readFileSync(fullPath, "utf-8");
19+
const regex = /className\(["'`](.*?)["'`]\)/g;
20+
let match;
21+
while ((match = regex.exec(content)) !== null) {
22+
collected.add("ste-" + match[1].replaceAll(" ", "-"));
23+
}
24+
}
25+
}
26+
}
27+
28+
traverseDir(rootDir);
29+
30+
// Write results
31+
fs.writeFileSync(outputFile, JSON.stringify([...collected], null, 2));
32+
console.log(`✅ Extracted ${collected.size} class names to ${outputFile}`);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Extract Class Names
2+
3+
on:
4+
push:
5+
paths:
6+
- "features/**.js"
7+
workflow_dispatch:
8+
9+
jobs:
10+
extract:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 20
20+
21+
- name: Run extraction script
22+
run: node .github/scripts/extract-classnames.js
23+
24+
- name: Commit and push updated class-names.json
25+
run: |
26+
git config user.name "github-actions[bot]"
27+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
28+
git add class-names.json
29+
git commit -m "Update class-names.json" || echo "No changes"
30+
git push

api/module.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ function scratchClass(name) {
2121
}
2222
}
2323

24+
function className(name) {
25+
return "ste-" + name.toLowerCase().replaceAll(" ", "-")
26+
}
27+
2428
ScratchTools.modules.forEach(async function (script) {
2529
var feature = await import(ScratchTools.dir + "/api/feature/index.js");
2630
var shouldBeRun = true;
@@ -41,6 +45,7 @@ ScratchTools.modules.forEach(async function (script) {
4145
fun.default({
4246
feature: featureGenerated,
4347
scratchClass,
48+
className,
4449
console: {
4550
log: function (content) {
4651
ste.console.log(content, script.feature.id);
@@ -78,6 +83,7 @@ ScratchTools.injectModule = async function (script) {
7883
fun.default({
7984
feature: featureGenerated,
8085
scratchClass,
86+
className,
8187
console: {
8288
log: function (content) {
8389
ste.console.log(content, script.feature.id);

class-names.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)