Giter VIP home page Giter VIP logo

scripting's Introduction

Scripting

The Scripting module is a no-dependency portable elixir module that eases starting and writing scripts in elixir.

Resources

generator

The generator can be used to create a script starting point template. It can generate templates or embed the Scripting module either as a BEAM or source for the most portability.

The generator is written using the Scripting module.

presentation

Check out the presentation directory for a progression of examples for scripts.

Please read the next section about making Scripting available for thse examples.

Embed Scripting

The scripting project does not have any dependencies and does not require mix. This project can be added as a dependency to another mix project and then used for writing scripts run with mix run.

The more interesting use case is writing stand-alone script that only depends on access to elixir, the base install.

For development

Compile the module:

elixirc lib/scripting.ex

This will create Elixir.Scripting.beam. A script under development can be run directly as long as this beam file is in your current directory since . is in the default code loading path.

For portability

The following strategies can be used to portably deploy a script:

Colocate the beam file

Put a copy of the Elixir.Scripting.beam file into the same directory as your script and add the following line as the second line of your script:

Code.append_path( Path.dirname( __ENV__.file() ) )

__ENV__.file() will resolve to the full path of the script being run and is conceptually the same as argv0.

Install a common copy

Put a copy of the beam file into a common directory. For example, a ~/ebin, add this as your line 2:

Code.append_path( Path.join( System.user_home(), "ebin" ) )

Embed Scripting

The generator can embed the source of the module or the beam file itself into your script. Look at embed-with-source or embed-with-beam. These will wrap your script and output to a new file. The script is still source and can be edited.

Note that embedding the beam file is more portable than you might expect. A beam file compiled on x86 can be used on an ARM, and vice-versa. The only real requirement is that the emulator version has to be equal or greater than the one it's compiled with. The generator will also embed a check of the beam version.

Installation

Install as a dependency with:

def deps do
  [
    {:scripting, "~> 1.0.0"}
  ]
end

To develop independent script, clone this repo:

git clone https://github.com/danj3/scripting

Documentation is at https://hexdocs.pm/scripting/.

scripting's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.