-
Notifications
You must be signed in to change notification settings - Fork 120
Commands, Generators, and Tasks
tower new <app-name> [options]
tower server
Note:
node server
works the same, and is the preferred approach to starting the server purely because it's common practice to do it that way.
Use the Tower.js console to programmatically mess around with your application data (in CoffeeScript).
tower console
To run the console in plain JavaScript, use the -j
option:
tower console -j
You can also have async callbacks run synchronously using node-fibers
by adding the -s
flag:
tower console -s
It's nice to run the console synchronously so you can quickly see the values of database calls for example:
$ tower console -s
tower> App.Post.limit(3).all().toJSON()
tower> [ { id: 506ecc603f1b040000000023,
title: 'est,molestias,aperiam',
body: null,
createdAt: Fri Oct 05 2012 05:02:40 GMT-0700 (PDT),
updatedAt: Fri Oct 05 2012 18:07:41 GMT-0700 (PDT) },
{ id: 506ecc603f1b040000000024,
title: 'fugiat,quaerat,distinctio',
body: null,
createdAt: Fri Oct 05 2012 05:02:40 GMT-0700 (PDT),
updatedAt: Fri Oct 05 2012 18:07:41 GMT-0700 (PDT) },
{ id: 506f778abf9a500000000002,
title: null,
body: null,
createdAt: Fri Oct 05 2012 17:12:58 GMT-0700 (PDT),
updatedAt: Fri Oct 05 2012 17:26:59 GMT-0700 (PDT) } ]
tower>
Also, data will update live in the browser if you have http://localhost:3000 open and you change data from within the terminal. It does this through TCP (through socket.io) internally.
tower generate <generator> [args] [options]
Tower comes with a full application skeleton generator similar to the Rails variant. To use the app generator, simply execute the following in a console.
tower new my-app
The generated application will have the following structure:
|-- app
| |-- client
| | |-- stylesheets
| | | `-- application.stylus
| | |-- config
| | | `-- assets.coffee
| |-- controllers
| | `-- applicationController.coffee
| |-- models
| |-- views
| | |-- layouts
| | | `-- application.coffee
| | |-- index.coffee
| `-- helpers
| | `-- applicationHelper.coffee
|-- Cakefile
|-- config
| |-- application.coffee
| |-- environments
| | |-- development.coffee
| | |-- production.coffee
| | `-- test.coffee
| |-- locale
| | `-- en.coffee
| |-- routes.coffee
| |-- database.coffee
|-- lib
|-- package.json
|-- public
| |-- favicon.ico
| |-- humans.txt
| `-- robots.txt
|-- README.md
|-- spec
| |-- helper.coffee
| |-- models
| `-- acceptance
`-- vendor
| |-- javascripts
| | |-- tower.js
| | |-- underscore.js
| `-- stylesheets
`-- Watchfile
The following options are currently supported:
--javascripts <format> Format for JavaScripts (coffee, js)
--stylesheets <format> Format for StyleSheets (styl, less, css)
--views <format> Format for Views (coffee, jade, mustache)
--database <type> Database type (mongodb, memory, sqlite3)
--test <framework> Testing framework (jasmine, vows, qunit, assert)
--docs <format> Documentation format (md, markdown, textile, txt)
-v, --version Output the version number
-h, --help Output usage information
In a future release Tower will likely support a --locales
option.
$ tower generate scaffold post title:string body:text belongsTo:user
create : app/models/shared/post.coffee
create : test/factories/postFactory.coffee
update : app/config/server/assets.coffee
update : app/config/client/bootstrap.coffee
update : app/controllers/server/applicationController.coffee
update : data/seeds.coffee
create : test/cases/models/shared/postTest.coffee
update : app/config/server/assets.coffee
create : app/templates/shared/posts
create : app/templates/shared/posts/_flash.coffee
create : app/templates/shared/posts/_form.coffee
create : app/templates/shared/posts/_item.coffee
create : app/templates/shared/posts/_list.coffee
create : app/templates/shared/posts/_table.coffee
create : app/templates/shared/posts/edit.coffee
create : app/templates/shared/posts/index.coffee
create : app/templates/shared/posts/new.coffee
create : app/templates/shared/posts/show.coffee
create : app/views/client/posts/form.coffee
update : app/config/server/assets.coffee
create : app/views/client/posts/index.coffee
update : app/config/server/assets.coffee
create : app/views/client/posts/show.coffee
update : app/config/server/assets.coffee
create : app/controllers/server/postsController.coffee
create : app/controllers/client/postsController.coffee
update : app/config/shared/routes.coffee
update : app/templates/shared/layout/_navigation.coffee
update : app/config/shared/locales/en.coffee
update : app/config/server/assets.coffee
create : test/cases/controllers/server/postsControllerTest.coffee
You can also pass options to the attibute inside square brackets!
$ tower generate scaffold post title:string[required:true,min:5] body:text active:boolean[default:false] belongsTo:author[type:user]
tower generate model post title:string body:text belongsTo:user
Generates:
|-- app
| |-- models
| | | `-- post.coffee
The Post model generated:
class App.Post extends Tower.Model
@field "id", type: "Id"
@field "title"
@field "body"
@belongs_to "user", type: "User", foreignKey: "userId"
@field "createdAt", type: "Time", default: -> new Date()
tower generate view Post title:string body:text belongsTo:user
Generates:
|-- app
| |-- views
| | |-- users
| | | `-- _form.coffee
| | | `-- edit.coffee
| | | `-- index.coffee
| | | `-- new.coffee
| | | `-- show.coffee
To create a Controller for the User model, execute the Controller Generator like this:
tower generate controller Post
The controller should generate a single controller file:
|-- app
| |-- controllers
| | | `-- postsController.coffee
The controller will initially be empty:
class App.PostsController extends Tower.Controller
Fill it out as needed:
class App.PostsController extends Tower.Controller
@respondTo "html", "json"
new: ->
@posts = Post.all()