-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jake Lauer
authored and
Jake Lauer
committed
Feb 6, 2024
1 parent
b891443
commit 7ddd315
Showing
15 changed files
with
4,314 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.* | ||
tsconfig.json | ||
/lib | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
16.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.`)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
}); | ||
}); | ||
})(); |