Skip to content

Commit 7eba5df

Browse files
committed
👷
1 parent 6073958 commit 7eba5df

4 files changed

Lines changed: 43 additions & 10 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,42 @@ jobs:
1919
- run: bun test
2020
env:
2121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
23+
test-lib:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
28+
- uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2.0.2
29+
with:
30+
bun-version: 1.3.12
31+
32+
- run: bun install --frozen-lockfile
33+
2234
- run: bun build:lib
23-
- run: |
24-
./packages/generate-snake-animation/dist/cli.js --github_user=platane --output=snake.svg
25-
test -f snake.svg
35+
36+
- name: run output=svg without dependencies
37+
run: |
38+
# run in an isolated dir
39+
cp -r ./packages/generate-snake-animation/dist ${{ runner.temp }}/snk1
40+
${{ runner.temp }}/snk1/cli.js --github_user=platane --output=snake.svg
2641
env:
2742
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2843

44+
- run: test -f snake.svg
45+
46+
- name: run output=gif with installed dependencies canvas, gifslice..
47+
run: |
48+
# run in an isolated dir
49+
cp -r ./packages/generate-snake-animation/dist ${{ runner.temp }}/snk2
50+
# install the dependencies in the parent dir, so node resolution see them
51+
bun add --cwd ${{ runner.temp }} canvas@3.2.0 gif-encoder-2@1.0.5 gifsicle@5.3.0
52+
bun ${{ runner.temp }}/snk2/cli.js --github_user=platane --output=snake.gif
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- run: test -f snake.gif
57+
2958
test-action:
3059
runs-on: ubuntu-latest
3160
steps:

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dev:demo": "( cd packages/demo ; npm run dev )",
2020
"build:demo": "( cd packages/demo ; npm run build )",
2121
"build:action": "( cd packages/action ; npm run build )",
22-
"build:lib": "( cd packages/generate-snake-animation ; npm run build )"
22+
"build:lib": "( cd packages/generate-snake-animation ; npm run build )",
23+
"publish:lib": "( cd packages/generate-snake-animation/dist ; npm publish )"
2324
}
2425
}

‎packages/generate-snake-animation/build.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ bunx dts-bundle-generator --out-file dist/generateSnakeAnimation.d.ts --project
1313
cat > dist/package.json << EOF
1414
{
1515
"name": "generate-snake-animation",
16-
"version": "$(node -p "require('./package.json').version")",
17-
"bin": { "snk": "./cli.js" },
16+
"version": "$(node -p "require('../../package.json').version")",
17+
"bin": { "snk": "cli.js" },
1818
"type": "module",
1919
"main": "./generateSnakeAnimation.js",
2020
"types": "./generateSnakeAnimation.d.ts",

‎packages/gif-creator/index.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import { step } from "@snk/solver/step";
1111
import { Color, copyGrid, Grid } from "@snk/types/grid";
1212
import type { Point } from "@snk/types/point";
1313
import { Snake } from "@snk/types/snake";
14-
import { createCanvas } from "canvas";
15-
// @ts-ignore
16-
import GIFEncoder from "gif-encoder-2";
17-
import gifsicle from "gifsicle";
1814

1915
export type { Options as DrawOptions } from "@snk/draw/drawWorld";
2016

@@ -28,6 +24,13 @@ export const createGif = async (
2824
animationOptions: AnimationOptions,
2925
) =>
3026
withTmpDir(async (dir) => {
27+
// import dependencies that are optionnals for svg
28+
//
29+
const { createCanvas } = await import("canvas");
30+
const { default: gifsicle } = await import("gifsicle");
31+
// @ts-ignore
32+
const { default: GIFEncoder } = await import("gif-encoder-2");
33+
3134
const { width, height } = getCanvasWorldSize(grid0, drawOptions);
3235

3336
const canvas = createCanvas(width, height);

0 commit comments

Comments
 (0)