Skip to content

Commit 536bf59

Browse files
committed
meteor create --example
1 parent eef4357 commit 536bf59

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

app/meteor/meteor.js

+53-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var files = require('../lib/files.js');
22
var path = require('path');
33
var _ = require('../lib/third/underscore.js');
44
var deploy = require('./deploy');
5+
var fs = require("fs");
56

67
var usage = function() {
78
process.stdout.write(
@@ -102,7 +103,7 @@ Commands.push({
102103
"the .meteor directory in the root of the project.\n"
103104
);
104105

105-
new_argv = opt.argv;
106+
var new_argv = opt.argv;
106107

107108
if (argv.help) {
108109
process.stdout.write(opt.help());
@@ -130,12 +131,35 @@ Commands.push({
130131
name: "create",
131132
help: "Create a new project",
132133
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" +
136141
"\n" +
137142
"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());
139163
process.exit(1);
140164
}
141165

@@ -154,18 +178,31 @@ Commands.push({
154178
var transform = function (x) {
155179
return x.replace(/~name~/g, path.basename(name));
156180
};
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);
167191
}
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+
}
169206
}
170207
});
171208

install.sh

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ function CPR {
3333
cp meteor "$TARGET_DIR/bin"
3434
CPR app "$TARGET_DIR"
3535
CPR packages "$TARGET_DIR"
36+
CPR examples "$TARGET_DIR"
37+
rm -rf "$TARGET_DIR"/examples/unfinished
3638

3739
mkdir -p "$PARENT/bin"
3840
rm -f "$PARENT/bin/meteor"

0 commit comments

Comments
 (0)