Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simplified skel template for new meteor apps.
meteor create --example doesn't require dirname.
meteor create --list instead of --list-examples.
  • Loading branch information
debergalis authored and n1mmy committed Apr 9, 2012
1 parent d7e35f3 commit 150a11b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 100 deletions.
36 changes: 21 additions & 15 deletions app/meteor/meteor.js
Expand Up @@ -134,49 +134,56 @@ Commands.push({
// reparse args
var opt = require('optimist')
.describe('example', 'Name of example application.')
.boolean('list-examples')
.describe('list-examples', 'Show list of available examples.')
.boolean('list')
.describe('list', 'Show list of available examples.')
.usage(
"Usage: meteor create [--example example_name] <name>\n" +
"Usage: meteor create <name>\n" +
" meteor create --example <example_name> [<name>]\n" +
"\n" +
"Make a subdirectory named <name> and create a new Meteor project\n" +
"there. You can also pass an absolute or relative path. Specify an\n" +
"example name to start with one of the example applications\n");

var new_argv = opt.argv;
var appname;

var example_dir = path.join(__dirname, '../../examples');
var examples = _.reject(fs.readdirSync(example_dir), function (e) {
return (e === 'unfinished');
});

if (new_argv['list-examples']) {
if (argv._.length === 1) {
appname = argv._[0];
} else if (argv._.length === 0 && new_argv.example) {
appname = new_argv.example;
}

if (new_argv['list']) {
process.stdout.write("Available examples:\n");
_.each(examples, function (e) {
process.stdout.write(" " + e + "\n");
});
process.exit(1);
};

if (argv.help || argv._.length !== 1 || !argv._[0].length) {
if (argv.help || !appname) {
process.stdout.write(opt.help());
process.exit(1);
}

var name = argv._[0];
if (path.existsSync(name)) {
process.stderr.write(name + ": Already exists\n");
if (path.existsSync(appname)) {
process.stderr.write(appname + ": Already exists\n");
process.exit(1);
}

if (files.find_app_dir(name)) {
if (files.find_app_dir(appname)) {
process.stderr.write(
"You can't create a Meteor project inside another Meteor project.\n");
process.exit(1);
}

var transform = function (x) {
return x.replace(/~name~/g, path.basename(name));
return x.replace(/~name~/g, path.basename(appname));
};

if (new_argv.example) {
Expand All @@ -187,19 +194,18 @@ Commands.push({
});
process.exit(1);
} else {
files.cp_r(path.join(example_dir, new_argv.example), name);
files.cp_r(path.join(example_dir, new_argv.example), appname);
}
} else {
files.cp_r(path.join(__dirname, 'skel'), name, {
files.cp_r(path.join(__dirname, 'skel'), appname, {
transform_filename: function (f) {
return transform(f);
},
transform_contents: function (contents, f) {
if (f.substr(-5) === ".html") {
if ((/(\.html|\.js|\.css)/).test(f))
return new Buffer(transform(contents.toString()));
} else {
else
return contents;
}
}
});
}
Expand Down
41 changes: 0 additions & 41 deletions app/meteor/skel/client/~name~.css

This file was deleted.

30 changes: 0 additions & 30 deletions app/meteor/skel/client/~name~.html

This file was deleted.

13 changes: 0 additions & 13 deletions app/meteor/skel/client/~name~.js

This file was deleted.

1 change: 0 additions & 1 deletion app/meteor/skel/model.js

This file was deleted.

Binary file removed app/meteor/skel/public/planes.png
Binary file not shown.
1 change: 1 addition & 0 deletions app/meteor/skel/~name~.css
@@ -0,0 +1 @@
/* CSS declarations go here */
15 changes: 15 additions & 0 deletions app/meteor/skel/~name~.html
@@ -0,0 +1,15 @@
<head>
<title>~name~</title>
</head>

<body>
{{> hello}}
</body>

<template name="hello">
<div class="hello">
<h1>Hello World!</h1>
{{greeting}}
<input type="button" value="Click" />
</div>
</template>
19 changes: 19 additions & 0 deletions app/meteor/skel/~name~.js
@@ -0,0 +1,19 @@
if (Meteor.is_client) {
Template.hello.greeting = function () {
return "Welcome to ~name~.";
};

Template.hello.events = {
'click input' : function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
}
};
}

if (Meteor.is_server) {
Meteor.startup(function () {
// code to run on server at startup
});
}

0 comments on commit 150a11b

Please sign in to comment.