diff --git a/build.sh b/build.sh index e0e089f..dac278a 100644 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ mkdir build cd main-web/client npm run build cd ../../ -mv main-web/client/client build/ +mv main-web/client/client build cd tools/janken npm run build cd ../../ @@ -10,6 +10,6 @@ mv tools/janken/tool build cd main-web/server npm run build cd ../../ -mv main-web/server/build server/ +mv main-web/server/build build/server tar czf build.tar.gz build/ rm -rf build/ \ No newline at end of file diff --git a/infra/custom_ami/packer/catherine-fc.json b/infra/custom_ami/packer/catherine-fc.json index 0987690..a7c01a7 100644 --- a/infra/custom_ami/packer/catherine-fc.json +++ b/infra/custom_ami/packer/catherine-fc.json @@ -38,7 +38,7 @@ { "type": "shell", "inline": [ - "sudo yum update", + "sudo yum -y update", "sudo yum -y install unzip", "sudo yum -y install nano", "sudo yum -y install dos2unix", diff --git a/infra/custom_ami/platform-uploads/opt/web-init/web-init.sh b/infra/custom_ami/platform-uploads/opt/web-init/web-init.sh index 226bf7b..c4ed74b 100644 --- a/infra/custom_ami/platform-uploads/opt/web-init/web-init.sh +++ b/infra/custom_ami/platform-uploads/opt/web-init/web-init.sh @@ -3,4 +3,5 @@ aws s3 cp s3://catherine-fc-infra/build.tar.gz . tar zxf build.tar.gz rm build.tar.gz -node build/server/index.js \ No newline at end of file +cd build +node server/index.js \ No newline at end of file diff --git a/infra/terraform/environments/catherine-fc/.gitignore b/infra/terraform/environments/catherine-fc/.gitignore new file mode 100644 index 0000000..c8ffcb9 --- /dev/null +++ b/infra/terraform/environments/catherine-fc/.gitignore @@ -0,0 +1 @@ +/.terraform/ diff --git a/infra/terraform/environments/catherine-fc/backend.tf b/infra/terraform/environments/catherine-fc/backend.tf new file mode 100644 index 0000000..5a11508 --- /dev/null +++ b/infra/terraform/environments/catherine-fc/backend.tf @@ -0,0 +1,8 @@ +terraform { + backend "s3" { + bucket = "catherine-fc-infra" + key = "catherine-fc-ec2/terraform.tfstate" + region = "ap-northeast-1" + encrypt = true + } +} diff --git a/infra/terraform/environments/catherine-fc/main.tf b/infra/terraform/environments/catherine-fc/main.tf new file mode 100644 index 0000000..88f4f63 --- /dev/null +++ b/infra/terraform/environments/catherine-fc/main.tf @@ -0,0 +1,12 @@ +module "catherine-fc" { + source = "../../modules/catherine-fc/main" + vpc_id = var.vpc_id[terraform.workspace] + internal_subnet_ids = var.internal_subnet_ids[terraform.workspace] + tags = var.tags + asg_tags = var.asg_tags + basename = "catherine-fc" + asg_caps = var.asg_caps["catherine-fc"] + ec2_instance_type = "t2.micro" + key_name = var.key_name[terraform.workspace] + asg_arn = module.catherine-fc.asg_arn +} diff --git a/infra/terraform/environments/catherine-fc/output.tf b/infra/terraform/environments/catherine-fc/output.tf new file mode 100644 index 0000000..d7a321a --- /dev/null +++ b/infra/terraform/environments/catherine-fc/output.tf @@ -0,0 +1,3 @@ +output "asg_arn" { + value = module.catherine-fc.asg_arn +} \ No newline at end of file diff --git a/infra/terraform/environments/catherine-fc/provider.tf b/infra/terraform/environments/catherine-fc/provider.tf new file mode 100644 index 0000000..3ea72c9 --- /dev/null +++ b/infra/terraform/environments/catherine-fc/provider.tf @@ -0,0 +1,4 @@ +provider "aws" { + region = "ap-northeast-1" + version = "~> 2.0" +} diff --git a/infra/terraform/environments/catherine-fc/variable.tf b/infra/terraform/environments/catherine-fc/variable.tf new file mode 100644 index 0000000..e21070a --- /dev/null +++ b/infra/terraform/environments/catherine-fc/variable.tf @@ -0,0 +1,46 @@ +variable "tags" { + type = map(string) + default = { + PROJECT = "CATHERINE_FC" + } +} + +variable "asg_tags" { + type = list(object({key=string, value=string, propagate_at_launch=bool})) + default = [ + { + key = "PROJECT", + value = "CATHERINE_FC", + propagate_at_launch = true + } + ] +} +variable "asg_caps" { + type = map(map(number)) + default = { + "catherine-fc" = { + min = 1 + max = 1 + desired = 1 + } + } +} + +variable "vpc_id" { + type = map(string) + default = { + prod = "vpc-c54553a2" + } +} +variable "internal_subnet_ids" { + type = map(list(string)) + default = { + prod = [ "subnet-0d0fdf45", "subnet-4dcecc16", "subnet-4dcecc16" ] + } +} +variable "key_name" { + type = map(string) + default = { + prod = "catherine-fc" + } +} \ No newline at end of file diff --git a/infra/terraform/modules/catherine-fc/main/autoscaling-group.tf b/infra/terraform/modules/catherine-fc/main/autoscaling-group.tf new file mode 100644 index 0000000..7a7d580 --- /dev/null +++ b/infra/terraform/modules/catherine-fc/main/autoscaling-group.tf @@ -0,0 +1,36 @@ +resource "aws_autoscaling_group" "es_asg" { + name = "${var.basename}-${terraform.workspace}" + + availability_zones = ["ap-northeast-1a", "ap-northeast-1c", "ap-northeast-1d"] + vpc_zone_identifier = var.internal_subnet_ids + + desired_capacity = var.asg_caps.desired + max_size = var.asg_caps.max + min_size = var.asg_caps.min + + launch_configuration = aws_launch_configuration.catherine_fc_conf.name + + tags = concat(var.asg_tags, [ + { + key = "STAGE_ENVIRONMENT", + value = "${terraform.workspace}", + propagate_at_launch = true + }, + { + key = "Name", + value = "${var.basename}-${terraform.workspace}", + propagate_at_launch = true + } + ]) + + enabled_metrics = [ + "GroupMinSize", + "GroupMaxSize", + "GroupDesiredCapacity", + "GroupInServiceInstances", + "GroupPendingInstances", + "GroupTerminatingInstances", + "GroupStandbyInstances", + "GroupTotalInstances" + ] +} diff --git a/infra/terraform/modules/catherine-fc/main/data.tf b/infra/terraform/modules/catherine-fc/main/data.tf new file mode 100644 index 0000000..fa68524 --- /dev/null +++ b/infra/terraform/modules/catherine-fc/main/data.tf @@ -0,0 +1,12 @@ +data "aws_caller_identity" "self" { } + +data "aws_ami" "catherine_fc_ami" { + most_recent = true + + filter { + name = "name" + values = [ "catherine-fc" ] + } + + owners = [ "353699021357" ] +} diff --git a/infra/terraform/modules/catherine-fc/main/iam.tf b/infra/terraform/modules/catherine-fc/main/iam.tf new file mode 100644 index 0000000..63ef086 --- /dev/null +++ b/infra/terraform/modules/catherine-fc/main/iam.tf @@ -0,0 +1,97 @@ +resource "aws_iam_instance_profile" "catherine_fc_profile" { + name_prefix = "${var.basename}-" + role = aws_iam_role.instance.name +} + +resource "aws_iam_role" "instance" { + name = "${var.basename}-${terraform.workspace}" + path = "/" + + assume_role_policy = < a { display:block; @@ -33,7 +33,7 @@ left: 0; right: 0; margin: auto; - background-image: url('./static/img/bgimage.png'); + background-image: url('https://static.catherine-fc.com/media/bgimage.png'); background-repeat: none; width: 1366px; height: 401px; @@ -41,7 +41,7 @@ transition: background-image 0.5s ease-in-out; &:hover { transition: background-image 0.5s ease-in-out; - background-image: url('./static/img/bgimagenight.png'); + background-image: url('https://static.catherine-fc.com/media/bgimagenight.png'); } } .logoHeader { @@ -52,7 +52,7 @@ margin: auto; width: 577px; height: 401px; - background-image: url('./static/img/cat_fb_logo.png'); + background-image: url('https://static.catherine-fc.com/media/cat_fb_logo.png'); background-repeat: none; z-index: 1; } @@ -65,7 +65,7 @@ margin: auto; width: 415px; height: 64px; - background-image: url('./static/img/faito_crab.png'); + background-image: url('https://static.catherine-fc.com/media/faito_crab.png'); background-repeat: none; z-index: 1; } @@ -77,7 +77,7 @@ display: flex; flex-direction: column; width: 100%; - background-image: url('./static/img/background.png'); + background-image: url('https://static.catherine-fc.com/media/background.png'); background-repeat: none; color: white; min-height: 100vh; @@ -108,7 +108,7 @@ float: right; width: 113px; height: 70px; - background-image: url('./static/img/twitch.png'); + background-image: url('https://static.catherine-fc.com/media/twitch.png'); background-size: 142px 70px; margin: 0 20px; background-repeat: none; @@ -122,7 +122,7 @@ .twitchHome { width: 113px; height: 70px; - background-image: url('./static/img/twitch.png'); + background-image: url('https://static.catherine-fc.com/media/twitch.png'); background-size: 142px 70px; margin: auto; background-repeat: none; @@ -138,7 +138,7 @@ width: 70px; height: 70px; margin: 0 20px; - background-image: url('./static/img/twitter.png'); + background-image: url('https://static.catherine-fc.com/media/twitter.png'); background-size: contain; &> a { display:block; @@ -151,7 +151,7 @@ width: 100px; height: 70px; margin: 0 20px; - background-image: url('./static/img/youtube.png'); + background-image: url('https://static.catherine-fc.com/media/youtube.png'); background-size: contain; &> a { display:block; @@ -255,7 +255,7 @@ height: 314px; margin: 20px auto; padding: 30px; - background-image: url('./static/img/playerbg.png'); + background-image: url('https://static.catherine-fc.com/media/playerbg.png'); background-repeat: none; font-family: 'M PLUS Rounded 1c'; &:nth-child(odd) { @@ -309,43 +309,43 @@ } .character-blue_cap { - @include characterImage('./static/img/00_bluecap_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/00_bluecap_1204.png'); } .character-red_cap { - @include characterImage('./static/img/00_redcap_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/00_redcap_1204.png'); } .character-vincent_shirt { - @include characterImage('./static/img/01_vincent_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/01_vincent_1204.png'); } .character-vincent_sheep { - @include characterImage('./static/img/01_sheep_vincent_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/01_sheep_vincent_1204.png'); } .character-katherine { - @include characterImage('./static/img/02_katherine_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/02_katherine_1204.png'); } .character-catherine { - @include characterImage('./static/img/03_catherine_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/03_catherine_1204.png'); } .character-rin { - @include characterImage('./static/img/04_rin_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/04_rin_1204.png'); } .character-orlando { - @include characterImage('./static/img/05_orlando_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/05_orlando_1204.png'); } .character-johny { - @include characterImage('./static/img/06_jonny_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/06_jonny_1204.png'); } .character-tobby { - @include characterImage('./static/img/07_tobby_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/07_tobby_1204.png'); } .character-erica { - @include characterImage('./static/img/08_erika_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/08_erika_1204.png'); } .character-master { - @include characterImage('./static/img/09_master_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/09_master_1204.png'); } .character-joker { - @include characterImage('./static/img/13_joker_1204.png'); + @include characterImage('https://static.catherine-fc.com/media/13_joker_1204.png'); } .titlePlayer { @@ -368,7 +368,7 @@ height: 800px; margin: 20px auto; padding: 50px; - background-image: url('./static/img/playerbg.png'); + background-image: url('https://static.catherine-fc.com/media/playerbg.png'); background-repeat: none; background-size: 980px 800px; font-family: 'M PLUS Rounded 1c'; @@ -382,7 +382,7 @@ margin-top: 70px; bottom: 0; left: 0; - background-image: url('./static/img/title_sheep.png'); + background-image: url('https://static.catherine-fc.com/media/title_sheep.png'); background-repeat: none; } .guideBody { @@ -401,7 +401,7 @@ width: 128px; height: 128px; margin: 20px; - background-image: url('./static/img/letterbox.png'); + background-image: url('https://static.catherine-fc.com/media/letterbox.png'); background-size: 128px 128px; background-repeat: none; & > a { @@ -415,7 +415,7 @@ width: 128px; height: 128px; margin: 20px auto; - background-image: url('./static/img/letterbox.png'); + background-image: url('https://static.catherine-fc.com/media/letterbox.png'); background-size: 128px 128px; background-repeat: none; & > a { @@ -436,7 +436,7 @@ width: 400px; height: 340px; margin: auto; - background-image: url('./static/img/chalice.png'); + background-image: url('https://static.catherine-fc.com/media/chalice.png'); background-size: contain; background-repeat: none; } @@ -444,7 +444,7 @@ width: 900px; height: 606px; margin: auto; - background-image: url('./static/img/players.png'); + background-image: url('https://static.catherine-fc.com/media/players.png'); background-size: contain; background-repeat: none; } @@ -452,7 +452,7 @@ width: 567px; height: 485px; margin: auto; - background-image: url('./static/img/scoreboard.png'); + background-image: url('https://static.catherine-fc.com/media/scoreboard.png'); background-size: contain; background-repeat: none; } @@ -460,7 +460,7 @@ width: 808px; height: 119px; margin: auto; - background-image: url('./static/img/straysheepcup0.png'); + background-image: url('https://static.catherine-fc.com/media/straysheepcup0.png'); background-size: contain; background-repeat: none; } @@ -468,7 +468,7 @@ width: 900px; height: 637px; margin: auto; - background-image: url('./static/img/rule.png'); + background-image: url('https://static.catherine-fc.com/media/rule.png'); background-size: contain; background-repeat: none; } @@ -482,7 +482,7 @@ width: 899px; height: 696px; margin: auto; - background-image: url('./static/img/0801.png'); + background-image: url('https://static.catherine-fc.com/media/0801.png'); background-size: contain; background-repeat: none; } @@ -491,7 +491,7 @@ width: 900px; height: 710px; margin: auto; - background-image: url('./static/img/0802.png'); + background-image: url('https://static.catherine-fc.com/media/0802.png'); background-size: contain; background-repeat: none; } @@ -499,7 +499,7 @@ width: 900px; height: 710px; margin: auto; - background-image: url('./static/img/0808.png'); + background-image: url('https://static.catherine-fc.com/media/0808.png'); background-size: contain; background-repeat: none; } @@ -507,7 +507,7 @@ width: 900px; height: 696px; margin: auto; - background-image: url('./static/img/0809.png'); + background-image: url('https://static.catherine-fc.com/media/0809.png'); background-size: contain; background-repeat: none; } @@ -515,7 +515,7 @@ width: 900px; height: 696px; margin: auto; - background-image: url('./static/img/0815.png'); + background-image: url('https://static.catherine-fc.com/media/0815.png'); background-size: contain; background-repeat: none; } diff --git a/tools/discord-commentator/.gitignore b/tools/discord-commentator/.gitignore new file mode 100644 index 0000000..4d29575 --- /dev/null +++ b/tools/discord-commentator/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/tools/discord-commentator/README.md b/tools/discord-commentator/README.md new file mode 100644 index 0000000..74735dc --- /dev/null +++ b/tools/discord-commentator/README.md @@ -0,0 +1,44 @@ +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.
+You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.
+It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.
+Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). diff --git a/tools/discord-commentator/package.json b/tools/discord-commentator/package.json new file mode 100644 index 0000000..dd39018 --- /dev/null +++ b/tools/discord-commentator/package.json @@ -0,0 +1,39 @@ +{ + "name": "discord-commentator", + "version": "0.1.0", + "private": true, + "dependencies": { + "@testing-library/jest-dom": "^4.2.4", + "@testing-library/react": "^9.5.0", + "@testing-library/user-event": "^7.2.1", + "@types/jest": "^24.9.1", + "@types/node": "^12.12.54", + "@types/react": "^16.9.44", + "@types/react-dom": "^16.9.8", + "react": "^16.13.1", + "react-dom": "^16.13.1", + "react-scripts": "3.4.1", + "typescript": "^3.7.5" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/tools/discord-commentator/public/favicon.ico b/tools/discord-commentator/public/favicon.ico new file mode 100644 index 0000000..bcd5dfd Binary files /dev/null and b/tools/discord-commentator/public/favicon.ico differ diff --git a/tools/discord-commentator/public/index.html b/tools/discord-commentator/public/index.html new file mode 100644 index 0000000..aa069f2 --- /dev/null +++ b/tools/discord-commentator/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + React App + + + +
+ + + diff --git a/tools/discord-commentator/public/logo192.png b/tools/discord-commentator/public/logo192.png new file mode 100644 index 0000000..fc44b0a Binary files /dev/null and b/tools/discord-commentator/public/logo192.png differ diff --git a/tools/discord-commentator/public/logo512.png b/tools/discord-commentator/public/logo512.png new file mode 100644 index 0000000..a4e47a6 Binary files /dev/null and b/tools/discord-commentator/public/logo512.png differ diff --git a/tools/discord-commentator/public/manifest.json b/tools/discord-commentator/public/manifest.json new file mode 100644 index 0000000..080d6c7 --- /dev/null +++ b/tools/discord-commentator/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/tools/discord-commentator/public/robots.txt b/tools/discord-commentator/public/robots.txt new file mode 100644 index 0000000..e9e57dc --- /dev/null +++ b/tools/discord-commentator/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/tools/discord-commentator/src/App.css b/tools/discord-commentator/src/App.css new file mode 100644 index 0000000..74b5e05 --- /dev/null +++ b/tools/discord-commentator/src/App.css @@ -0,0 +1,38 @@ +.App { + text-align: center; +} + +.App-logo { + height: 40vmin; + pointer-events: none; +} + +@media (prefers-reduced-motion: no-preference) { + .App-logo { + animation: App-logo-spin infinite 20s linear; + } +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/tools/discord-commentator/src/App.test.tsx b/tools/discord-commentator/src/App.test.tsx new file mode 100644 index 0000000..4db7ebc --- /dev/null +++ b/tools/discord-commentator/src/App.test.tsx @@ -0,0 +1,9 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + const { getByText } = render(); + const linkElement = getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/tools/discord-commentator/src/App.tsx b/tools/discord-commentator/src/App.tsx new file mode 100644 index 0000000..a53698a --- /dev/null +++ b/tools/discord-commentator/src/App.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import logo from './logo.svg'; +import './App.css'; + +function App() { + return ( +
+
+ logo +

+ Edit src/App.tsx and save to reload. +

+ + Learn React + +
+
+ ); +} + +export default App; diff --git a/tools/discord-commentator/src/index.css b/tools/discord-commentator/src/index.css new file mode 100644 index 0000000..ec2585e --- /dev/null +++ b/tools/discord-commentator/src/index.css @@ -0,0 +1,13 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/tools/discord-commentator/src/index.tsx b/tools/discord-commentator/src/index.tsx new file mode 100644 index 0000000..f5185c1 --- /dev/null +++ b/tools/discord-commentator/src/index.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import * as serviceWorker from './serviceWorker'; + +ReactDOM.render( + + + , + document.getElementById('root') +); + +// If you want your app to work offline and load faster, you can change +// unregister() to register() below. Note this comes with some pitfalls. +// Learn more about service workers: https://bit.ly/CRA-PWA +serviceWorker.unregister(); diff --git a/tools/discord-commentator/src/logo.svg b/tools/discord-commentator/src/logo.svg new file mode 100644 index 0000000..6b60c10 --- /dev/null +++ b/tools/discord-commentator/src/logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tools/discord-commentator/src/react-app-env.d.ts b/tools/discord-commentator/src/react-app-env.d.ts new file mode 100644 index 0000000..6431bc5 --- /dev/null +++ b/tools/discord-commentator/src/react-app-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/tools/discord-commentator/src/serviceWorker.ts b/tools/discord-commentator/src/serviceWorker.ts new file mode 100644 index 0000000..b09523f --- /dev/null +++ b/tools/discord-commentator/src/serviceWorker.ts @@ -0,0 +1,149 @@ +// This optional code is used to register a service worker. +// register() is not called by default. + +// This lets the app load faster on subsequent visits in production, and gives +// it offline capabilities. However, it also means that developers (and users) +// will only see deployed updates on subsequent visits to a page, after all the +// existing tabs open on the page have been closed, since previously cached +// resources are updated in the background. + +// To learn more about the benefits of this model and instructions on how to +// opt-in, read https://bit.ly/CRA-PWA + +const isLocalhost = Boolean( + window.location.hostname === 'localhost' || + // [::1] is the IPv6 localhost address. + window.location.hostname === '[::1]' || + // 127.0.0.0/8 are considered localhost for IPv4. + window.location.hostname.match( + /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ + ) +); + +type Config = { + onSuccess?: (registration: ServiceWorkerRegistration) => void; + onUpdate?: (registration: ServiceWorkerRegistration) => void; +}; + +export function register(config?: Config) { + if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { + // The URL constructor is available in all browsers that support SW. + const publicUrl = new URL( + process.env.PUBLIC_URL, + window.location.href + ); + if (publicUrl.origin !== window.location.origin) { + // Our service worker won't work if PUBLIC_URL is on a different origin + // from what our page is served on. This might happen if a CDN is used to + // serve assets; see https://github.com/facebook/create-react-app/issues/2374 + return; + } + + window.addEventListener('load', () => { + const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; + + if (isLocalhost) { + // This is running on localhost. Let's check if a service worker still exists or not. + checkValidServiceWorker(swUrl, config); + + // Add some additional logging to localhost, pointing developers to the + // service worker/PWA documentation. + navigator.serviceWorker.ready.then(() => { + console.log( + 'This web app is being served cache-first by a service ' + + 'worker. To learn more, visit https://bit.ly/CRA-PWA' + ); + }); + } else { + // Is not localhost. Just register service worker + registerValidSW(swUrl, config); + } + }); + } +} + +function registerValidSW(swUrl: string, config?: Config) { + navigator.serviceWorker + .register(swUrl) + .then(registration => { + registration.onupdatefound = () => { + const installingWorker = registration.installing; + if (installingWorker == null) { + return; + } + installingWorker.onstatechange = () => { + if (installingWorker.state === 'installed') { + if (navigator.serviceWorker.controller) { + // At this point, the updated precached content has been fetched, + // but the previous service worker will still serve the older + // content until all client tabs are closed. + console.log( + 'New content is available and will be used when all ' + + 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' + ); + + // Execute callback + if (config && config.onUpdate) { + config.onUpdate(registration); + } + } else { + // At this point, everything has been precached. + // It's the perfect time to display a + // "Content is cached for offline use." message. + console.log('Content is cached for offline use.'); + + // Execute callback + if (config && config.onSuccess) { + config.onSuccess(registration); + } + } + } + }; + }; + }) + .catch(error => { + console.error('Error during service worker registration:', error); + }); +} + +function checkValidServiceWorker(swUrl: string, config?: Config) { + // Check if the service worker can be found. If it can't reload the page. + fetch(swUrl, { + headers: { 'Service-Worker': 'script' } + }) + .then(response => { + // Ensure service worker exists, and that we really are getting a JS file. + const contentType = response.headers.get('content-type'); + if ( + response.status === 404 || + (contentType != null && contentType.indexOf('javascript') === -1) + ) { + // No service worker found. Probably a different app. Reload the page. + navigator.serviceWorker.ready.then(registration => { + registration.unregister().then(() => { + window.location.reload(); + }); + }); + } else { + // Service worker found. Proceed as normal. + registerValidSW(swUrl, config); + } + }) + .catch(() => { + console.log( + 'No internet connection found. App is running in offline mode.' + ); + }); +} + +export function unregister() { + if ('serviceWorker' in navigator) { + navigator.serviceWorker.ready + .then(registration => { + registration.unregister(); + }) + .catch(error => { + console.error(error.message); + }); + } +} diff --git a/tools/discord-commentator/src/setupTests.ts b/tools/discord-commentator/src/setupTests.ts new file mode 100644 index 0000000..74b1a27 --- /dev/null +++ b/tools/discord-commentator/src/setupTests.ts @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom/extend-expect'; diff --git a/tools/discord-commentator/tsconfig.json b/tools/discord-commentator/tsconfig.json new file mode 100644 index 0000000..f2850b7 --- /dev/null +++ b/tools/discord-commentator/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react" + }, + "include": [ + "src" + ] +} diff --git a/tools/janken/src/App.css b/tools/janken/src/App.css index 55d25f2..a4cb1be 100644 --- a/tools/janken/src/App.css +++ b/tools/janken/src/App.css @@ -1,7 +1,7 @@ .App { height: 100vh; width: 100vw; - background-image: url('./straysheep.png') ; + background-image: url('https://static.catherine-fc.com/tool/straysheep.png') ; background-size: cover; background-repeat: none; } diff --git a/tools/janken/src/component/stage/Stage.module.scss b/tools/janken/src/component/stage/Stage.module.scss index 4f69ac7..1194d6b 100644 --- a/tools/janken/src/component/stage/Stage.module.scss +++ b/tools/janken/src/component/stage/Stage.module.scss @@ -42,35 +42,35 @@ } .cementery { - @include stageImage('../../static/img/01.png'); + @include stageImage('https://static.catherine-fc.com/tool/01.png'); } .prison { - @include stageImage('../../static/img/02.png'); + @include stageImage('https://static.catherine-fc.com/tool/02.png'); } .torture { - @include stageImage('../../static/img/03.png'); + @include stageImage('https://static.catherine-fc.com/tool/03.png'); } .inquisition { - @include stageImage('../../static/img/04.png'); + @include stageImage('https://static.catherine-fc.com/tool/04.png'); } .quadrangle { - @include stageImage('../../static/img/05.png'); + @include stageImage('https://static.catherine-fc.com/tool/05.png'); } .clock { - @include stageImage('../../static/img/06.png'); + @include stageImage('https://static.catherine-fc.com/tool/06.png'); } .spiral { - @include stageImage('../../static/img/07.png'); + @include stageImage('https://static.catherine-fc.com/tool/07.png'); } .cathedral { - @include stageImage('../../static/img/08.png'); + @include stageImage('https://static.catherine-fc.com/tool/08.png'); } .empireo { - @include stageImage('../../static/img/09.png'); + @include stageImage('https://static.catherine-fc.com/tool/09.png'); } .close { - @include stageImage('../../static/img/10.png'); + @include stageImage('https://static.catherine-fc.com/tool/10.png'); } .arrange { - @include stageImage('../../static/img/11.png'); + @include stageImage('https://static.catherine-fc.com/tool/11.png'); } \ No newline at end of file diff --git a/tools/janken/src/static/img/01.png b/tools/janken/src/static/img/01.png deleted file mode 100644 index 01a8150..0000000 Binary files a/tools/janken/src/static/img/01.png and /dev/null differ diff --git a/tools/janken/src/static/img/02.png b/tools/janken/src/static/img/02.png deleted file mode 100644 index 2a320de..0000000 Binary files a/tools/janken/src/static/img/02.png and /dev/null differ diff --git a/tools/janken/src/static/img/03.png b/tools/janken/src/static/img/03.png deleted file mode 100644 index a202d94..0000000 Binary files a/tools/janken/src/static/img/03.png and /dev/null differ diff --git a/tools/janken/src/static/img/04.png b/tools/janken/src/static/img/04.png deleted file mode 100644 index 86da740..0000000 Binary files a/tools/janken/src/static/img/04.png and /dev/null differ diff --git a/tools/janken/src/static/img/05.png b/tools/janken/src/static/img/05.png deleted file mode 100644 index af2d4fc..0000000 Binary files a/tools/janken/src/static/img/05.png and /dev/null differ diff --git a/tools/janken/src/static/img/06.png b/tools/janken/src/static/img/06.png deleted file mode 100644 index e0f9978..0000000 Binary files a/tools/janken/src/static/img/06.png and /dev/null differ diff --git a/tools/janken/src/static/img/07.png b/tools/janken/src/static/img/07.png deleted file mode 100644 index cef210d..0000000 Binary files a/tools/janken/src/static/img/07.png and /dev/null differ diff --git a/tools/janken/src/static/img/08.png b/tools/janken/src/static/img/08.png deleted file mode 100644 index d628550..0000000 Binary files a/tools/janken/src/static/img/08.png and /dev/null differ diff --git a/tools/janken/src/static/img/09.png b/tools/janken/src/static/img/09.png deleted file mode 100644 index fa0bfcb..0000000 Binary files a/tools/janken/src/static/img/09.png and /dev/null differ diff --git a/tools/janken/src/static/img/10.png b/tools/janken/src/static/img/10.png deleted file mode 100644 index b0aa55a..0000000 Binary files a/tools/janken/src/static/img/10.png and /dev/null differ diff --git a/tools/janken/src/static/img/11.png b/tools/janken/src/static/img/11.png deleted file mode 100644 index e09530e..0000000 Binary files a/tools/janken/src/static/img/11.png and /dev/null differ diff --git a/tools/janken/src/straysheep.png b/tools/janken/src/straysheep.png deleted file mode 100644 index ae2c22d..0000000 Binary files a/tools/janken/src/straysheep.png and /dev/null differ