Skip to content
This repository has been archived by the owner on Dec 20, 2017. It is now read-only.

Commit

Permalink
settings in package.json, example
Browse files Browse the repository at this point in the history
  • Loading branch information
jgallen23 committed Feb 20, 2012
1 parent b835305 commit 262cca2
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.DS_Store
node_modules
/node_modules/
.coverage_data
11 changes: 8 additions & 3 deletions docs/TODO
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
v0.0.3:
- figure out how to handle AMD modules (aug) @done(2012-02-19)
- --verify (run in vm context) @done(2012-02-19)
- option to no-wrap if amd already set (aug) @done(2012-02-20)
- Cs set up examples as unit tests
- create history.md
- test on node 0.4
- update docs for package.json integration
- figure out how to handle AMD modules (aug) @done(2012-02-19)
- --verify (run in vm context) @done(2012-02-19)
- sketch out flow @done(2012-02-18)
- refactor file library @done(2012-02-19)
- refactor library to be chainable (don't pass in index file) @done(2012-02-19)
Expand All @@ -13,14 +14,18 @@ v0.0.3:
- a config file that can be checked into repo (or set in package.json) to let clientside know how to build @done(2012-02-18)
- overview of what each class does @done(2012-02-18)
- need library or should file be able to handle everything? @done(2012-02-18)
- Client side examples. Look at browserify @done(2012-02-19)
- some way to shim server requires (requires('request')) @done(2012-02-18)
- finish unit tests @done(2012-02-18)
- deptree @done(2012-02-18)
- library @done(2012-02-18)
- file @done(2012-02-18)
- wrap @done(2012-02-18)
Future:
- Client side examples. Look at browserify
- update unit tests
- read package.json for dependencies
- extract
- --stats to show filesize (lint?)
- think about full middleware (replace require, module.exports)
- clientside object - be able to turn off require check, module.exports if browser compatible version already exists
- file don't require library, but can be set
Expand Down
25 changes: 16 additions & 9 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var wrap = require('./wrap');
var lastId = 0;

var defaults = {
prefix: 'cs'
prefix: 'cs',
modify: true
};

var File = function(filename, options) {
Expand All @@ -16,7 +17,11 @@ var File = function(filename, options) {
filename = null;
}
this.options = aug({}, defaults, options);
this.generateId();
if (this.options.id) {
this.id = this.options.id
} else {
this.generateId();
}
if (filename) {
this.filename = filename;
this.dirname = path.dirname(filename);
Expand Down Expand Up @@ -85,13 +90,15 @@ File.prototype._parse = function() {
};

File.prototype.build = function() {
//TODO get burrito working
//regex
//this.replaceRequires();
this.replaceModuleExports();
//burrito
//this.parse();
this.wrap();
if (this.options.modify) {
//TODO get burrito working
//regex
//this.replaceRequires();
this.replaceModuleExports();
//burrito
//this.parse();
this.wrap();
}
return this.source;
};

Expand Down
14 changes: 12 additions & 2 deletions lib/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ var Library = function(options) {
var defaults = {
name: 'moduleName',
shim: {},
files: {}
files: {},
settings: {}
};
this.meta = aug({}, defaults, options);
this.depTree = new DepTree();
this.shims = {};
this.settings = {};

if (this.meta.main) {
this.meta.main = path.resolve(this.meta.main);
Expand All @@ -26,6 +28,7 @@ var Library = function(options) {
this.dirname = process.cwd();
}

this.processSettings();
this.processShims();

//must be after process shims
Expand All @@ -39,13 +42,20 @@ Library.prototype.addFile = function(filename, key) {
key = key || filename;
var f = this.meta.files[key];
if (!f) {
f = new File(filename);
f = new File(filename, this.settings[key]);
this.meta.files[key] = f;
this.addDependencies(f);
}
return f;
};

Library.prototype.processSettings = function() {
for (var key in this.meta.settings) {
var filepath = resolve(key, this.dirname);
this.settings[filepath] = this.meta.settings[key];
}
};

Library.prototype.processShims = function() {
for (var key in this.meta.shim) {
var filepath = this.meta.shim[key];
Expand Down
4 changes: 2 additions & 2 deletions lib/wrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function(variableName, source, returns) {
if (!returns) returns = 'exports';
var start = 'var '+variableName+' = (function(exports, module) {\n';
var end = '\nreturn '+returns+';\n})({}, true);';
var start = 'var '+variableName+' = (function(exports) {\n';
var end = '\nreturn '+returns+';\n})({});';
return start + source + end;
};
12 changes: 0 additions & 12 deletions test/examples/aug/index.html

This file was deleted.

27 changes: 0 additions & 27 deletions test/examples/aug/out.js

This file was deleted.

2 changes: 2 additions & 0 deletions test/examples/awesomeCalc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
@../../../bin/clientside > dist/awesomecalc.js
59 changes: 59 additions & 0 deletions test/examples/awesomeCalc/dist/awesomecalc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var AwesomeCalc = (function(exports) {
var cs1 = (function(exports) {

exports.add = function(num1, num2) {
return num1 + num2;
}

return exports;
})({});
/*!
* aug.js - A javascript library to extend existing objects and prototypes
* v0.0.1
* https://github.com/jgallen23/aug
* copyright JGA 2011
* MIT License
*/

!function (name, definition) {
if (typeof module != 'undefined' && module.exports) module.exports = definition();
else if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
else this[name] = definition();
}('aug', function() {

var aug = function __aug() {
var args = Array.prototype.slice.call(arguments);
var org = args.shift();
for (var i = 0, c = args.length; i < c; i++) {
var prop = args[i];
for (var name in prop) {
org[name] = prop[name];
}
}
return org;
};

return aug;
});

var cs0 = (function(exports) {
var calc = cs1;
var aug = window.aug;

var Calculator = function(options) {
var defaults = {
debug: false
}
this.options = aug({}, defaults, options);
}

Calculator.prototype.add = function(num1, num2) {
return calc.add(num1, num2);
}

exports = Calculator;

return exports;
})({});
return cs0;
})({});
15 changes: 15 additions & 0 deletions test/examples/awesomeCalc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var calc = require('calc');
var aug = require('aug');

var Calculator = function(options) {
var defaults = {
debug: false
}
this.options = aug({}, defaults, options);
}

Calculator.prototype.add = function(num1, num2) {
return calc.add(num1, num2);
}

module.exports = Calculator;
File renamed without changes.
Empty file.
1 change: 1 addition & 0 deletions test/examples/awesomeCalc/node_modules/calc/browserfs.js

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

4 changes: 4 additions & 0 deletions test/examples/awesomeCalc/node_modules/calc/main.js

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

9 changes: 9 additions & 0 deletions test/examples/awesomeCalc/node_modules/calc/package.json

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

12 changes: 12 additions & 0 deletions test/examples/awesomeCalc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "awesomeCalc",
"clientside": {
"name": "AwesomeCalc",
"settings": {
"aug": {
"modify": false,
"id": "window.aug"
}
}
}
}
12 changes: 12 additions & 0 deletions test/examples/awesomeCalc/test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title></title>
<script src="../dist/awesomecalc.js"></script>
<script>
var calc = new AwesomeCalc();
console.log(calc.add(1, 2));
</script>
</head>
<body>
</body>
</html>

0 comments on commit 262cca2

Please sign in to comment.