Skip to content

Commit

Permalink
Add typescript language
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdaming committed Jul 19, 2023
1 parent 325423d commit 055aa0a
Show file tree
Hide file tree
Showing 17 changed files with 2,576 additions and 13 deletions.
28 changes: 17 additions & 11 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Please see the documentation for all configuration options:
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
Expand All @@ -10,31 +10,37 @@ updates:
interval: "weekly"

# Maintain dependencies for Maven
- package-ecosystem: maven
- package-ecosystem: "maven"
directory: "/java"
schedule:
interval: weekly
interval: "weekly"

# Maintain dependencies for Gradle
- package-ecosystem: gradle
- package-ecosystem: "gradle"
directory: "/java"
schedule:
interval: weekly
interval: "weekly"

# Maintain dependencies for Go Modules
- package-ecosystem: gomod
- package-ecosystem: "gomod"
directory: "/go"
schedule:
interval: weekly
interval: "weekly"

# Maintain dependencies for Nuget
- package-ecosystem: nuget
- package-ecosystem: "nuget"
directory: "/csharp"
schedule:
interval: weekly
interval: "weekly"

# Maintain dependencies for Python
- package-ecosystem: pip
- package-ecosystem: "pip"
directory: "/python"
schedule:
interval: weekly
interval: "weekly"

# Maintain dependencies for Typescript
- package-ecosystem: "npm"
directory: "/typescript"
schedule:
interval: "weekly"
25 changes: 25 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Npm

on:
push:
branches:
- '**'
paths:
- 'typescript/**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Yarn install
working-directory: typescript
run: yarn install
- name: Test
working-directory: typescript
run: yarn jest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
**/csharp/**/obj/
**/csharp/**/TestResults/

# Typescript folders containing generated stuff
**/node_modules/
**/test_results/

# Python folders containing generated stuff
**/venv/
**/dist/
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ Available [here](http://codingdojo.org/kata/Bowling/)
- [Java](java/GETTING_STARTED.md)
- [C++](cpp/GETTING_STARTED.md)
- [Go](go/GETTING_STARTED.md)
- [C#](csharp/GETTING_STARTED.md)
- [Python](python/GETTING_STARTED.md)
- [Typescript](typescript/GETTING_STARTED.md)
- [C#](csharp/GETTING_STARTED.md)

## Session Quick Retrospective

Expand Down Expand Up @@ -64,8 +65,9 @@ You can fill it from [here](QuickRetrospective.md)
- [Java](java)
- [C++](cpp)
- [Go](go)
- [C#](csharp)
- [Python](python)
- [Typescript](typescript)
- [C#](csharp)

## License

Expand Down
1 change: 1 addition & 0 deletions typescript/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
4 changes: 4 additions & 0 deletions typescript/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 120,
"singleQuote": true
}
9 changes: 9 additions & 0 deletions typescript/.tcr/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
config:
git:
auto-push: true
polling-period: 2s
mob-timer:
duration: 5m0s
tcr:
language: typescript
toolchain: yarn
9 changes: 9 additions & 0 deletions typescript/.tcr/language/typescript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
toolchains:
default: yarn
compatible-with: [yarn]
source-files:
directories: [src]
patterns: ['(?i)^.*\.ts$']
test-files:
directories: [test]
patterns: ['(?i)^.*\.ts$']
12 changes: 12 additions & 0 deletions typescript/.tcr/toolchain/yarn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
build:
- os: [darwin, linux, windows]
arch: ["386", amd64, arm64]
command: yarn
arguments: [jest, --testNamePattern=DO-NOT-RUN-ANYTHING, --silent]
test:
- os: [darwin, linux, windows]
arch: ["386", amd64, arm64]
command: yarn
arguments: [jest]
test-result-dir: test_results

94 changes: 94 additions & 0 deletions typescript/GETTING_STARTED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Getting Started with Bowling Game kata in Typescript

## Prerequisites

- macOS, Linux or Windows
- [git](https://git-scm.com/) client
- [curl](https://curl.se/download.html) command line utility
- [node](https://nodejs.org/en/download)
- [yarn](https://classic.yarnpkg.com/lang/en/docs/install)
<details><summary>Details</summary>

You can install node directly or through nvm.

</details>

## Getting ready

### 1 - Clone the kata repository

```shell
git clone https://github.com/murex/Kata-BowlingGame.git
```

### 2 - Go to the kata's `typescript` directory

```shell
cd Kata-BowlingGame/typescript
```

### 3 - Download dependencies

```shell
yarn install
```

## Running the kata

You can run the kata from the command line or from your IDE of choice.

You may also run it using [TCR](../tcr/TCR.md) if you want to add a bit of spice.

- [From a terminal with Yarn](#running-the-kata-from-a-terminal-with-yarn)
- [From a terminal with TCR](#running-the-kata-from-a-terminal-with-tcr)

<a name="running-the-kata-from-a-terminal-with-yarn"/></a>

### Running the kata from a terminal with Yarn

> ***Reminder***: the command below should be run from [Kata-BowlingGame/typescript](.) directory
The kata comes with a Yarn test target pre-configured. Just type the following to run it.

```shell
yarn test
```

<a name="running-the-kata-from-a-terminal-with-tcr"/></a>

### Running the kata from a terminal with TCR

> ***Note to Windows users***
>
> Use a **git bash** terminal for running the command below.
> _Windows CMD and PowerShell are not supported_
Type the following to start TCR:

```shell
./tcrw
```

Refer to [Using TCR](#using-tcr) section for additional details about TCR and available options.

<a name="using-tcr"/></a>

## Using TCR

### Cheat Sheet

Here are the main shortcuts available once TCR utility is running:

| Shortcut | Description |
|-----------|-----------------------------------------------|
| `?` | List available options |
| `d` / `D` | Enter driver role (from main menu) |
| `n` / `N` | Enter navigator role (from main menu) |
| `q` / `Q` | Quit current role - Quit TCR (from main menu) |
| `t` / `T` | Query timer status (from driver role only) |
| `p` / `P` | Toggle on/off git auto-push (from main menu) |

### Additional Details

Refer to [TCR - Test && Commit || Revert](../tcr/TCR.md) page
for additional details and explanations about TCR utility.
4 changes: 4 additions & 0 deletions typescript/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
"preset": 'ts-jest',
"reporters": [ "default", "jest-junit" ]
};
20 changes: 20 additions & 0 deletions typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "bowling_game",
"version": "1.0.0",
"description": "Bowling Game",
"author": "Murex",
"license": "MIT",
"devDependencies": {
"@types/jest": "*",
"jest": "*",
"ts-jest": "*",
"jest-junit": "*",
"typescript": "*"
},
"scripts": {
"test": "jest --watchAll"
},
"jest-junit": {
"outputDirectory": "./test_results"
}
}
25 changes: 25 additions & 0 deletions typescript/src/BowlingGame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (c) 2023 Murex
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

export function bowlingScore(...rolls: number[]): number {
return 0;
}
24 changes: 24 additions & 0 deletions typescript/tcrw
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env sh
#
# Copyright (c) 2021 Murex
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

base_dir="$(cd "$(dirname -- "$0")" && pwd)"
. "${base_dir}/../tcr/tcr.sh"
8 changes: 8 additions & 0 deletions typescript/test/BowlingGame.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {bowlingScore} from "../src/BowlingGame";

describe("bowling_game", () => {
// Remove the ".skip" below to enable this test case
test.skip('acceptance test', () => {
expect(bowlingScore(1, 4, 4, 5, 6, 4, 5, 5, 10, 0, 1, 7, 3, 6, 4, 10, 2, 8, 6)).toEqual(133);
});
});
Loading

0 comments on commit 055aa0a

Please sign in to comment.