Browse Source

Add Gulp for buiding babylon cross platform

Gulp.js is a succesfful build system based on nodejs.
Easy to use and easy to configure. Plus it's cross-platform.
Dimitri Larue 11 years ago
parent
commit
4b41b80f1d
5 changed files with 218 additions and 0 deletions
  1. 16 0
      Tools/Gulp/.gitignore
  2. 49 0
      Tools/Gulp/gulp-shaders.js
  3. 105 0
      Tools/Gulp/gulpfile.js
  4. 17 0
      Tools/Gulp/package.json
  5. 31 0
      Tools/Gulp/readme.md

+ 16 - 0
Tools/Gulp/.gitignore

@@ -0,0 +1,16 @@
+#NodeJS
+node_modules
+
+
+# OS or Editor folders
+*.DS_Store
+._*
+Thumbs.db
+.cache
+.project
+.settings
+.tmproj
+nbproject
+*.sublime-project
+*.sublime-workspace
+.directory

+ 49 - 0
Tools/Gulp/gulp-shaders.js

@@ -0,0 +1,49 @@
+var through = require('through');
+
+var gutil = require('gulp-util');
+var PluginError = gutil.PluginError;
+var File = gutil.File;
+var path = require('path');
+
+
+var shaders = function shaders() {
+
+  var firstFile = null;
+  var content = {};
+
+  function bufferContents(file){
+    if (file.isNull()) return; // ignore
+    if (file.isStream()) return this.emit('error', new PluginError('gulp-shaders',  'Streaming not supported'));
+
+    if (!firstFile) firstFile = file;
+
+    var fileName = file.path
+      .replace(file.base, '')
+      .replace('.fragment', 'Pixel')
+      .replace('.vertex', 'Vertex')
+      .replace('.fx', 'Shader');
+
+    content[fileName] = file.contents.toString('utf8').substring(1); //stript the BOM character
+  }
+
+  function endStream(){
+
+    var joinedPath = path.join(firstFile.base, 'shaders.js');
+
+    var joinedFile = new File({
+      cwd: firstFile.cwd,
+      base: firstFile.base,
+      path: joinedPath,
+      contents: new Buffer('BABYLON.Effect.ShadersStore='+JSON.stringify(content)+';')
+    });
+
+
+    this.emit('data', joinedFile);
+    this.emit('end');
+
+  }
+
+  return through(bufferContents, endStream);
+}
+
+module.exports = shaders;

+ 105 - 0
Tools/Gulp/gulpfile.js

@@ -0,0 +1,105 @@
+var gulp = require('gulp'),
+    uglify = require('gulp-uglify'),
+    rename = require('gulp-rename'),
+    concat = require('gulp-concat'),
+    clean = require('gulp-clean'),
+    shaders = require('./gulp-shaders');
+
+gulp.task('shaders', function() {
+  return gulp.src(['../../Babylon/Shaders/*.fx'])
+    .pipe(shaders())
+    .pipe(gulp.dest('build/'))
+
+});
+
+gulp.task('scripts', ['shaders'] ,function() {
+  return gulp.src([
+      '../../Babylon/Math/babylon.math.js',
+      '../../Babylon/Math/babylon.axis.js',
+      '../../Babylon/Tools/babylon.database.js',
+      '../../Babylon/Tools/babylon.tools.js',
+      '../../Babylon/Collisions/babylon.pickingInfo.js',
+      '../../Babylon/babylon.engine.js',
+      '../../Babylon/babylon.node.js',
+      '../../Babylon/Culling/babylon.boundingSphere.js',
+      '../../Babylon/Culling/babylon.boundingBox.js',
+      '../../Babylon/Culling/babylon.boundingInfo.js',
+      '../../Babylon/Lights/babylon.light.js',
+      '../../Babylon/Lights/babylon.pointLight.js',
+      '../../Babylon/Lights/babylon.spotLight.js',
+      '../../Babylon/Lights/babylon.hemisphericLight.js',
+      '../../Babylon/Lights/babylon.directionalLight.js',
+      '../../Babylon/Lights/Shadows/babylon.shadowGenerator.js',
+      '../../Babylon/Collisions/babylon.collider.js',
+      '../../Babylon/Cameras/babylon.camera.js',
+      '../../Babylon/Cameras/babylon.freeCamera.js',
+      '../../Babylon/Cameras/babylon.touchCamera.js',
+      '../../Babylon/Cameras/babylon.arcRotateCamera.js',
+      '../../Babylon/Cameras/babylon.deviceOrientationCamera.js',
+      '../../Babylon/Rendering/babylon.renderingManager.js',
+      '../../Babylon/Rendering/babylon.renderingGroup.js',
+      '../../Babylon/babylon.scene.js',
+      '../../Babylon/Mesh/babylon.vertexBuffer.js',
+      '../../Babylon/Mesh/babylon.mesh.js',
+      '../../Babylon/Mesh/babylon.subMesh.js',
+      '../../Babylon/Materials/textures/babylon.baseTexture.js',
+      '../../Babylon/Materials/textures/babylon.texture.js',
+      '../../Babylon/Materials/textures/babylon.cubeTexture.js',
+      '../../Babylon/Materials/textures/babylon.renderTargetTexture.js',
+      '../../Babylon/Materials/textures/babylon.mirrorTexture.js',
+      '../../Babylon/Materials/textures/babylon.dynamicTexture.js',
+      '../../Babylon/Materials/textures/babylon.videoTexture.js',
+      '../../Babylon/Materials/babylon.effect.js',
+      'build/shaders.js',
+      '../../Babylon/Materials/babylon.material.js',
+      '../../Babylon/Materials/babylon.standardMaterial.js',
+      '../../Babylon/Materials/babylon.multiMaterial.js',
+      '../../Babylon/Tools/babylon.sceneLoader.js',
+      '../../Babylon/Tools/babylon.database.js',
+      '../../Babylon/Sprites/babylon.spriteManager.js',
+      '../../Babylon/Sprites/babylon.sprite.js',
+      '../../Babylon/Layer/babylon.layer.js',
+      '../../Babylon/Particles/babylon.particle.js',
+      '../../Babylon/Particles/babylon.particleSystem.js',
+      '../../Babylon/Animations/babylon.animation.js',
+      '../../Babylon/Animations/babylon.animatable.js',
+      '../../Babylon/Culling/Octrees/babylon.octree.js',
+      '../../Babylon/Culling/Octrees/babylon.octreeBlock.js',
+      '../../Babylon/Bones/babylon.bone.js',
+      '../../Babylon/Bones/babylon.skeleton.js',
+      '../../Babylon/Bones/babylon.skeleton.js',
+      '../../Babylon/PostProcess/babylon.postProcess.js',
+      '../../Babylon/PostProcess/babylon.postProcessManager.js',
+      '../../Babylon/PostProcess/babylon.passPostProcess.js',
+      '../../Babylon/PostProcess/babylon.blurPostProcess.js',
+      '../../Babylon/PostProcess/babylon.refractionPostProcess.js',
+      '../../Babylon/PostProcess/babylon.blackAndWhitePostProcess.js',
+      '../../Babylon/PostProcess/babylon.convolutionPostProcess.js',
+      '../../Babylon/PostProcess/babylon.fxaaPostProcess.js',
+      '../../Babylon/LensFlare/babylon.lensFlare.js',
+      '../../Babylon/LensFlare/babylon.lensFlareSystem.js',
+      '../../Babylon/Tools/babylon.filesInput.js',
+      '../../Babylon/Physics/babylon.physicsEngine.js',
+      '../../Babylon/Physics/babylon.sceneSerializer.js',
+    ])
+    .pipe(concat('babylon.js'))
+    .pipe(gulp.dest('build/'))
+    .pipe(rename({suffix: '.min'}))
+    //.pipe(uglify({ outSourceMap: true })) //waiting for https://github.com/gulpjs/gulp/issues/356
+    .pipe(uglify())
+    .pipe(gulp.dest('build/'))
+
+});
+
+gulp.task('clean', ['scripts'], function() {
+  return gulp.src(['build/shaders.js'], {read: false})
+    .pipe(clean());
+});
+
+gulp.task('default', function() {
+    gulp.start('shaders','scripts', 'clean');
+});
+
+gulp.task('watch', function() {
+  gulp.watch('src/**/*.js', ['default']);
+});

+ 17 - 0
Tools/Gulp/package.json

@@ -0,0 +1,17 @@
+{
+  "name": "BabylonJS",
+  "version": "1.9.0",
+  "description": "",
+  "main": "",
+  "dependencies": {
+    "through": "^2.3.4"
+  },
+  "devDependencies": {
+    "gulp-rename": "^1.2.0",
+    "gulp-concat": "^2.2.0",
+    "gulp-clean": "^0.2.4",
+    "gulp": "^3.5.6",
+    "gulp-uglify": "^0.2.1",
+    "gulp-util": "^2.2.14"
+  }
+}

+ 31 - 0
Tools/Gulp/readme.md

@@ -0,0 +1,31 @@
+Build Babylon.js with Gulp
+====================
+
+Build Babylon.js with [gulp](http://gulpjs.com/ "gulp") and npm ([nodejs](http://nodejs.org/ "nodejs")), easy and cross-platform
+
+(Paths in this file are relative to this file location.)
+
+## How to use it
+
+### First install gulp :
+
+```
+npm install -g gulp
+```
+
+### Install some dependencies :
+
+```
+npm install
+```
+
+### Build Babylon.js :
+
+```
+gulp
+```
+
+### Build Babylon.js when you save a file:
+```
+gulp watch
+```