-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from codecrafters-io/CC-1122-ts-support
feat: add typescript support, using bun runtime
- Loading branch information
Showing
27 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
* text=auto |
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 @@ | ||
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,39 @@ | ||
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/grep.png) | ||
|
||
This is a starting point for TypeScript solutions to the | ||
["Build Your Own grep" Challenge](https://app.codecrafters.io/courses/grep/overview). | ||
|
||
[Regular expressions](https://en.wikipedia.org/wiki/Regular_expression) | ||
(Regexes, for short) are patterns used to match character combinations in | ||
strings. [`grep`](https://en.wikipedia.org/wiki/Grep) is a CLI tool for | ||
searching using Regexes. | ||
|
||
In this challenge you'll build your own implementation of `grep`. Along the way | ||
we'll learn about Regex syntax, how parsers/lexers work, and how regular | ||
expressions are evaluated. | ||
|
||
**Note**: If you're viewing this repo on GitHub, head over to | ||
[codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
||
# Passing the first stage | ||
|
||
The entry point for your `grep` implementation is in `app/main.ts`. Study and | ||
uncomment the relevant code, and push your changes to pass the first stage: | ||
|
||
```sh | ||
git add . | ||
git commit -m "pass 1st stage" # any msg | ||
git push origin master | ||
``` | ||
|
||
Time to move on to the next stage! | ||
|
||
# Stage 2 & beyond | ||
|
||
Note: This section is for stages 2 and beyond. | ||
|
||
1. Ensure you have `bun (1.1)` installed locally | ||
1. Run `./your_grep.sh` to run your program, which is implemented in | ||
`app/main.ts`. | ||
1. Commit your changes and run `git push origin master` to submit your solution | ||
to CodeCrafters. Test output will be streamed to your terminal. |
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,27 @@ | ||
const args = process.argv; | ||
const pattern = args[3]; | ||
|
||
const inputLine: string = await Bun.stdin.text(); | ||
|
||
function matchPattern(inputLine: string, pattern: string): boolean { | ||
if (pattern.length === 1) { | ||
return inputLine.includes(pattern); | ||
} else { | ||
throw new Error(`Unhandled pattern: ${pattern}`); | ||
} | ||
} | ||
|
||
if (args[2] !== "-E") { | ||
console.log("Expected first argument to be '-E'"); | ||
process.exit(1); | ||
} | ||
|
||
// You can use print statements as follows for debugging, they'll be visible when running tests. | ||
console.log("Logs from your program will appear here!"); | ||
|
||
// Uncomment this block to pass the first stage | ||
// if (matchPattern(inputLine, pattern)) { | ||
// process.exit(0); | ||
// } else { | ||
// process.exit(1); | ||
// } |
Binary file not shown.
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 @@ | ||
# Set this to true if you want debug logs. | ||
# | ||
# These can be VERY verbose, so we suggest turning them off | ||
# unless you really need them. | ||
debug: false | ||
|
||
# Use this to change the TypeScript version used to run your code | ||
# on Codecrafters. | ||
# | ||
# Available versions: bun-1.1 | ||
language_pack: bun-1.1 |
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": "@codecrafters/build-your-own-grep", | ||
"description": "Build your own Grep challenge, from CodeCrafters", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "bun run app/main.ts" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^11.2.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,8 @@ | ||
#!/bin/sh | ||
# | ||
# DON'T EDIT THIS! | ||
# | ||
# CodeCrafters uses this file to test your code. Don't make any changes here! | ||
# | ||
# DON'T EDIT THIS! | ||
exec bun run app/main.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
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 @@ | ||
FROM oven/bun:1.1.4-alpine | ||
|
||
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb" | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json ./ | ||
COPY bun.lockb ./ | ||
|
||
# For reproducible builds. | ||
# This will install the exact versions of each package specified in the lockfile. | ||
# If package.json disagrees with bun.lockb, Bun will exit with an error. The lockfile will not be updated. | ||
RUN bun install --frozen-lockfile | ||
|
||
RUN mkdir -p /app-cached | ||
# If the node_modules directory exists, move it to /app-cached | ||
RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi |
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 @@ | ||
* text=auto |
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 @@ | ||
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,39 @@ | ||
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/grep.png) | ||
|
||
This is a starting point for TypeScript solutions to the | ||
["Build Your Own grep" Challenge](https://app.codecrafters.io/courses/grep/overview). | ||
|
||
[Regular expressions](https://en.wikipedia.org/wiki/Regular_expression) | ||
(Regexes, for short) are patterns used to match character combinations in | ||
strings. [`grep`](https://en.wikipedia.org/wiki/Grep) is a CLI tool for | ||
searching using Regexes. | ||
|
||
In this challenge you'll build your own implementation of `grep`. Along the way | ||
we'll learn about Regex syntax, how parsers/lexers work, and how regular | ||
expressions are evaluated. | ||
|
||
**Note**: If you're viewing this repo on GitHub, head over to | ||
[codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
||
# Passing the first stage | ||
|
||
The entry point for your `grep` implementation is in `app/main.ts`. Study and | ||
uncomment the relevant code, and push your changes to pass the first stage: | ||
|
||
```sh | ||
git add . | ||
git commit -m "pass 1st stage" # any msg | ||
git push origin master | ||
``` | ||
|
||
Time to move on to the next stage! | ||
|
||
# Stage 2 & beyond | ||
|
||
Note: This section is for stages 2 and beyond. | ||
|
||
1. Ensure you have `bun (1.1)` installed locally | ||
1. Run `./your_grep.sh` to run your program, which is implemented in | ||
`app/main.ts`. | ||
1. Commit your changes and run `git push origin master` to submit your solution | ||
to CodeCrafters. Test output will be streamed to your terminal. |
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,23 @@ | ||
const args = process.argv; | ||
const pattern = args[3]; | ||
|
||
const inputLine: string = await Bun.stdin.text(); | ||
|
||
function matchPattern(inputLine: string, pattern: string): boolean { | ||
if (pattern.length === 1) { | ||
return inputLine.includes(pattern); | ||
} else { | ||
throw new Error(`Unhandled pattern: ${pattern}`); | ||
} | ||
} | ||
|
||
if (args[2] !== "-E") { | ||
console.log("Expected first argument to be '-E'"); | ||
process.exit(1); | ||
} | ||
|
||
if (matchPattern(inputLine, pattern)) { | ||
process.exit(0); | ||
} else { | ||
process.exit(1); | ||
} |
Binary file not shown.
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 @@ | ||
# Set this to true if you want debug logs. | ||
# | ||
# These can be VERY verbose, so we suggest turning them off | ||
# unless you really need them. | ||
debug: false | ||
|
||
# Use this to change the TypeScript version used to run your code | ||
# on Codecrafters. | ||
# | ||
# Available versions: bun-1.1 | ||
language_pack: bun-1.1 |
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": "@codecrafters/build-your-own-grep", | ||
"description": "Build your own Grep challenge, from CodeCrafters", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "bun run app/main.ts" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^11.2.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,8 @@ | ||
#!/bin/sh | ||
# | ||
# DON'T EDIT THIS! | ||
# | ||
# CodeCrafters uses this file to test your code. Don't make any changes here! | ||
# | ||
# DON'T EDIT THIS! | ||
exec bun run app/main.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,33 @@ | ||
@@ -1,27 +1,23 @@ | ||
const args = process.argv; | ||
const pattern = args[3]; | ||
|
||
const inputLine: string = await Bun.stdin.text(); | ||
|
||
function matchPattern(inputLine: string, pattern: string): boolean { | ||
if (pattern.length === 1) { | ||
return inputLine.includes(pattern); | ||
} else { | ||
throw new Error(`Unhandled pattern: ${pattern}`); | ||
} | ||
} | ||
|
||
if (args[2] !== "-E") { | ||
console.log("Expected first argument to be '-E'"); | ||
process.exit(1); | ||
} | ||
|
||
-// You can use print statements as follows for debugging, they'll be visible when running tests. | ||
-console.log("Logs from your program will appear here!"); | ||
- | ||
-// Uncomment this block to pass the first stage | ||
-// if (matchPattern(inputLine, pattern)) { | ||
-// process.exit(0); | ||
-// } else { | ||
-// process.exit(1); | ||
-// } | ||
+if (matchPattern(inputLine, pattern)) { | ||
+ process.exit(0); | ||
+} else { | ||
+ process.exit(1); | ||
+} |
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,20 @@ | ||
The entry point for your grep implementation is in `app/main.ts`. | ||
|
||
Study and uncomment the relevant code: | ||
|
||
```typescript | ||
// Uncomment this block to pass the first stage | ||
if (matchPattern(inputLine, pattern)) { | ||
process.exit(0); | ||
} else { | ||
process.exit(1); | ||
} | ||
``` | ||
|
||
Push your changes to pass the first stage: | ||
|
||
``` | ||
git add . | ||
git commit -m "pass 1st stage" # any msg | ||
git push origin master | ||
``` |
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
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
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 @@ | ||
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,27 @@ | ||
const args = process.argv; | ||
const pattern = args[3]; | ||
|
||
const inputLine: string = await Bun.stdin.text(); | ||
|
||
function matchPattern(inputLine: string, pattern: string): boolean { | ||
if (pattern.length === 1) { | ||
return inputLine.includes(pattern); | ||
} else { | ||
throw new Error(`Unhandled pattern: ${pattern}`); | ||
} | ||
} | ||
|
||
if (args[2] !== "-E") { | ||
console.log("Expected first argument to be '-E'"); | ||
process.exit(1); | ||
} | ||
|
||
// You can use print statements as follows for debugging, they'll be visible when running tests. | ||
console.log("Logs from your program will appear here!"); | ||
|
||
// Uncomment this block to pass the first stage | ||
// if (matchPattern(inputLine, pattern)) { | ||
// process.exit(0); | ||
// } else { | ||
// process.exit(1); | ||
// } |
Binary file not shown.
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": "@codecrafters/build-your-own-grep", | ||
"description": "Build your own Grep challenge, from CodeCrafters", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "bun run app/main.ts" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^11.2.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,8 @@ | ||
#!/bin/sh | ||
# | ||
# DON'T EDIT THIS! | ||
# | ||
# CodeCrafters uses this file to test your code. Don't make any changes here! | ||
# | ||
# DON'T EDIT THIS! | ||
exec bun run app/main.ts "$@" |