🚀 bootstrap workspace
This commit is contained in:
19
.github/workflows/main.yml
vendored
Normal file
19
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
name: main
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 14
|
||||
|
||||
- uses: bahmutov/npm-install@v1
|
||||
|
||||
- run: yarn type
|
||||
- run: yarn lint
|
||||
- run: yarn test --ci
|
||||
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
npm-debug.log*
|
||||
yarn-error.log*
|
||||
dist
|
||||
build
|
||||
4
jest.config.js
Normal file
4
jest.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
};
|
||||
23
package.json
Normal file
23
package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "snk",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"repository": "github:platane/snk",
|
||||
"devDependencies": {
|
||||
"@types/jest": "26.0.4",
|
||||
"jest": "26.1.0",
|
||||
"prettier": "2.0.5",
|
||||
"ts-jest": "26.1.2",
|
||||
"typescript": "3.9.6"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/**"
|
||||
],
|
||||
"scripts": {
|
||||
"type": "tsc --noEmit",
|
||||
"lint": "yarn prettier -c '**/*.{ts,js,json,md,yml,yaml}' '!dist/**'",
|
||||
"test": "jest --verbose --passWithNoTests",
|
||||
"build": "( cd packages/demo ; yarn build )",
|
||||
"dev": "( cd packages/demo ; yarn dev )"
|
||||
}
|
||||
}
|
||||
24
packages/compute/generateGrid.ts
Normal file
24
packages/compute/generateGrid.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Grid, Color } from "./grid";
|
||||
|
||||
const rand = (a: number, b: number) => Math.floor(Math.random() * (b - a)) + a;
|
||||
|
||||
export const generateGrid = (
|
||||
width: number,
|
||||
height: number,
|
||||
options: { colors: Color[]; emptyP: number } = {
|
||||
colors: [1, 2, 3],
|
||||
emptyP: 2,
|
||||
}
|
||||
): Grid => {
|
||||
const g = {
|
||||
width,
|
||||
height,
|
||||
data: Array.from({ length: width * height }, () => {
|
||||
const x = rand(-options.emptyP, options.colors.length);
|
||||
|
||||
return x < 0 ? null : options.colors[x];
|
||||
}),
|
||||
};
|
||||
|
||||
return g;
|
||||
};
|
||||
25
packages/compute/grid.ts
Normal file
25
packages/compute/grid.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export type Color = number;
|
||||
|
||||
export type Grid = {
|
||||
width: number;
|
||||
height: number;
|
||||
data: (Color | null)[];
|
||||
};
|
||||
|
||||
export const getIndex = (grid: Grid, x: number, y: number) =>
|
||||
x * grid.height + y;
|
||||
|
||||
export const isInside = (grid: Grid, x: number, y: number) =>
|
||||
x >= 0 && y >= 0 && x < grid.width && y < grid.height;
|
||||
|
||||
export const getColor = (grid: Grid, x: number, y: number) =>
|
||||
grid.data[getIndex(grid, x, y)];
|
||||
|
||||
export const setColor = (
|
||||
grid: Grid,
|
||||
x: number,
|
||||
y: number,
|
||||
color: Color | null
|
||||
) => {
|
||||
grid.data[getIndex(grid, x, y)] = color;
|
||||
};
|
||||
13
packages/compute/index.ts
Normal file
13
packages/compute/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Grid, Color } from "./grid";
|
||||
|
||||
type Point = { x: number; y: number };
|
||||
|
||||
export const computeBestRun = (
|
||||
pattern: Color[],
|
||||
grid: Grid,
|
||||
originalPosition: Point
|
||||
) => {
|
||||
console.log(pattern, grid, originalPosition);
|
||||
|
||||
return [];
|
||||
};
|
||||
4
packages/compute/package.json
Normal file
4
packages/compute/package.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "@snk/compute",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
1
packages/demo/.gitignore
vendored
Normal file
1
packages/demo/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
webpack.config.js
|
||||
13
packages/demo/index.ts
Normal file
13
packages/demo/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// import { generateGrid } from "@snk/compute/generateGrid";
|
||||
|
||||
import { generateGrid } from "@snk/compute/generateGrid";
|
||||
|
||||
console.log("hello world");
|
||||
|
||||
export const run = async (a: number) => {
|
||||
generateGrid(100, 100);
|
||||
|
||||
console.log(a, generateGrid(100, 100));
|
||||
};
|
||||
|
||||
run(1);
|
||||
19
packages/demo/package.json
Normal file
19
packages/demo/package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@snk/demo",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@snk/compute": "1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"webpack": "4.43.0",
|
||||
"webpack-cli": "3.3.12",
|
||||
"webpack-dev-server": "3.11.0",
|
||||
"ts-loader": "8.0.1",
|
||||
"html-webpack-plugin": "4.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "tsc webpack.config.ts",
|
||||
"build": "yarn prepare ; webpack",
|
||||
"dev": "yarn prepare ; webpack-dev-server --port ${PORT-3000}"
|
||||
}
|
||||
}
|
||||
43
packages/demo/webpack.config.ts
Normal file
43
packages/demo/webpack.config.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import * as path from "path";
|
||||
|
||||
// @ts-ignore
|
||||
import * as HtmlWebpackPlugin from "html-webpack-plugin";
|
||||
import type { Configuration } from "webpack";
|
||||
|
||||
const basePathname = (process.env.BASE_PATHNAME || "")
|
||||
.split("/")
|
||||
.filter(Boolean);
|
||||
|
||||
const config: Configuration = {
|
||||
mode: "development",
|
||||
entry: "./index",
|
||||
resolve: { extensions: [".ts", ".js"] },
|
||||
output: {
|
||||
path: path.join(__dirname, "../../dist/demo"),
|
||||
filename: "[contenthash].js",
|
||||
publicPath: "/" + basePathname.map((x) => x + "/").join(""),
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
exclude: /node_modules/,
|
||||
test: /\.(js|ts)$/,
|
||||
loader: "ts-loader",
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
// game
|
||||
new HtmlWebpackPlugin({
|
||||
title: "demo",
|
||||
filename: "index.html",
|
||||
meta: {
|
||||
viewport: "width=device-width, initial-scale=1, shrink-to-fit=no",
|
||||
},
|
||||
}),
|
||||
],
|
||||
|
||||
devtool: false,
|
||||
};
|
||||
|
||||
export default config;
|
||||
13
tsconfig.json
Normal file
13
tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"jsx": "preserve",
|
||||
"lib": ["dom", "ES2020"],
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"isolatedModules": true
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user