Permalink
Browse files

initial implementation of three and three-math npm module creation code.

  • Loading branch information...
1 parent 9e46e56 commit fb5617d91056a59c7efcbf9ce01bd3f708ff5f8e @bhouston bhouston committed Dec 12, 2012
Showing with 258 additions and 1 deletion.
  1. +1 −1 .gitignore
  2. +12 −0 utils/npm/README.md
  3. +97 −0 utils/npm/build.js
  4. +13 −0 utils/npm/footer.js
  5. +3 −0 utils/npm/header.js
  6. +24 −0 utils/npm/test.js
  7. +54 −0 utils/npm/three-math.package.json
  8. +54 −0 utils/npm/three.package.json
View
@@ -1,4 +1,4 @@
.DS_Store
*.swp
.project
-utils/node_modules/*
+utils/npm/node_modules/*
View
@@ -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
+
View
@@ -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" );
+});
View
@@ -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;
+}
View
@@ -0,0 +1,3 @@
+
+var window = window || {};
+var self = self || {};
View
@@ -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();
@@ -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"
+ }
+
+}
@@ -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.