🚀 add action package
This commit is contained in:
56
packages/action/generateContributionSnake.ts
Normal file
56
packages/action/generateContributionSnake.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { getGithubUserContribution, Cell } from "@snk/github-user-contribution";
|
||||
import { generateEmptyGrid } from "@snk/compute/generateGrid";
|
||||
import { setColor } from "@snk/compute/grid";
|
||||
import { computeBestRun } from "@snk/compute";
|
||||
import { createGif } from "../gif-creator";
|
||||
|
||||
export const userContributionToGrid = (cells: Cell[]) => {
|
||||
const width = Math.max(...cells.map((c) => c.x));
|
||||
const height = Math.max(...cells.map((c) => c.y));
|
||||
|
||||
const grid = generateEmptyGrid(width, height);
|
||||
for (const c of cells) setColor(grid, c.x, c.y, c.k === 0 ? null : c.k);
|
||||
|
||||
return grid;
|
||||
};
|
||||
|
||||
export const generateContributionSnake = async (userName: string) => {
|
||||
const { cells, colorScheme } = await getGithubUserContribution(userName);
|
||||
|
||||
const grid0 = userContributionToGrid(cells);
|
||||
|
||||
const snake0 = [
|
||||
{ x: 4, y: -1 },
|
||||
{ x: 3, y: -1 },
|
||||
{ x: 2, y: -1 },
|
||||
{ x: 1, y: -1 },
|
||||
{ x: 0, y: -1 },
|
||||
];
|
||||
|
||||
const drawOptions = {
|
||||
sizeBorderRadius: 2,
|
||||
sizeCell: 16,
|
||||
sizeDot: 12,
|
||||
colorBorder: "#1b1f230a",
|
||||
colorDots: colorScheme,
|
||||
colorEmpty: colorScheme[0],
|
||||
colorSnake: "purple",
|
||||
};
|
||||
|
||||
const gameOptions = { maxSnakeLength: 5 };
|
||||
|
||||
const gifOptions = { delay: 20 };
|
||||
|
||||
const commands = computeBestRun(grid0, snake0, gameOptions).slice(0, 50);
|
||||
|
||||
const buffer = await createGif(
|
||||
grid0,
|
||||
snake0,
|
||||
commands,
|
||||
drawOptions,
|
||||
gameOptions,
|
||||
gifOptions
|
||||
);
|
||||
|
||||
return buffer;
|
||||
};
|
||||
19
packages/action/index.ts
Normal file
19
packages/action/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as fs from "fs";
|
||||
import * as core from "@actions/core";
|
||||
import { generateContributionSnake } from "./generateContributionSnake";
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log(core.getInput("user_name"));
|
||||
console.log(core.getInput("gif_out_path"));
|
||||
console.log("--");
|
||||
console.log(process.cwd());
|
||||
console.log("--");
|
||||
console.log(fs.readdirSync(process.cwd()));
|
||||
|
||||
const buffer = await generateContributionSnake(core.getInput("user_name"));
|
||||
fs.writeFileSync(core.getInput("gif_out_path"), buffer);
|
||||
} catch (e) {
|
||||
core.setFailed(`Action failed with "${e.message}"`);
|
||||
}
|
||||
})();
|
||||
15
packages/action/package.json
Normal file
15
packages/action/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@snk/action",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@snk/gif-creator": "1.0.0",
|
||||
"@snk/github-user-contribution": "1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@actions/core": "1.2.4",
|
||||
"@zeit/ncc": "0.22.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "ncc build ./index.ts --out dist"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user