MVC(1)                           User Commands                          MVC(1)

NAME
       mvc  -  Ejscript  Application  Generator for Server-Side JavaScript Web
       Applications.

SYNOPSIS
       mvc [--apply]] [--database DB]] [--full] [--keep] [--layout layoutPage]
       [--listen port[--min[--overwrite[--quiet[--verbose] [commands ...]

DESCRIPTION
       The  mvc command generates, manages and runs Ejscript web applications.
       It can generate Ejscript web applications, controllers, database migra-
       tions, models, scaffolds and views.

       Mvc  will create directories and generate configuration and source code
       files which can then be manually edited as required.  Mvc  is  intelli-
       gent  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.

       Mvc can run your application by invoking a configured web server.

GENERATING APPLICATIONS
       To  start  a  new  web  application,  run mvc to create the application
       directory and generate  the  application  configuration  and  essential
       script files. For example:

             mvc generate app myApp

       This  will  will  create  a set of directories which have the following
       meaning:

             bin            - Programs and scripts
             cache          - Cached views and web pages
             controllers    - Controller source
             db             - Databases and scripts
             db/migrations  - Databases migration scripts
             layouts        - Template layout files
             models         - Database model code
             src            - Extra application source code
             views          - View source files
             static         - Public web directory
             static/images  - Public images
             static/js      - Client side JavaScripts
             static/themes  - Application HTML themes

       Ejscript follows conventions where  specific  files  are  stored.  This
       greatly simplifies configuring a web application.

       Mvc will also create some files which have the following meaning:

             ejsrc                       - Application configuration file
             controllers/Base.es         - Application base controller class
             layouts/default.ejs         - Default layout web page
             static/layout.css           - Default layout CSS file
             static/themes/default.css   - Default theme CSS file
             static/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:

             mvc 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,  mvc  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:

             mvc 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:

             mvc 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 mvc generate migra-
       tion command. This command generates a migration for a  specific  model
       by creating or removing tables and columns. To generate a migration:

             mvc 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, mvc 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 mvc 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 mvc migrate forward to
       apply apply the next unapplied migration. Similarly mvc  migrate  back-
       ward  will  reverse  the  last applied migration.  You can also use mvc
       migrate NNN to migrate forward or backward to a specific migration. 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.

       Mvc can recompile everything via:

             mvc 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.

       Mvc  also  provides options for you to individually compile controllers
       and views. To recompile named views or controllers:

             mvc compile view NAMES ...

             mvc compile controller NAMES ...

       Models are compiled with application code into a single module file. To
       recompile the models and application source code:

             mvc compile app

       To compile the entire application and produce a single module file:

             mvc compile all

       To compile stand-alone Ejscript web pages:

             mvc 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:

             mvc 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:

             mvc clean

OPTIONS
       Mvc has the following command usage patterns:

             mvc clean
             mvc  compile  [all  | app | controller names | model names | view
            names]
             mvc compile path/name.ejs ...
             mvc generate [app name | controller name [action [, action] ...]|
            model name]
             mvc generate scaffold model [controller] [action [, action]...]
             mvc 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. Mvc normally will not overwrite  exist-
             ing  files. This is to preserve user changes to previously gener-
             ated files.

       --search ejsPath
             Set the module search path. The module search path is  a  set  of
             directories that the mvc command will use when locating and load-
             ing Ejscript modules.  The search path will always have some sys-
             tem  directories  appended to the end. These include paths speci-
             fied via the  EJSPATH environment variable and key system  direc-
             tories  such  as  the  Ejscript  system  module directory and the
             directory containing the mvc 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, mvc will use the fol-
             lowing 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-2010 Embedthis Software.  Ejscript is a trademark of
       Embedthis Software.

SEE ALSO
       ejsc, ejs, ejsmod

mvc                              December 2011                          MVC(1)