Skip to content

Commit

Permalink
Cut a release
Browse files Browse the repository at this point in the history
  • Loading branch information
maackle committed Jul 7, 2018
1 parent 7b550f6 commit 9453b00
Show file tree
Hide file tree
Showing 40 changed files with 699 additions and 190 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [
["env", {
"modules": false
}]
]
}
2 changes: 1 addition & 1 deletion bin/start-sbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function startSbot (path, port) {
return sbot
}

const main = startSbot('./ssb-data', 8088)
const main = startSbot('./ssb-data', 8008)
const devs = ['alice', 'bob', 'charlie'].map((name, i) => {
const port = 8081 + i
const sbot = startSbot(`./ssb-dev/${name}`, port)
Expand Down
2 changes: 1 addition & 1 deletion bin/test-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config = require('ssb-config/inject')('ssb', {
path: path,
// keys: keysMaster,
host: "localhost",
port: 8088,
port: 8008,
// master: keysMaster.id,
// master: [keysMaster.id, keysAlice.id],
caps: {
Expand Down
2 changes: 2 additions & 0 deletions electron/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<div id="app"></div>
<script>
require('./renderer.js')
// require('../output/App.UI.Main').main()
require('../dist/ui.js')
</script>
</body>
</html>
6 changes: 5 additions & 1 deletion electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const BrowserWindow = electron.BrowserWindow

const path = require('path')
const url = require('url')
const {startSbot} = require('./start-sbot-mainnet')

require('electron-reload')(path.join(__dirname, 'ui'))

Expand Down Expand Up @@ -40,7 +41,10 @@ function createWindow () {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {createWindow()})
app.on('ready', () => {
const sbot = startSbot(8008)
createWindow()
})

// Quit when all windows are closed.
app.on('window-all-closed', function () {
Expand Down
2 changes: 0 additions & 2 deletions electron/renderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.

require('../output/App.UI.Main').main()
40 changes: 40 additions & 0 deletions electron/start-sbot-mainnet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

const fs = require('fs')
const path = require('path')
const pull = require('pull-stream')
const ssbKeys = require('ssb-keys')
const bundle = require('../dist/db.js')
const {ssbIgoPlugin} = bundle

console.log(ssbIgoPlugin)

const sbotBuilder =
require('scuttlebot')
.use(require("scuttlebot/plugins/master"))
.use(require("scuttlebot/plugins/gossip"))
.use(require("scuttlebot/plugins/replicate"))
.use(require("ssb-private"))
.use(require("ssb-friends"))
.use(ssbIgoPlugin)

function dumpManifest(sbot, filePath) {
const manifest = JSON.stringify(sbot.getManifest())
fs.writeFileSync(path.join(filePath, "manifest.json"), manifest)
}

exports.startSbot = (port) => {

const config = require('ssb-config/inject')('ssb', {
host: "localhost",
port: port,
});

config.keys = ssbKeys.loadOrCreateSync(config.path + "/secret")
config.master = config.keys.id
console.log(`starting sbot in ${config.path} at port ${port}`)

const sbot = sbotBuilder(config)
dumpManifest(sbot, config.path)

return sbot
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "pulp build",
"bundle": "pulp build -O -I src --to dist/bundle.js -m App.UI.Main",
"bundle": "pulp build -O -I src --to dist/ui.js -m App.UI.Main && pulp build -O -I src --to dist/db.js -m App.DB.Main && cp output/Ssb.Common/foreign.js dist/ssb-common.js && echo \"Auto bundling done. Don't forget to manually add module.exports to db.js\"",
"dev": "concurrently --raw --kill-others \"bin/watch-es6.sh\" \"sass --watch electron/style:electron/build\"",
"electron": "electron ./electron/main.js",
"sbot": "node bin/start-sbot.js",
Expand All @@ -16,6 +16,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"babel-preset-env": "^1.7.0",
"concurrently": "^3.5.1",
"electron": "^1.8.4",
"electron-reload": "^1.2.2",
Expand Down
8 changes: 4 additions & 4 deletions src/App/Common.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Data.Array as Array
import Data.Maybe (Maybe(..))
import Debug.Trace (spy)
import Spork.Html as H
import Ssb.Client (getClient)
import Ssb.Config (Config(..), SSB, ConfigData, defaultConfigData)

mainShs = "1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s="
testShs = "GVZDyNf1TrZuGv3W5Dpef0vaITW1UqOUO3aWLNBp+7A="

standardConfig :: fx. Eff ( ssb :: SSB | fx ) Config
standardConfig = do
cfg <- defaultConfigData $ Just
{ path: "./ssb-data"
, keys: Nothing }
pure $ Config $ cfg { port = 8088, shs = testShs }
cfg <- defaultConfigData $ Nothing
pure $ Config $ cfg { port = 8008, shs = mainShs }

devConfig :: String -> Int -> fx. Eff ( ssb :: SSB | fx ) Config
devConfig path port = do
Expand Down
5 changes: 1 addition & 4 deletions src/App/DB/Main.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ exports.flumeUse =
sbot._flumeUse(indexName, view)

exports.liveStream =
view => () => {
console.log('new stream')
return view.stream({live: true})
}
view => () => view.stream({live: true})

exports._rawGet =
view => {
Expand Down
4 changes: 1 addition & 3 deletions src/App/DB/Main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var pull = require('pull-stream');
var Reduce = require('flumeview-reduce');
var Reduce = require("flumeview-reduce");

exports.mkFlumeReducer = function (version) {
return function (reducer) {
Expand Down Expand Up @@ -37,7 +36,6 @@ exports.flumeUse = function (sbot) {

exports.liveStream = function (view) {
return function () {
console.log('new stream');
return view.stream({ live: true });
};
};
Expand Down
5 changes: 4 additions & 1 deletion src/App/DB/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import Ssb.PullStream (PullStream)
import Ssb.Server (createFeed, createFeed', createFeedRemote', toPlugin)
import Ssb.Types (Sbot)

main :: Eff () Foreign
main = pure $ toForeign ssbIgoPlugin

ssbIgoPlugin =
{ init: \sbot -> unsafePerformEff $ init sbot
, name: "ssbIgo"
Expand Down Expand Up @@ -79,4 +82,4 @@ foreign import mkFlumeReducer :: String -> ReduceFnImpl -> MapFn -> FlumeData ->
foreign import mkFlumeReducer1 :: String -> ReduceFnImpl -> MapFn -> Codec FlumeData -> FlumeData -> FlumeReducer
foreign import flumeUse :: fx. Sbot -> String -> FlumeReducer -> Eff (ssb :: SSB | fx) FlumeView
foreign import liveStream :: fx. FlumeView -> Eff (ssb :: SSB | fx) PullStream
foreign import _rawGet :: FlumeView -> (FlumeData -> Unit) -- NOTE: the FFI here is hosed
foreign import _rawGet :: FlumeView -> (FlumeData -> Unit) -- NOTE: the FFI here is hosed
28 changes: 15 additions & 13 deletions src/App/Flume.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,26 @@ module App.Flume where
import Prelude

import App.Common (messageTypeString)
import App.IgoMsg (AcceptMatchPayload, BoardPosition(..), DeclineMatchFields, DeclineMatchPayload, IgoMove(..), IgoMsg(..), MsgKey, OfferMatchPayload, PlayMovePayload, RequestMatchPayload, SsbIgoMsg(..), StoneColor(..), parseIgoMessage)
import App.Utils (trace', upsert, (&))
import App.IgoMsg (AcceptMatchPayload, DeclineMatchFields, DeclineMatchPayload, IgoMove(Finalize, ToggleDead, Pass, PlayStone, Resign), IgoMsg(Kibitz, PlayMove, AcknowledgeDecline, DeclineMatch, AcceptMatch, WithdrawOffer, OfferMatch, ExpireRequest, RequestMatch), MsgKey, OfferMatchPayload, PlayMovePayload, RequestMatchPayload, StoneColor(Black, White), parseIgoMessage)
import App.Utils (upsert, (&))
import Control.Alt ((<|>))
import Data.Argonaut (Json, fromObject, jsonNull, toObject, toString)
import Data.Argonaut.Generic.Argonaut (decodeJson, encodeJson)
import Data.Array (last, length, snoc)
import Data.Array (filter, last, snoc)
import Data.Array as Array
import Data.Bifunctor (lmap)
import Data.Either (Either(..), either, hush)
import Data.Foreign (Foreign, toForeign)
import Data.Either (either, hush)
import Data.Function.Uncurried (Fn2)
import Data.Generic (class Generic, gEq, gShow)
import Data.Maybe (Maybe(..), fromJust, fromMaybe, maybe)
import Data.Maybe (Maybe(Nothing, Just), maybe)
import Data.Newtype (class Newtype, unwrap, wrap)
import Data.Record as Record
import Data.StrMap (StrMap, delete, fromFoldable, insert, lookup)
import Data.StrMap as M
import Data.Symbol (SProxy(..))
import Data.Traversable (sequence)
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Debug.Trace (spy, trace, traceA, traceAny, traceAnyA)
import Global.Unsafe (unsafeStringify)
import Partial (crashWith)
import Partial.Unsafe (unsafeCrashWith, unsafePartial)
import Debug.Trace (trace)
import Ssb.Types (UserKey, MessageKey)


Expand Down Expand Up @@ -223,7 +218,6 @@ reduceFn (db) json =
newMove = IndexedMove payload {rootAccept} {key, author}
moveStep = MoveStep {move, key}
newMatch = match # unwrap >>> (\m -> m { moves = snoc m.moves moveStep }) >>> wrap
_ = traceAny {newMove, newMatch}
in db { moves = M.insert key newMove db.moves
, matches = M.insert rootAccept newMatch db.matches }
Just err ->
Expand All @@ -234,7 +228,7 @@ reduceFn (db) json =
Nothing -> trace "invalid message chain" $ const db
Just match@(IndexedMatch {acceptMeta}) ->
let
newKibitz = spy $ KibitzStep {text, author}
newKibitz = KibitzStep {text, author}
append arr = Just $ snoc arr newKibitz
in db { matchKibitzes = upsert append acceptMeta.key [] db.matchKibitzes }

Expand Down Expand Up @@ -315,6 +309,14 @@ nextMover db match@(IndexedMatch {offerPayload, offerMeta}) =
Just (IndexedMove _ _ lastMeta) -> if author == lastMeta.author then opponentKey else author
Nothing -> firstMover

moveNumber :: IndexedMatch -> Int
moveNumber match@(IndexedMatch {moves}) =
Array.length $ filter gameMove moves
where
gameMove (MoveStep {move}) = case move of
PlayStone _ -> true
_ -> false

isMatchEnd :: IndexedMatch -> Boolean
isMatchEnd match@(IndexedMatch {moves}) =
let lastTwo = _.move <<< unwrap <$> Array.drop (Array.length moves - 2) moves
Expand Down
15 changes: 8 additions & 7 deletions src/App/UI/Action.purs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ update model = case _ of
else model { flume = FlumeDb $ reduceFn flume mapped }
UpdateFriends json ->
case decodeJson json :: Either String AboutMessage of
Left reason -> {model, effects: lift $ Aff.log reason *> Aff.log (show json) *> pure Noop}
Left reason -> {model, effects: lift $ pure Noop}
Right (AboutMessage {content}) ->
let
name = case content.name of
"" -> Nothing
a -> Just a
name = content.name
key = content.about
user = { name, key }
user = M.lookup key model.userKeys # case _ of
Nothing -> { name, key }
Just u -> maybe {name, key} (\name -> u { name = Just name}) name

in purely $ model
{ userKeys = M.insert key user model.userKeys
, userNames = maybe model.userNames (\n -> M.insert n user model.userNames) name
Expand Down Expand Up @@ -196,8 +197,8 @@ update model = case _ of
effect = liftEff do
case (f val) of
-- Left err -> preventDefault event *> traceA err *> pure Noop
Left err -> traceA err *> (pure $ UpdateModel (set (O.scratchOffer <<< O.errorMsg) $ Just err))
Right f -> traceA "OK" *> pure $ UpdateModel f
Left err -> pure $ UpdateModel (set (O.scratchOffer <<< O.errorMsg) $ Just err)
Right f -> pure $ UpdateModel f
in { model, effects: lift effect}


Expand Down
2 changes: 1 addition & 1 deletion src/App/UI/ClientQueries.es6.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const {exposeAff, exposeEff} = require('../../output/Ssb.Common/foreign')
const {exposeAff, exposeEff} = require('./ssb-common')

exports.getStream =
client => () =>
Expand Down
20 changes: 8 additions & 12 deletions src/App/UI/ClientQueries.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

var _require = require('../../output/Ssb.Common/foreign');

var exposeAff = _require.exposeAff;
var exposeEff = _require.exposeEff;
var _require = require('./ssb-common'),
exposeAff = _require.exposeAff,
exposeEff = _require.exposeEff;

exports.getStream = function (client) {
return function () {
Expand All @@ -16,10 +13,9 @@ exports._getDb = function (client) {
return client.ssbIgo.rawGet(function (err, val) {
return err ? fail(err) : pass(val);
});
}

// exports._testFeed =
// client => path => (fail, pass) =>
// client.ssbIgo.rawTestFeed(path, (err, val) => err ? fail(err) : pass(val))
;
};
};

// exports._testFeed =
// client => path => (fail, pass) =>
// client.ssbIgo.rawTestFeed(path, (err, val) => err ? fail(err) : pass(val))
2 changes: 0 additions & 2 deletions src/App/UI/Effect.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import App.UI.Model (DevIdentity)
import Control.Monad.Aff (Aff)
import Control.Monad.Aff.Console (CONSOLE, log)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Console as Eff
import DOM (DOM)
import DOM.Classy.Event (currentTarget)
import DOM.Classy.Node (nodeValue)
Expand Down Expand Up @@ -53,7 +52,6 @@ runEffect = case _ of
pure $ next who
ReturnEventTarget event next -> liftEff do
val <- nodeValue $ currentTarget event
Eff.log val
pure $ next val
RawEffect e -> e
-- PublishPrivate msg recips next ->
Expand Down
Loading

0 comments on commit 9453b00

Please sign in to comment.