Skip to content

Commit fb5617d

Browse files
committed
initial implementation of three and three-math npm module creation code.
1 parent 9e46e56 commit fb5617d

File tree

8 files changed

+258
-1
lines changed

8 files changed

+258
-1
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.DS_Store
22
*.swp
33
.project
4-
utils/node_modules/*
4+
utils/npm/node_modules/*

utils/npm/README.md

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

utils/npm/build.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
var fs = require( "fs" );
2+
var cp = require('child_process');
3+
4+
var commandLineArguments = process.argv.splice(2);
5+
6+
var outputRootDir = "./node_modules";
7+
var inputDir = "../../build";
8+
var readmeFileName = "../../README.md";
9+
10+
var headerFileName = "./header.js";
11+
var footerFileName = "./footer.js";
12+
13+
if( commandLineArguments.length == 0 ) {
14+
throw new Error( "build version must be specified as a command line argument (e.g. 0.54.3-dev)");
15+
}
16+
var buildVersion = commandLineArguments[0];
17+
18+
19+
var concateFiles = function ( inputFileNames, outputFileName ) {
20+
var buffer = [];
21+
for ( var i = 0; i < inputFileNames.length; i++ ) {
22+
buffer.push(
23+
fs.readFileSync( inputFileNames[i], 'utf8' )
24+
);
25+
}
26+
27+
var combinedContents = buffer.join("");
28+
fs.writeFileSync( outputFileName, combinedContents, 'utf8' );
29+
}
30+
31+
var createTemplatedFile = function ( templateFileName, replaceSet, outputFileName ) {
32+
var templateContents = fs.readFileSync( templateFileName, 'utf8' );
33+
for( var token in replaceSet ) {
34+
templateContents = templateContents.replace( "%"+token+"%", replaceSet[token] );
35+
}
36+
fs.writeFileSync( outputFileName, templateContents, 'utf8' );
37+
}
38+
39+
var copyFile = function( sourceFileName, destinationFileName ) {
40+
41+
var contents = fs.readFileSync( sourceFileName, 'utf8' );
42+
fs.writeFileSync( destinationFileName, contents, 'utf8' );
43+
44+
}
45+
46+
var buildModule = function ( name, version ) {
47+
48+
if( ! fs.existsSync( outputRootDir ) ) {
49+
fs.mkdirSync( outputRootDir );
50+
}
51+
52+
var outputModuleDir = outputRootDir + "/" + name;
53+
if( ! fs.existsSync( outputModuleDir ) ) {
54+
fs.mkdirSync( outputModuleDir );
55+
}
56+
// make directory moduleDir
57+
58+
var inputRawFileName = inputDir + "/" + name + ".js";
59+
var outputRawFileName = outputModuleDir + "/" + name + ".js";
60+
61+
concateFiles( [ headerFileName, inputRawFileName, footerFileName ], outputRawFileName );
62+
63+
var inputMinifiedFileName = inputDir + "/" + name + ".min.js";
64+
var outputMinifiedFileName = outputModuleDir + "/" + name + ".min.js";
65+
66+
concateFiles( [ headerFileName, inputMinifiedFileName, footerFileName ], outputMinifiedFileName );
67+
68+
var templatePackageFileName = "./" + name + ".package.json";
69+
var replaceSet = {
70+
"VERSION": buildVersion
71+
};
72+
var outputPackageFileName = outputModuleDir + "/package.json";
73+
createTemplatedFile( templatePackageFileName, replaceSet, outputPackageFileName );
74+
75+
var outputReadmeFileName = outputModuleDir + "/README.md";
76+
copyFile( readmeFileName, outputReadmeFileName );
77+
}
78+
79+
// TODO: make this non-Windows specific.
80+
var cmdExe = "cmd.exe";
81+
var args = [ "/c", "build_all.bat" ];
82+
var opts = { "cwd": ".." };
83+
var buildAll = cp.spawn( cmdExe, args, opts );
84+
85+
buildAll.stdout.on('data', function (data) {
86+
console.log('stdout: ' + data);
87+
});
88+
89+
buildAll.stderr.on('data', function (data) {
90+
console.log('stderr: ' + data);
91+
});
92+
93+
buildAll.on( 'exit', function ( exitCode ) {
94+
console.log( "exitCode: " + exitCode );
95+
buildModule( "three" );
96+
buildModule( "three-math" );
97+
});

utils/npm/footer.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
// Export the THREE object for **Node.js**, with
3+
// backwards-compatibility for the old `require()` API. If we're in
4+
// the browser, add `_` as a global object via a string identifier,
5+
// for Closure Compiler "advanced" mode.
6+
if (typeof exports !== 'undefined') {
7+
if (typeof module !== 'undefined' && module.exports) {
8+
exports = module.exports = THREE;
9+
}
10+
exports.THREE = THREE;
11+
} else {
12+
this['THREE'] = THREE;
13+
}

utils/npm/header.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
var window = window || {};
3+
var self = self || {};

utils/npm/test.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var threemath = function () {
2+
var THREE = require( "three-math" );
3+
4+
var a = new THREE.Vector3( 1, 1, 1 );
5+
console.log( a );
6+
7+
for( var i in THREE ) {
8+
console.log( i );
9+
}
10+
};
11+
12+
var three = function () {
13+
var THREE = require( "three" );
14+
15+
var a = new THREE.Vector3( 1, 1, 1 );
16+
console.log( a );
17+
18+
for( var i in THREE ) {
19+
console.log( i );
20+
}
21+
};
22+
23+
threemath();
24+
three();

utils/npm/three-math.package.json

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
3+
"name" : "three-math",
4+
5+
"version" : "%VERSION%",
6+
7+
"description" : "JavaScript 3D Math library",
8+
9+
"keywords" : [
10+
"3D",
11+
"WebGL",
12+
"Three",
13+
"ThreeJS",
14+
"CSS",
15+
"engine",
16+
"rendering",
17+
"geometry",
18+
"math"
19+
],
20+
21+
"homepage" : "http://mrdoob.github.com/three.js/",
22+
23+
"bugs" : {
24+
"url" : "https://github.com/mrdoob/three.js/issues"
25+
},
26+
27+
"author" : "three.js contributors",
28+
29+
"main" : "./three-math.js",
30+
31+
"repository" : {
32+
"type" : "git",
33+
"url" : "git://github.com/mrdoob/three.js.git"
34+
},
35+
36+
"scripts" : {
37+
"preinstall" : "ECHO todo",
38+
"test" : "ECHO todo"
39+
},
40+
41+
"license" : {
42+
"type" : "The MIT License",
43+
"url" : "https://raw.github.com/mrdoob/three.js/master/LICENSE"
44+
},
45+
46+
"engines" : {
47+
"node" : "*"
48+
},
49+
50+
"help" : {
51+
"web" : "http://stackoverflow.com/questions/tagged/three.js"
52+
}
53+
54+
}

utils/npm/three.package.json

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
3+
"name" : "three",
4+
5+
"version" : "%VERSION%",
6+
7+
"description" : "JavaScript 3D library",
8+
9+
"keywords" : [
10+
"3D",
11+
"WebGL",
12+
"Three",
13+
"ThreeJS",
14+
"CSS",
15+
"engine",
16+
"rendering",
17+
"geometry",
18+
"math"
19+
],
20+
21+
"homepage" : "http://mrdoob.github.com/three.js/",
22+
23+
"bugs" : {
24+
"url" : "https://github.com/mrdoob/three.js/issues"
25+
},
26+
27+
"author" : "three.js contributors",
28+
29+
"main" : "./three.js",
30+
31+
"repository" : {
32+
"type" : "git",
33+
"url" : "git://github.com/mrdoob/three.js.git"
34+
},
35+
36+
"scripts" : {
37+
"preinstall" : "ECHO todo",
38+
"test" : "ECHO todo"
39+
},
40+
41+
"license" : {
42+
"type" : "The MIT License",
43+
"url" : "https://raw.github.com/mrdoob/three.js/master/LICENSE"
44+
},
45+
46+
"engines" : {
47+
"node" : "*"
48+
},
49+
50+
"help" : {
51+
"web" : "http://stackoverflow.com/questions/tagged/three.js"
52+
}
53+
54+
}

0 commit comments

Comments
 (0)