Reorganize tsconfig.json files

According to:
https://github.com/RyanCavanaugh/learn-a
This commit is contained in:
Jerko Steiner 2019-01-18 22:42:18 +01:00
parent 7201cbcc34
commit 8fd2eafdca
23 changed files with 120 additions and 113 deletions

View File

@ -7,6 +7,6 @@
"react-redux": "^6.0.0",
"redux": "^4.0.1"
},
"main": "src/index.js",
"types": "src/index.d.ts"
"main": "lib/index.js",
"types": "lib/index.d.ts"
}

View File

@ -7,19 +7,18 @@ import {IRenderer} from './IRenderer'
export class ClientRenderer implements IRenderer {
constructor(
readonly createStore: IStoreFactory,
readonly Component: Component,
readonly RootComponent: typeof Component,
readonly target = document.body,
) {}
render() {
const state = (window as any).__PRELOADED_STATE__
const {Component} = this
render(state = (window as any).__PRELOADED_STATE__) {
const {RootComponent} = this
if (state) {
const store = this.createStore(state)
ReactDOM.hydrate(
<Provider store={store}>
<Component />
<RootComponent />
</Provider>,
this.target,
)
@ -27,11 +26,10 @@ export class ClientRenderer implements IRenderer {
const store = this.createStore()
ReactDOM.render(
<Provider store={store}>
<Component />
<RootComponent />
</Provider>,
this.target,
)
}
}
}

View File

@ -1,3 +1,3 @@
export interface IRenderer {
render(): any
render(state?: any): any
}

View File

@ -1,4 +1,4 @@
import {Store} from 'redux'
// TODO maybe Store should also be typed
export type IStoreFactory<T> = (state?: T) => Store
export type IStoreFactory = (state?: any) => Store

View File

@ -1,18 +1,22 @@
import React from 'react'
import {Component} from 'react'
import {IRenderer} from './IRenderer'
import {IStoreFactory} from './IStoreFactory'
import {Provider} from 'react-redux'
import {renderToNodeStream} from 'react-dom/server'
export class ServerRenderer implements IRenderer {
constructor(
readonly createStore: IStoreFactory,
readonly Component: Component,
readonly RootComponent: typeof Component,
) {}
render() {
const {Component} = this
render(state?: any) {
const {RootComponent} = this
const store = this.createStore(state)
const stream = renderToNodeStream(
<Provider store={store}>
<Component />
<RootComponent />
</Provider>,
)
return stream

View File

@ -1,19 +1,7 @@
{
"extends": "../tsconfig.common.json"
"compilerOptions": {
"lib": ["es2015", "dom"],
"target": "es3",
"moduleResolution": "node",
"jsx": "react",
"noImplicitAny": true,
"strict": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"plugins": [{
"name": "typescript-tslint-plugin",
"suppressWhileTypeErrorsPresent": true
}]
"outDir": "lib",
"rootDir": "src"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@rondo/common",
"private": true,
"main": "src/index.js",
"types": "src/index.d.ts"
"main": "lib/index.js",
"types": "lib/index.d.ts"
}

View File

@ -1,19 +1,7 @@
{
"extends": "../tsconfig.common.json",
"compilerOptions": {
"lib": ["es2015", "dom"],
"target": "es3",
"moduleResolution": "node",
"jsx": "react",
"noImplicitAny": true,
"strict": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"plugins": [{
"name": "typescript-tslint-plugin",
"suppressWhileTypeErrorsPresent": true
}]
"outDir": "lib",
"rootDir": "src"
}
}

View File

@ -34,6 +34,6 @@
"uuid": "^3.3.2",
"winston": "^3.1.0"
},
"main": "src/index.js",
"types": "src/index.d.ts"
"main": "lib/index.js",
"types": "lib/index.d.ts"
}

View File

@ -6,7 +6,7 @@ import {IApplication} from './IApplication'
import {IConfig} from './IConfig'
import {IDatabase} from '../database/IDatabase'
import {ILogger} from '../logger/ILogger'
import {IRoutes} from '../../common/REST'
import {IRoutes} from '@rondo/common'
import {ITransactionManager} from '../database/ITransactionManager'
import {IUserService, UserService} from '../services'
import {loggerFactory, LoggerFactory} from '../logger/LoggerFactory'

View File

@ -1,6 +1,6 @@
import express from 'express'
import {AsyncRouter} from '../router'
import {IRoutes} from '../../common/REST'
import {IRoutes} from '@rondo/common'
import {IDatabase} from '../database/IDatabase'
export interface IApplication {

View File

@ -1,4 +1,4 @@
import {IRoutes, IRoute, IMethod} from '../../common/REST'
import {IRoutes, IRoute, IMethod} from '@rondo/common'
import express, {NextFunction} from 'express'
export interface IRequest<T extends IRoute> extends express.Request {

View File

@ -1,6 +1,6 @@
import express from 'express'
import {AsyncRouter, IHandler} from './AsyncRouter'
import {IRoutes, IMethod} from '../../common/REST'
import {IRoutes, IMethod} from '@rondo/common'
import {ITransactionManager} from '../database/ITransactionManager'
export class TransactionalRouter<R extends IRoutes> extends AsyncRouter<R> {

View File

@ -1,8 +1,8 @@
import {IHandler} from '../middleware/IHandler'
import {AsyncRouter} from '../router'
import {IAPIDef} from '../../common/IAPIDef'
import {IRoutes} from '@rondo/common'
export abstract class BaseRoute<T extends IAPIDef> {
export abstract class BaseRoute<T extends IRoutes> {
readonly handle: IHandler
constructor(protected readonly t: AsyncRouter<T>) {

View File

@ -1,6 +1,6 @@
import {AsyncRouter} from '../router'
import {BaseRoute} from './BaseRoute'
import {IAPIDef} from '../../common/IAPIDef'
import {IAPIDef} from '@rondo/common'
import {IUserService} from '../services'
import {Authenticator} from '../middleware'

View File

@ -1,6 +1,6 @@
import {AsyncRouter} from '../router'
import {BaseRoute} from './BaseRoute'
import {IAPIDef} from '../../common/IAPIDef'
import {IAPIDef} from '@rondo/common'
import {IUserService} from '../services'
import {ensureLoggedInApi} from '../middleware'

View File

@ -1,45 +1,49 @@
import React from 'react'
import {CComponent} from '../../client/components/Component'
import {Provider} from 'react-redux'
// import React from 'react'
// import {CComponent} from '@rondo/client'
// import {Provider} from 'react-redux'
import {Router} from 'express'
import {createReadStream} from 'fs'
import {createStore} from '../../client/store'
import {join} from 'path'
import {renderToNodeStream} from 'react-dom/server'
// import {createReadStream} from 'fs'
// import {createStore} from '../../client/store'
// import {join} from 'path'
// import {renderToNodeStream} from 'react-dom/server'
export const application = Router()
application.get('/client.js', (req, res) => {
const stream = createReadStream(join(__dirname, '../build/client.js'))
stream.pipe(res)
})
// application.get('/client.js', (req, res) => {
// const stream = createReadStream(join(__dirname, '../build/client.js'))
// stream.pipe(res)
// })
application.get('/no-ssr', (req, res) => {
res.write('<!DOCTYPE html><html><head><title>My Page</title></head><body>')
res.write(`</body><script src='client.js'></script></html>`)
res.end()
})
// application.get('/no-ssr', (req, res) => {
// res.write('<!DOCTYPE html><html><head><title>My Page</title></head><body>')
// res.write(`</body><script src='client.js'></script></html>`)
// res.end()
// })
// application.get('/', (req, res) => {
// const store = createStore({
// csrfToken: req.csrfToken(),
// value: '1234',
// })
// const stream = renderToNodeStream(
// <Provider store={store}>
// <CComponent />
// </Provider>,
// )
// const state = store.getState()
// res.write('<!DOCTYPE html><html><head><title>My Page</title></head><body>')
// // TODO attach javascript
// stream.pipe(res, { end: false })
// stream.on('end', () => {
// res.write(`</body>
// <script>window.__PRELOADED_STATE__ = ${JSON.stringify(state)
// .replace( /</g, '\\u003c')}</script>
// <script src='client.js'></script>
// </html>`)
// res.end()
// })
// })
application.get('/', (req, res) => {
const store = createStore({
csrfToken: req.csrfToken(),
value: '1234',
})
const stream = renderToNodeStream(
<Provider store={store}>
<CComponent />
</Provider>,
)
const state = store.getState()
res.write('<!DOCTYPE html><html><head><title>My Page</title></head><body>')
// TODO attach javascript
stream.pipe(res, { end: false })
stream.on('end', () => {
res.write(`</body>
<script>window.__PRELOADED_STATE__ = ${JSON.stringify(state)
.replace( /</g, '\\u003c')}</script>
<script src='client.js'></script>
</html>`)
res.end()
})
res.json({csrfToken: req.csrfToken})
})

View File

@ -1,5 +1,5 @@
import supertest from 'supertest'
import {IMethod, IRoutes} from '../../common/REST'
import {IMethod, IRoutes} from '@rondo/common'
// https://stackoverflow.com/questions/48215950/exclude-property-from-type
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>

View File

@ -4,7 +4,7 @@ import {Connection, QueryRunner} from 'typeorm'
import {
ENTITY_MANAGER, ITransactionManager,
} from '../database/ITransactionManager'
import {IRoutes} from '../../common/REST'
import {IRoutes} from '@rondo/common'
import {IBootstrap} from '../application/IBootstrap'
import {RequestTester} from './RequestTester'

View File

@ -1,5 +1,5 @@
import {Bootstrap} from './application/Bootstrap'
import {IAPIDef} from '../common/IAPIDef'
import {IAPIDef} from '@rondo/common'
import {NamespaceMock, TestUtils} from './test-utils'
import {config} from './config'

View File

@ -1,19 +1,11 @@
{
"extends": "../tsconfig.common.json",
"compilerOptions": {
"lib": ["es2015", "dom"],
"target": "es3",
"moduleResolution": "node",
"jsx": "react",
"noImplicitAny": true,
"strict": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"plugins": [{
"name": "typescript-tslint-plugin",
"suppressWhileTypeErrorsPresent": true
}]
}
"outDir": "lib",
"rootDir": "src"
},
"references": [
{"path": "../client"},
{"path": "../common"}
]
}

View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
// following settings required for referenced projects
"composite": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"lib": ["es2015", "dom"],
"target": "es3",
"moduleResolution": "node",
"jsx": "react",
"noImplicitAny": true,
"strict": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"plugins": [{
"name": "typescript-tslint-plugin",
"suppressWhileTypeErrorsPresent": true
}]
}
}

8
packages/tsconfig.json Normal file
View File

@ -0,0 +1,8 @@
{
"files": [],
"references": [
{"path": "client"},
{"path": "common"},
{"path": "server"}
]
}