@@ -2,6 +2,7 @@ var files = require('../lib/files.js');
2
2
var path = require ( 'path' ) ;
3
3
var _ = require ( '../lib/third/underscore.js' ) ;
4
4
var deploy = require ( './deploy' ) ;
5
+ var fs = require ( "fs" ) ;
5
6
6
7
var usage = function ( ) {
7
8
process . stdout . write (
@@ -102,7 +103,7 @@ Commands.push({
102
103
"the .meteor directory in the root of the project.\n"
103
104
) ;
104
105
105
- new_argv = opt . argv ;
106
+ var new_argv = opt . argv ;
106
107
107
108
if ( argv . help ) {
108
109
process . stdout . write ( opt . help ( ) ) ;
@@ -130,12 +131,35 @@ Commands.push({
130
131
name : "create" ,
131
132
help : "Create a new project" ,
132
133
func : function ( argv ) {
133
- if ( argv . help || argv . _ . length !== 1 || ! argv . _ [ 0 ] . length ) {
134
- process . stdout . write (
135
- "Usage: meteor create <name>\n" +
134
+ // reparse args
135
+ var opt = require ( 'optimist' )
136
+ . describe ( 'example' , 'Name of example application.' )
137
+ . boolean ( 'list-examples' )
138
+ . describe ( 'list-examples' , 'Show list of available examples.' )
139
+ . usage (
140
+ "Usage: meteor create [--example example_name] <name>\n" +
136
141
"\n" +
137
142
"Make a subdirectory named <name> and create a new Meteor project\n" +
138
- "there. You can also pass an absolute or relative path.\n" ) ;
143
+ "there. You can also pass an absolute or relative path. Specify an\n" +
144
+ "example name to start with one of the example applications\n" ) ;
145
+
146
+ var new_argv = opt . argv ;
147
+
148
+ var example_dir = path . join ( __dirname , '../../examples' ) ;
149
+ var examples = _ . reject ( fs . readdirSync ( example_dir ) , function ( e ) {
150
+ return ( e === 'unfinished' ) ;
151
+ } ) ;
152
+
153
+ if ( new_argv [ 'list-examples' ] ) {
154
+ process . stdout . write ( "Available examples:\n" ) ;
155
+ _ . each ( examples , function ( e ) {
156
+ process . stdout . write ( " " + e + "\n" ) ;
157
+ } ) ;
158
+ process . exit ( 1 ) ;
159
+ } ;
160
+
161
+ if ( argv . help || argv . _ . length !== 1 || ! argv . _ [ 0 ] . length ) {
162
+ process . stdout . write ( opt . help ( ) ) ;
139
163
process . exit ( 1 ) ;
140
164
}
141
165
@@ -154,18 +178,31 @@ Commands.push({
154
178
var transform = function ( x ) {
155
179
return x . replace ( / ~ n a m e ~ / g, path . basename ( name ) ) ;
156
180
} ;
157
- files . cp_r ( path . join ( __dirname , 'skel' ) , name , {
158
- transform_filename : function ( f ) {
159
- return transform ( f ) ;
160
- } ,
161
- transform_contents : function ( contents , f ) {
162
- if ( f . substr ( - 5 ) === ".html" ) {
163
- return new Buffer ( transform ( contents . toString ( ) ) ) ;
164
- } else {
165
- return contents ;
166
- }
181
+
182
+ if ( new_argv . example ) {
183
+ if ( examples . indexOf ( new_argv . example ) === - 1 ) {
184
+ process . stderr . write ( "No such example application. Available examples include:\n" ) ;
185
+ _ . each ( examples , function ( e ) {
186
+ process . stdout . write ( " " + e + "\n" ) ;
187
+ } ) ;
188
+ process . exit ( 1 ) ;
189
+ } else {
190
+ files . cp_r ( path . join ( example_dir , new_argv . example ) , name ) ;
167
191
}
168
- } ) ;
192
+ } else {
193
+ files . cp_r ( path . join ( __dirname , 'skel' ) , name , {
194
+ transform_filename : function ( f ) {
195
+ return transform ( f ) ;
196
+ } ,
197
+ transform_contents : function ( contents , f ) {
198
+ if ( f . substr ( - 5 ) === ".html" ) {
199
+ return new Buffer ( transform ( contents . toString ( ) ) ) ;
200
+ } else {
201
+ return contents ;
202
+ }
203
+ }
204
+ } ) ;
205
+ }
169
206
}
170
207
} ) ;
171
208
0 commit comments