GithubHelp home page GithubHelp logo

edubart / luamon Goto Github PK

View Code? Open in Web Editor NEW
54.0 6.0 2.0 70 KB

Live development utility for Lua inspired by nodemon

License: MIT License

Makefile 1.17% Lua 98.83%
lua inotify live-coding monitor nodemon nelua luarocks

luamon's Introduction

Luamon

Luamon is a utility for quick live development in Lua. It will monitor for any changes in your source and automatically restart your Lua script or application. It works by watching for file and directories changes using the inotify API. It was inspired by nodemon, but made for Lua.

asciicast

Features

  • Automatic restarting of application.
  • Default for lua, but easy to run any executable (such as python, make, etc).
  • Ignoring specific files or directories.
  • Watch specific directories.
  • Works with server applications or one time run utilities and REPLs.

Installation

Install using LuaRocks:

luarocks install luamon

On Ubuntu you may have to install with:

luarocks install luamon INOTIFY_INCDIR=/usr/include/x86_64-linux-gnu

Example Usage

Make sure that you have luarocks binary PATH in your environment. And just run luamon with your script file as the input argument.

luamon myscript.lua

You can pass arguments to the script after --:

luamon myscript.lua -- --arg1 arg2

You can run with a different lua or any other language runner with -l:

luamon -l luajit myscript.lua

By default luamon tries to detect the language to be run and watches file extensions based on the detect language, for example in case you to run some file with .lua extension then it watches for any .lua file change in the working directory and runs lua.

Alternatively you can monitor different extensions with -e, for running python3 scripts for example you could do:

luamon -l python3 -e py myscript.py

Although you can just run python scripts by doing:

luamon myscript.py

Alternatively you can run any command with -x:

luamon -e js -x "nodejs app.js my args"

You could use for quick compile and testing C applications too:

luamon -e c,h -x "make && make test"

Advanced Usage

You can make more complex commands for live coding and testing:

luamon -e c,h,Makefile -l "make <input> && ./build/<input> <args>" example hello

The above calls make example && ./build/example hello on every .h, .c or Makefile file change.

Any option can be saved to a config file globally called .luamonrc in the user home folder or locally in the running folder, for example:

ext = {'h', 'c', 'Makefile'}
lang = "make <input> && ./build/<input> <args>"

Then you can just call:

luamon example

And will run as the example before.

You can override the languages to be detected in that config too, for example to make it uses always lua5.4 and python3 upon detection:

langs = {
  lua = {lang = 'lua5.4', ext = {'lua'}},
  python = {lang = 'python3', ext = {'py'}, ignore = {'.*', '*__pycache__*'}},
}

Some common languages comes pre configured like Lua, Python and Ruby, for all see the default config in luamon sources.

Help

Usage: luamon [-h] [-v] [-q] [-V] [-f] [-o] [-s] [-x] [-r] [-t]
       [--no-color] [--no-hup] [-e <ext>] [-w <watch>] [-i <ignore>]
       [-c <chdir>] [-d <delay>] [-l <lang>] <input> [<args>] ...

luamon

Arguments:
   input                 Input script to run
   args                  Script arguments

Options:
   -h, --help            Show this help message and exit.
   -v, --version         Print current luamon version and exit
   -q, --quiet           Be quiet, don't print any message
   -V, --verbose         Show details on what is causing restart
   -f, --fail-exit       Exit when the running command fails
   -o, --only-input      Watch only the input file for changes
   -s, --skip-first      Skip first run (wait for changes before running)
   -x, --exec            Execute a command instead of running a script
   -r, --restart         Automatically restart upon exit (run forever)
   -t, --term-clear      Clear terminal before each run
   --no-color            Don't colorize output
   --no-hup              Don't stop when terminal closes (SIGHUP signal)
      -e <ext>,          Extensions to watch, separated by commas (auto detected by default)
   --ext <ext>
        -w <watch>,      Directories to watch, separated by commas (default: .)
   --watch <watch>
         -i <ignore>,    Shell pattern of paths to ignore, separated by commas (default: .*)
   --ignore <ignore>
        -c <chdir>,      Change into directory before running the command
   --chdir <chdir>
        -d <delay>,      Delay between restart in milliseconds
   --delay <delay>
       -l <lang>,        Language runner to run (auto detected by default)
   --lang <lang>

Limitations

The packages depends on POSIX and Inotify APIs so it works only on systems that supports them, such as Linux.

License

MIT

luamon's People

Contributors

edubart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

dailyr linecode

luamon's Issues

Can't install on MacOS 11.4

❯ luarocks install luamon
Installing https://luarocks.org/luamon-0.5.2-1.src.rock
Missing dependencies for luamon 0.5.2-1:
   inotify >= 0.5.0 (not installed)
   penlight >= 1.7.0 (not installed)
   lua-term >= 0.7 (not installed)

luamon 0.5.2-1 depends on lua >= 5.1 (5.4-1 provided by VM)
luamon 0.5.2-1 depends on luaposix >= 34.0.4 (35.0-1 installed)
luamon 0.5.2-1 depends on luafilesystem >= 1.7.0 (1.8.0-1 installed)
luamon 0.5.2-1 depends on argparse >= 0.6.0 (0.7.1-1 installed)
luamon 0.5.2-1 depends on inotify >= 0.5.0 (not installed)
Installing https://luarocks.org/inotify-0.5-1.src.rock

Error: Failed installing dependency: https://luarocks.org/inotify-0.5-1.src.rock - Could not find header file for INOTIFY
  No file sys/inotify.h in /usr/local/include
  No file sys/inotify.h in /usr/include
  No file sys/inotify.h in /include
You may have to install INOTIFY in your system and/or pass INOTIFY_DIR or INOTIFY_INCDIR to the luarocks command.
Example: luarocks install inotify INOTIFY_DIR=/usr/local

dependencies

Not a bug!

I Needed these on a fresh ubuntu install:

luarocks install luamon INOTIFY_INCDIR=/usr/include/x86_64-linux-gnu

luarocks install luafilesystem

luarocks install penlight

Wait for child process to finish before restarting

Hi,

I'm using this to build latex files continuously while writing the source. Unfortunately some things break in my setup when aborting the build (some files containing caches kinda break).

It would be nice to have a flag "always wait for build to complete", which results in just completing the build and if normally a new build would run in the meantime, the already running build isn't aborted but only a flag is being set which issues an new build directly afterwards. I'd explicitly not be queuing this (just make a flag), to prevent that a huge amount of pending builds build up.

I'm not entirely sure how to add this to the existing project (thus this is only an issue and no PR), but maybe waitpid or kill(0) (to check if the child is still running) (see this post) can be used to achieve this.

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.