Skip to content

Commit

Permalink
Pages setup
Browse files Browse the repository at this point in the history
  • Loading branch information
albertprz committed May 2, 2024
1 parent b29d326 commit 4b4da11
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 92 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ jobs:

- name: Run the tests
run: npm run test

- name: Bundle the app
run: npm run bundle

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./prod
47 changes: 22 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,6 @@ for use for enterprise, personal & educational purposes.

![](assets/screenshot.png)

## Local Deployment

First, clone the repository:

```console
$ git clone https://github.com/albertprz/puresheet
$ cd puresheet
```

Then, install the following dependencies via `npm`:

```console
$ npm install -g purescript spago parcel
```

Finally build the project and launch it in localhost:


```console
$ npm run build
$ npm run serve
```

## Keybindings

#### General
Expand Down Expand Up @@ -134,6 +111,26 @@ $ npm run serve
Note: `Control` bindings also match the `Command` key on Mac OS.


## Available functions
## Local Deployment

First, clone the repository:

```console
$ git clone https://github.com/albertprz/puresheet
$ cd puresheet
```

Then, install the necessary dependencies via `npm`:

```console
$ npm install
```

Finally build the project and launch it in localhost:


Please see the [Prelude module](lib/Prelude.pursh) loaded at startup.
```console
$ npm run build
$ npm run serve
```

2 changes: 1 addition & 1 deletion dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<script src="./index.js" type="module"></script>
<script src="./index.js" type="module"></script>
</body>
</html>
12 changes: 0 additions & 12 deletions dev/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
import fs from "fs";
import path from "path";


const prelude = fs.readFileSync(path.join(__dirname, "../lib/Prelude.pursh"), "utf8");

const matrix = fs.readFileSync(path.join(__dirname, "../lib/Matrix.pursh"), "utf8");

const array = fs.readFileSync(path.join(__dirname, "../lib/Array.pursh"), "utf8");

window.loadedModules = [prelude, matrix, array]

require("../output/Main/index.js").main();
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"scripts": {
"build": "spago build",
"test": "spago -x test.dhall test",
"serve": "PARCEL_WORKER_BACKEND=process parcel dev/index.html --open",
"build-prod": "rm -rf prod && mkdir -p prod && cp dev/index.html prod/ && spago bundle-app --to prod/index.js && parcel build prod/index.html"
"clean": "rm -rf .parcel-cache",
"rebuild": "rm -rf output && spago build",
"serve": "parcel serve dev/index.html --open",
"bundle": "rm -rf prod && mkdir -p prod && cp dev/index.html prod/ && spago bundle-app --to prod/index.js && parcel build prod/index.html"
},
"devDependencies": {
"parcel": "^2.12.0",
"purescript": "^0.15.12",
"spago": "^0.21.0",
"parcel": "^2.9.3",
"path-browserify": "^1.0.1",
"process": "^0.11.10"
"spago": "^0.21.0"
}
}
1 change: 0 additions & 1 deletion spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
, "fast-vect"
, "filterable"
, "foldable-traversable"
, "foreign"
, "halogen"
, "halogen-hooks"
, "halogen-hooks-extra"
Expand Down
15 changes: 4 additions & 11 deletions src/AppStore.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import App.Components.Spreadsheet.Cell (Cell, CellValue)
import App.Components.Spreadsheet.Formula (Formula, FormulaId)
import App.Evaluator.Common (LocalFormulaCtx)
import App.Interpreter.Module (reloadModule)
import App.Lib.Array (array)
import App.Lib.Matrix (matrix)
import App.Lib.Prelude (prelude)
import App.SyntaxTree.Common (Module, QVar, QVarOp, preludeModule)
import App.SyntaxTree.FnDef (FnInfo, OpInfo)
import Data.Argonaut.Decode (fromJsonString)
Expand All @@ -16,8 +19,6 @@ import Data.Set as Set
import Data.Set.NonEmpty as NonEmptySet
import Data.Tree.Zipper (fromTree)
import Effect.Console as Logger
import Foreign (readArray, readString, unsafeToForeign)
import Foreign.Index ((!))
import Record (merge)
import Record.Extra (pick)
import Web.HTML (window)
Expand Down Expand Up @@ -75,24 +76,16 @@ getCachedStore = do

getInitialStore :: forall m. MonadEffect m => m Store
getInitialStore = liftEffect do
loadedModules <- getLoadedModules
(errors /\ newStore) <- runStateT (traverse reloadModule loadedModules)
emptyStore
traverse_ logError (foldMap blush errors)
pure newStore
where
loadedModules = [ prelude, matrix, array ]
logError err = do
Logger.error
("Module load error \n" <> "Parse Error: " <> show err)
pure emptyStore
getLoadedModules =
map (fromRight mempty)
$ runExceptT
$ traverse readString
=<< readArray
=<< (_ ! "loadedModules")
=<< unsafeToForeign
<$> liftEffect window

getFromLocalStorage :: forall m. MonadEffect m => m (Maybe Store)
getFromLocalStorage = liftEffect do
Expand Down
7 changes: 6 additions & 1 deletion lib/Array.pursh → src/Lib/Array.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Array
module App.Lib.Array where

array :: String
array =
"""module Array
def add (xs: [Number], ys: [Number]): [Number] =
Expand All @@ -24,3 +28,4 @@ def div (xs: [Number], ys: [Number]): [Number] =
// >>> [1, 2, 3], [4, 5, 6]
// >>> [1, 2, 3], [-1, -2, -3]
Prelude.zipWith (Prelude.div, xs, ys)
"""
7 changes: 6 additions & 1 deletion lib/Matrix.pursh → src/Lib/Matrix.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Matrix
module App.Lib.Matrix where

matrix :: String
matrix =
"""module Matrix
def add (xss: [[Number]], yss: [[Number]]): [[Number]] =
Expand Down Expand Up @@ -72,3 +76,4 @@ def average (xss: [[Number]]): Number =
// >>> [[1, 2], [3, 4]]
// >>> [[-1.5, 3.2], [-5.8]]
Prelude.div (sum (xss), 2)
"""
6 changes: 5 additions & 1 deletion lib/Prelude.pursh → src/Lib/Prelude.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Prelude
module App.Lib.Prelude where

prelude :: String
prelude =
"""module Prelude
op <| = apply R0
Expand Down Expand Up @@ -201,3 +204,4 @@ def average (xs: [Number]): Number =
// >>> [1, 2, 3, 4]
// >>> [-1.5, 3.2, -5.8]
sum (xs) / 2
"""
2 changes: 0 additions & 2 deletions test.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ in conf
, "aff"
, "quickcheck"
, "gen"
, "node-fs"
, "node-buffer"
, "effect"
]
}
38 changes: 7 additions & 31 deletions test/Interpreter/ExpressionSpec.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ module Interpreter.ExpressionSpec where

import TestPrelude

import App.AppStore (emptyStore, mkLocalContext)
import App.Components.Spreadsheet.Cell (Column(..), Row(..))
import App.Evaluator.Common (LocalFormulaCtx)
import App.Evaluator.Errors (EvalError(..), LexicalError(..), MatchError(..), TypeError(..))
import App.Interpreter.Expression (RunError(..))
import App.Interpreter.Expression as Interpreter
import App.Interpreter.Module (reloadModule)
import App.SyntaxTree.Common (QVar(..), QVarOp(..), Var(..), VarOp(..), preludeModule)
import App.Lib.Prelude (prelude)
import App.SyntaxTree.Common (QVar(..), QVarOp(..), Var(..), VarOp(..))
import App.SyntaxTree.FnDef (Object(..))
import Data.HashMap as HashMap
import Data.Set as Set
import Data.Tree.Zipper (fromTree)
import Effect.Unsafe (unsafePerformEffect)
import Node.Encoding (Encoding(..))
import Node.FS.Sync (readTextFile, realpath)
import Test.Spec.Assertions (shouldEqual)

spec :: Spec Unit
Expand Down Expand Up @@ -275,28 +271,8 @@ evalError :: forall a. EvalError -> Either RunError a
evalError = Left <<< EvalError'

formulaCtx :: LocalFormulaCtx
formulaCtx = unsafePerformEffect $
execStateT loadModuleFile emptyFormulaCtx
formulaCtx =
execState loadPrelude $ mkLocalContext emptyStore
where
loadModuleFile = do
fp <- liftEffect $ realpath "lib/Prelude.pursh"
contents <- liftEffect $ readTextFile UTF8 fp
resultOrErr <- reloadModule contents
liftEffect $
either (throw <<< ("Parser Error: " <> _) <<< show) pure resultOrErr

emptyFormulaCtx =
{ tableData: HashMap.empty
, fnsMap: HashMap.empty
, operatorsMap: HashMap.empty
, aliasedModulesMap: HashMap.empty
, importedModulesMap: HashMap.empty
, localFnsMap: HashMap.empty
, argsMap: HashMap.empty
, modules: Set.empty
, fnInfo: Nothing
, module': preludeModule
, scope: zero
, scopeLoc: fromTree $ mkLeaf zero
, lambdaCount: zero
}
loadPrelude =
unsafeFromJust <<< hush <$> reloadModule prelude

0 comments on commit 4b4da11

Please sign in to comment.