Logo

0x3d.Site

is designed for aggregating information.
Welcome
check repository here

run-elm

npm Travis branch AppVeyor branch

Run Elm code from the command line

Ever want to quickly try out some Elm code that's too complex for the REPL or too much of a hassle to bootstrap with the Elm architecture and the browser? run-elm has you covered. run-elm allows you to quickly define a module that you can run from the command line!

Prerequisites

run-elm requires Node versions >= 6.

run-elm also expects a current version of the Elm binary installed globally. You can install it with:

npm install -g elm

Installation

$ npm install -g run-elm

Usage

Write some Elm code, ensuring you declare a module name that matches the filename. Then, add an output constant of type String for whatever you want to print to the command line:

module Hello exposing (..)


output : String
output =
    "Hello World!"

Finally, run the code:

$ run-elm Hello.elm
Hello World!

You should see your message printed to the console.

Command Line Arguments

run-elm also supports command line arguments to output as a list of strings.

module Main exposing (output)


output : List String -> String
output args =
    String.join "-" args ++ "!"

Running this:

run-elm Main.elm hello world

Results in this:

hello-world!

run-elm automatically detects whether output is of type String or List String -> String, so passing no extra arguments to the command will simply make args an empty list and will not produce an error. Similarly, if output is String, extra command arguments are simply ignored as redundant.

Customizing Output Name

Specify a custom name for the output constant or function by adding --output-name=myCustomConstantOrFunction to the command:

module Hello exposing (..)


myCustomConstant : String
myCustomConstant =
    "Hello World!"
$ run-elm --output-name=myCustomConstant Hello.elm
Hello World!

Running Modules in Elm Project Subdirectories

By default, run-elm assumes that your Elm module is located in the root of its project directory. This means that Elm searches for elm-package.json and elm-stuff in the directory where the Elm file is and attempts to create these assets if they are missing.

However, this behaviour may be undesired if the Elm module you are trying to run is located in a subdirectory of your project. In this case, you can pass option --project-dir=/path/to/project to run-elm and thus help it pick the correct elm-package.json and elm-stuff. In this case, is important that elm-package.json mentions the subdirectory with your module in "source-directories" field. Otherwise, the module will not be visible from the project directory and the command will fail. See Elm docs for details.

If --project-dir is specified, it has to be one of the parent directories to your file. If the given directory does not contain elm-package.json and elm-stuff, these assets are created automatically. However, the command will likely fail because "source-directories" is set to ["."] by default, which does not include subdirectories.

Setting report format

Passing --report=json to run-elm makes Elm compilation errors in stderr easier to parse. Please note that only the last one or two lines in stderr may be valid JSON strings because there exist additional messages such as Error: Compilation failed.

Using custom elm-make instance

Passing --path-to-elm-make=/path/to/elm-make allows you to choose a custom elm-make instance (e.g. the one installed locally). Otherwise, a globally available elm-make command is used to compile Elm code.

Meta

Typing run-elm --help prints usage instructions, which can be handy for recalling what arguments and options the command accepts.

You can also check what version of run-elm you have installed by typing run-elm --version.

Node Module API

If you are using run-elm in a Node project, you don’t have to spawn a separate process and can use import / require instead.

import runElm from 'run-elm';
// or
// const runElm = require('run-elm').default;

(async () => {
  const { output, debugLog } = await runElm('path/to/Main.elm');
  // output: string
  // debugLog: string[]

  const anotherRunElmResult = await runElm(
    '/path/to/project/subdirectory/Custom.elm',
    {
      outputName: 'customOutput',
      projectDir: '/path/to/project',
      report: 'json',
      pathToElmMake: '/path/to/elm-make'
    }
  );
})();
Elm
Elm
Elm is a functional programming language designed for building front-end web applications. It emphasizes simplicity, performance, and reliability, producing no runtime errors. Elm is ideal for creating robust user interfaces.
compiler/hints at master · elm/compiler
compiler/hints at master · elm/compiler
GitHub - rogeriochaves/spades: Start an Elm SPA ready to the real world
GitHub - rogeriochaves/spades: Start an Elm SPA ready to the real world
GitHub - huytd/kanelm: Kanban board built with Elm
GitHub - huytd/kanelm: Kanban board built with Elm
GitHub - lydell/elm-watch: `elm make` in watch mode. Fast and reliable.
GitHub - lydell/elm-watch: `elm make` in watch mode. Fast and reliable.
GitHub - stereobooster/type-o-rama: 👾 JS type systems interportability
GitHub - stereobooster/type-o-rama: 👾 JS type systems interportability
GitHub - tarbh-engineering/journal: The secure, private journal.
GitHub - tarbh-engineering/journal: The secure, private journal.
GitHub - ashellwig/generator-elm-mdl: Yeoman generator for elm-mdl in pure elm
GitHub - ashellwig/generator-elm-mdl: Yeoman generator for elm-mdl in pure elm
GitHub - elmariofredo/elm-hn-pwa: Hacker News as a PWA built with Elm
GitHub - elmariofredo/elm-hn-pwa: Hacker News as a PWA built with Elm
GitHub - simonewebdesign/elm-new: 💾 Generate a new Elm project from the command line (Elm 0.16+)
GitHub - simonewebdesign/elm-new: 💾 Generate a new Elm project from the command line (Elm 0.16+)
GitHub - stil4m/elm-analyse: A tool that allows you to analyse your Elm code, identify deficiencies and apply best practices.
GitHub - stil4m/elm-analyse: A tool that allows you to analyse your Elm code, identify deficiencies and apply best practices.
GitHub - pzp1997/elm-ios: Bringing the wonders of Elm to the iOS platform
GitHub - pzp1997/elm-ios: Bringing the wonders of Elm to the iOS platform
GitHub - agrafix/elm-bridge: Haskell: Derive Elm types from Haskell types
GitHub - agrafix/elm-bridge: Haskell: Derive Elm types from Haskell types
articles/switching_from_imperative_to_functional_programming_with_games_in_Elm.md at master · Dobiasd/articles
articles/switching_from_imperative_to_functional_programming_with_games_in_Elm.md at master · Dobiasd/articles
GitHub - evancz/elm-todomvc: The TodoMVC app written in Elm, nice example for beginners.
GitHub - evancz/elm-todomvc: The TodoMVC app written in Elm, nice example for beginners.
GitHub - jschomay/elm-narrative-engine: A tool for building interactive fiction style stories in Elm.
GitHub - jschomay/elm-narrative-engine: A tool for building interactive fiction style stories in Elm.
GitHub - rtfeldman/grunt-elm: Grunt plugin that compiles Elm files to JavaScript.
GitHub - rtfeldman/grunt-elm: Grunt plugin that compiles Elm files to JavaScript.
GitHub - jfairbank/run-elm: Run Elm code from the command line
GitHub - jfairbank/run-elm: Run Elm code from the command line
GitHub - JustusAdam/elm-init: Initialise scaffolding for a new Elm project
GitHub - JustusAdam/elm-init: Initialise scaffolding for a new Elm project
GitHub - halfzebra/create-elm-app: 🍃 Create Elm apps with zero configuration
GitHub - halfzebra/create-elm-app: 🍃 Create Elm apps with zero configuration
GitHub - halfzebra/elm-examples: :book: Practical examples in Elm
GitHub - halfzebra/elm-examples: :book: Practical examples in Elm
GitHub - khusnetdinov/elmkit: :school_satchel: Elm kit is web application boilerplate kit for development. This kit build on Brunch, Node, Sass, Elm-lang. It helps you to start development more productive following best practices.
GitHub - khusnetdinov/elmkit: :school_satchel: Elm kit is web application boilerplate kit for development. This kit build on Brunch, Node, Sass, Elm-lang. It helps you to start development more productive following best practices.
GitHub - rofrol/elm-games: All Elm Games (hopefully)
GitHub - rofrol/elm-games: All Elm Games (hopefully)
GitHub - Chadtech/elmish-wasm: Experiment to compile something Elm-ish to Wasm
GitHub - Chadtech/elmish-wasm: Experiment to compile something Elm-ish to Wasm
GitHub - robertjlooby/elm-koans: A set of koans for learning Elm
GitHub - robertjlooby/elm-koans: A set of koans for learning Elm
Rework Vim install instructions · Issue #610 · avh4/elm-format
Rework Vim install instructions · Issue #610 · avh4/elm-format
GitHub - evancz/elm-architecture-tutorial: How to create modular Elm code that scales nicely with your app
GitHub - evancz/elm-architecture-tutorial: How to create modular Elm code that scales nicely with your app
GitHub - brian-watkins/elm-spec: Describe the behavior of Elm programs
GitHub - brian-watkins/elm-spec: Describe the behavior of Elm programs
GitHub - zwilias/elm-json: Install, upgrade and uninstall Elm dependencies
GitHub - zwilias/elm-json: Install, upgrade and uninstall Elm dependencies
GitHub - gicentre/litvis: Literate Visualization: Theory, software and examples
GitHub - gicentre/litvis: Literate Visualization: Theory, software and examples
GitHub - eeue56/elm-for-web-developers: A collection of tips for people using Elm from a web-dev background
GitHub - eeue56/elm-for-web-developers: A collection of tips for people using Elm from a web-dev background
Elm
More on Elm

Programming Tips & Tricks

Code smarter, not harder—insider tips and tricks for developers.

Error Solutions

Turn frustration into progress—fix errors faster than ever.

Shortcuts

The art of speed—shortcuts to supercharge your workflow.
  1. Collections 😎
  2. Frequently Asked Question's 🤯

Tools

available to use.

Made with ❤️

to provide resources in various ares.