Skip to content
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

storyshotsの導入 #398

Merged
merged 37 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2a399c4
npx -p @storybook/cli sb init --type react
kobakazu0429 Sep 22, 2019
e0f83bb
add @types/storybook__react
kobakazu0429 Sep 22, 2019
e3357a3
add webpack.config
kobakazu0429 Sep 22, 2019
0099fbe
using tsx
kobakazu0429 Sep 22, 2019
89c0319
comment: @storybook/source-loader
kobakazu0429 Sep 22, 2019
3fe7699
add stories
kobakazu0429 Sep 22, 2019
09c954b
storyshots
kobakazu0429 Sep 22, 2019
88fcc03
fix webpack config
kobakazu0429 Sep 22, 2019
ee040fd
add yarn commands
kobakazu0429 Sep 22, 2019
cf0dce8
fix name .spec. -> .test.
kobakazu0429 Sep 22, 2019
777b59d
update heroarea
kobakazu0429 Sep 22, 2019
ba500bf
update
kobakazu0429 Sep 22, 2019
eddf0be
update README
kobakazu0429 Sep 23, 2019
ef1274f
fix lint command
kobakazu0429 Sep 26, 2019
9eb2e8b
fix Personality API response type
kobakazu0429 Sep 26, 2019
ec04676
create chkDecorator
kobakazu0429 Sep 26, 2019
d4d7739
add declare mp3 type
kobakazu0429 Sep 26, 2019
cd54148
add mock data
kobakazu0429 Sep 26, 2019
858edfe
add RadioCard story
kobakazu0429 Sep 26, 2019
479783b
add @storybook/addon-storyshots-puppeteer
kobakazu0429 Sep 27, 2019
b62a857
Merge branch 'feature/react' into react/storyshots
kobakazu0429 Sep 27, 2019
28fc67a
update
kobakazu0429 Sep 27, 2019
1f8876a
fix
kobakazu0429 Sep 27, 2019
035c64d
use build file for frontend test with circleci
kobakazu0429 Oct 1, 2019
a501486
to circleci/node:12.8.1-browsers
kobakazu0429 Oct 1, 2019
e31a499
add command
kobakazu0429 Oct 1, 2019
497e9b7
update
kobakazu0429 Oct 1, 2019
56478b8
add NotoSans JP
kobakazu0429 Oct 2, 2019
4068a5c
update snapushots
kobakazu0429 Oct 2, 2019
d80d1b4
change to NotoSansJP local
kobakazu0429 Oct 2, 2019
8647939
update snapushots
kobakazu0429 Oct 2, 2019
6a27650
add effectedHeroImage
kobakazu0429 Oct 2, 2019
25bf9fa
wip
kobakazu0429 Oct 2, 2019
8cf00ac
add
kobakazu0429 Oct 4, 2019
2f46c96
fix
kobakazu0429 Oct 4, 2019
81f3ae2
fix
kobakazu0429 Oct 4, 2019
1f1070d
update circleci
kobakazu0429 Oct 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ jobs:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}

# Frontend setup
- run:
name: build frontend
working_directory: frontend
command: |
yarn install
yarn build

# Database setup
- run: mv config/database.yml.ci config/database.yml
- run: bundle exec rake db:create db:schema:load RAILS_ENV=test --trace
Expand All @@ -70,6 +62,23 @@ jobs:
path: /tmp/test-results
destination: test-results

frontend-build:
working_directory: ~/repo
docker:
- image: circleci/node:12.8.1
steps:
- checkout
- run:
name: Install test dependencies
command: |
cd frontend
yarn install --frozen-lockfile --prefer-offline
- run:
name: yarn test
command: |
cd frontend
yarn build

frontend-test:
working_directory: ~/repo
docker:
Expand All @@ -80,7 +89,12 @@ jobs:
name: Install test dependencies
command: |
cd frontend
yarn --frozen-lockfile --prefer-offline
yarn install --frozen-lockfile --prefer-offline
- run:
name: yarn storybook:build
command: |
cd frontend
yarn storybook:build
- run:
name: yarn test
command: |
Expand All @@ -92,4 +106,5 @@ workflows:
main:
jobs:
- build
- frontend-build
- frontend-test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@

/frontend/node_modules/*
/frontend/yarn-error.log

/frontend/storybook-static/
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![CircleCI](https://circleci.com/gh/kure-kosen/cho_kure_web/tree/feature%2Fdev.svg?style=svg)](https://circleci.com/gh/kure-kosen/cho_kure_web/tree/feature%2Fdev)
[![Maintainability](https://api.codeclimate.com/v1/badges/cef3c1298621fa26dd1c/maintainability)](https://codeclimate.com/github/kure-kosen/cho_kure_web/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/cef3c1298621fa26dd1c/test_coverage)](https://codeclimate.com/github/kure-kosen/cho_kure_web/test_coverage)
[![Netlify Status](https://api.netlify.com/api/v1/badges/52294771-4cc8-449a-9d67-3016d98b03b0/deploy-status)](https://app.netlify.com/sites/cho-kure-web-storybook/deploys)

## Ruby version

Expand Down Expand Up @@ -45,6 +46,28 @@ $ docker-compose run backend bin/rails db:create db:schema:load db:seed_fu

refer to [/frontend/README.md](/frontend/README.md)

## CircleCI

[CircleCI Local CLI](https://circleci.com/docs/2.0/local-cli/#quick-installation)

```bash
... installed CircleCI Local CLI
$ circleci local execute --job build
$ circleci local execute --job frontend-build
$ circleci local execute --job frontend-test
```

## SSL

```bash
... in production server
certbot-auto certificates
certbot-auto renew
# certbot-auto renew --dry-run
# certbot-auto renew --force-renew
service nginx restart
```

## その他

- 開発中にアプリケーションが送信したメールは `/letter_opener` で確認できます。
Expand Down
7 changes: 1 addition & 6 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
module ApplicationHelper
def webpack_javascript_include_tag(path)
path = "#{path}.js" unless path.ends_with?(".js")
path = if ENV["USE_WEBPACK_DEV_SERVER"].to_b
"http://localhost:5000/#{path}"
else
"/assets/build/#{find_hash_name(path)}"
end

path = ENV["USE_WEBPACK_DEV_SERVER"].to_b ? "http://localhost:5000/#{path}" : "/assets/build/#{find_hash_name(path)}"
javascript_include_tag(path)
end

Expand Down
22 changes: 12 additions & 10 deletions config/initializers/assets_manifest.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Rails.application.config.assets_manifest =
if File.exist?(Rails.root.join("public", "assets", "build", "manifest.json"))
JSON.parse(File.read(Rails.root.join("public", "assets", "build", "manifest.json")))
else
unless ENV["USE_WEBPACK_DEV_SERVER"].to_b
raise "\n
+--------------------------------------------------+
| public/assets/build/manifest.jsonが存在しません. |
| $ yarn build を実行してください. |
+--------------------------------------------------+
"
unless Rails.env.test?
if File.exist?(Rails.root.join("public", "assets", "build", "manifest.json"))
JSON.parse(File.read(Rails.root.join("public", "assets", "build", "manifest.json")))
else
unless ENV["USE_WEBPACK_DEV_SERVER"].to_b
raise "\n
+--------------------------------------------------+
| public/assets/build/manifest.jsonが存在しません. |
| $ yarn build を実行してください. |
+--------------------------------------------------+
"
end
end
end
19 changes: 19 additions & 0 deletions frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-typescript",
"@babel/preset-react"
],
"env": {
"test": {
"plugins": ["require-context-hook"]
}
}
}
1 change: 1 addition & 0 deletions frontend/.jest/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = '';
2 changes: 2 additions & 0 deletions frontend/.jest/register-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import registerRequireContextHook from "babel-plugin-require-context-hook/register";
registerRequireContextHook();
2 changes: 2 additions & 0 deletions frontend/.storybook/addons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@storybook/addon-actions/register';
import '@storybook/addon-links/register';
21 changes: 21 additions & 0 deletions frontend/.storybook/chkDecorator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import "normalize.css";

import React from "react";
import { BrowserRouter } from "react-router-dom";
import { makeDecorator } from "@storybook/addons";
import GlobalStyle from "../src/constants/styles/global";

export const chkDecorator = makeDecorator({
name: "withSomething",
parameterName: "something",
wrapper: (storyFn, context) => {
return (
<BrowserRouter>
<>
{storyFn(context)}
<GlobalStyle />
</>
</BrowserRouter>
);
}
});
8 changes: 8 additions & 0 deletions frontend/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {configure, addDecorator} from '@storybook/react';

import { chkDecorator } from "./chkDecorator";

// automatically import all files ending in *.stories.tsx
configure(require.context('../stories', true, /\.stories\.tsx$/), module);

addDecorator(chkDecorator);
1 change: 1 addition & 0 deletions frontend/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
29 changes: 29 additions & 0 deletions frontend/.storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

const path = require('path');

module.exports = ({config}) => {
config.module.rules.push(
{
test: /\.(ts|tsx)?$/,
loader: require.resolve('ts-loader'),
exclude: /node_modules/,
options: {transpileOnly: true}
},
{
test: /\.(ts|tsx)?$/,
loader: require.resolve('react-docgen-typescript-loader'),
exclude: /node_modules/
});
// {
// test: /\.stories\.tsx?$/,
// loader: require.resolve('@storybook/source-loader'),
// options: { injectParameters: true },
// enforce: 'pre',
// }

config.resolve.extensions.push('.js', '.ts', '.tsx');
config.resolve.alias = {'@': path.resolve(__dirname, '../src')};

return config;
};
14 changes: 10 additions & 4 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
[![CircleCI](https://circleci.com/gh/kure-kosen/cho_kure_web/tree/feature%2Fdev.svg?style=svg)](https://circleci.com/gh/kure-kosen/cho_kure_web/tree/feature%2Fdev)
[![Maintainability](https://api.codeclimate.com/v1/badges/cef3c1298621fa26dd1c/maintainability)](https://codeclimate.com/github/kure-kosen/cho_kure_web/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/cef3c1298621fa26dd1c/test_coverage)](https://codeclimate.com/github/kure-kosen/cho_kure_web/test_coverage)
[![Netlify Status](https://api.netlify.com/api/v1/badges/52294771-4cc8-449a-9d67-3016d98b03b0/deploy-status)](https://app.netlify.com/sites/cho-kure-web-storybook/deploys)

## How to Dev

```bash
$ yarn install

# Commands
$ yarn start # Start webpack-dev-server, open http://localhost:3000/app
$ yarn dev # same as $ yarn start
$ yarn build # Build to /public/assets/build/
$ yarn lint # Check type and syntax, auto fix
$ yarn start # Start webpack-dev-server, open http://localhost:3000/app
$ yarn dev # same as $ yarn start
$ yarn build # Build to /public/assets/build/
$ yarn lint # Check type and syntax, auto fix
$ yarn test # Test
$ yarn test:console # Test with console.log
$ yarn test:clean # Clear cache
$ yarn storybook # Start storybook
$ yarn storybook:build # Build to /frontend/storybook-static/
```
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 7 additions & 9 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module.exports = {
verbose: true,
transform: {
".*\\.(ts|tsx)$": "./node_modules/ts-jest"
},
setupFiles: ["<rootDir>/.jest/register-context.ts"],
testMatch: ["**/*.test.(ts|tsx)"],
moduleNameMapper: {
"^@/(.*)$": '<rootDir>/src/$1',
},
testMatch: [
"**/*.spec.(ts|tsx)"
],
moduleFileExtensions: ["js", "ts", "tsx"]
"^@/(.*)$": "<rootDir>/src/$1",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/.jest/fileMock.js",
"\\.(css|less|scss|sss|styl)$": "<rootDir>/node_modules/jest-css-modules"
}
};
37 changes: 30 additions & 7 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
"build": "webpack --color --progress --config ./config/webpack.config.prod.js",
"dev": "webpack-dev-server --config ./config/webpack.config.dev.js",
"start": "yarn dev",
"lint": "tslint --fix -c ./tslint.json 'src/**/*{.ts,.tsx}'",
"test": "jest --colors"
"lint": "tslint --fix -c ./tslint.json '@(src|stories)/**/*.{ts,tsx}'",
"test": "jest --colors",
"test:update": "yarn test -u",
"test:console": "yarn test --silent=false --verbose false",
"test:clean": "jest --clearCache",
"storybook": "start-storybook -p 6006",
"storybook:build": "build-storybook"
},
"lint-staged": {
"*.{js,ts,tsx}": [
Expand All @@ -20,23 +25,41 @@
]
},
"devDependencies": {
"@types/jest": "^24.0.17",
"@babel/core": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.6.0",
"@storybook/addon-actions": "^5.2.1",
"@storybook/addon-links": "^5.2.1",
"@storybook/addon-storyshots": "^5.2.1",
"@storybook/addon-storyshots-puppeteer": "^5.2.1",
"@storybook/addon-viewport": "^5.2.1",
"@storybook/addons": "^5.2.1",
"@storybook/react": "^5.2.1",
"@types/jest": "^24.0.18",
"@types/react": "^16.8.17",
"@types/react-dom": "^16.8.4",
"@types/react-router-dom": "^4.3.3",
"@types/react-slick": "^0.23.4",
"@types/storybook__addon-storyshots-puppeteer": "^5.1.0",
"@types/styled-components": "^4.1.15",
"babel-jest": "^24.9.0",
"babel-loader": "^8.0.6",
"babel-plugin-require-context-hook": "^1.0.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^5.0.3",
"css-loader": "^2.1.1",
"file-loader": "^3.0.1",
"fork-ts-checker-webpack-plugin": "^1.2.0",
"html-webpack-plugin": "^3.2.0",
"jest": "^24.9.0",
"jest-css-modules": "^2.1.0",
"prettier": "^1.17.0",
"react-docgen-typescript-loader": "^3.2.1",
"react-test-renderer": "^16.9.0",
"style-loader": "^0.23.1",
"ts-jest": "^24.0.2",
"ts-loader": "^6.0.2",
"ts-loader": "6.1.2",
"tslint": "^5.16.0",
"tslint-config-prettier": "^1.18.0",
"tslint-loader": "^3.5.4",
Expand All @@ -54,8 +77,8 @@
"mobx": "^5.9.4",
"mobx-react-lite": "^1.3.2",
"normalize.css": "^8.0.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-router-dom": "^5.0.0",
"react-slick": "^0.24.0",
"react-twitter-widgets": "^1.7.1",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/PersonalityApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface IPersonality {
description: string;
image: string;
tag_list: string[];
radios: Exclude<IRadio, "personalities">;
radios?: Exclude<IRadio, "personalities">;
}

export default class PersonalityApi {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading