mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 18:29:08 +00:00
add stylelint
This commit is contained in:
parent
47a2e5694e
commit
928c9cf07c
83 changed files with 10807 additions and 1770 deletions
15
packages/roleypoly-server/.babelrc
Normal file
15
packages/roleypoly-server/.babelrc
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"presets": [ ["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": true
|
||||
}
|
||||
}], "@babel/preset-flow" ],
|
||||
"plugins": [
|
||||
"@babel/plugin-syntax-dynamic-import",
|
||||
"@babel/plugin-proposal-class-properties",
|
||||
"@babel/plugin-proposal-optional-chaining",
|
||||
["@babel/plugin-transform-runtime",
|
||||
{ "helpers": false }]
|
||||
],
|
||||
"ignore": ["ui/**/*"]
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
// @flow
|
||||
import Sequelize from 'sequelize'
|
||||
import Next from 'next'
|
||||
import connector from '@roleypoly/ui/connector'
|
||||
import type Next from 'next'
|
||||
import betterRouter from 'koa-better-router'
|
||||
import type EventEmitter from 'events'
|
||||
import fs from 'fs'
|
||||
import logger from './logger'
|
||||
import ServerService from './services/server'
|
||||
import DiscordService from './services/discord'
|
||||
|
@ -16,7 +16,6 @@ import fetchApis from './api'
|
|||
|
||||
import type SocketIO from 'socket.io'
|
||||
import type KoaApp, { Context } from 'koa'
|
||||
|
||||
const log = logger(__filename)
|
||||
|
||||
type HTTPHandler = (path: string, handler: (ctx: Context, next: () => void) => any) => void
|
||||
|
@ -73,12 +72,8 @@ class Roleypoly {
|
|||
const dev = process.env.NODE_ENV !== 'production'
|
||||
|
||||
// simple check if we're in a compiled situation or not.
|
||||
let uiDir = './ui'
|
||||
if (!fs.existsSync(uiDir) && fs.existsSync('../ui')) {
|
||||
uiDir = '../ui'
|
||||
}
|
||||
|
||||
const ui = Next({ dev, dir: uiDir })
|
||||
const ui = connector({ dev })
|
||||
const uiHandler = ui.getRequestHandler()
|
||||
|
||||
const appUrl = process.env.APP_URL
|
||||
|
|
|
@ -3,13 +3,11 @@ import 'dotenv/config'
|
|||
import logger from './logger'
|
||||
import http from 'http'
|
||||
import Koa from 'koa'
|
||||
import SocketIO from 'socket.io'
|
||||
import Roleypoly from './Roleypoly'
|
||||
import ksuid from 'ksuid'
|
||||
import bodyParser from 'koa-bodyparser'
|
||||
import compress from 'kompression'
|
||||
import session from 'koa-session'
|
||||
import invariant from 'invariant'
|
||||
import Keygrip from 'keygrip'
|
||||
|
||||
const log = logger(__filename)
|
||||
|
@ -17,13 +15,12 @@ const app = new Koa()
|
|||
|
||||
// Create the server and socket.io server
|
||||
const server = http.createServer(app.callback())
|
||||
const io = SocketIO(server, { transports: ['websocket'], path: '/api/socket.io' })
|
||||
|
||||
const M = new Roleypoly(io, app) // eslint-disable-line no-unused-vars
|
||||
const M = new Roleypoly(null, app) // eslint-disable-line no-unused-vars
|
||||
|
||||
const appKey = process.env.APP_KEY
|
||||
if (appKey == null) {
|
||||
throw invariant(false, '')
|
||||
if (appKey == null || appKey === '') {
|
||||
throw new Error('APP_KEY not set')
|
||||
}
|
||||
app.keys = new Keygrip([ appKey ])
|
||||
|
||||
|
|
62
packages/roleypoly-server/package.json
Normal file
62
packages/roleypoly-server/package.json
Normal file
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
"name": "@roleypoly/server",
|
||||
"private": true,
|
||||
"version": "2.0.0",
|
||||
"scripts": {
|
||||
"dev": "babel-node index.js",
|
||||
"start": "NODE_ENV=production node dist/index.js",
|
||||
"pretest": "standard --fix",
|
||||
"build": "NODE_ENV=production babel --delete-dir-on-start -d dist ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordjs/uws": "^11.149.1",
|
||||
"@roleypoly/types": "^2.0.0",
|
||||
"@roleypoly/ui": "^2.0.0",
|
||||
"bufferutil": "^4.0.1",
|
||||
"chalk": "^2.4.2",
|
||||
"dotenv": "^7.0.0",
|
||||
"eris": "^0.9.0",
|
||||
"erlpack": "discordapp/erlpack",
|
||||
"eventemitter3": "^3.1.0",
|
||||
"fnv-plus": "^1.2.12",
|
||||
"glob": "^7.1.3",
|
||||
"immutable": "^4.0.0-rc.12",
|
||||
"keygrip": "^1.0.3",
|
||||
"koa": "^2.7.0",
|
||||
"koa-better-router": "^2.1.1",
|
||||
"koa-bodyparser": "^4.2.1",
|
||||
"koa-session": "^5.10.1",
|
||||
"kompression": "^1.0.0",
|
||||
"ksuid": "^1.2.0",
|
||||
"lru-cache": "^5.1.1",
|
||||
"moment": "^2.24.0",
|
||||
"moniker": "^0.1.2",
|
||||
"nanoid": "^2.0.1",
|
||||
"pg": "^7.9.0",
|
||||
"pg-hstore": "^2.3.2",
|
||||
"sequelize": "^5.2.10",
|
||||
"superagent": "^5.0.2",
|
||||
"zlib-sync": "^0.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.4.3",
|
||||
"@babel/core": "^7.4.3",
|
||||
"@babel/node": "^7.2.2",
|
||||
"@babel/plugin-proposal-class-properties": "^7.4.0",
|
||||
"@babel/plugin-proposal-optional-chaining": "^7.2.0",
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
|
||||
"@babel/plugin-transform-runtime": "^7.4.3",
|
||||
"@babel/preset-env": "^7.4.3",
|
||||
"@babel/preset-flow": "^7.0.0",
|
||||
"await-outside": "^2.1.2",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"babel-plugin-transform-flow-strip-types": "^6.22.0",
|
||||
"chokidar": "^2.1.5",
|
||||
"eslint-plugin-flowtype": "^3.4.2",
|
||||
"flow-bin": "^0.96.0",
|
||||
"flow-typed": "^2.5.1",
|
||||
"jest": "^24.6.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"standard": "12.0.1"
|
||||
}
|
||||
}
|
8
packages/roleypoly-server/util/areduce.js
Normal file
8
packages/roleypoly-server/util/areduce.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
// @flow
|
||||
export default async function<T, V> (array: Array<T>, predicate: (Array<V>, T) => Promise<Array<V>>, acc: Array<V>): Promise<Array<V>> {
|
||||
for (let i of array) {
|
||||
acc = await predicate(acc, i)
|
||||
}
|
||||
|
||||
return acc
|
||||
}
|
4
packages/roleypoly-server/util/error.js
Normal file
4
packages/roleypoly-server/util/error.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export default ($, ctx) => {
|
||||
ctx.res.statusCode = ctx.status
|
||||
return $.ui.renderError(null, ctx.req, ctx.res, '/_error', {})
|
||||
}
|
10
packages/roleypoly-server/util/model-methods.js
Normal file
10
packages/roleypoly-server/util/model-methods.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
const ksuid = require('ksuid')
|
||||
|
||||
module.exports = {
|
||||
ksuid (field = 'id') {
|
||||
return async function () {
|
||||
this.id = await ksuid.random()
|
||||
return this
|
||||
}
|
||||
}
|
||||
}
|
81
packages/roleypoly-server/util/rpcrepl.js
Normal file
81
packages/roleypoly-server/util/rpcrepl.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
import dotenv from 'dotenv'
|
||||
import repl from 'repl'
|
||||
import os from 'os'
|
||||
import { addAwaitOutsideToReplServer } from 'await-outside'
|
||||
import Roleypoly from '../Roleypoly'
|
||||
import chokidar from 'chokidar'
|
||||
import logger from '../logger'
|
||||
process.env.DEBUG = false
|
||||
process.env.IS_BOT = false
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const log = logger(__filename)
|
||||
|
||||
const RP = new Roleypoly(null, null)
|
||||
const reset = async (r) => {
|
||||
await RP.awaitServices()
|
||||
|
||||
r.context.RP = RP
|
||||
|
||||
r.context.ctx = { session: { userId: RP.ctx.discord.cfg.rootUsers.values().next().value } }
|
||||
r.context.guest = { session: {} }
|
||||
|
||||
r.context.g_rpc = {}
|
||||
r.context.rpc = {}
|
||||
r.context.reload = () => {
|
||||
RP.ctx.RPC.reload()
|
||||
r.context.$RPC = RP.ctx.RPC.rpcMap
|
||||
for (let fn in r.context.$RPC) {
|
||||
r.context.g_rpc[fn] = r.context.$RPC[fn].bind(null, r.context.guest)
|
||||
r.context.rpc[fn] = r.context.$RPC[fn].bind(null, r.context.ctx)
|
||||
}
|
||||
}
|
||||
|
||||
r.context.reload()
|
||||
}
|
||||
|
||||
const motd = () => {
|
||||
console.log(`~~ Roleypoly RPC REPL.
|
||||
\`ctx\` a mocked koa context, defaulting to first root user.
|
||||
\`rpc\` maps to all rpc functions, prefilled with ctx.
|
||||
|
||||
\`guest\` maps to a mock guest sessioned koa context.
|
||||
\`g_rpc\` maps to all rpc, prefilled with guest.
|
||||
|
||||
\`$RPC\` maps to all rpc functions as they are.
|
||||
\`RP\` maps to the Roleypoly app. It does NOT have HTTP stuff running.
|
||||
\`reload()\` to refresh RPC functions.
|
||||
\`reset()\` to reset this REPL.
|
||||
`)
|
||||
}
|
||||
|
||||
const start = async () => {
|
||||
if (repl.REPLServer.prototype.setupHistory == null) {
|
||||
console.log(' * History is available on node v11.10.0 and newer.\n')
|
||||
}
|
||||
const r = repl.start('> ')
|
||||
addAwaitOutsideToReplServer(r)
|
||||
r.setupHistory && r.setupHistory(os.homedir() + '/.ROLEYPOLY_RPCREPL_HISTORY', (e) => e && console.error(e))
|
||||
r.context.reset = async () => {
|
||||
await reset(r)
|
||||
motd()
|
||||
r.displayPrompt()
|
||||
}
|
||||
|
||||
await r.context.reset()
|
||||
const rpcWatcher = chokidar.watch('rpc/**', { persistent: true })
|
||||
rpcWatcher.on('ready', () => {
|
||||
rpcWatcher.on('all', (_, path) => {
|
||||
if (r.context.reload) r.context.reload()
|
||||
log.info('reloaded RPCs')
|
||||
r.displayPrompt()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
start().catch(e => console.error(e))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
9
packages/roleypoly-types/category.js.flow
Normal file
9
packages/roleypoly-types/category.js.flow
Normal file
|
@ -0,0 +1,9 @@
|
|||
// @flow
|
||||
export type Category = {
|
||||
hidden: boolean,
|
||||
name: string,
|
||||
roles: string[],
|
||||
_roles?: any,
|
||||
type: 'single' | 'multi' | string
|
||||
}
|
||||
|
21
packages/roleypoly-types/index.js
Normal file
21
packages/roleypoly-types/index.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
// @flow
|
||||
export type {
|
||||
PresentableRole,
|
||||
CachedRole,
|
||||
Permissions
|
||||
} from './role'
|
||||
|
||||
export type {
|
||||
PresentableServer,
|
||||
ServerModel,
|
||||
ServerSlug
|
||||
} from './server'
|
||||
|
||||
export type {
|
||||
Category
|
||||
} from './category'
|
||||
|
||||
export type {
|
||||
UserPartial,
|
||||
Member
|
||||
} from './user'
|
5
packages/roleypoly-types/package.json
Normal file
5
packages/roleypoly-types/package.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "@roleypoly/types",
|
||||
"version": "2.0.0",
|
||||
"private": true
|
||||
}
|
22
packages/roleypoly-types/role.js.flow
Normal file
22
packages/roleypoly-types/role.js.flow
Normal file
|
@ -0,0 +1,22 @@
|
|||
// @flow
|
||||
|
||||
export type PresentableRole = {
|
||||
id: string,
|
||||
color: number,
|
||||
name: string,
|
||||
position: number,
|
||||
safe: boolean
|
||||
}
|
||||
|
||||
export type Permissions = {
|
||||
canManageRoles: boolean,
|
||||
isAdmin: boolean,
|
||||
faked?: boolean,
|
||||
__faked?: Permissions
|
||||
}
|
||||
|
||||
export type CachedRole = {
|
||||
id: string,
|
||||
position: number,
|
||||
color?: number
|
||||
}
|
30
packages/roleypoly-types/server.js.flow
Normal file
30
packages/roleypoly-types/server.js.flow
Normal file
|
@ -0,0 +1,30 @@
|
|||
// @flow
|
||||
import type { Category } from './category'
|
||||
import type { PresentableRole, Permissions } from './role'
|
||||
|
||||
export type ServerSlug = {
|
||||
id: string,
|
||||
name: string,
|
||||
ownerID: string,
|
||||
icon: string
|
||||
}
|
||||
|
||||
export type ServerModel = {
|
||||
id: string,
|
||||
categories: {
|
||||
[uuid: string]: Category
|
||||
},
|
||||
message: string
|
||||
}
|
||||
|
||||
export type PresentableServer = ServerModel & {
|
||||
id: string,
|
||||
gm?: {
|
||||
color: number | string,
|
||||
nickname: string,
|
||||
roles: string[]
|
||||
},
|
||||
server: ServerSlug,
|
||||
roles: ?PresentableRole[],
|
||||
perms: Permissions
|
||||
}
|
14
packages/roleypoly-types/user.js.flow
Normal file
14
packages/roleypoly-types/user.js.flow
Normal file
|
@ -0,0 +1,14 @@
|
|||
// @flow
|
||||
import type { Member as ErisMember } from 'eris'
|
||||
|
||||
export type UserPartial = {
|
||||
id: string,
|
||||
username: string,
|
||||
discriminator: string,
|
||||
avatar: string
|
||||
}
|
||||
|
||||
export type Member = ErisMember & {
|
||||
color?: number,
|
||||
__faked?: true
|
||||
}
|
7
packages/roleypoly-ui/connector.js
Normal file
7
packages/roleypoly-ui/connector.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
const next = require('next')
|
||||
|
||||
const connector = ({ dev }) => {
|
||||
return next({ dev })
|
||||
}
|
||||
|
||||
module.exports = connector
|
14
packages/roleypoly-ui/next.config.js
Normal file
14
packages/roleypoly-ui/next.config.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
require('dotenv').config({ quiet: true })
|
||||
module.exports = {
|
||||
publicRuntimeConfig: {
|
||||
BOT_HANDLE: process.env.BOT_HANDLE
|
||||
},
|
||||
webpack: config => {
|
||||
// Fixes npm packages that depend on `fs` module
|
||||
config.node = {
|
||||
fs: 'empty'
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
}
|
50
packages/roleypoly-ui/package.json
Normal file
50
packages/roleypoly-ui/package.json
Normal file
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"name": "@roleypoly/ui",
|
||||
"private": true,
|
||||
"version": "2.0.0",
|
||||
"dependencies": {
|
||||
"@roleypoly/types": "^2.0.0",
|
||||
"color": "^3.1.0",
|
||||
"eventemitter3": "^3.1.0",
|
||||
"fast-redux": "^0.7.1",
|
||||
"immutable": "^4.0.0-rc.12",
|
||||
"moment": "^2.24.0",
|
||||
"next": "^8.0.4",
|
||||
"next-redux-wrapper": "^3.0.0-alpha.2",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6",
|
||||
"react-redux": "^6.0.1",
|
||||
"react-typist": "^2.0.5",
|
||||
"redux": "^4.0.1",
|
||||
"redux-devtools-extension": "^2.13.8",
|
||||
"redux-thunk": "^2.3.0",
|
||||
"styled-components": "^4.2.0",
|
||||
"superagent": "^5.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@babel/core": "^7.4.0",
|
||||
"@babel/node": "^7.2.2",
|
||||
"@babel/plugin-proposal-class-properties": "^7.4.0",
|
||||
"@babel/plugin-proposal-optional-chaining": "^7.2.0",
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
|
||||
"@babel/plugin-transform-runtime": "^7.4.0",
|
||||
"@babel/preset-env": "^7.4.2",
|
||||
"@babel/preset-flow": "^7.0.0",
|
||||
"await-outside": "^2.1.2",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"babel-plugin-styled-components": "^1.10.0",
|
||||
"babel-plugin-transform-flow-strip-types": "^6.22.0",
|
||||
"enzyme": "^3.9.0",
|
||||
"enzyme-adapter-react-16": "^1.11.2",
|
||||
"enzyme-to-json": "^3.3.5",
|
||||
"eslint-plugin-flowtype": "^3.4.2",
|
||||
"flow-bin": "^0.96.0",
|
||||
"flow-typed": "^2.5.1",
|
||||
"jest": "^24.6.0",
|
||||
"jest-styled-components": "^6.3.1",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"react-test-renderer": "^16.8.6",
|
||||
"standard": "12.0.1"
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import { Provider } from 'react-redux'
|
|||
import ErrorP, { Overlay } from './_error'
|
||||
import styled from 'styled-components'
|
||||
import { withRedux } from '../config/redux'
|
||||
import type { UserPartial } from '../../services/discord'
|
||||
import type { UserPartial } from '@roleypoly/types'
|
||||
|
||||
type NextPage = React.Component<any> & React.StatelessFunctionalComponent<any> & {
|
||||
getInitialProps: (ctx: any, ...args: any) => any
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// @flow
|
||||
import superagent from 'superagent'
|
||||
import RPCError from '../../rpc/_error'
|
||||
import RPCError from '@roleypoly/server/rpc/_error'
|
||||
|
||||
export type RPCResponse = {
|
||||
response?: mixed,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// @flow
|
||||
import { dynamicPropertyConfig } from 'fast-redux'
|
||||
// import { Map } from 'immutable'
|
||||
import type { PresentableServer } from '../../services/presentation'
|
||||
// import type { Category } from '../../models/Server'
|
||||
import type { PresentableServer } from '@roleypoly/types'
|
||||
import RPC from '../config/rpc'
|
||||
import { action } from './servers'
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
// @flow
|
||||
import type { ServerSlug as BackendServerSlug } from '../services/presentation'
|
||||
import type Router from 'next/router'
|
||||
|
||||
export type PageProps = {
|
||||
router: Router,
|
||||
dispatch: (...any) => mixed
|
||||
}
|
||||
|
||||
export type ServerSlug = BackendServerSlug
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue