Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Lauer authored and Jake Lauer committed Feb 6, 2024
1 parent b891443 commit 7ddd315
Show file tree
Hide file tree
Showing 15 changed files with 4,314 additions and 0 deletions.
2,500 changes: 2,500 additions & 0 deletions .assets/logo.ai

Large diffs are not rendered by default.

Binary file added .assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,546 changes: 1,546 additions & 0 deletions .assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
ecmaVersion: 2018,
sourceType: "module",
tsconfigRootDir: __dirname,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:mocha/recommended",
"prettier",
],
plugins: [],
rules: {
"no-async-promise-executor": "off",
"@typescript-eslint/no-floating-promises": ["error"],
"@typescript-eslint/no-explicit-any": "off",
},
overrides: [
{
files: ["**/*.test.ts", "**/*.test.tsx"],
rules: {
"@typescript-eslint/no-unused-vars": ["off"],
},
},
],
};
11 changes: 11 additions & 0 deletions .examples/TicTacToe/GameState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type Board = [[Square, Square, Square], [Square, Square, Square], [Square, Square, Square]];

export type MarkType = "X" | "O";

export type Square = MarkType | undefined;

export interface GameState {
board: Board;
lastPlayer: MarkType;
lastPlayedCoords: [number, number]; // Row index, column index
}
16 changes: 16 additions & 0 deletions .examples/TicTacToe/GameStateEvolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Evolver } from "@bad-cards/theseus";

import { GameState, MarkType } from "./GameState";

export const { GameStateEvolver } = Evolver.create("GameStateEvolver", { noun: "gameState" })
.toEvolve<GameState>()
.withMutators({
setSquare: ({ mutableGameState }, coords: [number, number], mark: MarkType) => {
const [row, col] = coords;
mutableGameState.board[row][col] = mark;
mutableGameState.lastPlayer = mark;
mutableGameState.lastPlayedCoords = coords;

return mutableGameState;
},
});
12 changes: 12 additions & 0 deletions .examples/TicTacToe/GameStateRefinery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Refinery } from "@bad-cards/theseus";

import { GameState } from "./GameState";

export const GameStateRefinery = Refinery.create({ name: "GameStateRefinery", dataNoun: "GameState" })
.toRefine<GameState>()
.withForges({
squareAvailable: ({ immutableGameState }, coords: [number, number]) => {
const [row, col] = coords;
return immutableGameState.board[row][col] === undefined;
},
});
11 changes: 11 additions & 0 deletions .examples/TicTacToe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@bad-cards/theseus",
"version": "1.0.0",
"description": "A fun tic-tac-toe game.",
"author": "Jake Lauer",
"license": "MIT",
"dependencies": {
"@bad-cards/theseus": "1.0.7"
},
"main": "index.ts"
}
28 changes: 28 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Ignore issues with self-signed certs
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

module.exports = {
// Use ts-node rather than node, so we get TypeScript support
require: [
"ts-node/register"
],
// Search the whole tree
recursive: true,
// Match the following extensions
extension: [
"js",
"ts",
"tsx"
],
// Skip over shit
ignore: [
"**/node_modules/**/*",
],
// TBH I don't know why this is required, but removing it breaks things and it's not in the docs for Mocha.
// Seems as though this determines the search pattern, but then why do I also have to specify extensions?
spec: [
"**/*.test.js",
"**/*.test.ts",
"**/*.test.tsx"
]
}
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.*
tsconfig.json
/lib
node_modules
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.17.0
13 changes: 13 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"arrowParens": "always",
"printWidth": 120,
"trailingComma": "all",
"tabWidth": 4,
"tabs": true,
"semi": true,
"singleQuote": false,
"bracketSpacing": true,
"bracketSameLine": false,
"proseWrap": "always",
"experimentalTernaries": true
}
8 changes: 8 additions & 0 deletions .scripts/get-package-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { readFileSync } = require("fs");

function getPackageJson() {
const packageJson = JSON.parse(readFileSync("./package.json", "utf8"));
return packageJson;
}

module.exports = getPackageJson;
17 changes: 17 additions & 0 deletions .scripts/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const chalk = require("chalk");
const { execSync } = require("child_process");
const getPackageJson = require("./get-package-json");

const packageJson = getPackageJson();

const gitPendingResults = execSync("git status --porcelain").toString();
const gitHasPendingTheseusChanges = gitPendingResults.includes("packages/theseus");
if (gitHasPendingTheseusChanges) {
throw new Error("Git has pending changes in this package. Commit or stash them before updating the version");
}

const existingNpmVersion = execSync("npm view @bad-cards/theseus version").toString().trim();

if (existingNpmVersion === packageJson.version) {
console.log(chalk.red(`Version ${packageJson.version} already published to npm.`));
}
117 changes: 117 additions & 0 deletions .scripts/update-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
const arg = require("arg");
const { execSync } = require("child_process");
const fs = require("fs");
const prompts = require("prompts");

const getPackageJson = require("./get-package-json");

const validIncrementTypes = ["major", "minor", "patch"];

const args = arg({
// Increments the major version number. Exclusive with --minor and --patch.
"--type": String,
// Commits the version change to git.
"--commit": Boolean,
});

const getIncrement = (onContinue) => {
let type = args["--type"];

// Ensure that --type is one of "major", "minor", or "patch"
if (!validIncrementTypes.includes(type)) {
prompts(
{
type: "select",
name: "incrementType",
message: "What type of update is this?",
choices: [
{ title: "Major", value: "major" },
{ title: "Minor", value: "minor" },
{ title: "Patch", value: "patch" },
{ title: "Quit", value: undefined },
],
},
{
onSubmit: (_, answer) => {
console.log(`Answer: ${answer}`);

if (!answer) {
throw new Error("No increment type provided");
}

onContinue(answer);
},
},
);
} else {
onContinue(type);
}
};

const tryCommit = (onContinue) => {
prompts(
{
type: "select",
name: "commit",
message: "Commit package.json to Git?",
choices: [
{ title: "Yes, commit it!", value: true },
{ title: "No, don't commit it.", value: false },
],
},
{
onSubmit: (_, answer) => {
const doCommit = answer.commit;

onContinue(doCommit);
},
},
);
};

(function () {
getIncrement((increment) => {
console.log(`Increment: ${increment}`);
const verToSemver = (ver) => `${ver.major}.${ver.minor}.${ver.patch}`;

const packageJson = getPackageJson();

const versionParts = packageJson.version.split(".");
const version = {
major: Number(versionParts[0]),
minor: Number(versionParts[1]),
patch: Number(versionParts[2]),
};

switch (increment) {
case "major":
version.major++;
version.minor = 0;
version.patch = 0;
break;
case "minor":
version.minor++;
version.patch = 0;
break;
case "patch":
version.patch++;
break;
}

console.log(`Updating to version ${verToSemver(version)}`);

const newVersion = `${version.major}.${version.minor}.${version.patch}`;
packageJson.version = newVersion;

fs.writeFileSync("./package.json", JSON.stringify(packageJson, null, 4));
console.log(`Updated package.json to version ${newVersion}`);

tryCommit((doCommit) => {
if (doCommit) {
execSync(`git add package.json`);
execSync(`git commit -m "Update version to ${newVersion}" -- package.json`);
console.log("Committed package.json to git!");
}
});
});
})();

0 comments on commit 7ddd315

Please sign in to comment.