LoginSignup
8
5

More than 5 years have passed since last update.

PureScript のインストールと内容確認

Last updated at Posted at 2016-12-01

この記事は (bouzuya) PureScript Advent Calendar 2016 の 1 日目。 (bouzuya) PureScript Advent Calendar 2016 は bouzuya の PureScript 学習の記録だ。

概要

今日は PureScript のコンパイラーなどを含む purescript パッケージ (0.10.2) をインストールする。

インストール方法

PureScript の DOWNLOAD を見るといくつかのインストール方法があるようだ。

  • GitHub から Binary を得る
  • NPM
  • Homebrew
  • Stack

NPM でインストール

ぼくは NPM を選択した。理由は次の 3 つ。

  • Getting Started でそうしているから
  • ぼくが JavaScript 界隈から入ってきているから
  • bodil/pulpbower/bower のために結局 NPM を使うことになるから
    • これは psc-package を使えば不要かもしれない (未検証)

次のようにインストールした。

$ mkdir project1
$ cd project1/
$ npm init -y
$ npm install -D purescript

npm については説明しない。

Getting Started の記述は無視して npm install --global を避けた。理由は CI などで環境依存に困るのを避けるためだ。PATH にさえ注意すれば、この変更は問題にならないだろう。

動かしてみる

$ ls node_modules/.bin

すると、purescript およびその依存関係によってインストールされた実行ファイルを見ることができる。 node_modules/purescript/ から来るのは psc からはじまるファイルのようだ。

  • psc …… コンパイラー
  • psc-bundle …… bundler (browserify, webpack 的な)
  • psc-docs …… ドキュメント生成
  • psc-ide-client …… IDE 補助
  • psc-ide-server …… IDE 補助
  • psc-package …… パッケージマネージャー
  • psc-publish …… ドキュメントのアップロード
  • psci …… 対話環境

上記の説明は、後述の --help からの想像。

psc を動かしてみる

まずは psc のバージョンとヘルプを確認する。

$ $(npm bin)/psc --version
0.10.2
$ $(npm bin)/psc --help
psc - Compiles PureScript to Javascript

Usage: psc [FILE] [-o|--output ARG] [--no-tco] [--no-magic-do] [--no-opts]
           [-v|--verbose-errors] [-c|--comments] [--source-maps] [--dump-corefn]
           [-p|--no-prefix] [--json-errors]

Available options:
  --version                Show the version number
  -h,--help                Show this help text
  FILE                     The input .purs file(s)
  -o,--output ARG          The output directory (default: "output")
  --no-tco                 Disable tail call optimizations
  --no-magic-do            Disable the optimization that overloads the do
                           keyword to generate efficient code specifically for
                           the Eff monad
  --no-opts                Skip the optimization phase
  -v,--verbose-errors      Display verbose error messages
  -c,--comments            Include comments in the generated code
  --source-maps            Generate source maps
  --dump-corefn            Dump the (functional) core representation of the
                           compiled code at output/*/corefn.json
  -p,--no-prefix           Do not include comment header
  --json-errors            Print errors to stderr as JSON

psc 0.10.2

Hello World! したくなるところだが、NPM パッケージ purescript には入出力のための関数どころか、標準的な関数さえ含まれていないので、ここはスルー。

psci を動かしてみる

次は psci のバージョンとヘルプを確認する。

$ $(npm bin)/psci --version
0.10.2

バージョンはさすがに psc と同じ。ヘルプのほうは……。

$ $(npm bin)/psci --help
psci - Interactive mode for PureScript

Usage: psci [FILE] ([-p|--port ARG] | [--node-opts NODE_OPTS])

Available options:
  --version                Show the version number
  -h,--help                Show this help text
  FILE                     Optional .purs files to load on start
  -p,--port ARG            The web server port
  --node-opts NODE_OPTS    Flags to pass to node, separated by spaces

psci 0.10.2

なるほど REPL っぽい。ちなみに動かすとエラーになる。

$ $(npm bin)/psci
PSCi requires the psci-support package to be installed.
You can install it using Bower as follows:

  bower i purescript-psci-support --save-dev

Or using psc-package:

  psc-package install psci-support

For help getting started, visit http://wiki.purescript.org/PSCi

psc-bundle --help

psc-bundle は bundler のようだ。ブラウザ向けに commonjs が動くようにまとめてくれるのだろう。

$ $(npm bin)/psc-bundle --help
psc-bundle - Bundles compiled PureScript modules for the browser

Usage: psc-bundle FILE [-o|--output ARG] [-m|--module ARG] [--main ARG]
                  [-n|--namespace ARG]

Available options:
  --version                Show the version number
  -h,--help                Show this help text
  FILE                     The input .js file(s)
  -o,--output ARG          The output .js file
  -m,--module ARG          Entry point module name(s). All code which is not a
                           transitive dependency of an entry point module will
                           be removed.
  --main ARG               Generate code to run the main method in the specified
                           module.
  -n,--namespace ARG       Specify the namespace that PureScript modules will be
                           exported to when running in the
                           browser. (default: "PS")

psc-bundle 0.10.2

psc-docs --help

psc-docs は Markdown のドキュメントを生成するようだ。

$ $(npm bin)/psc-docs --help
psc-docs - Generate Markdown documentation from PureScript source files

Usage: psc-docs [--format FORMAT] [FILE] [--docgen ARG]

Available options:
  --version                Show the version number
  -h,--help                Show this help text
  --format FORMAT          Set output FORMAT (markdown | etags | ctags)
  FILE                     The input .purs file(s)
  --docgen ARG             A list of module names which should appear in the
                           output. This can optionally include file paths to
                           write individual modules to, by separating with a
                           colon ':'. For example, Prelude:docs/Prelude.md. This
                           option may be specified multiple times.

Examples:
  print documentation for Data.List to stdout:
    psc-docs "src/**/*.purs" ".psc-package/*/*/*/src/**/*.purs" \
      --docgen Data.List

  write documentation for Data.List to docs/Data.List.md:
    psc-docs "src/**/*.purs" ".psc-package/*/*/*/src/**/*.purs" \
      --docgen Data.List:docs/Data.List.md

  write documentation for Data.List to docs/Data.List.md, and
  documentation for Data.List.Lazy to docs/Data.List.Lazy.md:
    psc-docs "src/**/*.purs" ".psc-package/*/*/*/src/**/*.purs" \
      --docgen Data.List:docs/Data.List.md \
      --docgen Data.List.Lazy:docs/Data.List.Lazy.md

psc-docs 0.10.2

psc-package --help

psc-package は依存関係のパッケージを管理するようだ。

$ $(npm bin)/psc-package --help
Usage: psc-package COMMAND
  Manage package dependencies

Available options:
  --version                Show the version number
  -h,--help                Show this help text

Available commands:
  init                     Initialize a new package
  update                   Update dependencies
  install                  Install the named package
  build                    Build the current package and dependencies
  dependencies             List all (transitive) dependencies for the current
                           package
  sources                  List all (active) source paths for dependencies

psc-package 0.10.2

psc-publish --help

psc-publish はドキュメントを Pursuit にアップロードするようだ。Pursuit は PureScript の API reference だ。 pursuit はおそらく何度も出てくる。

$ $(npm bin)/psc-publish --help
psc-publish - Generates documentation packages for upload to
http://pursuit.purescript.org

Usage: psc-publish [--dry-run]

Available options:
  --version                Show the version number
  -h,--help                Show this help text
  --dry-run                Produce no output, and don't require a tagged version
                           to be checked out.

psc-publish 0.10.2

その他

ほか (psc-ide-client, psc-ide-server) は説明がでなかったので割愛。おそらく TypeScript の tsserver に相当するもの。

参考

次回以降の TODO

  • psc-package を試す
  • psci を試す
  • pulp を試す

あたりへ進みたい。

8
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5