Skip to content

Commit

Permalink
initial implementation of three and three-math npm module creation code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Dec 12, 2012
1 parent 9e46e56 commit fb5617d
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.DS_Store
*.swp
.project
utils/node_modules/*
utils/npm/node_modules/*
12 changes: 12 additions & 0 deletions utils/npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
To build the npm modules:

1. install nodejs.
2. install npm (if it was not installed with nodejs)
3. determine the version of THREE that you want to publish (usually it is specified in src/Three.js as the REVISION)
4. increment the fix number above what was previously published if you are re-publishing an existing Three.js version.
5. add "-dev" to the version number if this is a development branch.
6. run the follow to build both the three and three-math node modules
* node build.js 0.54.3-dev
7. npm publish node_module/three
8. npm publish node_module/three-math

97 changes: 97 additions & 0 deletions utils/npm/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
var fs = require( "fs" );
var cp = require('child_process');

var commandLineArguments = process.argv.splice(2);

var outputRootDir = "./node_modules";
var inputDir = "../../build";
var readmeFileName = "../../README.md";

var headerFileName = "./header.js";
var footerFileName = "./footer.js";

if( commandLineArguments.length == 0 ) {
throw new Error( "build version must be specified as a command line argument (e.g. 0.54.3-dev)");
}
var buildVersion = commandLineArguments[0];


var concateFiles = function ( inputFileNames, outputFileName ) {
var buffer = [];
for ( var i = 0; i < inputFileNames.length; i++ ) {
buffer.push(
fs.readFileSync( inputFileNames[i], 'utf8' )
);
}

var combinedContents = buffer.join("");
fs.writeFileSync( outputFileName, combinedContents, 'utf8' );
}

var createTemplatedFile = function ( templateFileName, replaceSet, outputFileName ) {
var templateContents = fs.readFileSync( templateFileName, 'utf8' );
for( var token in replaceSet ) {
templateContents = templateContents.replace( "%"+token+"%", replaceSet[token] );
}
fs.writeFileSync( outputFileName, templateContents, 'utf8' );
}

var copyFile = function( sourceFileName, destinationFileName ) {

var contents = fs.readFileSync( sourceFileName, 'utf8' );
fs.writeFileSync( destinationFileName, contents, 'utf8' );

}

var buildModule = function ( name, version ) {

if( ! fs.existsSync( outputRootDir ) ) {
fs.mkdirSync( outputRootDir );
}

var outputModuleDir = outputRootDir + "/" + name;
if( ! fs.existsSync( outputModuleDir ) ) {
fs.mkdirSync( outputModuleDir );
}
// make directory moduleDir

var inputRawFileName = inputDir + "/" + name + ".js";
var outputRawFileName = outputModuleDir + "/" + name + ".js";

concateFiles( [ headerFileName, inputRawFileName, footerFileName ], outputRawFileName );

var inputMinifiedFileName = inputDir + "/" + name + ".min.js";
var outputMinifiedFileName = outputModuleDir + "/" + name + ".min.js";

concateFiles( [ headerFileName, inputMinifiedFileName, footerFileName ], outputMinifiedFileName );

var templatePackageFileName = "./" + name + ".package.json";
var replaceSet = {
"VERSION": buildVersion
};
var outputPackageFileName = outputModuleDir + "/package.json";
createTemplatedFile( templatePackageFileName, replaceSet, outputPackageFileName );

var outputReadmeFileName = outputModuleDir + "/README.md";
copyFile( readmeFileName, outputReadmeFileName );
}

// TODO: make this non-Windows specific.
var cmdExe = "cmd.exe";
var args = [ "/c", "build_all.bat" ];
var opts = { "cwd": ".." };
var buildAll = cp.spawn( cmdExe, args, opts );

buildAll.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});

buildAll.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});

buildAll.on( 'exit', function ( exitCode ) {
console.log( "exitCode: " + exitCode );
buildModule( "three" );
buildModule( "three-math" );
});
13 changes: 13 additions & 0 deletions utils/npm/footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

// Export the THREE object for **Node.js**, with
// backwards-compatibility for the old `require()` API. If we're in
// the browser, add `_` as a global object via a string identifier,
// for Closure Compiler "advanced" mode.
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = THREE;
}
exports.THREE = THREE;
} else {
this['THREE'] = THREE;
}
3 changes: 3 additions & 0 deletions utils/npm/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

var window = window || {};
var self = self || {};
24 changes: 24 additions & 0 deletions utils/npm/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var threemath = function () {
var THREE = require( "three-math" );

var a = new THREE.Vector3( 1, 1, 1 );
console.log( a );

for( var i in THREE ) {
console.log( i );
}
};

var three = function () {
var THREE = require( "three" );

var a = new THREE.Vector3( 1, 1, 1 );
console.log( a );

for( var i in THREE ) {
console.log( i );
}
};

threemath();
three();
54 changes: 54 additions & 0 deletions utils/npm/three-math.package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{

"name" : "three-math",

"version" : "%VERSION%",

"description" : "JavaScript 3D Math library",

"keywords" : [
"3D",
"WebGL",
"Three",
"ThreeJS",
"CSS",
"engine",
"rendering",
"geometry",
"math"
],

"homepage" : "http://mrdoob.github.com/three.js/",

"bugs" : {
"url" : "https://github.com/mrdoob/three.js/issues"
},

"author" : "three.js contributors",

"main" : "./three-math.js",

"repository" : {
"type" : "git",
"url" : "git://github.com/mrdoob/three.js.git"
},

"scripts" : {
"preinstall" : "ECHO todo",
"test" : "ECHO todo"
},

"license" : {
"type" : "The MIT License",
"url" : "https://raw.github.com/mrdoob/three.js/master/LICENSE"
},

"engines" : {
"node" : "*"
},

"help" : {
"web" : "http://stackoverflow.com/questions/tagged/three.js"
}

}
54 changes: 54 additions & 0 deletions utils/npm/three.package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{

"name" : "three",

"version" : "%VERSION%",

"description" : "JavaScript 3D library",

"keywords" : [
"3D",
"WebGL",
"Three",
"ThreeJS",
"CSS",
"engine",
"rendering",
"geometry",
"math"
],

"homepage" : "http://mrdoob.github.com/three.js/",

"bugs" : {
"url" : "https://github.com/mrdoob/three.js/issues"
},

"author" : "three.js contributors",

"main" : "./three.js",

"repository" : {
"type" : "git",
"url" : "git://github.com/mrdoob/three.js.git"
},

"scripts" : {
"preinstall" : "ECHO todo",
"test" : "ECHO todo"
},

"license" : {
"type" : "The MIT License",
"url" : "https://raw.github.com/mrdoob/three.js/master/LICENSE"
},

"engines" : {
"node" : "*"
},

"help" : {
"web" : "http://stackoverflow.com/questions/tagged/three.js"
}

}

0 comments on commit fb5617d

Please sign in to comment.