Skip to content

Commit

Permalink
run native examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cadorn committed Feb 15, 2012
1 parent 58bc879 commit b9d3442
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 5 deletions.
22 changes: 17 additions & 5 deletions examples/04-NodeJSPlatformFeatures/01-Globals/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,33 @@ exports.main = function()
throw new Error("The '__filename' global variable should be defined!");
}

if (__filename !== (require.sandbox.id + module.id))
// TODO: Detect running mode and insist on test if running in sourcemint loader.
if (typeof require.sandbox !== "undefined")
{
throw new Error("The '__filename' global does not equal the value of 'require.sandbox.id + module.id'!");
if (__filename !== (require.sandbox.id + module.id))
{
throw new Error("The '__filename' global does not equal the value of 'require.sandbox.id + module.id'!");
}
}

if (typeof __dirname === "undefined")
{
throw new Error("The '__dirname' global variable should be defined!");
}

if (__dirname !== (require.sandbox.id + module.id).replace(/\/([^\/]*)$/,""))
// TODO: Detect running mode and insist on test if running in sourcemint loader.
if (typeof require.sandbox !== "undefined")
{
throw new Error("The '__dirname' global does not equal the value of 'PATH.dirname(require.sandbox.id + module.id)'!");
if (__dirname !== (require.sandbox.id + module.id).replace(/\/([^\/]*)$/,""))
{
throw new Error("The '__dirname' global does not equal the value of 'PATH.dirname(require.sandbox.id + module.id)'!");
}
}


console.log("01-Globals OK");
}


if (require.main === module) {
exports.main();
}
8 changes: 8 additions & 0 deletions examples/04-NodeJSPlatformFeatures/01-Globals/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"name": "sourcemint-platform-nodejs-examples-04-NodeJSPlatformFeatures-01-Globals",
"version": "0.1.0",
"engines": {
"nodejs": "0.x"
},
"scripts": {
"test": "node main"
},
"main": "./main.js",
"config": {
"github.com/sourcemint/bundler-js/0/-meta/config/0": {
Expand Down
69 changes: 69 additions & 0 deletions examples/04-NodeJSPlatformFeatures/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

var ERROR = require("sourcemint-platform-nodejs/lib/util/error"),
EXEC = require("child_process").exec;
PATH = require("path"),
FS = require("fs");


exports.main = function()
{
var done = Q.ref();

var basePath = __dirname;

FS.readdirSync(basePath).forEach(function(filename)
{
var exampleBasePath = basePath + "/" + filename;

if (PATH.existsSync(exampleBasePath + "/package.json"))
{
done = Q.when(done, function()
{
return runExample(exampleBasePath);
});
}
});

return done;
}

function runExample(path)
{
var deferred = Q.defer();

console.log("Running example: " + path);

EXEC("npm install", {
cwd: path
}, function(err, stdout, stderr)
{
if (err) deferred.reject(err);
else if (stderr) deferred.reject(stderr)
else {

process.stdout.write(stdout);

EXEC("npm test", {
cwd: path
}, function(err, stdout, stderr)
{
if (err) deferred.reject(err);
else if (stderr) deferred.reject(stderr)
else {

process.stdout.write(stdout);

deferred.resolve();
}
});
}
});

return deferred.promise;
}


if (require.main === module) {
exports.main().fail(ERROR.logError);
}

13 changes: 13 additions & 0 deletions examples/04-NodeJSPlatformFeatures/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "sourcemint-platform-nodejs-examples-04-NodeJSPlatformFeatures",
"version": "0.1.0",
"engines": {
"nodejs": "0.x"
},
"dependencies": {
"q": "0.x"
},
"scripts": {
"test": "node main"
}
}

0 comments on commit b9d3442

Please sign in to comment.