Permalink
Browse files

some initial examples

  • Loading branch information...
0 parents commit ca6743d6b510ce67580d0c8a6cb244a5720b0204 @cadorn cadorn committed Feb 23, 2012
Showing with 803 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 .travis.yml
  3. +36 −0 01-RequireJSModulesToBrowser/dist/modules.js
  4. +14 −0 01-RequireJSModulesToBrowser/index.html
  5. +51 −0 01-RequireJSModulesToBrowser/main.js
  6. +8 −0 01-RequireJSModulesToBrowser/modules/greeting.js
  7. +10 −0 01-RequireJSModulesToBrowser/modules/main.js
  8. +8 −0 01-RequireJSModulesToBrowser/modules/package.json
  9. +18 −0 01-RequireJSModulesToBrowser/package.json
  10. +33 −0 01-RequireJSModulesToBrowser/test.js
  11. +105 −0 02-RequireJSPackagesToBrowser/dist/boot.js
  12. +35 −0 02-RequireJSPackagesToBrowser/dist/boot/3eec0df8f2de2377a1e4948edd7d6ed9ff9d4956/logger/console.js
  13. +3 −0 ...gesToBrowser/dist/boot/3eec0df8f2de2377a1e4948edd7d6ed9ff9d4956/logger/console/logger/suffix.json
  14. +1 −0 02-RequireJSPackagesToBrowser/dist/boot/H.txt
  15. +35 −0 02-RequireJSPackagesToBrowser/dist/boot/b7e3fe2b00b4550bbd0600676eeee1eb6ad55bbe/logger/console.js
  16. +3 −0 ...gesToBrowser/dist/boot/b7e3fe2b00b4550bbd0600676eeee1eb6ad55bbe/logger/console/logger/suffix.json
  17. +3 −0 02-RequireJSPackagesToBrowser/dist/boot/logger/suffix.json
  18. +15 −0 02-RequireJSPackagesToBrowser/index.html
  19. +55 −0 02-RequireJSPackagesToBrowser/main.js
  20. +18 −0 02-RequireJSPackagesToBrowser/package.json
  21. +16 −0 02-RequireJSPackagesToBrowser/packages/boot/main.js
  22. +12 −0 02-RequireJSPackagesToBrowser/packages/boot/package.json
  23. +15 −0 02-RequireJSPackagesToBrowser/packages/packageA/greetings.js
  24. +16 −0 02-RequireJSPackagesToBrowser/packages/packageA/logger.js
  25. +16 −0 02-RequireJSPackagesToBrowser/packages/packageA/logger/console.js
  26. +3 −0 02-RequireJSPackagesToBrowser/packages/packageA/logger/suffix.json
  27. +18 −0 02-RequireJSPackagesToBrowser/packages/packageA/package.json
  28. +9 −0 02-RequireJSPackagesToBrowser/packages/packageB/package.json
  29. +15 −0 02-RequireJSPackagesToBrowser/packages/packageB/words/hello.js
  30. +25 −0 02-RequireJSPackagesToBrowser/packages/packageC/H.js
  31. +1 −0 02-RequireJSPackagesToBrowser/packages/packageC/H.txt
  32. +10 −0 02-RequireJSPackagesToBrowser/packages/packageC/package.json
  33. +33 −0 02-RequireJSPackagesToBrowser/test.js
  34. +75 −0 README.md
  35. +17 −0 package.json
  36. +65 −0 tests.js
@@ -0,0 +1 @@
+node_modules/
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
+ - 0.7
@@ -0,0 +1,36 @@
+require.bundle("", function(require)
+{
+ function define(id, dependencies, moduleInitializer)
+ {
+ return function(require, exports, module) {
+ if (typeof moduleInitializer === "function") {
+ return moduleInitializer.apply(moduleInitializer, dependencies.map(function(name) {
+ if (name === "require") return require;
+ if (name === "exports") return exports;
+ if (name === "module") return module;
+ return require(name);
+ }))
+ } else
+ if (typeof dependencies === "object") {
+ return dependencies;
+ }
+ }
+ }
+ require.memoize("/main.js", define('',["./greeting"], function(GREETING)
+ {
+ return {
+ main: function()
+ {
+ console.log(GREETING.getGreeting());
+ }
+ };
+ }));
+ require.memoize("/greeting.js", define('',['require','exports','module'],function(require, exports, module)
+ {
+ exports.getGreeting = function()
+ {
+ return "Hello from 01-RequireJSModulesToBrowser!";
+ }
+ }));
+ require.memoize("/package.json", {"main":"/main.js","directories":{"lib":""},"mappings":{}});
+});
@@ -0,0 +1,14 @@
+<html>
+ <head>
+ <script type="text/javascript" src="loader.js"></script>
+ <script type="text/javascript">
+ require.sandbox("modules.js", function(sandbox)
+ {
+ sandbox.main();
+ });
+ </script>
+ </head>
+ <body>
+ <p>Check your browser's console for 'console.log()' messages!</p>
+ </body>
+</html>
@@ -0,0 +1,51 @@
+
+var PATH = require("path"),
+ CONNECT = require("connect"),
+ BUNDLER = require("sourcemint-platform-nodejs/lib/bundler");
+
+
+exports.main = function(onReadyDeferred, options)
+{
+ var server = CONNECT();
+
+ server.use(CONNECT.router(function(app)
+ {
+ app.get(/^\/$/, CONNECT.static(__dirname));
+
+ app.get(/^\/loader.js/, CONNECT.static(PATH.dirname(require.resolve("sourcemint-loader-js/loader.js"))));
+
+ app.get(/^(\/modules)(\.js)?(\/(.*))?$/, function (req, res)
+ {
+ var modulesPath = __dirname + "/" + req.params[0];
+
+ // TODO: Maybe we can do without this.
+ req.url = req.url.substring(10 + req.params[0].length + (req.params[1] || "").length);
+
+ // TODO: Make this `connect` compatible.
+ BUNDLER.Middleware(modulesPath, __dirname + "/dist", {
+ packageIdHashSeed: "__EXAMPLE__"
+ }).handle(req, res);
+ });
+ }));
+
+ /*TEST*/ if (onReadyDeferred) {
+ /*TEST*/ server.once("listening", function() {
+ /*TEST*/ onReadyDeferred.resolve(function onTestDone(stoppedCallback) {
+ /*TEST*/ server.once("close", function() {
+ /*TEST*/ stoppedCallback();
+ /*TEST*/ });
+ /*TEST*/ server.close();
+ /*TEST*/ });
+ /*TEST*/ });
+ /*TEST*/ }
+
+ server.listen(options.port, "127.0.0.1");
+
+ console.log("Server running at http://127.0.0.1:" + options.port + "/");
+}
+
+if (require.main === module) {
+ exports.main(null, {
+ port: 1337
+ });
+}
@@ -0,0 +1,8 @@
+
+define(function(require, exports, module)
+{
+ exports.getGreeting = function()
+ {
+ return "Hello from 01-RequireJSModulesToBrowser!";
+ }
+});
@@ -0,0 +1,10 @@
+
+define(["./greeting"], function(GREETING)
+{
+ return {
+ main: function()
+ {
+ console.log(GREETING.getGreeting());
+ }
+ };
+});
@@ -0,0 +1,8 @@
+{
+ "main": "./main.js",
+ "config": {
+ "github.com/sourcemint/bundler-js/0/-meta/config/0": {
+ "adapter": "github.com/sourcemint/sdk-requirejs/0"
+ }
+ }
+}
@@ -0,0 +1,18 @@
+{
+ "name": "sourcemint-examples-js-01-RequireJSModulesToBrowser",
+ "version": "0.1.0",
+ "engines": {
+ "nodejs": "0.x"
+ },
+ "dependencies": {
+ "connect": "1.x",
+ "sourcemint-platform-nodejs": "0.x",
+ "sourcemint-loader-js": "0.x"
+ },
+ "devDependencies": {
+ "zombie": "0.x"
+ },
+ "scripts": {
+ "test": "node test"
+ }
+}
@@ -0,0 +1,33 @@
+
+var HELPER = require("sourcemint-platform-nodejs/tests/test-helper"),
+ ASSERT = require("assert"),
+ BROWSER = require("zombie");
+
+
+HELPER.makeTest(require, exports, module, function(Q, onTestDoneDeferred, options)
+{
+ Q.call(function()
+ {
+ (new BROWSER({
+ silent: true,
+ debug: false
+ })).visit("http://127.0.0.1:" + options.port + "/", function(err, browser)
+ {
+ if (err) {
+ onTestDoneDeferred.reject(err);
+ } else
+ if (browser.error) {
+ Q.call(function() {
+ throw new Error(browser.error);
+ }).fail(onTestDoneDeferred.reject);
+ } else
+ if (browser.window.console.output !== "Hello from 01-RequireJSModulesToBrowser!\n") {
+ Q.call(function() {
+ throw new Error("Incorrect console output! Got [" + browser.window.console.output + "]");
+ }).fail(onTestDoneDeferred.reject);
+ } else {
+ onTestDoneDeferred.resolve();
+ }
+ });
+ }).fail(onTestDoneDeferred.reject);
+});
@@ -0,0 +1,105 @@
+require.bundle("", function(require)
+{
+ function define(id, dependencies, moduleInitializer)
+ {
+ return function(require, exports, module) {
+ if (typeof moduleInitializer === "function") {
+ return moduleInitializer.apply(moduleInitializer, dependencies.map(function(name) {
+ if (name === "require") return require;
+ if (name === "exports") return exports;
+ if (name === "module") return module;
+ return require(name);
+ }))
+ } else
+ if (typeof dependencies === "object") {
+ return dependencies;
+ }
+ }
+ }
+ require.memoize("/main.js", define('',['require','exports','module','helpers/greetings','helpers/logger','letters/H'],function(require, exports, module)
+ {
+ // One-way dependency.
+ var GREETINGS = require("helpers/greetings"),
+ LOGGER = require("helpers/logger"),
+ LETTERS = require("letters/H");
+
+ exports.main = function(options)
+ {
+ LETTERS.load(function()
+ {
+ LOGGER.log(GREETINGS.getGreeting());
+ });
+ }
+ }));
+ require.memoize("b7e3fe2b00b4550bbd0600676eeee1eb6ad55bbe/greetings.js", define('',['require','exports','module','package/hello'],function(require, exports, module)
+ {
+ var HELLO = require("package/hello");
+
+ exports.getGreeting = function()
+ {
+ return HELLO.getWord() + " from " + HELLO.getName();
+ }
+
+ exports.getName = function()
+ {
+ return "02-RequireJSPackagesToBrowser";
+ }
+ }));
+ require.memoize("b7e3fe2b00b4550bbd0600676eeee1eb6ad55bbe/logger.js", define('',['require','exports','module'],function(require, exports, module)
+ {
+ exports.log = function(message)
+ {
+ // NOTE: `require(["./logger/console"], ...)` will currently create a **STATIC** link.
+ // TODO: Fix to create a dynamic link instead. See `sourcemint/sdk-requirejs/lib/bundler::parseModule()`
+
+ var loggerID = "./logger/console";
+
+ require([loggerID], function(LOGGER)
+ {
+ LOGGER.log(message);
+ });
+ }
+ }));
+ require.memoize("7c6ac439eb93e47d1c182c68092caf4ae323c5c4/words/hello.js", define('',['require','exports','module','package/greetings','letters/H'],function(require, exports, module)
+ {
+ var GREETINGS = require("package/greetings");
+
+ exports.getWord = function()
+ {
+ return require("letters/H").getLetter() + "ello";
+ }
+
+ exports.getName = function()
+ {
+ return GREETINGS.getName();
+ }
+ }));
+ require.memoize("108cbe849fb3dc44e8a21940a3ba536c0b08aa74/H.js", define('',['require','exports','module'],function(require, exports, module)
+ {
+ // TODO: Allow mapping a global to a package alias in package.json.
+ // var JQUERY = require("$"); // Where '$' is mapped to <Global>.$ which is jQuery in this case.
+ // Also map to pureJS file and export globals so we can require them here.
+ var JQUERY = $;
+
+ var letter = false;
+
+ exports.load = function(loadedCallback)
+ {
+ JQUERY.get(require.sandbox.id + require.id("./H.txt"), function(data)
+ {
+ letter = data;
+
+ loadedCallback();
+ });
+ }
+
+ exports.getLetter = function()
+ {
+ return letter;
+ }
+ }));
+ require.memoize("/package.json", {"main":"/main.js","mappings":{"helpers":"b7e3fe2b00b4550bbd0600676eeee1eb6ad55bbe","letters":"108cbe849fb3dc44e8a21940a3ba536c0b08aa74"},"directories":{"lib":""}});
+ require.memoize("b7e3fe2b00b4550bbd0600676eeee1eb6ad55bbe/package.json", {"mappings":{"package":"7c6ac439eb93e47d1c182c68092caf4ae323c5c4"},"directories":{"lib":""}});
+ require.memoize("7c6ac439eb93e47d1c182c68092caf4ae323c5c4/package.json", {"mappings":{"package":"b7e3fe2b00b4550bbd0600676eeee1eb6ad55bbe","letters":"108cbe849fb3dc44e8a21940a3ba536c0b08aa74"},"directories":{"lib":"words"}});
+ require.memoize("108cbe849fb3dc44e8a21940a3ba536c0b08aa74/package.json", {"directories":{"lib":""},"mappings":{}});
+});
@@ -0,0 +1,35 @@
+require.bundle("", function(require)
+{
+ function define(id, dependencies, moduleInitializer)
+ {
+ return function(require, exports, module) {
+ if (typeof moduleInitializer === "function") {
+ return moduleInitializer.apply(moduleInitializer, dependencies.map(function(name) {
+ if (name === "require") return require;
+ if (name === "exports") return exports;
+ if (name === "module") return module;
+ return require(name);
+ }))
+ } else
+ if (typeof dependencies === "object") {
+ return dependencies;
+ }
+ }
+ }
+ require.memoize("/logger/console.js", define('',['require','exports','module'],function(require, exports, module)
+ {
+ // TODO: Allow mapping a global to a package alias in package.json.
+ // var JQUERY = require("$"); // Where '$' is mapped to <Global>.$ which is jQuery in this case.
+ // Also map to pureJS file and export globals so we can require them here.
+ var JQUERY = $;
+
+ exports.log = function(message)
+ {
+ JQUERY.get(require.sandbox.id + require.id("./suffix.json"), function(data)
+ {
+ console.log(message + data.character);
+ });
+ }
+ }));
+ require.memoize("/package.json", {"mappings":{},"main":"/logger/console.js","directories":{"lib":""}});
+});
@@ -0,0 +1 @@
+H
@@ -0,0 +1,35 @@
+require.bundle("", function(require)
+{
+ function define(id, dependencies, moduleInitializer)
+ {
+ return function(require, exports, module) {
+ if (typeof moduleInitializer === "function") {
+ return moduleInitializer.apply(moduleInitializer, dependencies.map(function(name) {
+ if (name === "require") return require;
+ if (name === "exports") return exports;
+ if (name === "module") return module;
+ return require(name);
+ }))
+ } else
+ if (typeof dependencies === "object") {
+ return dependencies;
+ }
+ }
+ }
+ require.memoize("/logger/console.js", define('',['require','exports','module'],function(require, exports, module)
+ {
+ // TODO: Allow mapping a global to a package alias in package.json.
+ // var JQUERY = require("$"); // Where '$' is mapped to <Global>.$ which is jQuery in this case.
+ // Also map to pureJS file and export globals so we can require them here.
+ var JQUERY = $;
+
+ exports.log = function(message)
+ {
+ JQUERY.get(require.sandbox.id + require.id("./suffix.json"), function(data)
+ {
+ console.log(message + data.character);
+ });
+ }
+ }));
+ require.memoize("/package.json", {"mappings":{},"main":"/logger/console.js","directories":{"lib":""}});
+});
@@ -0,0 +1,3 @@
+{
+ "character": "!"
+}
Oops, something went wrong.

0 comments on commit ca6743d

Please sign in to comment.