-
Notifications
You must be signed in to change notification settings - Fork 23
/
generators.coffee
executable file
·146 lines (112 loc) · 4.18 KB
/
generators.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fs = require 'fs'
path = require 'path'
vows = require "vows"
assert = require "assert"
{FsUtil} = (require __dirname + "/../lib/toaster").toaster.utils
{spawn_toaster,snapshot} = require "./utils/utils"
# testing new project creation
# ------------------------------------------------------------------------------
vows.describe('Generators (-n, -i)')
.addBatch( 'A new project created':
# testing default values
# --------------------------------------------------------------------------
'with default values':
topic: ->
# console.log "topic"
# cleaning first
if fs.existsSync (folder = __dirname + "/_tmp/new_default_project")
# console.log "clean"
FsUtil.rmdir_rf folder
# console.log "spawn: " + folder
# spawning toaster
toaster = spawn_toaster ['-n', folder]
toaster.stdout.on 'data', (data)->
# console.log "data: "
# console.log data.toString()
question = data.toString()
if question.indexOf( "Path to your src folder" ) >= 0
toaster.stdin.write '\n'
else if question.indexOf( "Path to your release file" ) >= 0
toaster.stdin.write '\n'
else if question.indexOf( "Starting from your webroot" ) >= 0
toaster.stdin.write '\n'
toaster.stderr.on 'data', (data)=>
# console.log "data"
console.log data.toString()
@callback null, null
toaster.on 'exit', (code)=>
# console.log "exit"
model = snapshot "#{__dirname}/_templates/new_default_project"
created = snapshot "#{__dirname}/_tmp/new_default_project"
@callback model, created
# console.log "end"
undefined
'should match the default template':( model, created )->
assert.isObject model
assert.isObject created
for alias, contents of model
a = created[ alias ]
b = contents
assert.equal a, b
# testing custom values
# --------------------------------------------------------------------------
'with custom values':
topic: ->
# cleaning first
if fs.existsSync (folder = __dirname + "/_tmp/new_custom_project")
FsUtil.rmdir_rf folder
toaster = spawn_toaster ['-n', folder]
toaster.stdout.on 'data', (data)->
question = data.toString()
if question.indexOf( "Path to your src folder" ) >= 0
toaster.stdin.write 'custom_src'
else if question.indexOf( "Path to your release file" ) >= 0
toaster.stdin.write 'custom_www/custom_js/custom_app.js'
else if question.indexOf( "Starting from your webroot" ) >= 0
toaster.stdin.write 'custom_js'
toaster.stderr.on 'data', (data)->
console.log data.toString()
@callback null, null
toaster.on 'exit', (code)=>
model = snapshot "#{__dirname}/_templates/new_custom_project"
created = snapshot "#{__dirname}/_tmp/new_custom_project"
@callback model, created
undefined
'should match the custom template':( model, created )->
assert.isObject model
assert.isObject created
for alias, contents of model
a = created[ alias ]
b = contents
assert.equal a, b
# testing existent projects initialization
# ------------------------------------------------------------------------------
# vows.describe( "Initializing" )
).addBatch( 'A config file created for an existent project':
topic: ->
template = (__dirname + "/_templates/existing_project/toaster.coffee")
folder = (__dirname + "/_tmp/existing_project")
created = "#{folder}/toaster.coffee"
# cleaning first
FsUtil.rmdir_rf folder if fs.existsSync folder
fs.mkdirSync folder, "0777"
toaster = spawn_toaster ['-i', '_tmp/existing_project']
toaster.stdout.on 'data', (data)->
question = data.toString()
if question.indexOf( "Path to your src folder" ) >= 0
toaster.stdin.write 'src'
else if question.indexOf( "Path to your release file" ) >= 0
toaster.stdin.write 'www/js/app.js'
else if question.indexOf( "Starting from your webroot" ) >= 0
toaster.stdin.write 'js'
toaster.stderr.on 'data', (data)=>
console.log data.toString()
@callback null, null
toaster.on 'exit', (code)=>
model = fs.readFileSync template, "utf-8"
created = fs.readFileSync created, "utf-8"
@callback model, created
undefined
'should match the \'toaster.coffee\' template':( model, created )->
assert.equal true, true
).export module