Skip to content

Commit

Permalink
Merge branch 'master' of github.com:luna/luna-studio
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Kłosowski committed Sep 18, 2017
2 parents fa4768e + f7eee7e commit e877d97
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 165 deletions.
110 changes: 20 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,23 @@
# New Byte Order repository
# Luna Studio

## Requirements

### Common

* [Stack](http://haskellstack.org/)

### For backend

* pkg-config (```brew install pkg-config```, not required on Windows)
* ZeroMQ (```brew install zmq```, for Windows download [zmq.zip](https://s3-eu-west-1.amazonaws.com/luna-zmq-win/zmq.zip))

### For frontend

* [NodeJS](http://nodejs.org/)
* [Supervisord](http://supervisord.org/)
* [Bower](https://bower.io) (```npm install -g bower```)
* [Brunch](http://brunch.io) v.1.8.5 (```npm install -g brunch@1.8.5```)
* `happy`, `hsc2hs`, `hscolour` - ```$ cd ~ && stack install happy hsc2hs hscolour```


## Building backend

0. On Windows, unpack [zmq.zip](https://s3-eu-west-1.amazonaws.com/luna-zmq-win/zmq.zip) to c:\zmq and modify (or create) environment variables:
* append c:\zmq\include to CPATH (equivalently, pass `--extra-include-dirs=c:\zmq\include` to stack)
* append c:\zmq\lib to LIBRARY_PATH (equivalently, pass `--extra-lib-dirs=c:\zmq\lib` to stack)
* append c:\zmq\bin to PATH

```shell
$ git clone git@github.com:luna/luna-studio.git
$ cd luna-studio
$ REPO_DIR=`pwd`
$ cd $REPO_DIR/build/backend
$ stack build --copy-bins --fast --install-ghc
```

## Building frontend

Currently not tested on Windows

```shell
$ cd $REPO_DIR/nodelab
$ npm install
$ bower install --allow-root
$ brunch build # -P -- for production build
```

## Running

### Backend

```shell
$ cd $REPO_DIR/supervisor
$ supervisord # will start everyting
$ supervisorctl status # for status
$ supervisorctl restart all # to restart everyting
$ supervisorctl tail -f logger # to tail logger output (see supervisord manual for more)
```

### GUI

```shell
$ cd $REPO_DIR/nodelab
$ brunch watch --server # or serve $REPO_DIR/nodelab/www using any HTTP server
```

### Run GUI in Atom

Create folder ```.luna-atom``` (name can be changed) and export path to it as ```LUNA_HOME```. Then:

```shell
$ cd $REPO_DIR/nodelab
$ npm install -g less
$ python3 ./script/atom_install.py
$ python3 ./script/atom_run.py
```

Every change in nodelab code requires rerun of ```atom_install.py``` script and reload of Atom (OSX shortcut: ```ctrl + alt + cmd + L```, Linux shortcut: ```ctrl + shift + F5```).


## Known problems

* If you have experienced problems like: ```Oops. Connection to the server was closed. Please reload page to reconnect again.``` open browser console and ```setBackendAddress("ws://localhost:8088")``` and reload browser.

* Building frontend may currently not work until you install `ghc` globally. It happens on OS X El Capitan, so in that case:
```brew install ghc```. This issue is caused by `happy` package - see https://github.com/commercialhaskell/stack/issues/1258 for more information.

* Installing atom dependencies on **Windows** resulting in ```MSBUILD : error MSB4132: The tools version "2.0" is unrecognized. Available tools versions are "4.0".```, missing python etc. Solution from [here](https://github.com/chjj/pty.js/issues/60)
1. open up a new cmd as administrator and run this command:
1. ```npm install --global --production windows-build-tools```
2. ```npm config set msvs_version 2015 --global```
2. close all instances of shell/cmd, reopen a cmd (regular this time, non-administrator) return to your directory where you are trying to run npm install and run it again
TODO: GHC reqs

## Building
1. Download `luna-manager` from http://luna-lang.org/luna-manager
2. Use `bash` as your shell environment. Other shells will be supported in the future.
3. Run `luna-manager develop luna-studio`, which will create a directory at `~/luna-develop`. You can optionally pass `--path PATH` command line argument to manually specify the destination.
4. For your convenience export following environment variables:
* `export LUNA_DEV=~/luna-develop`
* `export LUNA_STUDIO_DEV=$LUNA_DEV/apps/luna-studio`

5. Change your working directory to `cd $LUNA_STUDIO_DEV`
6. Run `source luna-shell.sh` which will setup your development environment.
7. To build `luna-studio` from sources call `./build`. For further usage information call `./build --help`.
8. After successful build you can test your new `luna-studio` version at `./dist/bin/main/luna-studio`. Use `--help` for available running options.

## Build environment
* Your luna-studio build environment `$LUNA_STUDIO_DEV` is a `git` repository and you can use it just as a regular source code repository.
* If you use `git clean -x` git will remove the `$LUNA_STUDIO_DEV/dist` directory content, which contains dependencies needed for building `luna-studio`, which were downloaded there by `luna-manager`. To setup them again again call `luna-manager develop luna-studio --path $LUNA_DEV --download-dependencies`.

11 changes: 6 additions & 5 deletions bootstrap.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-8.2 --install-ghc runghc --package base --package exceptions --package shelly --package text --package directory --package system-filepath --verbose -- -hide-all-packages
-- stack --resolver lts-8.2 --install-ghc runghc --package base --package exceptions --package shelly --package text --package directory --package system-filepath -- -hide-all-packages
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
Expand Down Expand Up @@ -177,18 +177,19 @@ generateLunaShellScript = do
nodeBinPath = current </> tools </> "node" </> supportedNodeVersion </> "bin"
addLdLibraryPath = "export LD_LIBRARY_PATH=" <> Shelly.toTextIgnore lbsPath
paths = preparePaths [stackPath, pyenvShimsFolder, pyenvBinFolder, nodeBinPath]
addPath = "export PATH=" <> paths <> ":" <> stackPaths <> ":" <> ":$PATH"
addPath = "export PATH=" <> paths <> ":" <> T.strip stackPaths <> ":$PATH"
pyenvEnviromentVar = "export PYENV_ROOT=" <> (Shelly.toTextIgnore $ current </> tools </> "python" </> "pyenv")
loadPython = "pyenv" <> " local " <> Shelly.toTextIgnore supportedPythonVersion
lunaShellPath = current </> lunaShell
fullCode = T.unlines ["#!/bin/sh", addLdLibraryPath, addPath, pyenvEnviromentVar, loadPython, shellCmd]
liftIO $ Data.Text.IO.writeFile (encodeString lunaShellPath) fullCode

stackSetupForLunaStudio :: (MonadIO m, MonadSh m, Shelly.MonadShControl m) => m ()
stackSetupForLunaStudio = Shelly.chdir "luna-studio" $ do
Shelly.echo "install GHCJS"
stackSetupForLunaStudio = do
current <- currentPath
Shelly.cmd (current </>stack) "setup"
Shelly.chdir (current </>"luna-studio") $ do
Shelly.echo "install GHCJS"
Shelly.cmd (current </>stack) "setup"


main :: IO ()
Expand Down
75 changes: 75 additions & 0 deletions libs/luna-empire/test/FileLoadSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import Data.Text.Span (LeftSpacedSpan (..), SpacedSpan (..))
import Empire.ASTOp (runASTOp)
import qualified Empire.ASTOps.Modify as ASTModify
import qualified Empire.ASTOps.Parse as ASTParse
import qualified Empire.ASTOps.Print as ASTPrint
import qualified Empire.ASTOps.Read as ASTRead
Expand Down Expand Up @@ -1326,6 +1327,80 @@ spec = around withChannels $ parallel $ do
let loc' = loc |> foo
(input, _) <- Graph.withGraph loc' $ runASTOp $ GraphBuilder.getEdgePortMapping
Graph.movePort loc' (outPortRef input [Port.Projection 0]) 2
it "removes last port in top-level def" $ \env -> do
let initialCode = Text.pack $ normalizeQQ [r|
def foo aaaa:
«0»c = aaaa + 2
c
|]
code <- evalEmp env $ do
Library.createLibrary Nothing "TestPath"
let loc = GraphLocation "TestPath" $ Breadcrumb []
Graph.loadCode loc initialCode
[foo] <- Graph.getNodes loc
let loc' = loc |>= foo ^. Node.nodeId
(input, _) <- Graph.withGraph loc' $ runASTOp $ GraphBuilder.getEdgePortMapping
Graph.removePort loc' (outPortRef input [Port.Projection 0])
code <- Graph.withUnit loc $ use Graph.code
return code
normalizeQQ (Text.unpack code) `shouldBe` normalizeQQ [r|
def foo:
«0»c = aaaa + 2
c
|]
it "removes last port in nested def" $ \env -> do
let initialCode = Text.pack $ normalizeQQ [r|
def main:
«2»def foo aaaa:
«0»c = aaaa + 2
c
«1»d = foo 3
d
|]
code <- evalEmp env $ do
Library.createLibrary Nothing "TestPath"
let loc = GraphLocation "TestPath" $ Breadcrumb []
Graph.loadCode loc initialCode
[main] <- Graph.getNodes loc
let loc' = loc |>= main ^. Node.nodeId
nodes <- Graph.getNodes loc'
let Just foo = find (\node -> node ^. Node.name == Just "foo") nodes
loc'' = loc' |> foo ^. Node.nodeId
(input, _) <- Graph.withGraph loc'' $ runASTOp $ GraphBuilder.getEdgePortMapping
Graph.removePort loc'' (outPortRef input [Port.Projection 0])
code <- Graph.withUnit loc $ use Graph.code
return code
normalizeQQ (Text.unpack code) `shouldBe` normalizeQQ [r|
def main:
«2»def foo:
«0»c = aaaa + 2
c
«1»d = foo 3
d
|]
it "doesn't remove last port in a lambda" $ let
initialCode = [r|
def main:
«0»foo = aaaa:
aaaa + 3
«1»c = foo 2 2
c
|]
expectedCode = [r|
def main:
foo = aaaa:
aaaa + 3
c = foo 3 3
c
|]
in specifyCodeChange initialCode expectedCode $ \loc -> do
Just foo <- Graph.withGraph loc $ runASTOp $ Graph.getNodeIdForMarker 0
Just c <- Graph.withGraph loc $ runASTOp $ Graph.getNodeIdForMarker 1
let loc' = loc |> foo
(input, _) <- Graph.withGraph loc' $ runASTOp $ GraphBuilder.getEdgePortMapping
Graph.removePort loc' (outPortRef input [Port.Projection 0])
`catch` (\(_e::ASTModify.CannotRemovePortException) -> return ())
Graph.setNodeExpression loc c "foo 3 3"
it "removes port in a lambda" $ let
initialCode = [r|
def main:
Expand Down
17 changes: 13 additions & 4 deletions luna-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ packages:
deps:
- zmq-1.0.0
- atom-1.18.0
- winSW-1.0.0
appType: GuiApp
synopsis: studio synopsis

Expand All @@ -33,8 +34,8 @@ packages:
path: https://s3-us-west-2.amazonaws.com/packages-luna/linux/studio/zmq/zmq.tar.gz
deps: []
windows.x64:
path: https://s3-eu-west-1.amazonaws.com/luna-zmq-win/zmq.zip
deps: []
path: https://s3-us-west-2.amazonaws.com/packages-luna/windows/zmq/zmq1.zip
deps: []
darwin.x64:
path: https://s3-us-west-2.amazonaws.com/packages-luna/darwin/studio/zmq/zmq.zip
deps: []
Expand All @@ -58,8 +59,8 @@ packages:
path: https://github.com/atom/atom/releases/download/v1.18.0/atom.x86_64.rpm
deps: []
windows.x64:
path: https://github.com/atom/atom/releases/download/v1.18.0/atom-windows.zip
deps: []
path: https://github.com/atom/atom/releases/download/v1.18.0/atom-windows.zip
deps: []
darwin.x64:
path: https://github.com/atom/atom/releases/download/v1.18.0/atom-mac.zip
deps: []
Expand All @@ -76,3 +77,11 @@ packages:
deps: []
appType: BatchApp
synopsis: studio synopsis
winSW:
versions:
1.0.0:
windows.x64:
path: https://s3-us-west-2.amazonaws.com/packages-luna/windows/WinSW/WinSW.zip
deps: []
appType: BatchApp
synopsis: winSW synopsis
20 changes: 11 additions & 9 deletions luna-studio/node-editor/src/NodeEditor/Handler/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ import qualified NodeEditor.Event.Atom as Atom
import NodeEditor.Event.Event (Event (Atom, Init, Shortcut, UI))
import NodeEditor.Event.Mouse (mousePosition)
import qualified NodeEditor.Event.Shortcut as Shortcut
import NodeEditor.Event.UI (UIEvent (AppEvent))
import NodeEditor.Event.UI (UIEvent (AppEvent, SidebarEvent))
import qualified NodeEditor.React.Event.App as App
import qualified NodeEditor.React.Event.Sidebar as Sidebar
import NodeEditor.State.Action (actionsClosingOnMouseLeave)
import NodeEditor.State.Global (State)
import qualified NodeEditor.State.Global as Global
import qualified NodeEditor.State.UI as UI

handle :: Event -> Maybe (Command Global.State ())
handle (UI (AppEvent (App.MouseMove evt _))) = Just $ Global.ui . UI.mousePos <~ mousePosition evt
handle (UI (AppEvent App.Resize )) = Just updateScene
handle (UI (AppEvent App.MouseLeave )) = Just $ endActions actionsClosingOnMouseLeave
handle (Shortcut (Shortcut.Event command _)) = Just $ handleCommand command
handle Init = Just $ Batch.getProgram def >> Batch.searchNodes
handle (Atom (Atom.SetFile path) ) = Just $ setFile path
handle (Atom Atom.UnsetFile ) = Just unsetFile
handle _ = Nothing
handle (UI (AppEvent (App.MouseMove evt _))) = Just $ Global.ui . UI.mousePos <~ mousePosition evt
handle (UI (SidebarEvent (Sidebar.MouseMove evt _ _))) = Just $ Global.ui . UI.mousePos <~ mousePosition evt
handle (UI (AppEvent App.Resize )) = Just updateScene
handle (UI (AppEvent App.MouseLeave )) = Just $ endActions actionsClosingOnMouseLeave
handle (Shortcut (Shortcut.Event command _)) = Just $ handleCommand command
handle Init = Just $ Batch.getProgram def >> Batch.searchNodes
handle (Atom (Atom.SetFile path)) = Just $ setFile path
handle (Atom Atom.UnsetFile) = Just unsetFile
handle _ = Nothing


handleCommand :: Shortcut.Command -> Command State ()
Expand Down
42 changes: 22 additions & 20 deletions luna-studio/node-editor/src/NodeEditor/Handler/Camera.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@ module NodeEditor.Handler.Camera
( handle
) where

import Common.Action.Command (Command)
import Common.Action.Command (Command)
import Common.Prelude
import LunaStudio.Data.Vector2 (Vector2 (Vector2))
import NodeEditor.Action.Camera (centerGraph, panCamera, panDown, panDrag, panLeft, panRight, panUp, resetCamera, resetPan,
resetZoom, startPanDrag, startZoomDrag, stopPanDrag, stopZoomDrag, wheelZoom, zoomDrag, zoomIn,
zoomOut)
import NodeEditor.Event.Event (Event (Shortcut, UI))
import NodeEditor.Event.Mouse (mousePosition)
import qualified NodeEditor.Event.Mouse as Mouse
import qualified NodeEditor.Event.Shortcut as Shortcut
import NodeEditor.Event.UI (UIEvent (AppEvent))
import qualified NodeEditor.React.Event.App as App
import NodeEditor.State.Action (Action (continue))
import NodeEditor.State.Global (State)
import React.Flux (MouseEvent, wheelDeltaX, wheelDeltaY)
import LunaStudio.Data.Vector2 (Vector2 (Vector2))
import NodeEditor.Action.Camera (centerGraph, panCamera, panDown, panDrag, panLeft, panRight, panUp, resetCamera, resetPan,
resetZoom, startPanDrag, startZoomDrag, stopPanDrag, stopZoomDrag, wheelZoom, zoomDrag,
zoomIn, zoomOut)
import NodeEditor.Event.Event (Event (Shortcut, UI))
import NodeEditor.Event.Mouse (mousePosition)
import qualified NodeEditor.Event.Mouse as Mouse
import qualified NodeEditor.Event.Shortcut as Shortcut
import NodeEditor.Event.UI (UIEvent (AppEvent, SidebarEvent))
import qualified NodeEditor.React.Event.App as App
import qualified NodeEditor.React.Event.Sidebar as Sidebar
import NodeEditor.State.Action (Action (continue))
import NodeEditor.State.Global (State)
import React.Flux (MouseEvent, wheelDeltaX, wheelDeltaY)


-- TODO[react]: Consider mac trackpad!!!
handle :: Event -> Maybe (Command State ())
handle (Shortcut (Shortcut.Event command _)) = Just $ handleCommand command
handle (UI (AppEvent (App.MouseDown e _))) = Just $ handleMouseDown e
handle (UI (AppEvent (App.MouseMove e _))) = Just $ handleMouseMove e
handle (UI (AppEvent (App.MouseUp _))) = Just $ continue stopPanDrag >> continue stopZoomDrag
handle (UI (AppEvent (App.Wheel m w))) = Just $ handleMouseWheel m delta where
handle (Shortcut (Shortcut.Event command _)) = Just $ handleCommand command
handle (UI (AppEvent (App.MouseDown e _))) = Just $ handleMouseDown e
handle (UI (AppEvent (App.MouseMove e _))) = Just $ handleMouseMove e
handle (UI (SidebarEvent (Sidebar.MouseMove e _ _))) = Just $ handleMouseMove e
handle (UI (AppEvent (App.MouseUp _))) = Just $ continue stopPanDrag >> continue stopZoomDrag
handle (UI (AppEvent (App.Wheel m w))) = Just $ handleMouseWheel m delta where
deltaX = fromIntegral $ -(wheelDeltaX w)
deltaY = fromIntegral $ -(wheelDeltaY w)
delta = Vector2 deltaX deltaY
handle _ = Nothing
handle _ = Nothing


-- TODO consider using state and below approach
Expand Down
2 changes: 1 addition & 1 deletion luna-studio/node-editor/src/NodeEditor/Handler/Connect.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import NodeEditor.State.Global (State)
handle :: Event -> Maybe (Command State ())
handle (UI (ConnectionEvent (Connection.MouseDown evt connId end'))) = Just $ handleConnectionMouseDown evt connId end'
handle (UI (AppEvent (App.MouseMove evt _ ))) = Just $ continue $ handleMove evt
handle (UI (SidebarEvent (Sidebar.MouseMove evt _ ))) = Just $ continue $ handleMove evt
handle (UI (SidebarEvent (Sidebar.MouseMove evt _ _ ))) = Just $ continue $ handleMove evt
handle (UI (AppEvent (App.MouseUp evt ))) = Just $ continue $ handleMouseUp evt
handle (UI (AppEvent App.Click )) = Just $ continue (end :: Connect -> Command State ())
handle (UI (PortEvent (Port.MouseUp portRef ))) = Just $ continue $ handlePortMouseUp portRef
Expand Down
Loading

0 comments on commit e877d97

Please sign in to comment.