Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
a bunch of module crap
Browse files Browse the repository at this point in the history
build is now working with require -- for html and js files

remove html stuff.. it was cool as fuck, but just doesn't make sense for ender

tighten up depency copy and sex up codez

git local file includes with file analysis working for non --modules flag

i believe add is working again, but now with single files + analyzing... hoorays

quick asdfasldkfj
  • Loading branch information
fat committed Jun 24, 2011
1 parent 888ecdb commit 45798e5
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 160 deletions.
45 changes: 45 additions & 0 deletions bin/find-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env node
//adapted from node-jitsu's very excellent project require-analyzer
//https://github.com/nodejitsu/require-analyzer

var Module = require('module').Module
, __load = Module._load
, path = require('path')
, packages = {};

//
// Monkey punch `Module._load()` to observe the names
// of packages as they are loaded.
//
Module._load = function (name, parent) {
console.log('__!name::' + name);
console.log('__!path::' + (/^[./]/.test(name) ? Module._resolveFilename(name, parent)[1] : name));
return __load.apply(Module, arguments);
}

try {
process.nextTick(function () {
process.exit(0);
});

if (process.argv[3] === 'null') {
Module._load(process.argv[2], null, true)
} else {
//simulate module loading with correct paths from content
module = new Module(process.argv[2]);
module.paths = Module._nodeModulePaths(path.dirname(module.filename));
module._compile(process.argv[3], process.argv[2]);
}
}
catch (ex) {
//
// Log errors and attempt to log as many packages as we can.
//
var eStr = '' + (ex
? (ex.stack ? ex.stack : ex)
: 'falsey error: ' + ex)

eStr.split('\n').forEach(function (line) {
console.error('__!err::' + line);
});
}
104 changes: 104 additions & 0 deletions lib/ender.analyzer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//adapted from node-jitsu's require-analyzer
//analyzes js files for require statements
//https://github.com/nodejitsu/require-analyzer

var spawn = require('child_process').spawn
, path = require('path')
, CMD = require('./ender.cmd')
, NPM = require('./ender.npm');

var analyzer = module.exports = function (target, content, callback) {
console.log('analyzing ' + target + '...');

var packageNames = []
, packagePaths = []
, merged = {}
, errs = ['The following error was encountered while trying to parse ' + target.yellow]
, deps = spawn('node', [path.join(__dirname, '..', 'bin', 'find-dependencies'), target, content]);

function parseLines(data, prefix, fn) {
data = data.toString();
if (data !== '') {
data.toString().split('\n').filter(function (line) {
return line !== '';
}).forEach(function (line) {
if (line.indexOf(prefix) !== -1) {
line = line.replace(prefix, '');
fn(line);
}
});
}
}

deps.stdout.on('data', function (data) {
parseLines(data, '__!name::', function (dep) {
packageNames.push(dep);
});
parseLines(data, '__!path::', function (dep) {
packagePaths.push(dep);
});
});

deps.stderr.on('data', function (data) {
parseLines(data, '__!err::', function (line) {
errs.push(line);
});
});

var timeoutId = setTimeout(function () {
deps.kill();
}, 5000);

deps.on('exit', function () {
clearTimeout(timeoutId);
if (errs.length > 1) {
var last = packageNames[packageNames.length - 1];
if (last && !/^[.\/]/.test(last)) { //is NPM package...
console.log(('Pausing dependency analysis on ' + target).yellow);
console.log('The dependency ' + last.red + ' could not be found...');
CMD.ask(
'Would you like ender to install it [yes|no]?'.cyan, /(yes|no)/, function (data) {
if (data === 'yes') {
NPM.install([last], function () {
analyzer(target, content, callback);
});
} else {
console.log('continuing without ' + target + '\'s dependencies...');
callback(null, [packageNames[0]], [packagePaths[0]]);
}
}
);
} else {
askCallback(packageNames, packagePaths, target, callback);
}
} else {
askCallback(packageNames, packagePaths, target, callback);
}
});
};

function askCallback (packageNames, packagePaths, target, callback) {

if (packageNames.length > 1) {
console.log(('The following dependencies were found for ' + target + ':').yellow)

for (var head, i = 0, l = packageNames.length; i < l; i++) {
head = i == (packageNames.length - 1) ? '└' : '├';
console.log(' - ' + packageNames[i]);
}

CMD.ask(
'Would you like ender to include these in your ender build [yes|no]?'.cyan, /(yes|no)/, function (data) {
if (data === 'yes') {
callback(null, packageNames, packagePaths);
} else {
callback(null, [packageNames[0]], [packagePaths[0]]);
}
}
);
} else {
callback(null, packageNames, packagePaths);
}


}
30 changes: 25 additions & 5 deletions lib/ender.cmd.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*COMMAND METHODS*/
var UTIL = require('./ender.util');

module.exports = {
var UTIL = require('./ender.util')
, CMD = module.exports = {

process: function (cmd, callback) {
var args = typeof cmd == 'string' ? cmd.split(' ').slice(1) : cmd.slice(2)
Expand All @@ -18,9 +17,12 @@ module.exports = {
} else if (args[i] == '--use' || args[i] == '-u') {
options['use'] = args[i + 1] && args[i + 1].replace(/\.js$/, '');
args.splice(i, 2);
} else if (args[i] == '--silent' || args[i] == '-s') {
} else if (args[i] == '--silent' || args[i] == '-s') {
options['silent'] = true;
args.splice(i, 1);
} else if (args[i] == '--modules' || args[i] == '--commonJS') {
options['modules'] = true;
args.splice(i, 1);
} else if (args[i] == '--help') {
options['help'] = true;
args.splice(i, 1);
Expand All @@ -46,7 +48,25 @@ module.exports = {
}

, normalize: function (packages) {
return UTIL.reject(packages, ['ender-js']);
return UTIL.reject(packages, ['ender-js', 'ender-modules']);
}

, ask: function (question, format, callback) {
var stdin = process.stdin, stdout = process.stdout;

stdin.resume();
stdout.write(question + ": ");

stdin.once('data', function(data) {
data = data.toString().trim();

if (format.test(data)) {
callback(data);
} else {
stdout.write("Please respond with either yes or no...\n".red);
CMD.ask(question, format, callback);
}
});
}

};
Loading

0 comments on commit 45798e5

Please sign in to comment.