forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial implementation of three and three-math npm module creation code.
- Loading branch information
Showing
8 changed files
with
258 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
var window = window || {}; | ||
var self = self || {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
||
} |