Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test new app command, add library generator (doesnt work yet)

  • Loading branch information...
commit 3f18f4cc58ad83b6c098a0750999de2a6d8b967e 1 parent 02a4afd
@lancejpollard lancejpollard authored
Showing with 328 additions and 27 deletions.
  1. +1 −1  Watchfile
  2. +1 −1  lib/tower/server/command/generate.js
  3. +7 −4 lib/tower/server/command/new.js
  4. +49 −0 lib/tower/server/generator/generators/library/libraryGenerator.js
  5. +15 −0 lib/tower/server/generator/generators/library/templates/README.md
  6. 0  ...nerators/modules/moduleGenerator.coffee → lib/tower/server/generator/generators/library/templates/cake
  7. +35 −0 lib/tower/server/generator/generators/library/templates/gitignore
  8. 0  lib/tower/server/generator/generators/library/templates/index.coffee
  9. 0  lib/tower/server/generator/generators/library/templates/npmignore
  10. +55 −0 lib/tower/server/generator/generators/library/templates/pack
  11. +20 −0 lib/tower/server/generator/generators/library/templates/watch
  12. +0 −2  lib/tower/server/generator/generators/modules/moduleGenerator.js
  13. +1 −1  src/tower/server/command.coffee
  14. +1 −0  src/tower/server/command/console.coffee
  15. +1 −1  src/tower/server/command/generate.coffee
  16. +17 −14 src/tower/server/command/new.coffee
  17. +36 −0 src/tower/server/generator/generators/library/libraryGenerator.coffee
  18. +6 −0 test/cases/server/command/consoleCommandTest.coffee
  19. +7 −0 test/cases/server/command/generateCommandTest.coffee
  20. +66 −0 test/cases/server/command/newCommandTest.coffee
  21. +6 −0 test/cases/server/command/serverCommandTest.coffee
  22. +2 −1  test/cases/server/controller/resourcefulTest.coffee
  23. +1 −1  test/cases/server/generator/actionsTest.coffee
  24. +1 −1  test/cases/server/generator/appGeneratorTest.coffee
View
2  Watchfile
@@ -9,7 +9,7 @@ mint = require('mint')
require("design.io-javascripts")
compress: false
debug: false
- ignore: /(lib|public|node_modules|server\.js|spec|test|dist|generators\/.*\/templates)/
+ ignore: /(lib\/|public|node_modules|server\.js|spec|test|dist)/
#outputPath: (path) ->
# "spec/tmp/test.css"
write: (path, string) ->
View
2  lib/tower/server/command/generate.js
@@ -3,7 +3,7 @@ Tower.Command.Generate = (function() {
function Generate(argv) {
var program;
- this.program = program = require('commander');
+ this.program = program = new (require('commander').Command);
program.version(Tower.version).option('-v, --version').option('-h, --help', '\ \ Usage:\n\ \ tower generate <generator> <name> [attributes] [options]\n\ \ \n\ \ Generators:\n\ \ tower generate scaffold <name> [attributes] [options] generate model, views, and controller\n\ \ tower generate model <name> [attributes] [options] generate a model\n\ \ \n\ \ Options:\n\ \ -h, --help output usage information\n\ \ -v, --version output version number\n\ \ \n\ \ Examples:\n\ \ tower generate scaffold Post title:string body:text belongsTo:user\n\ \ tower generate model Post title:string body:text belongsTo:user\n\ \ ');
program.parse(argv);
program.help || (program.help = program.rawArgs.length === 3);
View
11 lib/tower/server/command/new.js
@@ -2,16 +2,19 @@
Tower.Command.New = (function() {
function New(argv) {
- var program;
- this.program = program = require('commander');
- program.version(Tower.version).option('--template <name>', 'Path to an application template (can be a filesystem path or URL)').option('--skip-procfile', "Don't create a Procfile (for Heroku)").option('--skip-git', "Skip Git ignores and keeps").option('--skip-assets', "Skip downloading javascripts, stylesheets, swfs, etc.").option('-T, --title <title>', 'Your project title (as opposed to its file name)').option('-D, --description <description>', 'Your project tagline (one sentence)', "").option('-K, --keywords <keywords>', 'Your project keywords (e.g. "node.js, file uploading, s3")', "").option('-n, --namespace <namespace>', 'Global namespace for your app (defaults to App)').option('-p, --persistence <name>', 'Preconfigure for selected database (options: mongodb)', "mongodb").option('-e, --engine <engine>', 'Preconfigure for template engine (options: coffeekup/jade/eco/ejs)').option('-s, --stylesheets <names>', 'Stylesheets to use (defaults to twitter-bootstrap)', "twitter-bootstrap").option('-t, --test <name>', 'Test framework (defaults to mocha)', "mocha").option('-d, --deployment <names>', 'Deployment options (defaults to heroku, only heroku works now)', "heroku").option('-w, --worker <names>', 'Background worker (defaults to kue)', "kue").option('-v, --version', 'output version number').option('-h, --help', '\ \ Usage:\n\ \ tower new <app-name> [options]\n\ \ \n\ \ Options:\n\ \ -T, --title <title> project title (as opposed to its file name)\n\ \ -D, --description <description> project tagline (one sentence)\n\ \ -K, --keywords <keywords> project keywords (e.g. "node.js, file uploading, s3")\n\ \ -n, --namespace <namespace> global namespace for your app (defaults to YourProjectName)\n\ \ -h, --help output usage information\n\ \ -v, --version output version number\n\ \ --skip-procfile skip creating a Procfile (for deploying to Heroku)\n\ \ --skip-git Skip Git ignores and keeps\n\ \ ');
+ var array, program;
+ this.program = program = new (require('commander').Command);
+ array = function(value) {
+ return value.split(/,?\s+/);
+ };
+ program.version(Tower.version).option('--template <name>', 'Path to an application template (can be a filesystem path or URL)').option('--skip-procfile [value]', "Don't create a Procfile (for Heroku)", false).option('--skip-git [value]', "Skip Git ignores and keeps", false).option('--skip-assets [value]', "Skip downloading javascripts, stylesheets, swfs, etc.", false).option('-T, --title <name>', 'Your project title (as opposed to its file name)').option('-D, --description <description>', 'Your project tagline (one sentence)', "").option('-K, --keywords <keywords>', 'Your project keywords (e.g. "node.js, file uploading, s3")', "").option('-n, --namespace <namespace>', 'Global namespace for your app (defaults to App)', "App").option('-p, --persistence <name>', 'Preconfigure for selected database (options: mongodb)', array, ["mongodb"]).option('-e, --engine <engine>', 'Preconfigure for template engine (options: coffeekup/jade/eco/ejs)', "coffee").option('-s, --stylesheets <names>', 'Stylesheets to use (defaults to twitter-bootstrap)', array, ["twitter-bootstrap"]).option('-t, --test <name>', 'Test framework (defaults to mocha)', "mocha").option('-d, --deployment <names>', 'Deployment options (defaults to heroku, only heroku works now)', array, ["heroku"]).option('-w, --worker <names>', 'Background worker (defaults to kue)', "kue").option('-v, --version', 'output version number').option('-h, --help', '\ \ Usage:\n\ \ tower new <app-name> [options]\n\ \ \n\ \ Options:\n\ \ -T, --title <title> project title (as opposed to its file name)\n\ \ -D, --description <description> project tagline (one sentence)\n\ \ -K, --keywords <keywords> project keywords (e.g. "node.js, file uploading, s3")\n\ \ -n, --namespace <namespace> global namespace for your app (defaults to YourProjectName)\n\ \ -h, --help output usage information\n\ \ -v, --version output version number\n\ \ --skip-procfile skip creating a Procfile (for deploying to Heroku)\n\ \ --skip-git Skip Git ignores and keeps\n\ \ ');
program.parse(argv);
program.help || (program.help = program.rawArgs.length === 3);
if (program.help) {
console.log(program.options[program.options.length - 1].description);
process.exit();
}
- program.namespace || (program.namespace = "App");
+ program;
}
New.prototype.run = function() {
View
49 lib/tower/server/generator/generators/library/libraryGenerator.js
@@ -0,0 +1,49 @@
+var __hasProp = Object.prototype.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+
+Tower.Generator.LibraryGenerator = (function(_super) {
+
+ __extends(LibraryGenerator, _super);
+
+ function LibraryGenerator() {
+ LibraryGenerator.__super__.constructor.apply(this, arguments);
+ }
+
+ LibraryGenerator.prototype.sourceRoot = __dirname;
+
+ LibraryGenerator.prototype.buildApp = function(name) {
+ var app;
+ if (name == null) name = this.appName;
+ app = LibraryGenerator.__super__.buildApp.call(this, name);
+ app.title = this.program.title || _.titleize(app.name);
+ app.description = this.program.description;
+ app.keywords = this.program.keywords;
+ return app;
+ };
+
+ LibraryGenerator.prototype.run = function() {
+ return this.inside(this.app.name, '.', function() {
+ if (!this.program.skipGitfile) this.template("gitignore", ".gitignore");
+ this.template("npmignore", ".npmignore");
+ this.template("cake", "Cakefile");
+ this.template("pack", "package.json");
+ this.template("README.md");
+ this.directory("lib");
+ this.inside("src", function() {
+ return this.template("index.coffee", "" + this.app.name + ".coffee");
+ });
+ this.inside("test", function() {
+ this.template("server.coffee");
+ this.template("client.coffee");
+ return this.template("mocha.opts");
+ });
+ this.directory("tmp");
+ return this.template("watch", "Watchfile");
+ });
+ };
+
+ return LibraryGenerator;
+
+})(Tower.Generator);
+
+module.exports = Tower.Generator.LibraryGenerator;
View
15 lib/tower/server/generator/generators/library/templates/README.md
@@ -0,0 +1,15 @@
+# <%= app.title %>
+
+## Install
+
+```
+npm install <%= app.name %>
+```
+
+## Test
+
+Run tests:
+
+```
+npm test
+```
View
0  ...nerator/generators/modules/moduleGenerator.coffee → ...erver/generator/generators/library/templates/cake
File renamed without changes
View
35 lib/tower/server/generator/generators/library/templates/gitignore
@@ -0,0 +1,35 @@
+## MAC OS
+.DS_Store
+*.gem
+## TEXTMATE
+*.tmproj
+tmtags
+
+## EMACS
+*~
+\#*
+.\#*
+
+## VIM
+*.swp
+
+## PROJECT::GENERAL
+coverage
+rdoc
+pkg
+*.log
+
+## PROJECT::SPECIFIC
+
+.project
+*~
+*.diff
+*.patch
+*.psd
+cdn/jquery-mobile/git
+.DS_Store
+cache/
+combined/
+combine/
+npm-debug.log
+tmp/
View
0  lib/tower/server/generator/generators/library/templates/index.coffee
No changes.
View
0  lib/tower/server/generator/generators/library/templates/npmignore
No changes.
View
55 lib/tower/server/generator/generators/library/templates/pack
@@ -0,0 +1,55 @@
+{
+ "name": "<%= app.name %>",
+ "private": true,
+ "version": "0.0.1",
+ "description": "<%= app.description %>",
+ "homepage": "http://<%= user.username %>.github.com/<%= app.name %>",
+ "main": "./server.js",
+ "author": "<%= user.name %> <<%= user.email %>>",
+ "keywords": [
+ "node"
+ ],
+ "maintainers": [{
+ "name": "<%= user.name %>",
+ "email": "<%= user.email %>"
+ }],
+ "contributors": [
+
+ ],
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://mths.be/mit"
+ }
+ ],
+ "bugs": {
+ "url": "https://github.com/<%= user.username %>/<%= app.name %>/issues"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/<%= user.username %>/<%= app.name %>.git"
+ },
+ "engines": {
+ "node": ">= 0.4.0",
+ "npm": "1"
+ },
+ "dependencies": {
+
+ },
+ "devDependencies": {
+ "coffee-script": ">= 1.1.3",
+ "pathfinder": ">= 0.3.0",
+ "mocha": ">= 0.12.1",
+ "chai": ">= 0.3.3",
+ "sinon": ">= 1.3.1",
+ "design.io": ">= 0.3.0",
+ "design.io-javascripts": ">= 0.3.0",
+ "design.io-stylesheets": ">= 0.3.0",
+ "forever": ">= 0.8.5"
+ },
+ "scripts": {
+ "test": "./node_modules/mocha/bin/mocha $(find test -name \"*Test.coffee\")",
+ "prepublish": "npm prune; rm -rf node_modules/*/{test,example,bench}*",
+ "start": "node server.js -e production"
+ }
+}
View
20 lib/tower/server/generator/generators/library/templates/watch
@@ -0,0 +1,20 @@
+require('design.io').extension('watchfile')
+
+async = require('async')
+File = require('pathfinder').File
+mint = require('mint')
+
+require("design.io-stylesheets") /(app\/client|lib\/stylesheets|vendor\/stylesheets)/
+ compress: false
+ debug: false
+ ignore: /(public|node_modules)/
+ paths: ["./app/client/stylesheets", "./vendor/stylesheets/bootstrap"]
+ outputPath: (path) ->
+ "public/stylesheets/#{path}".replace(/\.(sass|scss|stylus|styl|less|css)/, ".css")
+
+require("design.io-javascripts")
+ compress: false
+ debug: false
+ ignore: /(public|node_modules|server|app\/views)/
+ outputPath: (path) ->
+ "public/javascripts/#{path}".replace(/\.(js|coffee)/, ".js")
View
2  lib/tower/server/generator/generators/modules/moduleGenerator.js
@@ -1,2 +0,0 @@
-
-
View
2  src/tower/server/command.coffee
@@ -8,7 +8,7 @@ Tower.Command =
# Figure out the command you want to run, then run it.
#
- # @param [Array] argv
+ # @param [Array] argv Command line arguments (["node", "tower", "new", "blog"])
#
# @return [void]
run: (argv) ->
View
1  src/tower/server/command/console.coffee
@@ -25,6 +25,7 @@ class Tower.Command.Console
if program.help
console.log program.options[program.options.length - 1].description
process.exit()
+
Tower.env = @program.environment
run: ->
View
2  src/tower/server/command/generate.coffee
@@ -1,6 +1,6 @@
class Tower.Command.Generate
constructor: (argv) ->
- @program = program = require('commander')
+ @program = program = new (require('commander').Command)
# tower generate template
# tower generate model
View
31 src/tower/server/command/new.coffee
@@ -1,23 +1,26 @@
class Tower.Command.New
constructor: (argv) ->
- @program = program = require('commander')
-
+ @program = program = new (require('commander').Command)
+
+ array = (value) ->
+ value.split(/,?\s+/)
+
program
.version(Tower.version)
.option('--template <name>', 'Path to an application template (can be a filesystem path or URL)')
- .option('--skip-procfile', "Don't create a Procfile (for Heroku)")
- .option('--skip-git', "Skip Git ignores and keeps")
- .option('--skip-assets', "Skip downloading javascripts, stylesheets, swfs, etc.")
- .option('-T, --title <title>', 'Your project title (as opposed to its file name)')
+ .option('--skip-procfile [value]', "Don't create a Procfile (for Heroku)", false)
+ .option('--skip-git [value]', "Skip Git ignores and keeps", false)
+ .option('--skip-assets [value]', "Skip downloading javascripts, stylesheets, swfs, etc.", false)
+ .option('-T, --title <name>', 'Your project title (as opposed to its file name)')
.option('-D, --description <description>', 'Your project tagline (one sentence)', "")
.option('-K, --keywords <keywords>', 'Your project keywords (e.g. "node.js, file uploading, s3")', "")
- .option('-n, --namespace <namespace>', 'Global namespace for your app (defaults to App)')
- .option('-p, --persistence <name>', 'Preconfigure for selected database (options: mongodb)', "mongodb")
- .option('-e, --engine <engine>', 'Preconfigure for template engine (options: coffeekup/jade/eco/ejs)')
- .option('-s, --stylesheets <names>', 'Stylesheets to use (defaults to twitter-bootstrap)', "twitter-bootstrap")
+ .option('-n, --namespace <namespace>', 'Global namespace for your app (defaults to App)', "App")
+ .option('-p, --persistence <name>', 'Preconfigure for selected database (options: mongodb)', array, ["mongodb"])
+ .option('-e, --engine <engine>', 'Preconfigure for template engine (options: coffeekup/jade/eco/ejs)', "coffee")
+ .option('-s, --stylesheets <names>', 'Stylesheets to use (defaults to twitter-bootstrap)', array, ["twitter-bootstrap"])
.option('-t, --test <name>', 'Test framework (defaults to mocha)', "mocha")
# heroku, nodejitsu, dotcloud, etc.
- .option('-d, --deployment <names>', 'Deployment options (defaults to heroku, only heroku works now)', "heroku")
+ .option('-d, --deployment <names>', 'Deployment options (defaults to heroku, only heroku works now)', array, ["heroku"])
.option('-w, --worker <names>', 'Background worker (defaults to kue)', "kue")
.option('-v, --version', 'output version number')
.option '-h, --help', '''
@@ -37,14 +40,14 @@ class Tower.Command.New
'''
program.parse(argv)
-
+
program.help ||= program.rawArgs.length == 3
if program.help
console.log program.options[program.options.length - 1].description
process.exit()
-
- program.namespace ||= "App"
+
+ program
run: ->
Tower.Generator.run("app", program: @program, appName: @program.args[1])
View
36 src/tower/server/generator/generators/library/libraryGenerator.coffee
@@ -0,0 +1,36 @@
+class Tower.Generator.LibraryGenerator extends Tower.Generator
+ sourceRoot: __dirname
+
+ buildApp: (name = @appName) ->
+ app = super(name)
+
+ app.title = @program.title || _.titleize(app.name)
+ app.description = @program.description
+ app.keywords = @program.keywords
+
+ app
+
+ run: ->
+ @inside @app.name, '.', ->
+ @template "gitignore", ".gitignore" unless @program.skipGitfile
+ @template "npmignore", ".npmignore"
+
+ @template "cake", "Cakefile"
+ @template "pack", "package.json"
+ @template "README.md"
+
+ @directory "lib"
+
+ @inside "src", ->
+ @template "index.coffee", "#{@app.name}.coffee"
+
+ @inside "test", ->
+ @template "server.coffee"
+ @template "client.coffee"
+ @template "mocha.opts"
+
+ @directory "tmp"
+
+ @template "watch", "Watchfile"
+
+module.exports = Tower.Generator.LibraryGenerator
View
6 test/cases/server/command/consoleCommandTest.coffee
@@ -0,0 +1,6 @@
+command = ->
+ defaultArgs = ["node", "tower", "console"]
+ (new Tower.Command.Console(defaultArgs.concat(_.args(arguments)))).program
+
+describe "Tower.Command.Console", ->
+ describe "tower console", ->
View
7 test/cases/server/command/generateCommandTest.coffee
@@ -0,0 +1,7 @@
+command = ->
+ defaultArgs = ["node", "tower", "generate"]
+ (new Tower.Command.Generate(defaultArgs.concat(_.args(arguments)))).program
+
+describe "Tower.Command.Generate", ->
+ describe "tower generate scaffold", ->
+
View
66 test/cases/server/command/newCommandTest.coffee
@@ -0,0 +1,66 @@
+command = ->
+ defaultArgs = ["node", "tower", "new", "blog"]
+ (new Tower.Command.New(defaultArgs.concat(_.args(arguments)))).program
+
+describe "Tower.Command.New", ->
+ describe "tower new blog", ->
+ test "default", ->
+ assert.equal command().namespace, "App"
+
+ test "-n, --namespace", ->
+ assert.equal command("-n", "Blog").namespace, "Blog"
+ assert.equal command("--namespace", "Blog").namespace, "Blog"
+
+ test '--template', ->
+ template = "http://raw.github.com/viatropos/tower-generators/tree/master/lib/default.js"
+
+ assert.equal command("--template", template).template, template
+
+ test '--skip-procfile', ->
+ assert.isFalse command().skipProcfile
+ assert.isTrue command("--skip-procfile").skipProcfile
+
+ test '--skip-git', ->
+ assert.isFalse command().skipGit
+ assert.isTrue command("--skip-git").skipGit
+
+ test '--skip-assets', ->
+ assert.isFalse command().skipAssets
+ assert.isTrue command("--skip-assets").skipAssets
+
+ test '-T, --title', ->
+ assert.equal command().title, undefined
+ assert.equal command("-T", "My Blog").title, "My Blog"
+
+ test '-D, --description', ->
+ assert.equal command().description, ""
+ assert.equal command("-D", "A description").description, "A description"
+
+ test '-K, --keywords', ->
+ assert.equal command().keywords, ""
+ assert.equal command("-K", "ruby, javascript").keywords, "ruby, javascript"
+
+ test '-p, --persistence', ->
+ assert.deepEqual command().persistence, ["mongodb"]
+ assert.deepEqual command("--persistence", "mongodb redis").persistence, ["mongodb", "redis"]
+ assert.deepEqual command("--persistence", "mongodb, redis").persistence, ["mongodb", "redis"]
+
+ test '-e, --engine', ->
+ assert.equal command().engine, "coffee"
+ assert.equal command("--engine", "ejs").engine, "ejs"
+
+ test '-s, --stylesheets', ->
+ assert.deepEqual command().stylesheets, ["twitter-bootstrap"]
+ assert.deepEqual command("--stylesheets", "twitter-bootstrap compass").stylesheets, ["twitter-bootstrap", "compass"]
+
+ test '-t, --test', ->
+ assert.equal command().test, "mocha"
+ assert.equal command("--test", "jasmine").test, "jasmine"
+
+ test '-d, --deployment', ->
+ assert.deepEqual command().deployment, ["heroku"]
+ assert.deepEqual command("--deployment", "nodejitsu heroku").deployment, ["nodejitsu", "heroku"]
+
+ test '-w, --worker', ->
+ assert.deepEqual command().worker, "kue"
+ assert.deepEqual command("--worker", "coffee-resque").worker, "coffee-resque"
View
6 test/cases/server/command/serverCommandTest.coffee
@@ -0,0 +1,6 @@
+command = ->
+ defaultArgs = ["node", "tower", "server"]
+ (new Tower.Command.Server(defaultArgs.concat(_.args(arguments)))).program
+
+describe "Tower.Command.Server", ->
+ describe "tower server", ->
View
3  test/cases/server/controller/resourcefulTest.coffee
@@ -182,4 +182,5 @@ describeWith = (store) ->
done()
describeWith(Tower.Store.Memory)
-describeWith(Tower.Store.MongoDB)
+unless Tower.client
+ describeWith(Tower.Store.MongoDB)
View
2  test/cases/server/generator/actionsTest.coffee
@@ -75,4 +75,4 @@ describe 'Tower.Generator.Actions', ->
test '#appendToFile'
test '#appendFile'
test '#commentLines'
- test '#uncommentLines'
+ test '#uncommentLines'
View
2  test/cases/server/generator/appGeneratorTest.coffee
@@ -3,7 +3,7 @@ sourceRoot = null
destinationRoot = null
describe 'Tower.Generator.AppGenerator', ->
- beforeEach ->
+ before ->
sourceRoot = "#{process.cwd()}/lib/tower/server/generator/generators/tower/app"
destinationRoot = "#{process.cwd()}/test/tmp/myapp"
#generator = new Tower.Generator.AppGenerator(
Please sign in to comment.
Something went wrong with that request. Please try again.