Browse Source

npm run build-watch - automatically rebuild three.js when changes made (#9004)

* add auto-builder.

* do an initial build when watching.

* add include directory in build-watch.

* incorporate zz85's suggestions.
Ben Houston (Clara.io) 9 years ago
parent
commit
c06169348a
2 changed files with 20 additions and 2 deletions
  1. 3 1
      package.json
  2. 17 1
      utils/build/build.js

+ 3 - 1
package.json

@@ -21,6 +21,7 @@
   },
   "scripts": {
     "build": "cd ./utils/build && node build.js --include common --include extras",
+    "dev": "chokidar \"./src/**/*.*\" \"./utils/build/includes/*.*\" --initial -c \"npm run build\"",
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "repository": {
@@ -41,7 +42,8 @@
   "homepage": "http://threejs.org/",
   "devDependencies": {
     "argparse": "^1.0.3",
+    "chokidar-cli": "1.2.0",
     "jscs": "^1.13.1",
     "uglify-js": "^2.6.0"
-  }
+    }
 }

+ 17 - 1
utils/build/build.js

@@ -20,8 +20,11 @@ function main() {
 	var args = parser.parseArgs();
 	
 	var output = args.output;
-	console.log(' * Building ' + output);
+
+	console.log('Building ' + output + ':');
 	
+	var startMS = Date.now();
+
 	var sourcemap = '';
 	var sourcemapping = '';
 
@@ -39,6 +42,8 @@ function main() {
 		buffer.push('function ( root, factory ) {\n\n\tif ( typeof define === \'function\' && define.amd ) {\n\n\t\tdefine( [ \'exports\' ], factory );\n\n\t} else if ( typeof exports === \'object\' ) {\n\n\t\tfactory( exports );\n\n\t} else {\n\n\t\tfactory( root );\n\n\t}\n\n}( this, function ( exports ) {\n\n');
 	};
 	
+	console.log( '  Collecting source files.' );
+
 	for ( var i = 0; i < args.include.length; i ++ ){
 		
 		var contents = fs.readFileSync( './includes/' + args.include[i] + '.json', 'utf8' );
@@ -76,10 +81,14 @@ function main() {
 	
 	if ( !args.minify ){
 
+		console.log( '  Writing output.' );
+
 		fs.writeFileSync( output, temp, 'utf8' );
 
 	} else {
 
+		console.log( '  Uglyifying.' );
+
 		var LICENSE = "threejs.org/license";
 
 		// Parsing
@@ -125,16 +134,23 @@ function main() {
 		compressed_ast.print( stream );
 		var code = stream.toString();
 
+		console.log( '  Writing output.' );
+
 		fs.writeFileSync( output, code + sourcemapping, 'utf8' );
 
 		if ( args.sourcemaps ) {
 
+			console.log( '  Writing source map.' );
+
 			fs.writeFileSync( sourcemap, source_map.toString(), 'utf8' );
 
 		}
 
 	}
 
+	var deltaMS = Date.now() - startMS;
+	console.log( "  --- Build time: " + ( deltaMS / 1000 ) + "s" );
+
 }
 
 main();