diff --git a/.github/workflows/branch-sync.yml b/.github/workflows/branch-sync.yml deleted file mode 100644 index ff4d7d08..00000000 --- a/.github/workflows/branch-sync.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Bedrock Branch - -on: - push: - branches: [ main ] - - -permissions: write-all - -jobs: - sync: - runs-on: ubuntu-latest - steps: - - name: Checkout main - uses: actions/checkout@v3 - with: - ref: main - fetch-depth: 0 - - name: Sync main to bedrock - run: | - git checkout bedrock - rsync -av bedrock/pack . - git add ./RP - git merge main - git push origin bedrock diff --git a/package.json b/package.json index a8ecebd5..22238098 100644 --- a/package.json +++ b/package.json @@ -1,3 +1,3 @@ -{ "dependencies": { "sharp": "^0.33.2" }, "devDependencies": { "@types/bun": "latest", "@types/node": "^20.11.19" }, "name": "jg-rtx", "module": "index.ts", "type": "module", "peerDependencies": { +{ "dependencies": { "sharp": "^0.33.3" }, "devDependencies": { "@types/bun": "latest", "@types/node": "^20.11.19" }, "name": "jg-rtx", "module": "index.ts", "type": "module", "peerDependencies": { "typescript": "^5.0.0" } } \ No newline at end of file diff --git a/src/scripts/resize.ts b/src/scripts/resize.ts new file mode 100644 index 00000000..cf672acb --- /dev/null +++ b/src/scripts/resize.ts @@ -0,0 +1,52 @@ +import sharp from "sharp"; +import { readdir, copyFile, mkdir, stat } from "node:fs/promises"; +import { dirname, basename } from "node:path"; + +const resize = async (input: string, output: string, size?: number) => { + try { + const img = sharp(input); + const { width } = await img.metadata() ?? { width: size ?? 256 }; + + await img.resize(size ?? Math.max(0.5 * width!, 16), null).toFile(output); + } catch (err) { + console.error(`File ${input} could not be resized: ${err}`); + } +}; + +const resizeImages = async (inputDir: string, outputDir: string, width: number) => { + const files = await readdir(inputDir); + for (const file of files) { + const src = `${inputDir}/${file}`; + const dest = `${outputDir}/${file}`; + + if ((await stat(src)).isDirectory()) { + await resizeImages(src, dest, width); + continue; + } + + try { + await mkdir(dirname(dest), { recursive: true }); + } catch (err) { + console.error(`Directory ${dirname(dest)} could not be created: ${err}`); + } + + if (!file.endsWith(".png")) { + // try { + // await copyFile(src, dest); + // console.log(`📋 COPIED ${basename(src)}`); + // } catch (err) { + // console.error(`File ${basename(src)} could not be copied: ${err}`); + // } + continue; + } + + try { + await resize(src, dest, width); + console.log(`📏 RESIZED ${basename(src)}`); + } catch(err) { + console.error(`File ${basename(src)} could not be resized: ${err}`); + } + } +}; + +await resizeImages("../../bedrock/pack/RP/textures/blocks", "../../dist/64x", 64);