Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pulled out demo app, migrated installation and app-gen to Jake.

  • Loading branch information...
commit 91599f54e1957fe1cde2506fe8af05d1ff226bb3 1 parent d9f5899
mde authored
View
8 Makefile
@@ -2,6 +2,12 @@
all: install
+#install:
+# mkdir -p ~/.node_libraries/geddy; cp -R lib ~/.node_libraries/geddy/; cp -R scripts ~/.node_libraries/geddy/; cp scripts/geddy-gen /usr/local/bin/; cp scripts/geddy /usr/local/bin/
+
install:
- mkdir -p ~/.node_libraries/geddy; cp -R lib ~/.node_libraries/geddy/; cp -R scripts ~/.node_libraries/geddy/; cp scripts/geddy-gen /usr/local/bin/; cp scripts/geddy /usr/local/bin/
+ mkdir -p ~/.node_libraries/jake; cp ./scripts/jake.js ~/.node_libraries/jake/; cp ./scripts/jake /usr/local/bin; jake -f `pwd`/scripts/Jakefile default asdf:ASDF, foo=bar
+
+clean:
+ rm -fr ~/.node_libraries/geddy; rm /usr/local/bin/geddy*
View
59 scripts/Jakefile.js
@@ -0,0 +1,59 @@
+var sys = require('sys');
+
+exports.tasks = {
+ 'default': {
+ 'desc': 'Installs the Geddy Web-app development framework',
+ 'task': function (env) {
+ sys.puts('Installing Geddy ...');
+ var cmds = [
+ 'mkdir -p ~/.node_libraries/geddy',
+ 'cp -R lib ~/.node_libraries/geddy/',
+ 'cp -R scripts ~/.node_libraries/geddy/',
+ 'cp scripts/geddy-gen /usr/local/bin/',
+ 'cp scripts/geddy /usr/local/bin/'
+ ];
+ runCmds(cmds);
+ }
+ },
+
+ 'app': {
+ 'desc': 'Creates a new Geddy app scaffold.',
+ 'task': function (env) {
+ var dir = env.appName;
+ sys.puts('Creating app ' + dir);
+ var cmds = [
+ 'mkdir -p ./' + dir,
+ 'mkdir -p ./' + dir + '/config',
+ 'mkdir -p ./' + dir + '/app/controllers',
+ 'mkdir -p ./' + dir + '/public',
+ 'cp ~/.node_libraries/geddy/scripts/gen/router.js ' + dir + '/config/',
+ 'cp ~/.node_libraries/geddy/scripts/gen/main.js ' + dir + '/app/controllers/'
+ ]
+ runCmds(cmds);
+ }
+ }
+
+};
+
+var runCmds = function (arr) {
+ var run = function (cmd) {
+ sys.exec(cmd, function (err, stdout, stderr) {
+ if (err) {
+ sys.puts('Error: ' + JSON.stringify(err));
+ }
+ else if (stderr) {
+ sys.puts('Error: ' + stderr);
+ }
+ else {
+ if (arr.length) {
+ var next = arr.shift();
+ run(next);
+ }
+ else {
+ }
+ }
+ });
+ };
+ run(arr.shift());
+};
+
View
3  scripts/foo
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo $@
View
10 scripts/geddy-gen
@@ -1,10 +1,4 @@
#!/bin/bash
-if [ $1 = 'app' ]; then
- mkdir $2
- mkdir $2/config
- cp ~/.node_libraries/geddy/scripts/router.js $2/config/
- mkdir -p $2/app/controllers
- cp ~/.node_libraries/geddy/scripts/main.js $2/app/controllers/
- mkdir $2/public
-fi
+node ~/.node_libraries/jake/jake.js -f ~/.node_libraries/geddy/scripts/Jakefile $1 appName=$2
+
View
0  scripts/main.js → scripts/gen/main.js
File renamed without changes
View
0  scripts/router.js → scripts/gen/router.js
File renamed without changes
View
0  scripts/users.js → scripts/gen/users.js
File renamed without changes
View
4 scripts/jake
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+node ~/.node_libraries/jake/jake.js $@
+
View
86 scripts/jake.js
@@ -0,0 +1,86 @@
+var sys = require('sys');
+var args = process.argv.slice(2);
+
+var opts = {};
+var optsReg = {
+ directory: ['-C', '--directory'],
+ jakefile: ['-f', '--file']
+};
+var optsReverseMap = {};
+var optsItem;
+for (var p in optsReg) {
+ opts[p] = null;
+ optsItem = optsReg[p];
+ for (var i = 0; i < optsItem.length; i++) {
+ optsReverseMap[optsItem[i]] = p;
+ }
+}
+
+var taskName;
+var arg;
+var argName;
+var argItems;
+
+while (args.length) {
+ if (taskName) {
+ break;
+ }
+ arg = args.shift();
+ if (arg.indexOf('--') == 0) {
+ argItems = arg.split('=');
+ argName = optsReverseMap[argItems[0]];
+ if (argName) {
+ opts[argName] = argItems[1];
+ }
+ else {
+ throw new Error('Unknown option "' + argItems[0] + '"');
+ }
+ }
+ else if (arg.indexOf('-') == 0) {
+ argName = optsReverseMap[arg];
+ if (argName) {
+ opts[argName] = args.shift();
+ }
+ else {
+ throw new Error('Unknown option "' + arg + '"');
+ }
+ }
+ else {
+ taskName = arg;
+ }
+}
+
+taskName = taskName || 'default';
+opts.jakefile = opts.jakefile || './Jakefile';
+
+if (opts.directory) {
+ process.chdir(opts.directory);
+}
+var tasks = require(opts.jakefile).tasks;
+
+var jake = new function () {
+ this.runTask = function (name, args) {
+ var task = tasks[name];
+ var deps = task.deps;
+ if (deps && deps instanceof Array) {
+ for (var i = 0; i < deps.length; i++) {
+ this.runTask.call(this, deps[i], args);
+ }
+ }
+ task.task.call(task, this.processArgs(args));
+ };
+
+ this.processArgs = function (args) {
+ var pat = /:|=/;
+ var ret = {};
+ var argItems;
+ for (var i = 0; i < args.length; i++) {
+ argItems = args[i].split(pat);
+ ret[argItems[0]] = argItems[1];
+ }
+ return ret;
+ };
+
+}();
+
+jake.runTask(taskName, args);
Please sign in to comment.
Something went wrong with that request. Please try again.