Skip to content

Commit 7dd4cd1

Browse files
authored
Merge pull request #8 from rolling-scopes/feat/add-merch-metadata
feat: add script for catalog
2 parents 676d7b2 + 600f0d9 commit 7dd4cd1

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

.github/workflows/build.yaml

+46-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,51 @@ jobs:
5050
.map(dirent => dirent.name)
5151
.filter(name => !name.startsWith('.'));
5252
fs.writeFileSync('./cleaned/filelist.json', JSON.stringify(fileNames, null, 2));
53+
54+
- name: Create merch data
55+
uses: satackey/[email protected]
56+
with:
57+
script: |
58+
const fs = require("fs");
59+
const path = require("path");
60+
const previewFormat = [".webp", ".png"];
61+
const noDownloadFormat = [".json", ".webp"];
62+
function capitalizeWords(str) {
63+
return str.replace(/-/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
64+
}
65+
function getDirectoryStructure(dir) {
66+
const result = {};
67+
const items = fs.readdirSync(dir, { withFileTypes: true });
68+
const files = items.filter((item) => !item.isDirectory());
69+
const directories = items.filter((item) => item.isDirectory());
70+
if (directories.length === 0 && files.length > 0) {
71+
const preview = files.filter((file) => previewFormat.some((format) => file.name.endsWith(format)))
72+
.map((file) => path.join(dir, file.name));
73+
const download = files.filter((file) => !noDownloadFormat.some((format) => file.name.endsWith(format)))
74+
.map((file) => path.join(dir, file.name));
75+
return {
76+
name: capitalizeWords(path.basename(dir)),
77+
preview: preview,
78+
download: download,
79+
};
80+
}
81+
directories.forEach((directory) => {
82+
result[directory.name] = getDirectoryStructure(
83+
path.join(dir, directory.name)
84+
);
85+
});
86+
return result;
87+
}
88+
const merchStructure = getDirectoryStructure("./merch");
89+
const assetsStructure = getDirectoryStructure("./assets");
90+
const stickersStructure = getDirectoryStructure("./stickers");
91+
const combinedStructure = {
92+
merch: merchStructure,
93+
assets: assetsStructure,
94+
stickers: stickersStructure,
95+
};
96+
fs.writeFileSync("./filelist.json", JSON.stringify(combinedStructure, null, 2));
97+
5398
- name: Upload to CDN
5499
env:
55100
AWS_ACCESS_KEY_ID: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }}
@@ -59,4 +104,4 @@ jobs:
59104
aws s3 cp stickers s3://cdn.rs.school/sloths/stickers --recursive --cache-control "public,max-age=300,immutable"
60105
aws s3 cp cleaned s3://cdn.rs.school/sloths/cleaned --recursive --cache-control "public,max-age=300,immutable"
61106
aws s3 cp assets s3://cdn.rs.school/assets --recursive --cache-control "public,max-age=300,immutable"
62-
aws s3 cp merch s3://cdn.rs.school/merch --recursive --cache-control "public,max-age=300,immutable"
107+
aws s3 cp merch s3://cdn.rs.school/merch --recursive --cache-control "public,max-age=300,immutable"

0 commit comments

Comments
 (0)