Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken build and use browserify + uglify-js to build new artifacts. #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ BIN=./node_modules/.bin
MOCHA=$(BIN)/mocha
COFFEE=$(BIN)/coffee --js
CJSIFY=$(BIN)/cjsify --export Bencode src/index.coffee
BROWSERIFY=$(BIN)/browserify
UGLIFY=$(BIN)/uglifyjs

SRCS = $(shell find src -name "*.coffee" -type f | sort)
LIBS = $(SRCS:src/%.coffee=lib/%.js)
Expand All @@ -14,10 +16,10 @@ lib/%.js: src/%.coffee
$(COFFEE) <"$<" >"$@"

browser: bencode.js bencode-min.js
bencode.js: $(SRCS)
$(CJSIFY) --no-node > bencode.js
bencode-min.js: $(SRCS)
$(CJSIFY) --no-node --minify > bencode-min.js
bencode.js: $(LIBS)
$(BROWSERIFY) lib/index.js --standalone Bencode > $@
bencode-min.js: bencode.js
$(UGLIFY) $< > $@

.PHONY: test

Expand Down
2 changes: 1 addition & 1 deletion bencode-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

292 changes: 132 additions & 160 deletions bencode.js
Original file line number Diff line number Diff line change
@@ -1,166 +1,138 @@
(function (global) {
function require(file, parentModule) {
if ({}.hasOwnProperty.call(require.cache, file))
return require.cache[file];
var resolved = require.resolve(file);
if (!resolved)
throw new Error('Failed to resolve module ' + file);
var module$ = {
id: file,
require: require,
filename: file,
exports: {},
loaded: false,
parent: parentModule,
children: []
};
if (parentModule)
parentModule.children.push(module$);
var dirname = file.slice(0, file.lastIndexOf('/') + 1);
require.cache[file] = module$.exports;
resolved.call(module$.exports, module$, module$.exports, dirname, file);
module$.loaded = true;
return require.cache[file] = module$.exports;
}
require.modules = {};
require.cache = {};
require.resolve = function (file) {
return {}.hasOwnProperty.call(require.modules, file) ? require.modules[file] : void 0;
};
require.define = function (file, fn) {
require.modules[file] = fn;
};
require.define('/src/index.coffee', function (module, exports, __dirname, __filename) {
module.exports = {
encode: require('/src/encode.coffee', module),
decode: require('/src/decode.coffee', module)
};
});
require.define('/src/decode.coffee', function (module, exports, __dirname, __filename) {
var read;
read = function (str) {
var arr, bencoded, cache$, cache$1, cursor, key, keyLength, obj, startPos, stringLength, value, valueLength;
switch (str[0]) {
case 'i':
bencoded = str.match(/^i-?\d+e/)[0];
return [
bencoded.length,
+bencoded.slice(1, -1)
];
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
stringLength = str.match(/^\d+/)[0];
startPos = stringLength.length + 1;
bencoded = str.slice(0, startPos + +stringLength);
return [
bencoded.length,
bencoded.slice(startPos)
];
case 'l':
cursor = 1;
arr = function (accum$) {
var cache$, entry, entryLength;
while (str[cursor] !== 'e') {
cache$ = read(str.slice(cursor));
entryLength = cache$[0];
entry = cache$[1];
cursor += entryLength;
accum$.push(entry);
}
return accum$;
}.call(this, []);
return [
cursor + 1,
arr
];
case 'd':
cursor = 1;
obj = {};
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Bencode = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// Generated by CoffeeScript 2.0.0-beta4
void function () {
var read;
read = function (str) {
var arr, bencoded, cache$, cache$1, cursor, key, keyLength, obj, startPos, stringLength, value, valueLength;
switch (str[0]) {
case 'i':
bencoded = str.match(/^i-?\d+e/)[0];
return [
bencoded.length,
+bencoded.slice(1, -1)
];
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
stringLength = str.match(/^\d+/)[0];
startPos = stringLength.length + 1;
bencoded = str.slice(0, startPos + +stringLength);
return [
bencoded.length,
bencoded.slice(startPos)
];
case 'l':
cursor = 1;
arr = function (accum$) {
var cache$, entry, entryLength;
while (str[cursor] !== 'e') {
cache$ = read(str.slice(cursor));
keyLength = cache$[0];
key = cache$[1];
cache$1 = read(str.slice(cursor + keyLength));
valueLength = cache$1[0];
value = cache$1[1];
cursor += keyLength + valueLength;
obj[key] = value;
}
return [
cursor + 1,
obj
];
}
};
module.exports = function (str) {
return read(str)[1];
};
});
require.define('/src/encode.coffee', function (module, exports, __dirname, __filename) {
var encode, encodeDictionary, encodeInteger, encodeList, encodeString;
encodeString = function (s) {
return '' + s.length + ':' + s;
};
encodeInteger = function (i) {
return 'i' + i + 'e';
};
encodeList = function (array) {
var encodedContents;
encodedContents = function (accum$) {
var object;
for (var i$ = 0, length$ = array.length; i$ < length$; ++i$) {
object = array[i$];
accum$.push(encode(object));
entryLength = cache$[0];
entry = cache$[1];
cursor += entryLength;
accum$.push(entry);
}
return accum$;
}.call(this, []).join('');
return 'l' + encodedContents + 'e';
};
encodeDictionary = function (object) {
var encodedContents, keys;
keys = function (accum$) {
var key;
for (key in object) {
if (!isOwn$(object, key))
continue;
accum$.push(key);
}
return accum$;
}.call(this, []).sort();
encodedContents = function (accum$) {
var key;
for (var i$ = 0, length$ = keys.length; i$ < length$; ++i$) {
key = keys[i$];
accum$.push('' + encode(key) + encode(object[key]));
}
return accum$;
}.call(this, []).join('');
return 'd' + encodedContents + 'e';
};
encode = function (object) {
switch (false) {
case !(typeof object === 'string'):
return encodeString(object);
case !(typeof object === 'number'):
return encodeInteger(0 | object);
case !('[object Array]' === {}.toString.call(object)):
return encodeList(object);
default:
return encodeDictionary(object);
}.call(this, []);
return [
cursor + 1,
arr
];
case 'd':
cursor = 1;
obj = {};
while (str[cursor] !== 'e') {
cache$ = read(str.slice(cursor));
keyLength = cache$[0];
key = cache$[1];
cache$1 = read(str.slice(cursor + keyLength));
valueLength = cache$1[0];
value = cache$1[1];
cursor += keyLength + valueLength;
obj[key] = value;
}
};
module.exports = encode;
function isOwn$(o, p) {
return {}.hasOwnProperty.call(o, p);
return [
cursor + 1,
obj
];
}
});
global.Bencode = require('/src/index.coffee');
}.call(this, this));
};
module.exports = function (str) {
return read(str)[1];
};
}.call(this);

},{}],2:[function(require,module,exports){
// Generated by CoffeeScript 2.0.0-beta8
void function () {
var encode, encodeDictionary, encodeInteger, encodeList, encodeString;
encodeString = function (s) {
return '' + s.length + ':' + s;
};
encodeInteger = function (i) {
return 'i' + i + 'e';
};
encodeList = function (array) {
var encodedContents, object;
encodedContents = function (accum$) {
for (var i$ = 0, length$ = array.length; i$ < length$; ++i$) {
object = array[i$];
accum$.push(encode(object));
}
return accum$;
}.call(this, []).join('');
return 'l' + encodedContents + 'e';
};
encodeDictionary = function (object) {
var encodedContents, key, keys;
keys = function (accum$) {
for (key in object) {
if (!isOwn$(object, key))
continue;
accum$.push(key);
}
return accum$;
}.call(this, []).sort();
encodedContents = function (accum$1) {
for (var i$ = 0, length$ = keys.length; i$ < length$; ++i$) {
key = keys[i$];
accum$1.push('' + encode(key) + encode(object[key]));
}
return accum$1;
}.call(this, []).join('');
return 'd' + encodedContents + 'e';
};
encode = function (object) {
switch (false) {
case !(typeof object === 'string'):
return encodeString(object);
case !(typeof object === 'number'):
return encodeInteger(Math.floor(object));
case !('[object Array]' === {}.toString.call(object)):
return encodeList(object);
default:
return encodeDictionary(object);
}
};
module.exports = encode;
function isOwn$(o, p) {
return {}.hasOwnProperty.call(o, p);
}
}.call(this);

},{}],3:[function(require,module,exports){
// Generated by CoffeeScript 2.0.0-beta4
module.exports = {
encode: require('./encode'),
decode: require('./decode')
};

},{"./decode":1,"./encode":2}]},{},[3])(3)
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
, "mocha" : ">=1.8.2"
, "coffee-script-redux" : "2.0.0-beta8"
, "commonjs-everywhere" : "~0.6.1"
, "browserify" : "^14.5.0"
, "uglify-js" : "^3.2.0"
}

, "repository":
Expand Down