proper refactor, express to deps as it was missing
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/7c460a8a Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/7c460a8a Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/7c460a8a Branch: refs/heads/cordova-client Commit: 7c460a8a24c60a0d03de4cc6335a1632b937d49e Parents: 4681a89 Author: Fil Maj <maj....@gmail.com> Authored: Thu Jul 26 00:07:50 2012 -0700 Committer: Fil Maj <maj....@gmail.com> Committed: Thu Jul 26 00:07:50 2012 -0700 ---------------------------------------------------------------------- cordova.js | 96 ++++------------------------------------------------ package.json | 3 +- src/create.js | 35 +++++++++++++++++++ src/docs.js | 21 +++++++++++ src/help.js | 29 ++++++++++++++++ 5 files changed, 94 insertions(+), 90 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/7c460a8a/cordova.js ---------------------------------------------------------------------- diff --git a/cordova.js b/cordova.js index e26f774..e3149cc 100755 --- a/cordova.js +++ b/cordova.js @@ -1,91 +1,9 @@ -var fs = require('fs'), - path = require('path'), - util = require('util'), - exec = require('child_process').exec, - dist = process.env.CORDOVA_HOME !== undefined ? process.env.CORDOVA_HOME : path.join(__dirname, 'lib', 'cordova-1.9.0'), - colors = require('colors'), - wrench = require('wrench'), - config_parser = require('./src/config_parser'); - module.exports = { - help: function help () { - var raw = fs.readFileSync(path.join(__dirname, 'doc', 'help.txt')).toString('utf8').split("\n"); - return raw.map(function(line) { - if (line.match(' ')) { - var prompt = ' $ ', - isPromptLine = !(!(line.indexOf(prompt) != -1)); - if (isPromptLine) { - return prompt.green + line.replace(prompt, ''); - } - else { - return line.split(/\./g).map( function(char) { - if (char === '') { - return '.'.grey; - } - else { - return char; - } - }).join(''); - } - } - else { - return line.magenta; - } - }).join("\n"); - }, - docs: function docs () { - - var express = require('express'), - port = 2222, - static = path.join(dist, 'doc'), - server = express.createServer(); - - server.configure(function() { - server.use(express.static(static)); - server.use(express.errorHandler({ dumpExceptions: true, showStack: true })); - }); - - server.get('/', function(req, res) { - return res.render('index.html'); - }); - - console.log("\nServing Cordova/Docs at: ".grey + 'http://localhost:2222'.blue.underline + "\n"); - console.log('Hit ctrl + c to terminate the process.'.cyan); - server.listen(parseInt(port, 10)); - }, - create: function create (dir) { - if (dir === undefined) { - return module.exports.help(); - } - - - var mkdirp = wrench.mkdirSyncRecursive, - cpr = wrench.copyDirSyncRecursive; - if (dir && (dir[0] == '~' || dir[0] == '/')) { - } else { - dir = dir ? path.join(process.cwd(), dir) : process.cwd(); - } - - // Check for existing cordova project - // TODO: this should throw... - try { - if (fs.lstatSync(path.join(dir, '.cordova')).isDirectory()) { - console.error('Cordova project already exists at ' + dir + ', aborting.'); - return; - } - } catch(e) { /* no dirs, we're fine */ } - - // Create basic project structure. - mkdirp(path.join(dir, '.cordova')); - mkdirp(path.join(dir, 'platforms')); - mkdirp(path.join(dir, 'plugins')); - mkdirp(path.join(dir, 'www')); - - // Copy in base template - cpr(path.join(__dirname, 'templates', 'www'), path.join(dir, 'www')); - }, - platform:require('./src/platform'), - build:require('./src/build'), - emulate:require('./src/emulate'), - plugin:require('./src/plugin') + help: require('./src/help'), + docs: require('./src/docs'), + create: require('./src/create'), + platform: require('./src/platform'), + build: require('./src/build'), + emulate: require('./src/emulate'), + plugin: require('./src/plugin') }; http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/7c460a8a/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index c7282ad..6a376bc 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "wrench":"1.3.9", "elementtree":"0.1.1", "pluginstall":"git+https://github.com/filmaj/pluginstall.git", - "ncallbacks":"1.0.0" + "ncallbacks":"1.0.0", + "express":"3.0" }, "devDependencies": { "jasmine-node":">=1.0.0" http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/7c460a8a/src/create.js ---------------------------------------------------------------------- diff --git a/src/create.js b/src/create.js new file mode 100644 index 0000000..0296f70 --- /dev/null +++ b/src/create.js @@ -0,0 +1,35 @@ +var wrench = require('wrench'), + path = require('path'), + fs = require('fs'), + help = require('./help'), + mkdirp = wrench.mkdirSyncRecursive, + cpr = wrench.copyDirSyncRecursive; + +module.exports = function create (dir) { + if (dir === undefined) { + return help(); + } + + if (dir && (dir[0] == '~' || dir[0] == '/')) { + } else { + dir = dir ? path.join(process.cwd(), dir) : process.cwd(); + } + + // Check for existing cordova project + // TODO: this should throw... + try { + if (fs.lstatSync(path.join(dir, '.cordova')).isDirectory()) { + console.error('Cordova project already exists at ' + dir + ', aborting.'); + return; + } + } catch(e) { /* no dirs, we're fine */ } + + // Create basic project structure. + mkdirp(path.join(dir, '.cordova')); + mkdirp(path.join(dir, 'platforms')); + mkdirp(path.join(dir, 'plugins')); + mkdirp(path.join(dir, 'www')); + + // Copy in base template + cpr(path.join(__dirname, '..', 'templates', 'www'), path.join(dir, 'www')); +}; http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/7c460a8a/src/docs.js ---------------------------------------------------------------------- diff --git a/src/docs.js b/src/docs.js new file mode 100644 index 0000000..ba8bde0 --- /dev/null +++ b/src/docs.js @@ -0,0 +1,21 @@ +var express = require('express'), + path = require('path'), + colors = require('colors'), + port = 2222, + statik = path.join(__dirname, '..', 'doc'), + server = express.createServer(); + +module.exports = function docs () { + server.configure(function() { + server.use(express['static'](statik)); + server.use(express.errorHandler({ dumpExceptions: true, showStack: true })); + }); + + server.get('/', function(req, res) { + return res.render('index.html'); + }); + + console.log("\nServing Cordova/Docs at: ".grey + 'http://localhost:2222'.blue.underline + "\n"); + console.log('Hit ctrl + c to terminate the process.'.cyan); + server.listen(parseInt(port, 10)); +}; http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/7c460a8a/src/help.js ---------------------------------------------------------------------- diff --git a/src/help.js b/src/help.js new file mode 100644 index 0000000..05695ba --- /dev/null +++ b/src/help.js @@ -0,0 +1,29 @@ +var fs = require('fs'), + colors = require('colors'), + path = require('path'); + +module.exports = function help () { + var raw = fs.readFileSync(path.join(__dirname, '..', 'doc', 'help.txt')).toString('utf8').split("\n"); + return raw.map(function(line) { + if (line.match(' ')) { + var prompt = ' $ ', + isPromptLine = !(!(line.indexOf(prompt) != -1)); + if (isPromptLine) { + return prompt.green + line.replace(prompt, ''); + } + else { + return line.split(/\./g).map( function(char) { + if (char === '') { + return '.'.grey; + } + else { + return char; + } + }).join(''); + } + } + else { + return line.magenta; + } + }).join("\n"); +};