EJSWEB(1) User Commands EJSWEB(1)
NAME
ejsweb - Ejscript Application Generator for Server-Side JavaScript Web
Applications.
SYNOPSIS
ejsweb [--apply]] [--database DB]] [--keep] [--layout layoutPage]
[--overwrite[--quiet[--reverse[--verbose] [commands ...]
DESCRIPTION
The ejsweb command generates, manages and runs Ejscript web applica-
tions. It can generate Ejscript web applications, controllers, data-
base migrations, models, scaffolds and views.
Ejsweb will create directories and generate configuration and source
code files which can then be manually edited as required. Ejsweb is
intelligent and will not overwrite existing files, so you can safely
edit and regenerate without losing your changes. You can overwrite your
changes if you wish to by using the --overwrite switch.
Ejsweb can run your application by invoking a configured web server.
GENERATING APPLICATIONS
To start a new web application, run ejsweb to create the application
directory and generate the application configuration and essential
script files. For example:
ejsweb generate app myApp
This will will create a set of directories which have the following
meaning:
.tmp - Temporary working directory
.ejs - State files used by ejsweb
bin - Programs and scripts
config - Configuration files
controllers - Controller source
db - Databases and scripts
db/migrations - Databases migration scripts
doc - Documentation for the application
logs - Log files
models - Database model code
messages - Internationalization messages
test - Unit tests
src - Extra application source code
utils - Program utilities
views - View source files
views/layouts - View layout files
web - Public web directory
web/images - Public images
web/js - Client side JavaScripts
web/themes - Application HTML themes
Most of these directories are initially empty, but may be used over
time. Ejscript follows conventions where specific files are stored.
This greatly simplifies configuring a web application.
Ejsweb will also create some files which have the following meaning:
config/config.ecf - Application configuration file
config/compiler.ecf - Compiler configuration file
config/database.ecf - Database configuration file
config/view.ecf - View connector configuration file
controllers/Base.es - Application base controller class
views/layouts/default.ejs - Default layout web page
web/layout.css - Default layout CSS file
web/themes/default.css - Default theme CSS file
web/js/jquery.js - Jquery client side script
README - Documentation explaining files and
directories
GENERATING CONTROLLERS
Controllers are the primary mechanism for responding to client
requests. To generate a controller, run:
ejsweb generate controller NAME [actions...]
This will create a controller of the requested name. It will create a
controller class file in the controllers directory. If action names are
requested, the controller class will define an action method for each
name. If not action names are requested, ejsweb will define a default
action named index. Actions are controller functions that are invoked
in response to client requests. You can edit the controller source to
meet your needs.
GENERATING MODELS
Database models are Ejscript classes that encapsulate database data and
provide access methods. They provide a conduit to interact with the
database. To generate a model:
ejsweb generate model MODEL [field:type ...]
This will create a database model and will generate a model class under
the models directory. It will also create a database migration to cre-
ate a database table of the same name as the model. If field:type val-
ues are supplied, the database migration will include code to create a
column for each specified field of the requested type. The valid data-
base types are: binary, boolean, date, datetime, decimal, float, inte-
ger, number, string, text, time, timestamp.
GENERATING SCAFFOLDS
A scaffold is a generated database migration, database model, con-
troller and set of views that provides add, edit and list functionality
for a database model. Scaffolds are useful to quickly generate chunks
of the application and prototype web pages and actions for managing a
datbase table. To generate a scaffold:
ejsweb generate scaffold MODEL [field:type ...]
This will create a scaffold for the specified database model and will
generate a controller of the same name. If field:type values are sup-
plied, the database migration will include code to create a column for
each specified field of the requested type. The valid database types
are: binary, boolean, date, datetime, decimal, float, integer, number,
string, text, time, timestamp. The scaffold will include an edit
action and view that provides add and edit capability. The list action
and view, provides the ability to list the database table rows and
select an entry to edit.
You can use the --apply switch to apply the database migration to
upgrade the database.
GENERATING MIGRATIONS
Database migrations are scripts which modify the database schema or
content. You can create database migrations by the ejsweb generate
migration command. This command generates a migration for a specific
model by creating or removing tables and columns. To generate a migra-
tion:
ejsweb generate migration description MODEL [field:type ...]
This will create a migration script under the db/migrations directory.
Migration scripts filenames are timestamped and use the description is
used as part of the filename for the migration script (so keep it short
and sweet).
For each specified field:type pair, ejsweb will generate add column
code in the migration script. If the --reverse switch is specified,
then remove column code will be generated. To change the type or name
of a column, remove then re-add the column.
APPLYING MIGRATIONS
Migration scripts can be run via the ejsweb migrate command. With not
other parameters, the command will run all migrations that have not yet
been applied to the database. You can also use ejsweb migrate forward
to apply apply the next unapplied migration. Similarly ejsweb migrate
backward will reverse the last applied migration. You can also use
ejsweb migrate NNN to migrate forward or backward to a specific migra-
tion. NNN is the migration sequence number which is the number at the
start of the migration script file name.
COMPILING
Ejscript compiles models, views and controllers into Ejscript byte-code
modules. These are then loaded and run by Ejscript in response to
incoming client requests. Code is compiled only once but can be run
many times to service incoming requests.
In development mode, Ejscript will automatically compile the relevant
portions of the application if the source code is modified. It can
intelligently recompile views, actions, controllers and database models
as required. However, you can also explicilty recompile portions or the
complete appliction.
Ejsweb can recompile everything via:
ejsweb compile ....
This will compile each controller and view and also recompile the
application and module source code. Module files for each component
will be generated.
Ejsweb also provides options for you to individually compile con-
trollers and views. To recompile named views or controllers:
ejsweb compile view NAMES....
ejsweb compile controller NAMES....
Models are compiled with application code into a single module file. To
recompile the models and application source code:
ejsweb compile app.
To compile the entire application and produce a single module file:
ejsweb compile all.
To compile stand-alone Ejscript web pages:
ejsweb compile path/name.ejs....
When compiling views, you can use the --keep switch to preserve the
intermediate generated Ejscript source file.
RUNNING
To run your application:
ejsweb run
This requires that your config/config.ecf file be modified to define
command to run your web server.
CLEANING
To clean all generated module files:
ejsweb clean
OPTIONS
Ejsweb has the following command usage patterns:
ejsweb clean
ejsweb compile [all | app | controller names | model names | view
names]
ejsweb compile path/name.ejs ...
ejsweb generate [app name | controller name [action [, action]
...]| model name]
ejsweb generate scaffold model [controller] [action [,
action]...]
ejsweb run
--database connector
Select a database connector to use. Currently this switch is not
implemented and sqlite is the only connector supported.
--keep
Preserve generated intermediate Ejscript source files. These
files are generated when blending views with layout pages.
--layout layoutPage
Change the name of the default layout page if a view does not
explicitly specify a layout page.
--overwrite
Overwrite existing files. Ejsweb normally will not overwrite
existing files. This is to preserve user changes to previously
generated files.
--search ejsPath
Set the module search path. The module search path is a set of
directories that the ejsweb command will use when locating and
loading Ejscript modules. The search path will always have some
system directories appended to the end. These include paths spec-
ified via the EJSPATH environment variable and key system direc-
tories such as the Ejscript system module directory and the
directory containing the ejsweb command.
The search path value is similar in format to the system PATH
variable format. On windows, path segments are separated by ";"
and on Linux, Unix, FreeBSD and MAC, the path segments are sepa-
rated by ":" delimiters.
Given a module named "a.b.c" in a script, ejsweb will use the
following search strategy to locate the module:
1. Search for a module file named "a.b.c.mod"
2. Search for a module file named "a/b/c.mod"
3. Search for a module file named "a.b.c.mod" in the search path
4. Search for a module file named c.mod in the search path
--verbose or -v
Run in verbose mode and trace actions to the console.
REPORTING BUGS
Report bugs to dev@embedthis.com.
COPYRIGHT
Copyright (C) 2004-2012 Embedthis Software. Ejscript is a trademark of
Embedthis Software.
SEE ALSO
ejsc, ejs, ejsmod, ejsvm
ejsweb March 2012 EJSWEB(1)