Permalink
Browse files

Changes to support new versions of node and npm.

  • Loading branch information...
1 parent 50a4f86 commit 712c8fee50fa858068cb5d82e3a427e5098843b0 @jefftrudeau committed Apr 18, 2011
Showing with 91 additions and 69 deletions.
  1. +8 −45 archetype.js
  2. +56 −1 cli.js
  3. +1 −1 lib/module/service.js
  4. +1 −1 lib/project/server.js
  5. +1 −1 lib/services/system.js
  6. +24 −20 package.json
View
@@ -8,48 +8,11 @@
* Copyright (C) Jeff Trudeau
*/
-var common = require('./lib/common'),
- pwd = process.env.PWD,
- util = require('util');
-
-var create_dir = function (path) {
- console.log('creating directory: '+path);
- common.dir.create(path);
-};
-
-var create_file = function (src, dst, re, str) {
- console.log('creating file: '+dst);
- common.file.writeFile(dst, common.file.read(src).replace(re, str));
-};
-
-var commands = {
-
- create_module: function (name, others) {
- ['model', 'route', 'service'].forEach(function (e, i) {
- create_file(__dirname+'/lib/module/'+e+'.js', pwd+'/'+e+'s/'+name+'.js', /%MODULE%/g, name);
- });
- create_file(__dirname+'/lib/module/template.html', pwd+'/templates/'+name+'_index.html', '', '');
- },
-
- create_project: function (name, others) {
- create_dir(pwd+'/'+name);
- ['models', 'routes', 'services', 'templates'].forEach(function (e, i) {
- create_dir(pwd+'/'+name+'/'+e);
- });
- ['option', 'server'].forEach(function (e, i) {
- create_file(__dirname+'/lib/project/'+e+'.js', pwd+'/'+name+'/'+e+'.js', /%PROJECT%/g, name);
- });
- }
-
-};
-
-(function () {
- var args = process.argv.splice(2),
- _args = {key: args.shift().replace(/-/, '_'), value: args.shift(), others: {}};
- for (var i in args) _args.others[args[i].split(/=/)[0]] = args[i].split(/=/)[1] || true;
- if (typeof(commands[_args.key]) == 'function') {
- console.log(_args.key+' called with '+_args.value+' and '+util.inspect(_args.others));
- commands[_args.key](_args.value, _args.others);
- }
- else console.log('archetype: ' + _args.key + ': command not found');
-})();
+this.common = require('./lib/common');
+this.database = require('./lib/database').database;
+this.log = require('./lib/log').log;
+this.option = require('./lib/option').option;
+this.route = require('./lib/route').route;
+this.server = require('./lib/server').server;
+this.service = require('./lib/service').service;
+this.template = require('./lib/template').template;
View
57 cli.js
@@ -1,2 +1,57 @@
#!/usr/bin/env node
-require('./archetype.js');
+var common = require('./archetype').common,
+ opt = require('optimist'),
+ pwd = process.env.PWD,
+ util = require('util');
+
+var create_dir = function (path) {
+ console.log('creating directory: '+path);
+ common.dir.create(path);
+};
+
+var create_file = function (src, dst, re, str) {
+ console.log('creating file: '+dst);
+ common.file.writeFile(dst, common.file.read(src).replace(re, str));
+};
+
+var commands = {
+
+ create_module: function (name, others) {
+ ['model', 'route', 'service'].forEach(function (e, i) {
+ create_file(__dirname+'/lib/module/'+e+'.js', pwd+'/'+e+'s/'+name+'.js', /%MODULE%/g, name);
+ });
+ create_file(__dirname+'/lib/module/template.html', pwd+'/templates/'+name+'_index.html', '', '');
+ },
+
+ create_project: function (name, others) {
+ create_dir(pwd+'/'+name);
+ ['models', 'routes', 'services', 'templates'].forEach(function (e, i) {
+ create_dir(pwd+'/'+name+'/'+e);
+ });
+ ['option', 'server'].forEach(function (e, i) {
+ create_file(__dirname+'/lib/project/'+e+'.js', pwd+'/'+name+'/'+e+'.js', /%PROJECT%/g, name);
+ });
+ }
+
+};
+
+(function () {
+ var args = opt.argv._.slice(), min = 2, valid = false;
+ if (args.length >= min) {
+ var key = args.shift().replace(/-/, '_');
+ if (typeof(commands[key]) == 'function') {
+ var value = args.shift(), others = {}, valid = true;
+ console.log(key+' called with '+value+' and '+util.inspect(others));
+ commands[key](value, others);
+ }
+ }
+ if (!valid)
+ opt.usage(
+'archetype: command-line interface to the archetype web framework for Node.js\n' +
+'Usage:\n' +
+' $0 [ options ] [ action ]\n' +
+'Options: []\n' +
+'Actions: [ create-project PROJECT ]\n' +
+' [ create-module MODULE ]\n'
+ ).demandCount(min).demand(['A valid action is required.']);
+})();
View
@@ -1,6 +1,6 @@
// automatically generated by archetype.js
-var models = require('archetype/database').database.models;
+var models = require('archetype').database.models;
this.index = function (request, response) {
models.%MODULE%.sync();
View
@@ -2,6 +2,6 @@
archetype_project_root = __dirname;
-var server = require('archetype/server').server;
+var server = require('archetype').server;
server.init();
View
@@ -8,7 +8,7 @@
* Copyright (C) Jeff Trudeau
*/
-var models = require('archetype/database').database.models;
+var models = require('archetype').database.models;
this.index = function (request, response) {
models.system.sync();
View
@@ -1,21 +1,25 @@
-{
- "name": "archetype",
- "version": "0.0.3",
- "author": "Jeff Trudeau <jeff.trudeau@gmail.com>",
- "bin": { "archetype": "./cli.js" },
- "dependencies": { "sequelize": ">=0.4.3" },
- "description": "A web framework leveraging Node.js",
- "engines": { "node": ">=0.2.6 <=0.3.5-pre" },
- "licenses": [ { "type": "GPL v2", "url": "http://www.gnu.org/licenses/gpl-2.0.txt" } ],
- "modules": {
- "common": "./lib/common",
- "database": "./lib/database",
- "log": "./lib/log",
- "option": "./lib/option",
- "route": "./lib/route",
- "server": "./lib/server",
- "service": "./lib/service",
- "template": "./lib/template"
- },
- "repository": { "type": "git", "url": "http://github.com/jefftrudeau/archetype.git" }
+{ "name": "archetype"
+, "version": "0.0.4"
+, "author": "Jeff Trudeau <jeff.trudeau@gmail.com>"
+, "bin": { "archetype": "./cli.js" }
+, "dependencies":
+ { "optimist": "~0.1.9"
+ , "sequelize": "~0.4.3"
+ }
+, "description": "A web framework leveraging Node.js"
+, "directories": { "lib": "./lib" }
+, "engines":
+ { "node": "~0.5.0-pre"
+ , "npm": "~1.0.1rc9"
+ }
+, "licenses":
+ [ { "type": "GPL v2"
+ , "url": "http://www.gnu.org/licenses/gpl-2.0.txt"
+ }
+ ]
+, "main": "./archetype.js"
+, "repository":
+ { "type": "git"
+ , "url": "http://github.com/jefftrudeau/archetype.git"
+ }
}

0 comments on commit 712c8fe

Please sign in to comment.