Permalink
Browse files

`brunch generate` now creates corresponding test.

Related: #120.
  • Loading branch information...
1 parent 093a27e commit 23f42768cd37fb4dd3560340fca255b494097110 @paulmillr paulmillr committed Jan 7, 2012
Showing with 25 additions and 10 deletions.
  1. +1 −1 CHANGELOG.md
  2. +21 −6 src/brunch.coffee
  3. +3 −3 src/command.coffee
View
@@ -14,7 +14,7 @@ located in separate repo,
* Added support for CoffeeScript in `vendor/scripts`.
* Added support for Stylus / LESS in `vendor/styles`.
* Templates have moved from `app/templates` to `app/views/templates`.
-* Command line API improved:
+* Updated command line API:
* `brunch build` and `brunch watch` now compile files in current working
directory (instead of in `./brunch/` subdir).
* Added `brunch generate` command. It's basically a shortcut for creating new
View
@@ -41,6 +41,7 @@ config.files['#{destinationPath}'].languages['#{regExp}']: #{error}.
# persistent - Should watcher be stopped after compiling the app first time?
# callback - Callback that would be executed on each compilation.
#
+# Returns `fs_utils.FSWatcher` object.
watchApplication = (rootPath, buildPath, config, persistent, callback) ->
if typeof buildPath is 'object'
[config, persistent, callback] = [buildPath, config, persistent]
@@ -121,7 +122,7 @@ exports.watch = (rootPath, buildPath, config, callback = (->)) ->
# Generate new controller / model / view and its tests.
#
# rootPath - path to application directory.
-# type - one of: collection, model, router, style, view
+# type - one of: collection, model, router, style, view.
# name - filename.
#
# Examples
@@ -133,7 +134,6 @@ exports.watch = (rootPath, buildPath, config, callback = (->)) ->
exports.generate = (rootPath, type, name, callback = (->)) ->
extension = switch type
when 'style' then 'styl'
- when 'template' then 'eco'
else 'coffee'
filename = "#{name}.#{extension}"
filePath = path.join rootPath, 'app', "#{type}s", filename
@@ -145,7 +145,22 @@ exports.generate = (rootPath, type, name, callback = (->)) ->
else
''
- fs.writeFile filePath, data, (error) ->
- return helpers.logError error if error?
- helpers.log "Generated #{filePath}"
- callback()
+ generateFile = (callback) ->
+ fs.writeFile filePath, data, (error) ->
+ return helpers.logError error if error?
+ helpers.log "Generated #{filePath}"
+ callback()
+
+ generateTests = (callback) ->
+ return callback() unless extension is 'coffee'
+ testFilePath = path.join(
+ rootPath, 'test', 'unit', "#{type}s", "#{name}_test.#{extension}"
+ )
+ fs.writeFile testFilePath, '', (error) ->
+ return helpers.logError error if error?
+ helpers.log "Generated #{testFilePath}"
+ callback()
+
+ generateFile ->
+ generateTests ->
+ callback()
View
@@ -45,7 +45,7 @@ commandLineConfig =
full: 'output'
callback: (options) ->
config = helpers.loadConfig 'config.coffee'
- brunch.build process.cwd(), options.buildPath, config
+ brunch.build '.', options.buildPath, config
watch:
help: 'Watch brunch directory and rebuild if something changed'
@@ -68,7 +68,7 @@ the server would run'
callback: (options) ->
config = helpers.loadConfig 'config.coffee'
config.port = options.port if options.server
- brunch.watch process.cwd(), options.buildPath, config
+ brunch.watch '.', options.buildPath, config
generate:
help: 'Generate model, view or route for current project'
@@ -85,7 +85,7 @@ the server would run'
metavar: 'NAME'
required: yes
callback: (options) ->
- brunch.generate process.cwd(), options.type, options.name
+ brunch.generate '.', options.type, options.name
options:
version:

0 comments on commit 23f4276

Please sign in to comment.