Command-Line Interface
JsWeb comes with a powerful command-line interface (CLI) that helps you manage your project, run the development server, and handle database migrations. The main command is jsweb
, and it must be run from your project's root directory.
jsweb new <project_name>
This command scaffolds a new JsWeb project, creating a standard directory structure and all the essential files to get you started quickly.
jsweb new my_awesome_app
It generates an app.py
, a config.py
with a unique secret key, and blueprints for views, authentication, and models, along with templates and static files.
jsweb run
Starts the built-in development server. It dynamically loads your application and configuration from the current directory.
jsweb run
Options:
--host <address>
: Specifies the host address to bind the server to (e.g.,0.0.0.0
to make it accessible from other devices on your network). This will override theHOST
setting in yourconfig.py
file.--port <number>
: Sets the port number for the server. This will override thePORT
setting in yourconfig.py
file.--reload
: Enables a development-friendly auto-reloader. The server will automatically restart whenever it detects changes in your project files, ensuring you don't have to stop and start it manually.--qr
: Displays a QR code in your terminal. Scanning this code on a mobile device will open your application, which is very useful for quick testing on phones and tablets on the same local network.
# Run with auto-reload on port 8080, accessible on the local network
jsweb run --reload --host 0.0.0.0 --port 8080
jsweb db
This is a group of commands for managing your database schema migrations with Alembic. It helps you keep your database structure in sync with your application's models.
jsweb db prepare
Compares your SQLAlchemy models in models.py
against the current state of the database and automatically generates a new migration script with the detected changes (e.g., new tables, columns, or modifications).
# After changing your models, run:
jsweb db prepare -m "Add a bio field to the User model"
The command will first check if your database is up-to-date. If not, it will prompt you to run db upgrade
first. It also gives you a readable preview of the changes before creating the script.
Options:
-m <message>
or--message <message>
: Provides a short, descriptive message for the migration. If you don't provide one, a message will be auto-generated based on the detected changes.
jsweb db upgrade
Applies all pending (unapplied) migration scripts to your database, bringing its schema up to the latest version defined by your models.
jsweb db upgrade
You should run this command after creating a new migration with jsweb db prepare
or when setting up your application in a new environment to initialize the database schema.