diff --git a/LICENSE b/LICENSE index 91038416..732bb0e0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013-16 PureScript +Copyright (c) 2013-20 PureScript All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 4ff4c755..1b7f48db 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,50 @@ -# PureScript API +# Try PureScript [![Build Status](https://api.travis-ci.org/purescript/trypurescript.svg?branch=master)](http://travis-ci.org/purescript/trypurescript) -Very basic web service which wraps the PureScript compiler. +[Try PureScript](https://try.purescript.org) is an online PureScript code editor for quickly experimenting with PureScript code snippets and ideas. It consists of a client and a server component, both of which live within this repository. -[Client code](https://github.com/purescript/trypurescript/tree/gh-pages) +## Features: -## API +- Writing code using the [Ace Editor](http://ace.c9.io) +- Automatic compilation +- PureScript syntax highlighting +- Run and print output or show resulting JavaScript +- Multiple view modes: code, output or both +- Persistent session +- Load PureScript code from Github Gists -### Compile PureScript code - -**POST /compile** - -- Request body: PureScript code -- Response body: Either `{ js: "..." }` or `{ error: "..." }` -- Status code: 200 (success) +### Control Features via the Query String -The response does not use error codes, to make it easier to use the API from another domain using CORS. +Most of these features can be controlled not only from the toolbar, but also using the [query parameters](https://en.wikipedia.org/wiki/Query_string): -The output code will contain references to preloaded modules using `require` calls. To run these files in the browser, it is necessary to either use a `require` shim (such as require1k), or replace these calls and deploy a bundle of precompiled modules (the Try PureScript client uses the second approach). +- **Load From Gist**: Load PureScript code from Gist id using the `gist` parameter + - Example: `gist=37c3c97f47a43f20c548` will load the code from this Gist if the file was named `Main.purs` -## Configuration +- **View Mode**: Control the view mode using the `view` parameter + - Options are: `code`, `output`, `both` (default) + - Example: `view=output` will only display the output -The application takes the following arguments on the command line: +- **Auto Compile**: Automatic compilation can be turned off using the `compile` parameter + - Options are: `true` (default), `false` + - Example: `compile=false` will turn auto compilation off -- port number -- a list of input source files +- **JavaScript Code Generation**: Print the resulting JavaScript code in the output window instead of the output of the program using the `js` parameter + - Options are: `true`, `false` (default) + - Example: `js=true` will print JavaScript code instead of the program's output -### Example +- **Session**: Load code from a session which is stored with [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) using the `session` parameter + - Usually managed by Try PureScript + - Example: `session=9162f098-070f-4053-60ea-eba47021450d` (Note: will probably not work for you) + - When used with the `gist` query parameter the code will be loaded from the Gist and not the session - dist/build/trypurescript/trypurescript 8081 'bower_components/purescript-*/src/**/*.purs' - -# Development +## Development -## 1. Client setup +### 1. Client setup -``` +```sh git clone git@github.com:purescript/trypurescript.git -cd trypurescript -git co gh-pages +cd trypurescript/client bower install npm install @@ -49,32 +55,50 @@ httpserver 8080 #eg with: alias httpserver='python -m SimpleHTTPServer' open http://localhost:8080 ``` -## 2. Work with local compile server +### 2. Local compile server setup -``` +```sh git clone git@github.com:purescript/trypurescript.git cd trypurescript stack build -# use one of the backends -cd staging/core -# get the sources of the deps +# Install PureScript dependencies +cd staging psc-package install # note: globs like **/src/** do not work -stack exec trypurescript 8081 ".psc-package/psc-0.13.6/*/*/src/**/*.purs" "src/*.purs" +stack exec trypurescript 8081 ".psc-package/psc-0.13.6-*/*/*/src/**/*.purs" "src/*.purs" # should output that is is compiling the sources (first time) # then: Setting phasers to stun... (port 8081) (ctrl-c to quit) ``` -## 3. Point client to local compile server +## Server API -(instead of the ones at try.purescript.org) -``` -# edit API.purs +The server is a very basic web service which wraps the PureScript compiler, allowing clients to send PureScript code to be compiled and receiving either compiled JS or error messages in response. - , compile: compile "http://localhost:8081" - , getBundle: getDefaultBundle "http://localhost:8081" +### Compile PureScript code -``` +**POST /compile** + +- Request body: PureScript code +- Response body: Either `{ js: "..." }` or `{ error: "..." }` +- Status code: 200 (success) + +Note that if the code in the request body fails to compile, this is considered a success from the perspective of the API, so compilation failures will be returned with 2xx status codes. +Among other things, this makes it easier to use the API from another domain using CORS. + +The output code will contain references to preloaded modules using `require` calls. +To run these files in the browser, it is necessary to either use a `require` shim (such as require1k), or replace these calls and deploy a bundle of precompiled modules. +The Try PureScript client uses the second approach. + +### Configuration + +The server application takes the following arguments on the command line: + +- port number +- a list of input source files + +#### Example + + dist/build/trypurescript/trypurescript 8081 'bower_components/purescript-*/src/**/*.purs' diff --git a/client/README.md b/client/README.md deleted file mode 100644 index 8af77c70..00000000 --- a/client/README.md +++ /dev/null @@ -1,62 +0,0 @@ -Try PureScript --------------- - -[Try PureScript](https://try.purescript.org) is an online PureScript code editor for quickly experimenting with PureScript code snippets and ideas. - -## How to Add a New Backend - -- Create a `bower.json`/`psc-package.json` file with all the dependencies you want to be available for the library backend and optionally an extra `Try` module if you want. [Example PR](https://github.com/purescript/trypurescript/pull/84/files) -- Write an example in a github gist and name it `Main.purs`. [Example Gist](https://gist.github.com/ff1e87f0872d2d891e77d209d8f7706d) -- add a backend button and a backend option in `index.html` and `index.js` respectively. [Example PR](https://github.com/purescript/trypurescript/pull/85/files) - - Note to link the gist from the previous bullet in the `mainGist` field in `index.js` -- Ask phil to update the `core` main gist to link to the new backend - - -## Features: - -- Writing code using the [Ace Editor](http://ace.c9.io) -- Automatic compilation -- PureScript syntax highlighting -- Run and print output or show resulting JavaScript -- Multiple view modes: code, output or both -- Persistent session -- Load PureScript code from Github Gists -- Save PureScript code as anonymous Github Gists - - (_Note: These Gists are not associated with your GitHub account and are visible to anyone with a link to them_) - - -## Control Features via the Query String - -Most of these features can be controlled not only from the toolbar, but also using the [query parameters](https://en.wikipedia.org/wiki/Query_string): - -- **Load From Gist**: Load PureScript code from Gist id using the `gist` parameter - - Example: `gist=37c3c97f47a43f20c548` will load the code from this Gist if the file was named `Main.purs` - -- **View Mode**: Control the view mode using the `view` parameter - - Options are: `code`, `output`, `both` - - Example: `view=output` will only display the output - -- **Backend**: Control which backend will compile your code using the `backend` parameter - - Options are: `core`, `thermite`, `slides`, `flare`, `mathbox`, `behavior` - - Example: `backend=thermite` will use the thermite backend - -- **Auto Compile**: Automatic compilation can be turned off using the `compile` parameter - - Options are: `true`, `false` - - Example: `compile=false` will turn auto compilation off - -- **JavaScript Code Generation**: Print the resulting JavaScript code in the output window instead of the output of the program using the `js` parameter - - Options are: `true`, `false` - - Example: `js=true` will print JavaScript code instead of the program's output - -- **Session**: Load code from a session which is stored with [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) using the `session` parameter - - Usually managed by Try PureScript - - Example: `session=9162f098-070f-4053-60ea-eba47021450d` (Note: will probably not work for you) - - When used with the `gist` query parameter the code will be loaded from the Gist and not the session - -## Packages - -- The packages set and compiler version for Try-PureScript can be viewed [here](https://github.com/purescript/trypurescript/tree/master/staging/core/psc-package.json). - -- The packages set and compiler version for Try-Thermite can be viewed [here](https://github.com/paf31/try-thermite/blob/gh-pages/staging/psc-package.json). - - diff --git a/client/index.html b/client/index.html index 25ed84f5..5ebac864 100644 --- a/client/index.html +++ b/client/index.html @@ -63,7 +63,7 @@ diff --git a/client/src/Try/Config.purs b/client/src/Try/Config.purs index 374464b2..5c6218f1 100644 --- a/client/src/Try/Config.purs +++ b/client/src/Try/Config.purs @@ -7,4 +7,4 @@ compileUrl :: String compileUrl = "http://localhost:8081" mainGist :: String -mainGist = "e1d317102aad40207309d8873e301273" +mainGist = "7ad2b2eef11ac7dcfd14aa1585dd8f69" diff --git a/staging/behaviors/psc-package.json b/staging/behaviors/psc-package.json deleted file mode 100644 index 12d77691..00000000 --- a/staging/behaviors/psc-package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "trybehaviors", - "set": "master", - "source": "https://github.com/purescript/package-sets.git", - "depends": [ - "drawing", - "behaviors", - "prelude" - ] -} \ No newline at end of file diff --git a/staging/behaviors/src/FRP/Try.purs b/staging/behaviors/src/FRP/Try.purs deleted file mode 100644 index 62544264..00000000 --- a/staging/behaviors/src/FRP/Try.purs +++ /dev/null @@ -1,17 +0,0 @@ -module FRP.Try (defaultMain) where - -import Prelude - -import Control.Monad.Eff (Eff) -import Data.Foldable (for_) -import FRP (FRP) -import FRP.Behavior (Behavior, animate) -import Graphics.Canvas (CANVAS, getCanvasElementById, getContext2D) -import Graphics.Drawing (Drawing, render) - -defaultMain :: Behavior Drawing -> Eff (canvas :: CANVAS, frp :: FRP) Unit -defaultMain b = do - canvas <- getCanvasElementById "canvas" - for_ canvas \c -> do - ctx <- getContext2D c - animate b (render ctx) diff --git a/staging/flare/psc-package.json b/staging/flare/psc-package.json deleted file mode 100644 index b9695a69..00000000 --- a/staging/flare/psc-package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "tryflare", - "set": "master", - "source": "https://github.com/purescript/package-sets.git", - "depends": [ - "sparkle", - "console", - "const", - "exists", - "free", - "graphs", - "profunctor", - "quickcheck", - "semirings", - "validation" - ] -} diff --git a/staging/mathbox/psc-package.json b/staging/mathbox/psc-package.json deleted file mode 100644 index 53db2648..00000000 --- a/staging/mathbox/psc-package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "trymathbox", - "set": "psc-0.11.6", - "source": "https://github.com/purescript/package-sets.git", - "depends": [ - "mathbox" - ] -} diff --git a/staging/core/psc-package.json b/staging/psc-package.json similarity index 100% rename from staging/core/psc-package.json rename to staging/psc-package.json diff --git a/staging/core/src/TryPureScript.js b/staging/src/TryPureScript.js similarity index 100% rename from staging/core/src/TryPureScript.js rename to staging/src/TryPureScript.js diff --git a/staging/core/src/TryPureScript.purs b/staging/src/TryPureScript.purs similarity index 100% rename from staging/core/src/TryPureScript.purs rename to staging/src/TryPureScript.purs diff --git a/staging/thermite/psc-package.json b/staging/thermite/psc-package.json deleted file mode 100644 index 053f4e59..00000000 --- a/staging/thermite/psc-package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "staging", - "set": "psc-0.11.7", - "source": "https://github.com/purescript/package-sets.git", - "depends": [ - "react-dom", - "thermite", - "validation" - ] -} diff --git a/staging/thermite/src/Thermite/Try.purs b/staging/thermite/src/Thermite/Try.purs deleted file mode 100644 index 5ffe32e1..00000000 --- a/staging/thermite/src/Thermite/Try.purs +++ /dev/null @@ -1,24 +0,0 @@ -module Thermite.Try where - -import Prelude - -import Control.Monad.Eff (Eff) -import Data.Maybe (fromJust) -import Data.Newtype (wrap) -import DOM (DOM) as DOM -import DOM.HTML (window) as DOM -import DOM.HTML.Types (htmlDocumentToParentNode) as DOM -import DOM.HTML.Window (document) as DOM -import DOM.Node.ParentNode (querySelector) as DOM -import Partial.Unsafe (unsafePartial) -import React (createFactory) as R -import ReactDOM (render) as R -import Thermite as T - --- | The main method creates the task list component, and renders it to the document body. -defaultMain :: forall state action eff. T.Spec eff state Unit action -> state -> Eff (dom :: DOM.DOM | eff) Unit -defaultMain spec initialState = void do - let component = T.createClass spec initialState - document <- DOM.window >>= DOM.document - container <- unsafePartial fromJust <$> DOM.querySelector (wrap "#app") (DOM.htmlDocumentToParentNode document) - R.render (R.createFactory component unit) container