Browse files

add basic generator

  • Loading branch information...
1 parent d96d926 commit 19e5db236ef0e3f6110fc2f1743a9793115daba4 @maccman committed Feb 11, 2012
Showing with 58 additions and 3 deletions.
  1. +3 −0 README.md
  2. +32 −3 bin/ace
  3. +2 −0 generators/app.coffee
  4. +11 −0 generators/layout.eco
  5. +10 −0 generators/package.json
View
3 README.md
@@ -1,5 +1,8 @@
##Usage
+ npm install -g ace
+
+ ace myapp.js
ace myapp.coffee
##Response
View
35 bin/ace
@@ -15,7 +15,36 @@ try {
require('coffee-script');
} catch(e) { }
-filename = argv[0];
+var copy = function(from, to){
+ var data = fs.readFileSync(from, 'utf8');
+ fs.writeFileSync(to, data, 'utf8');
+};
+
+var command = argv[0];
+var filename = argv[1];
+
+if (filename) {
+ filename = path.resolve(filename);
+}
+
+if (command === 'new' && filename) {
+ fs.mkdirSync(filename, 0775);
+ fs.mkdirSync(filename + '/public', 0775);
+ fs.mkdirSync(filename + '/views', 0775);
+
+ var generatorPath = path.join(
+ __dirname, '..', 'generators'
+ );
+
+ copy(path.join(generatorPath, 'package.json'),
+ path.join(filename, 'package.json'));
+ copy(path.join(generatorPath, 'app.coffee'),
+ path.join(filename, 'app.coffee'));
+ copy(path.join(generatorPath, 'layout.eco'),
+ path.join(filename, 'views', 'layout.eco'));
+ console.log('Generated: ' + filename);
+ return;
+}
if ( !filename ) {
try {
@@ -31,11 +60,11 @@ if ( !filename ) {
if ( !filename ) {
console.log("Ace usage:");
- console.log("\tace PATH");
+ console.log("\tace new PATH");
+ console.log("\tace server PATH");
return;
}
-filename = path.resolve(filename);
process.chdir(path.dirname(filename));
var app = new App;
View
2 generators/app.coffee
@@ -0,0 +1,2 @@
+app.get '/', ->
+ 'Hello World!'
View
11 generators/layout.eco
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Application</title>
+</head>
+<body>
+ <div id="app">
+ <%- @body %>
+ </div>
+</body>
+</html>
View
10 generators/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "app",
+ "version": "0.0.1",
+ "author": "maccman",
+ "dependencies": {
+ "ace": "git://github.com/maccman/ace.git#master",
+ "coffee-script": "latest",
+ "eco": "latest"
+ }
+}

0 comments on commit 19e5db2

Please sign in to comment.