forked from codecrafters-io/build-your-own-gleam-chess-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Update Gleam Chess Bot for JavaScript support #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0e60c0b
feat: update challenge name and slug to include JS in README and cour…
ryan-gang 7241fbd
feat: update starter template to support JS
ryan-gang f00a61b
feat: update Dockerfile to use Node slim image and support JavaScript…
ryan-gang f2ccadf
chore: add compiled files
ryan-gang 21ee48a
feat: update compile script to build and run chess_bot with Deno
ryan-gang 3a07b75
chore: add compiled files
ryan-gang 96ef923
feat: update compile and run scripts to ensure compatibility with Den…
ryan-gang a10b38a
feat: update compile and run scripts to streamline Deno execution for…
ryan-gang 3b8adac
feat: update Dockerfile to version 1.10 and specify Deno version
ryan-gang 77277c3
feat: update Gleam version to 1.10 in codecrafters.yml files
ryan-gang d31c1b5
chore: update slugs
ryan-gang fe6cfbc
fix: correct README link text and update run script command for Deno
ryan-gang 3d3596e
chore: add compiled starter and solutions
ryan-gang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -8,4 +8,5 @@ | |
|
||
set -e # Exit on failure | ||
|
||
gleam export erlang-shipment | ||
gleam deps download | ||
gleam build --target javascript |
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
*.beam | ||
*.ez | ||
/build | ||
erl_crash.dump | ||
erl_crash.dump |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -1,67 +1,49 @@ | ||
import chess_bot/chess | ||
|
||
import gleam/dynamic/decode | ||
import gleam/erlang/process | ||
import gleam/io | ||
import gleam/javascript/promise.{type Promise} | ||
import gleam/json | ||
import mist | ||
import wisp.{type Request, type Response} | ||
import wisp/wisp_mist | ||
import glen | ||
import glen/status | ||
import chess_bot/chess | ||
import gleam/io | ||
|
||
pub fn main() { | ||
wisp.configure_logger() | ||
wisp.set_logger_level(wisp.CriticalLevel) | ||
|
||
let secret_key_base = wisp.random_string(64) | ||
|
||
// You can use print statements as follows for debugging, they'll be visible when running tests. | ||
io.println("Logs from your program will appear here!") | ||
|
||
// Uncomment this block to pass the first stage | ||
// | ||
// let assert Ok(_) = | ||
// handle_request | ||
// |> wisp_mist.handler(secret_key_base) | ||
// |> mist.new | ||
// |> mist.bind("0.0.0.0") | ||
// |> mist.port(8000) | ||
// |> mist.start_http | ||
// | ||
// process.sleep_forever() | ||
//} | ||
// | ||
// fn handle_request(request: Request) -> Response { | ||
// case wisp.path_segments(request) { | ||
// ["move"] -> handle_move(request) | ||
// _ -> wisp.ok() | ||
// } | ||
// } | ||
// fn move_decoder() { | ||
// use fen <- decode.field("fen", decode.string) | ||
// use turn <- decode.field("turn", chess.player_decoder()) | ||
// use failed_moves <- decode.field("failed_moves", decode.list(decode.string)) | ||
// decode.success(#(fen, turn, failed_moves)) | ||
// } | ||
// | ||
// fn handle_move(request: Request) -> Response { | ||
// use body <- wisp.require_string_body(request) | ||
// | ||
// let decode_result = json.parse(body, move_decoder()) | ||
// case decode_result { | ||
// Error(_) -> { | ||
// io.println("Failed to decode JSON") | ||
// wisp.bad_request() | ||
// } | ||
// Ok(move) -> { | ||
// let move_result = chess.move(move.0, move.1, move.2) | ||
// case move_result { | ||
// Ok(move) -> { | ||
// wisp.ok() |> wisp.string_body(move) | ||
// } | ||
// Error(reason) -> { | ||
// wisp.internal_server_error() |> wisp.string_body(reason) | ||
// } | ||
// } | ||
// } | ||
// } | ||
// Uncomment this block to pass the first stage | ||
// | ||
// glen.serve(8000, handle_request) | ||
} | ||
|
||
fn handle_request(request: glen.Request) -> Promise(glen.Response) { | ||
case glen.path_segments(request) { | ||
["move"] -> handle_move(request) | ||
_ -> glen.response(status.ok) |> promise.resolve | ||
} | ||
} | ||
|
||
fn move_decoder() { | ||
use fen <- decode.field("fen", decode.string) | ||
use turn <- decode.field("turn", chess.player_decoder()) | ||
use failed_moves <- decode.field("failed_moves", decode.list(decode.string)) | ||
decode.success(#(fen, turn, failed_moves)) | ||
} | ||
|
||
fn handle_move(request: glen.Request) -> Promise(glen.Response) { | ||
use body <- glen.require_string_body(request) | ||
let decode_result = json.parse(body, move_decoder()) | ||
case decode_result { | ||
Error(_) -> glen.response(status.bad_request) |> promise.resolve | ||
Ok(move) -> { | ||
let move_result = chess.move(move.0, move.1, move.2) | ||
case move_result { | ||
Ok(move) -> | ||
glen.response(status.ok) |> glen.text_body(move) |> promise.resolve | ||
Error(reason) -> | ||
glen.response(status.internal_server_error) | ||
|> glen.text_body(reason) | ||
|> promise.resolve | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -9,4 +9,4 @@ pub fn main() { | |
pub fn hello_world_test() { | ||
1 | ||
|> should.equal(1) | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
7 changes: 5 additions & 2 deletions
7
dockerfiles/gleam-1.9.Dockerfile → dockerfiles/gleam-1.10.Dockerfile
This file contains hidden or 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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
# syntax=docker/dockerfile:1.7-labs | ||
FROM ghcr.io/gleam-lang/gleam:v1.9.1-erlang-alpine | ||
FROM ghcr.io/gleam-lang/gleam:v1.10.0-node-slim | ||
|
||
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="gleam.toml,manifest.toml" | ||
|
||
WORKDIR /app | ||
COPY --exclude=.git --exclude=README.md . /app | ||
ryan-gang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
RUN gleam export erlang-shipment | ||
RUN gleam deps download | ||
RUN gleam build --target javascript | ||
|
||
RUN npm install -g [email protected] | ||
|
||
# Cache build directory | ||
RUN mkdir -p /app-cached | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -8,4 +8,5 @@ | |
|
||
set -e # Exit on failure | ||
|
||
gleam export erlang-shipment | ||
gleam deps download | ||
gleam build --target javascript |
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
solutions/gleam/01-si0/code/.gitignore → solutions/gleam/01-qc6/code/.gitignore
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
*.beam | ||
*.ez | ||
/build | ||
erl_crash.dump | ||
erl_crash.dump |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
solutions/gleam/01-si0/code/README.md → solutions/gleam/01-qc6/code/README.md
This file contains hidden or 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
This file contains hidden or 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
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.