Skip to main content

Streamline your web dev experience with stella - reload for the terminal as well as browser.

Project description

stella

stella_logo

stella_demo

Downloads

stella is a command line utility made for streamlining web development experience. It is able to reload server as well as the browser page on every file change. You can use it like any other file watcher too - with builtin .gitignore detection and obedience, along with several other features like multiple command execution, and the npm-scripts like interface.


📝 Table of Contents


⚡️ Installation

Using pipx (recommended):

pipx install stellapy

To upgrade:

pipx upgrade stellapy 

On Windows:

pip install -U stellapy

On Linux/MacOS:

pip3 install -U stellapy

💫 Motivation

I wanted a CLI that could live reload the browser page as well as live restart the server. I tried to find such a tool, but didn't find one. So I made stella - that could reload backend as well as frontend code. Also the builtin "debug modes" of web frameworks sucked.


⚙️ How does stella work?

stella continuously watches for file changes in the project, while respecting the gitignore file and whenever a change is made, it kills the existing process and spawns a new process using subprocess. What about browser reload? It uses selenium to accomplish that.


💡 Usage

This section briefly describes how to use the stella CLI.

init

stella init

The init command writes a default stella.yml config file in the working directory. The default configuration looks like this:

# yaml-language-server: $schema=https://raw.githubusercontent.com/shravanasati/stellapy/master/schema.json 
browser: firefox
include_only: []
poll_interval: 500
browser_wait_interval: 1000
scripts:
- name: default
  url: ''
  command: echo 'hello'
  shell: true

This yaml file comes with a schema which can be utilized by yaml language servers to provide autocompletion and validation to make sure the config is correct.

Configuration

Let's quickly go over the config options:

  • browser: This option specifies the browser to use when url is given. The only valid options for browser currently are firefox, chrome, edge and safari.

  • include_only: The list of gitignore-style patterns to consider for live reload. This will be used along with the ignore file (stella.ignore or .gitignore) to match files. eg. include_only: ["*.py", "*.env"].

  • poll_interval: The duration in milliseconds to poll the filesystem for changes. This has been modified past v0.3.0 - it now signifies the threshold duration for which stella should accept changes.

  • browser_wait_interval: This is the duration in milliseconds between the execution of given command on the terminal and browser page refresh. This can be used in situations when the server takes some time before it is ready to listen on a given port.

  • scripts: This the list of npm style scripts that take 4 parameters each.

    • name: Name of the script. To execute a certain script, use its name in the stella run SCRIPT_NAME command. The script named default will be used in case SCRIPT_NAME is not provided. Note that this parameter is case-insensitive, for convenience.

    • url: The URL to listen to on the browser. Set it to an empty string ('') if you don't want live reload on the browser. eg. localhost:8000.

      Note: For chrome and edge, URLs starting with localhost won't work, prepend the url with a scheme like http:// or file://. Not tested on safari, but if you see data; in the address bar, this URL change should fix it.

    • command: A single command or a list of commands to execute on the terminal. eg.

      command: python3 app.py
      
      command: 
        - go fmt ./...
        - go build
        - ./main.exe
      

      If a list of commands are provided, the shell will be considered true even if it's false, and these commands will be executed sequentially one after the other.

    • shell: Boolean value which indicates whether to execute commands inside a shell context (like bash, powershell, zsh...) or as an independent process. This is useful if you want to execute shell scripts directly without invoking the shell interpreter. On Windows, powershell is used as shell (instead of cmd). On Linux and MacOS, the shell used is determined by SHELL environment variable. If it's not present, /bin/sh will be used.

Ignore

You can create a stella.ignore file in the project with gitignore-style patterns to exclude certain directories and files to watch.

Otherwise, .gitignore also just works, and is the recommended way.

However, stella.ignore will be the first one that will be searched for. If it's not found, stella will resort to .gitignore.

Ignore patterns are cached once stella is started, similar to the stella configuration. If you change either of them, in order to see the desired changes, you need to either type rc and press enter or stop stella and run it again.

run

stella run SCRIPT_NAME
stella run SCRIPT_NAME --config-file /path/to/config/stella.yml

The run command is used to start stella. It expects one optional argument: the script name (case-insensitive) to run from the config file.

An optional --config-file (-c for short) flag can be used to specify the config file to be used. Alternatively, an environment variable named STELLA_CONFIG can be set for the same.

If not provided, stella will attempt to find stella.yml in the current directory or its parent folders until its found.

While stella is running, you can input rs to restart the server and refresh the browser page manually, and rb to refresh the browser page.

Since v0.3.0, you can also reload the stella configuration by typing rc and pressing enter. This will close the existing browser window and the running process, and restart the same script with the stella configuration.

To stop stella, input ex. It will close the browser as well as kill the running process gracefully (it sends SIGTERM on Unix based systems and CTRL_BREAK_EVENT on Windows).

If an error is encountered on refreshing the browser page (an event which can happen often, primarily due to server taking a long time to restart or the command failed to execute successfully), stella will retry with the exponential backoff strategy (2^n) until the browser refresh is successfull or a new change is detected.


📄 Licensing

License © 2021-Present Shravan Asati

This repository is licensed under the MIT license. See LICENSE for details.


👥 Contribution

Contribution is more than welcome. For more guidelines on contributing to stella, refer CONTRIBUTING.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stellapy-0.4.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

stellapy-0.4.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file stellapy-0.4.0.tar.gz.

File metadata

  • Download URL: stellapy-0.4.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.7-200.fc40.x86_64

File hashes

Hashes for stellapy-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2b4312dc73869d554e95c1b75e4eaf824fcac10b9ca5fd066cecb28ad9bbeb85
MD5 69db004270bacc8c4d16165947fedc95
BLAKE2b-256 8160959ffc49f028ae2e4bd2327ba1cc5d4d4a4bd3aab71bdaf052d6fdb35271

See more details on using hashes here.

File details

Details for the file stellapy-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: stellapy-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.7-200.fc40.x86_64

File hashes

Hashes for stellapy-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 04935885fc2fdc10a684f93d530281e91af16e1a3ce6e35b98e957788542a931
MD5 a336d6e18b276ae035d8ac2a3754eb80
BLAKE2b-256 c724ba1e374c1308d37e3edf8d846f61fc2e40290812729d2f07c690e6774feb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page