-
Notifications
You must be signed in to change notification settings - Fork 50
Tidying up a bit #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Tidying up a bit #143
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9eec093
Consolidate READMEs, remove some references to backends
hdgarrood 8b8e89e
Update default gist ID
hdgarrood 26aba02
adjust heading levels
hdgarrood a816bc6
Update link pointing to gh-pages branch
hdgarrood 8f0b0ac
Update README.md
hdgarrood 23da1f8
Update README.md
hdgarrood 0fcdc98
Mention defaults with query string parameters
hdgarrood f1647fc
Reword 200 response status rationale
hdgarrood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,50 @@ | ||
# PureScript API | ||
# Try PureScript | ||
|
||
[](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 [email protected]: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 [email protected]: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' |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably include the default for each of these, ie.
You could judge this for yourself by loading up the default Try PureScript page, but if you're say crafting a query string based off of this section in the readme it would be useful to see which options you can skip.