Skip to content

Commit

Permalink
🧩 [consolidate]: drawFig', drawFile' helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolyp committed Nov 25, 2024
1 parent adabd91 commit e44b358
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 100 deletions.
40 changes: 20 additions & 20 deletions puppeteer.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
const express = require('express');
const serve = require('express-static');
require('http-shutdown').extend();
const express = require('express')
const serve = require('express-static')
require('http-shutdown').extend()

const app = express();
const app = express()
const [,, module_, website] = process.argv
const root = __dirname + '/dist/' + website

const root = __dirname + '/dist/' + process.argv[3];
app.use(serve(root));
app.use(serve(root))

const server = app.listen(8080, function() {
console.log("Serving content from " + root);
}).withShutdown();
console.log("Serving content from " + root)
}).withShutdown()

(async () => {
;(async () => {
try {
const module = process.argv[2]
console.log('Loading Puppeteer test module:', module);
import('./output-es/' + module + '/index.js').then(({ main }) => {
main().then(serverDown);
console.log('Loading Puppeteer test module:', module_)
import('./output-es/' + module_ + '/index.js').then(({ main }) => {
main().then(serverDown)
}).catch(err => {
console.error("Failed to load PureScript output:", err);
});
console.error("Failed to load PureScript output:", err)
})
} catch (error) {
console.error('Error:', error);
console.error('Error:', error)
}
})();
})()

function serverDown() {
console.log('Shutting down server')
server.shutdown(function(err) {
if (err) {
return console.log('shutdown failed', err.message);
return console.log('shutdown failed', err.message)
}
console.log('Everything is cleanly shutdown.');
});
console.log('Server shut down.')
})
}
10 changes: 9 additions & 1 deletion src/App/Fig.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module App.Fig where
import Prelude hiding (absurd, compare)

import App.CodeMirror (EditorView, addEditorView, dispatch, getContentsLength, update)
import App.Util (SelState, 𝕊, as𝕊, getPersistent, getTransient, selState, to𝕊)
import App.Util (SelState, 𝕊, as𝕊, getPersistent, getTransient, runAff', selState, to𝕊)
import App.Util.Selector (envVal)
import App.View (view)
import App.View.Util (Direction(..), Fig, FigSpec, HTMLId, View, drawView)
Expand All @@ -14,8 +14,10 @@ import Data.Newtype (unwrap)
import Data.Profunctor.Strong ((***))
import Data.Set as Set
import Data.Traversable (sequence_)
import Data.Tuple (uncurry)
import Desugarable (desug)
import Effect (Effect)
import Effect.Aff (Aff)
import EvalGraph (graphEval, graphGC, withOp)
import GaloisConnection ((***)) as GC
import GaloisConnection (GaloisConnection(..), dual, meet)
Expand Down Expand Up @@ -88,6 +90,12 @@ drawFile :: File × String -> Effect Unit
drawFile (file × src) =
addEditorView (codeMirrorDiv $ unwrap file) >>= drawCode src

drawFile' :: Aff (File × String) -> Effect Unit
drawFile' = runAff' drawFile

drawFig' :: Aff (HTMLId × Fig) -> Effect Unit
drawFig' = runAff' (uncurry drawFig)

unprojExpr :: forall a. BoundedMeetSemilattice a => Raw EnvExpr -> GaloisConnection (Env a) (EnvExpr a)
unprojExpr (EnvExpr _ e) = GC
{ fwd: \γ -> EnvExpr γ (topOf e)
Expand Down
7 changes: 3 additions & 4 deletions src/App/Util.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Data.Profunctor.Strong ((&&&), first)
import Data.Show.Generic (genericShow)
import Data.String (joinWith)
import Data.String.CodeUnits (drop, take)
import Data.Traversable (sequence, sequence_)
import Data.Tuple (snd)
import DataType (cCons, cNil)
import Dict (Dict)
Expand Down Expand Up @@ -141,10 +140,10 @@ dict toDict (Val _ v) = toDict (P.dict.unpack v)
class Reflect a b where
from :: Partial => a -> b

runAffs_ :: forall a. (a -> Effect Unit) -> Array (Aff a) -> Effect Unit
runAffs_ f as = flip runAff_ (sequence as) case _ of
runAff' :: forall a. (a -> Effect Unit) -> Aff a -> Effect Unit
runAff' f a = flip runAff_ a case _ of
Left err -> log $ show err
Right as' -> as' <#> f # sequence_
Right a' -> f a'

-- Unpack d3.js data and event type associated with mouse event target.
selectionEventData :: forall a. Event -> a × Selector Val
Expand Down
6 changes: 2 additions & 4 deletions website/Article.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ module Website.Article where

import Prelude hiding (absurd)

import App.Fig (drawFig, loadFig)
import App.Util (runAffs_)
import Data.Tuple (uncurry)
import App.Fig (drawFig', loadFig)
import Effect (Effect)
import Website.Misc.EnergyScatter as EnergyScatter
import Util ((×))
Expand All @@ -13,4 +11,4 @@ import Util ((×))
-- For now just load a specific figure.

main :: Effect Unit
main = runAffs_ (uncurry drawFig) [ ("fig" × _) <$> loadFig EnergyScatter.fig ]
main = drawFig' (("fig" × _) <$> loadFig EnergyScatter.fig)
9 changes: 3 additions & 6 deletions website/Esop2025Artifact/Fig2.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ module Website.Esop2025Artifact.Fig2 where

import Prelude hiding (absurd)

import App.Fig (drawFig, loadFig)
import App.Util (runAffs_)
import Data.Tuple (uncurry)
import App.Fig (drawFig', loadFig)
import Effect (Effect)
import Test.Specs.LinkedOutputs (movingAverages_spec)
import Util ((×))

main :: Effect Unit
main = runAffs_ (uncurry drawFig)
[ ("fig" × _) <$> loadFig movingAverages_spec.spec
]
main = drawFig' (("fig" × _) <$> loadFig movingAverages_spec.spec)

8 changes: 2 additions & 6 deletions website/Esop2025Artifact/Fig4.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module Website.Esop2025Artifact.Fig4 where

import Prelude

import App.Fig (drawFig, loadFig)
import App.Util (runAffs_)
import App.Fig (drawFig', loadFig)
import App.View.Util (FigSpec)
import Bind ((↦))
import Data.Tuple (uncurry)
import Effect (Effect)
import Module (File(..))
import Util ((×))
Expand All @@ -23,6 +21,4 @@ spec =
}

main :: Effect Unit
main = runAffs_ (uncurry drawFig)
[ ("fig" × _) <$> loadFig spec
]
main = drawFig' (("fig" × _) <$> loadFig spec)
4 changes: 3 additions & 1 deletion website/FluidOrg.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ <h4>Computational transparency as infrastructure</h4>
</div>
</div>

<script>
<script src="fluid.js">
/*
const worker = new Worker('worker.js')
console.log('Starting worker')
Expand All @@ -128,6 +129,7 @@ <h4>Computational transparency as infrastructure</h4>
worker.onerror = function (e) {
console.error('Worker error:', e.message)
}
*/
</script>
</body>
</html>
10 changes: 3 additions & 7 deletions website/FluidOrg.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ module Website.FluidOrg where

import Prelude hiding (absurd)

import App.Fig (drawFig, drawFile, loadFig)
import App.Util (runAffs_)
import Data.Tuple (uncurry)
import App.Fig (drawFile', drawFig', loadFig)
import Effect (Effect)
import Module (File(..), Folder(..), loadFile')
import Util ((×))
import Website.Misc.NonRenewables as NonRenewables

main :: Effect Unit
main = do
runAffs_ drawFile
[ loadFile' (Folder "fluid/example/plot") (File "non-renewables") ]
runAffs_ (uncurry drawFig)
[ ("fig" × _) <$> loadFig NonRenewables.fig ]
drawFile' (loadFile' (Folder "fluid/example/plot") (File "non-renewables"))
drawFig' (("fig" × _) <$> loadFig NonRenewables.fig)
12 changes: 4 additions & 8 deletions website/FluidOrg/Convolution.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ module Website.FluidOrg.Convolution where

import Prelude hiding (absurd)

import App.Fig (drawFig, drawFile, loadFig)
import App.Util (runAffs_)
import App.Fig (drawFig', drawFile', loadFig)
import App.View.Util (FigSpec)
import Data.Tuple (uncurry)
import Effect (Effect)
import Module (File(..), Folder(..), loadFile')
import Util ((×))
Expand All @@ -24,8 +22,6 @@ fig =

main :: Effect Unit
main = do
runAffs_ drawFile
[ loadFile' (Folder "fluid/lib") (File "convolution")
, loadFile' (Folder "fluid/example/slicing/convolution") (File "emboss")
]
runAffs_ (uncurry drawFig) [ ("fig" × _) <$> loadFig fig ]
drawFile' (loadFile' (Folder "fluid/lib") (File "convolution"))
drawFile' (loadFile' (Folder "fluid/example/slicing/convolution") (File "emboss"))
drawFig' (("fig" × _) <$> loadFig fig)
6 changes: 2 additions & 4 deletions website/FluidOrg/ConvolutionWrapped.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ module Website.FluidOrg.ConvolutionWrapped where

import Prelude hiding (absurd)

import App.Fig (drawFig, loadFig)
import App.Util (runAffs_)
import App.Fig (drawFig', loadFig)
import App.View.Util (FigSpec)
import Data.Tuple (uncurry)
import Effect (Effect)
import Module (File(..))
import Util ((×))
Expand All @@ -23,4 +21,4 @@ fig =
}

main :: Effect Unit
main = runAffs_ (uncurry drawFig) [ ("fig" × _) <$> loadFig fig ]
main = drawFig' (("fig" × _) <$> loadFig fig)
8 changes: 3 additions & 5 deletions website/FluidOrg/MovingAverage.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ module Website.FluidOrg.MovingAverage where

import Prelude hiding (absurd)

import App.Fig (drawFig, drawFile, loadFig)
import App.Util (runAffs_)
import Data.Tuple (uncurry)
import App.Fig (drawFig', drawFile', loadFig)
import Effect (Effect)
import Module (File(..), Folder(..), loadFile')
import Test.Specs.LinkedOutputs (movingAverages_spec)
import Util ((×))

main :: Effect Unit
main = do
runAffs_ drawFile [ loadFile' (Folder "fluid/example/linked-outputs") (File "moving-average") ]
runAffs_ (uncurry drawFig) [ ("fig" × _) <$> loadFig movingAverages_spec.spec ]
drawFile' (loadFile' (Folder "fluid/example/linked-outputs") (File "moving-average"))
drawFig' (("fig" × _) <$> loadFig movingAverages_spec.spec)
8 changes: 8 additions & 0 deletions website/FluidOrg/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
self.onmessage = function (e) {
try {
importScripts('fluid.js')
self.postMessage({ status: 'fluid.js executed successfully' })
} catch (err) {
self.postMessage({ error: 'Failed to load or execute fluid.js: ' + err.message })
}
}
6 changes: 2 additions & 4 deletions website/Misc/EnergyScatter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module Website.Misc.EnergyScatter where

import Prelude hiding (absurd)

import App.Fig (drawFig, loadFig)
import App.Util (runAffs_)
import App.Fig (drawFig', loadFig)
import App.View.Util (FigSpec)
import Bind ((↦))
import Data.Tuple (uncurry)
import Effect (Effect)
import Module (File(..))
import Util ((×))
Expand All @@ -23,4 +21,4 @@ fig =
}

main :: Effect Unit
main = runAffs_ (uncurry drawFig) [ ("fig" × _) <$> loadFig fig ]
main = drawFig' (("fig" × _) <$> loadFig fig)
6 changes: 2 additions & 4 deletions website/Misc/ExplainableBarChart.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ module Website.Misc.ExplainableBarChart where

import Prelude

import App.Fig (drawFig, loadFig)
import App.Util (runAffs_)
import App.Fig (drawFig', loadFig)
import App.View.Util (FigSpec)
import Data.Tuple (uncurry)
import Effect (Effect)
import Module (File(..))
import Util ((×))
Expand All @@ -24,4 +22,4 @@ fig =
}

main :: Effect Unit
main = runAffs_ (uncurry drawFig) [ ("fig" × _) <$> loadFig fig ]
main = drawFig' (("fig" × _) <$> loadFig fig)
6 changes: 2 additions & 4 deletions website/Misc/Methane.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module Website.Misc.Methane where

import Prelude

import App.Fig (drawFig, loadFig)
import App.Util (runAffs_)
import App.Fig (drawFig', loadFig)
import App.View.Util (FigSpec)
import Bind ((↦))
import Data.Tuple (uncurry)
import Effect (Effect)
import Module (File(..))
import Util ((×))
Expand All @@ -20,4 +18,4 @@ figSpec =
}

main :: Effect Unit
main = runAffs_ (uncurry drawFig) [ ("fig" × _) <$> loadFig figSpec ]
main = drawFig' (("fig" × _) <$> loadFig figSpec)
8 changes: 2 additions & 6 deletions website/Misc/NonRenewables.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module Website.Misc.NonRenewables where

import Prelude

import App.Fig (drawFig, loadFig)
import App.Util (runAffs_)
import App.Fig (drawFig', loadFig)
import App.View.Util (FigSpec)
import Bind ((↦))
import Data.Tuple (uncurry)
import Effect (Effect)
import Module (File(..))
import Util ((×))
Expand All @@ -23,6 +21,4 @@ fig =
}

main :: Effect Unit
main = runAffs_ (uncurry drawFig)
[ ("fig" × _) <$> loadFig fig
]
main = drawFig' (("fig" × _) <$> loadFig fig)
6 changes: 2 additions & 4 deletions website/Misc/Renewables.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module Website.Misc.Renewables where

import Prelude hiding (absurd)

import App.Fig (drawFig, loadFig)
import App.Util (runAffs_)
import App.Fig (drawFig', loadFig)
import App.View.Util (FigSpec)
import Bind ((↦))
import Data.Tuple (uncurry)
import Effect (Effect)
import Module (File(..))
import Util ((×))
Expand All @@ -22,4 +20,4 @@ figSpec =
}

main :: Effect Unit
main = runAffs_ (uncurry drawFig) [ ("fig" × _) <$> loadFig figSpec ]
main = drawFig' (("fig" × _) <$> loadFig figSpec)
12 changes: 4 additions & 8 deletions website/Misc/RenewablesLinked.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module Website.Misc.RenewablesLinked where

import Prelude hiding (absurd)

import App.Fig (drawFig, drawFile, loadFig)
import App.Util (runAffs_)
import App.Fig (drawFig', drawFile', loadFig)
import App.View.Util (FigSpec)
import Bind ((↦))
import Data.Tuple (uncurry)
import Effect (Effect)
import Module (File(..), Folder(..), loadFile')
import Util ((×))
Expand All @@ -21,8 +19,6 @@ fig =

main :: Effect Unit
main = do
runAffs_ drawFile
[ loadFile' (Folder "fluid/example/slicing/linked-outputs") (File "bar-chart-line-chart")
, loadFile' (Folder "fluid/dataset") (File "renewables")
]
runAffs_ (uncurry drawFig) [ ("fig" × _) <$> loadFig fig ]
drawFile' (loadFile' (Folder "fluid/example/slicing/linked-outputs") (File "bar-chart-line-chart"))
drawFile' (loadFile' (Folder "fluid/dataset") (File "renewables"))
drawFig' (("fig" × _) <$> loadFig fig)
Loading

0 comments on commit e44b358

Please sign in to comment.