mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 10:19:10 +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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue