Skip to content

Commit 0c2f9b9

Browse files
committed
๐Ÿ› ์›Œํฌํ”Œ๋กœ์šฐ ์ˆ˜์ •
1 parent ac3aae5 commit 0c2f9b9

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

โ€Ž.github/workflows/process-images.yamlโ€Ž

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,23 @@ jobs:
2424
restore-keys: |
2525
${{ runner.os }}-primes-
2626
- name: Install dependencies
27-
if: steps.cache.outputs.cache-hit != 'true'
2827
run: npm ci
28+
- name: Create tsconfig.build.json
29+
run: |
30+
echo '{
31+
"extends": "./tsconfig.json",
32+
"compilerOptions": {
33+
"target": "ES2021",
34+
"module": "ES2020",
35+
"outDir": "./dist",
36+
"noEmit": false
37+
},
38+
"include": ["scripts/**/*"],
39+
"exclude": ["src/**/*", "dist"]
40+
}' > tsconfig.build.json
2941
- name: Build TypeScript
3042
run: |
31-
npx tsc ./scripts/action-process-images.ts --outDir ./dist --esModuleInterop --target ES2021 --jsx react --skipLibCheck
43+
npx tsc ./scripts/action-process-images.ts ./scripts/github-api.ts ./scripts/sharp-api.ts --outDir ./dist --esModuleInterop --target ES2021 --module ES2020 --moduleResolution bundler --allowJs --isolatedModules --skipLibCheck --jsx react
3244
- name: โœง Process images and Report results
3345
run: node ./dist/action-process-images.js
3446
env:

โ€Žscripts/action-process-images.tsโ€Ž

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createComment, createCommit, imageToTreeBlob } from './github-api'
2-
import { sharpImages } from './sharp-api'
1+
import { createComment, createCommit, imageToTreeBlob } from './github-api.js'
2+
import { sharpImages } from './sharp-api.js'
33

44
const formatByte = (byte: number) => {
55
let num = +byte
@@ -25,7 +25,9 @@ const formatImages = (num: number) => {
2525
}
2626

2727
console.log('\n::โœง:: Generating Blobsโ€ฆ')
28-
const imageBlobs = await Promise.all(sharpedImageList.map(imageToTreeBlob))
28+
const imageBlobs = await Promise.all(
29+
sharpedImageList.filter((image) => image.convertedToAvif && image.avifPath).map(imageToTreeBlob)
30+
)
2931

3032
console.log('\n::โœง:: Committing filesโ€ฆ')
3133
const commit = await createCommit({

โ€Žscripts/github-api.tsโ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'node:fs/promises'
22

33
import { Octokit, type RestEndpointMethodTypes } from '@octokit/rest'
44

5-
import type { ProcessedResult } from './sharp-api'
5+
import type { ProcessedResult } from './sharp-api.js'
66

77
export type GitTreeBlob = RestEndpointMethodTypes['git']['createTree']['parameters']['tree'][number]
88

@@ -37,6 +37,7 @@ const imageToBase64 = async (path: string) => {
3737
}
3838

3939
export const imageToTreeBlob = async (image: ProcessedResult) => {
40+
const filePath = image.convertedToAvif ? image.avifPath! : image.path
4041
const encodedImage = await imageToBase64(image.path)
4142

4243
const blob = await api.rest.git.createBlob({
@@ -48,7 +49,7 @@ export const imageToTreeBlob = async (image: ProcessedResult) => {
4849
console.log('โœง', image.name, blob.data.url)
4950

5051
return {
51-
path: image.path,
52+
path: filePath,
5253
mode: '100644',
5354
type: 'blob',
5455
sha: blob.data.sha,

0 commit comments

Comments
ย (0)