Skip to content

Commit

Permalink
TS Server
Browse files Browse the repository at this point in the history
  • Loading branch information
marudor committed Apr 14, 2019
1 parent e25782a commit 137738e
Show file tree
Hide file tree
Showing 74 changed files with 2,046 additions and 435 deletions.
3 changes: 2 additions & 1 deletion .babelrc.js
@@ -1,4 +1,4 @@
const TestConfig = require('./.babelrc.server.js');
const { overrides, ...TestConfig } = require('./.babelrc.server.js');

module.exports = {
presets: [
Expand Down Expand Up @@ -31,4 +31,5 @@ module.exports = {
},
test: TestConfig,
},
overrides,
};
22 changes: 22 additions & 0 deletions .babelrc.server.js
Expand Up @@ -23,6 +23,7 @@ module.exports = {
'module-resolver',
{
root: 'src',
extensions: ['.js', '.jsx', '.ts', '.tsx'],
resolvePath: (sourcePath, currentFile, opts) => {
const path = require('babel-plugin-module-resolver').resolvePath(
sourcePath.replace(/^(Abfahrten|Common|Routing)\//, 'client/$1/'),
Expand All @@ -42,4 +43,25 @@ module.exports = {
},
],
],
overrides: [
{
test: ['**/*.ts'],
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
targets: {
node: '10',
},
loose: false,
useBuiltIns: 'entry',
modules: 'commonjs',
corejs: 3,
},
],
'babel-preset-joblift',
],
},
],
};
21 changes: 20 additions & 1 deletion .eslintrc.js
@@ -1,5 +1,10 @@
module.exports = {
extends: ['joblift/base', 'joblift/react', 'joblift/flowtype'],
extends: [
'joblift/base',
'joblift/react',
'joblift/sort-imports',
'joblift/flowtype',
],
parser: 'babel-eslint',
env: {
browser: true,
Expand All @@ -18,4 +23,18 @@ module.exports = {
settings: {
'import/resolver': 'webpack',
},
overrides: [
{
rules: {
'no-unused-vars': 0,
},
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
project: './tsconfig.json',
tsconfigRootDir: './',
},
},
],
};
2 changes: 2 additions & 0 deletions .flowconfig
Expand Up @@ -28,6 +28,8 @@ module.system.node.resolve_dirname=./src
module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.ts
module.file_ext=.tsx
module.system=haste

include_warnings=true
Expand Down
10 changes: 10 additions & 0 deletions .gitlab-ci.yml
Expand Up @@ -66,6 +66,16 @@ flow:
paths:
- node_modules/

tsc:
image: node:10
stage: test
script: yarn tsc
cache:
policy: pull
key: '$CI_COMMIT_REF_SLUG'
paths:
- node_modules/

build:app:
stage: build
variables:
Expand Down
28 changes: 28 additions & 0 deletions @types/db-stations.d.ts
@@ -0,0 +1,28 @@
declare module 'db-stations/data.json' {
export type OpenDataStation = {
type: 'station';
id: string;
ds100: string;
nr: number;
name: string;
weight: number;
location: {
type: 'location';
latitude: number;
longitude: number;
};
operator: {
type: 'operator';
id: string;
name: string;
};
address: {
city: string;
zipcode: string;
street: string;
};
};

declare const stations: OpenDataStation[];
export default stations;
}
1 change: 1 addition & 0 deletions @types/flowMigration.d.ts
@@ -0,0 +1 @@
type $Values<O extends object> = O[keyof O];
22 changes: 22 additions & 0 deletions @types/global.d.ts
@@ -0,0 +1,22 @@
namespace NodeJS {
interface Global {
PROD: boolean;
SERVER: boolean;
}
}

type Features = {
'google-analytics': boolean;
routing: boolean;
};

type StationSearchType =
| 'dbNav'
| 'openData'
| 'openDataOffline'
| 'openDB'
| 'hafas'
| 'favOpenDB'
| 'stationsData'
| 'favendo'
| '';
6 changes: 6 additions & 0 deletions @types/react-router.d.ts
@@ -0,0 +1,6 @@
declare module 'react-router' {
interface StaticRouterContext {
url?: string;
status?: number;
}
}
7 changes: 7 additions & 0 deletions @types/universal-cookie-koa.d.ts
@@ -0,0 +1,7 @@
import Cookies from 'universal-cookie';

declare module 'koa' {
interface Request {
universalCookies: Cookies;
}
}
10 changes: 10 additions & 0 deletions devIndex.js
@@ -0,0 +1,10 @@
if (process.env.NODE_ENV !== 'production') {
const config = require('./.babelrc.server');

require('@babel/register')({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
...config,
});
}

require('./src/server/index.ts');
74 changes: 67 additions & 7 deletions package.json
Expand Up @@ -10,18 +10,19 @@
"scripts": {
"build:client:perf": "npm run cleanup && NODE_ENV=production webpack --profile --json > ./webpack-stats.json && webpack-bundle-analyzer ./webpack-stats.json dist/client/static --mode static -s gzip --report ./BundleReport.html --no-open",
"build:client": "node scripts/buildClient",
"build:server": "babel src --no-babelrc --config-file ./.babelrc.server.js --out-dir dist/server --copy-files",
"build:server": "babel src -x '.ts,.tsx,.js,.jsx' --no-babelrc --config-file ./.babelrc.server.js --out-dir dist/server --copy-files",
"build": "npm run cleanup && npm run build:client && npm run build:server",
"cleanup": "rimraf dist && mkdir dist",
"dev:server:test": "npm run start:server:test",
"dev:server": "npm run start:server",
"dev:test": "npm run dev:server:test",
"dev": "npm run dev:server",
"lint": "eslint --ext .js,.jsx src",
"lint": "eslint --ext .js,.jsx,.ts,.tsx src test scripts",
"start:server:test": "TESTDATA=1 npm run start:server",
"start:server": "node --inspect src/server/index.js",
"start:server": "node --inspect devIndex.js",
"flow": "flow check",
"test": "npm run lint && npm run test:server && npm run test:client && flow",
"tsc": "tsc",
"test": "npm run lint && npm run test:server && npm run test:client && tsc && flow",
"test:codecov": "codecov",
"test:client": "jest --config test/client/jest.config.js",
"test:server": "TZ=Europe/Berlin jest --config test/server/jest.config.js"
Expand All @@ -43,7 +44,66 @@
"@babel/preset-env": "^7.4.3",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@babel/register": "^7.4.0",
"@types/axios": "^0.14.0",
"@types/babel-core": "^6.25.6",
"@types/bunyan": "^1.8.6",
"@types/bunyan-format": "^0.2.0",
"@types/cheerio": "^0.22.11",
"@types/chokidar": "^2.1.3",
"@types/compression-webpack-plugin": "^2.0.0",
"@types/core-js": "^2.5.0",
"@types/create-react-class": "^15.6.2",
"@types/date-fns": "^2.6.0",
"@types/debounce-promise": "^3.1.1",
"@types/diff": "^4.0.2",
"@types/ejs": "^2.6.3",
"@types/eslint": "^4.16.6",
"@types/eslint-plugin-prettier": "^2.2.0",
"@types/iconv-lite": "^0.0.1",
"@types/iltorb": "^2.3.0",
"@types/jest": "^24.0.11",
"@types/jss": "^9.5.8",
"@types/koa": "^2.0.48",
"@types/koa-bodyparser": "^4.2.2",
"@types/koa-bunyan-logger": "^2.1.0",
"@types/koa-router": "^7.0.40",
"@types/koa-static": "^4.0.1",
"@types/koa-webpack": "^5.0.1",
"@types/lodash": "^4.14.123",
"@types/lolex": "^3.1.1",
"@types/mini-css-extract-plugin": "^0.2.0",
"@types/nock": "^9.3.1",
"@types/node-cache": "^4.1.3",
"@types/node-sass": "^4.11.0",
"@types/optimize-css-assets-webpack-plugin": "^1.3.4",
"@types/prettier": "^1.16.1",
"@types/qs": "^6.5.3",
"@types/react": "^16.8.13",
"@types/react-dom": "^16.8.4",
"@types/react-helmet-async": "^1.0.0",
"@types/react-jss": "^8.6.3",
"@types/react-redux": "^7.0.6",
"@types/react-router": "^4.4.5",
"@types/react-router-config": "^1.1.2",
"@types/react-router-dom": "^4.3.2",
"@types/react-select": "^2.0.16",
"@types/redux": "^3.6.0",
"@types/redux-actions": "^2.6.0",
"@types/redux-thunk": "^2.1.0",
"@types/reselect": "^2.2.0",
"@types/rimraf": "^2.0.2",
"@types/serialize-javascript": "^1.5.0",
"@types/stylelint": "^9.10.0",
"@types/supertest": "^2.0.7",
"@types/terser-webpack-plugin": "^1.2.1",
"@types/typescript": "^2.0.0",
"@types/universal-cookie": "^2.2.0",
"@types/uuid": "^3.4.4",
"@types/webpack": "^4.4.27",
"@types/webpack-bundle-analyzer": "^2.13.1",
"@typescript-eslint/parser": "^1.6.0",
"autoprefixer": "^9.5.1",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
Expand All @@ -53,7 +113,6 @@
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-module-resolver": "^3.2.0",
"babel-plugin-remove-webpack": "^1.1.0",
"babel-plugin-stateless-func-to-pure": "^0.0.2",
"babel-plugin-transform-require-ignore": "^0.1.1",
"babel-preset-joblift": "^3.3.2",
"cache-loader": "^2.0.1",
Expand All @@ -62,13 +121,13 @@
"compression-webpack-plugin": "^2.0.0",
"css-loader": "^2.1.1",
"eslint": "^5.16.0",
"eslint-config-joblift": "^3.3.2",
"eslint-config-joblift": "^3.3.4",
"eslint-config-prettier": "^4.1.0",
"eslint-import-resolver-webpack": "^0.11.1",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-flowtype": "^3.6.1",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "^2.17.0",
"eslint-plugin-import": "^2.17.1",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
Expand Down Expand Up @@ -96,6 +155,7 @@
"stylelint-config-standard": "^18.2.0",
"supertest": "^4.0.2",
"terser-webpack-plugin": "^1.2.3",
"typescript": "^3.4.3",
"url-loader": "^1.1.2",
"webpack": "^4.30.0",
"webpack-bundle-analyzer": "^3.3.2",
Expand Down
24 changes: 13 additions & 11 deletions scripts/generateMostSearched.js
Expand Up @@ -24,14 +24,16 @@ const mostUsedNames = [
'Berlin-Spandau',
].map(n => n.toLowerCase());

Promise.all(mostUsedNames.map(s => search(s).then(s => s[0]))).then(stations => {
// eslint-disable-next-line no-console
console.log(
JSON.stringify(
stations.map(s => ({
title: s.title,
id: s.id,
}))
)
);
});
Promise.all(mostUsedNames.map(s => search(s).then(s => s[0]))).then(
stations => {
// eslint-disable-next-line no-console
console.log(
JSON.stringify(
stations.map(s => ({
title: s.title,
id: s.id,
}))
)
);
}
);
2 changes: 1 addition & 1 deletion src/client/Abfahrten/reducer/abfahrten.js
Expand Up @@ -34,7 +34,7 @@ export type State = {
};

const defaultState = {
selectedDetail: localStorage.getItem('selectedDetail'),
selectedDetail: null,
abfahrten: null,
wings: null,
currentStation: null,
Expand Down

0 comments on commit 137738e

Please sign in to comment.