提交 fb5617d9 编写于 作者: B Ben Houston

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

上级 9e46e56e
.DS_Store
*.swp
.project
utils/node_modules/*
\ No newline at end of file
utils/npm/node_modules/*
\ No newline at end of file
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
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" );
});
\ No newline at end of file
// 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;
}
var window = window || {};
var self = self || {};
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();
\ No newline at end of file
{
"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"
}
}
\ No newline at end of file
{
"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"
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册