Explorar o código

ES6 back in first step

sebastien %!s(int64=6) %!d(string=hai) anos
pai
achega
2f264c5899

+ 132 - 0
Tools/Publisher/config/config.json

@@ -0,0 +1,132 @@
+{
+    "basePath": "../../dist/preview release/",
+    "packages": [
+        {
+            "name": "core",
+            "path": "../../"
+        },
+        {
+            "name": "gui",
+            "path": "gui/"
+        },
+        {
+            "name": "materials",
+            "path": "materialsLibrary/"
+        },
+        {
+            "name": "postProcess",
+            "path": "postProcessesLibrary/"
+        },
+        {
+            "name": "gltf2interface",
+            "path": "gltf2interface/"
+        },
+        {
+            "name": "loaders",
+            "path": "loaders/"
+        },
+        {
+            "name": "serializers",
+            "path": "serializers/"
+        },
+        {
+            "name": "proceduralTextures",
+            "path": "proceduralTexturesLibrary/"
+        },
+        {
+            "name": "inspector",
+            "path": "inspector/"
+        },
+        {
+            "name": "viewer",
+            "path": "Viewer/"
+        },
+        {
+            "name": "viewer-assets",
+            "path": "Viewer/build/assets/",
+            "required": [
+                "../../Viewer/assets/readme.md",
+                "../../Viewer/assets/package.json"
+            ]
+        }
+    ],
+    "es6": [
+        {
+            "name": "gui",
+            "path": "../../gui/",
+            "buildPath": "build/",
+            "packageName": "babylonjs-gui-es6",
+            "payload": {
+                "name": "babylonjs-gui-es6",
+                "description": "The Babylon.js GUI library is an extension you can use to generate interactive user interface. It is build on top of the DynamicTexture.",
+                "keywords": [
+                    "gui"
+                ],
+                "dependencies": {
+                    "babylonjs": true
+                }
+            }
+        },
+        {
+            "name": "materialsLibrary",
+            "path": "../../materialsLibrary/",
+            "buildPath": "build/",
+            "packageName": "babylonjs-materials-es6",
+            "payload": {
+                "name": "babylonjs-materials-es6",
+                "description": "The Babylon.js materials library is a collection of advanced materials to be used in a Babylon.js scene.",
+                "keywords": [
+                    "3D",
+                    "javascript",
+                    "html5",
+                    "webgl",
+                    "materials"
+                ],
+                "dependencies": {
+                    "babylonjs": true
+                }
+            }
+        },
+        {
+            "name": "inspector",
+            "path": "../../inspector/",
+            "buildPath": "build/",
+            "packageName": "babylonjs-inspector-es6",
+            "payload": {
+                "name": "babylonjs-inspector-es6",
+                "description": "The Babylon.js inspector.",
+                "keywords": [
+                    "inspector"
+                ],
+                "dependencies": {
+                    "babylonjs-gui": true,
+                    "babylonjs": true
+                }
+            }
+        },
+        {
+            "name": "viewer",
+            "path": "../../Viewer/",
+            "buildPath": "build/src/",
+            "packageName": "babylonjs-viewer-es6",
+            "payload": {
+                "name": "babylonjs-viewer-es6",
+                "description": "A simple-to-use viewer based on BabylonJS to display 3D elements natively",
+                "keywords": [
+                    "viewer"
+                ],
+                "dependencies": {
+                    "babylonjs-loaders": true,
+                    "babylonjs": true,
+                    "babylonjs-gltf2interface": true,
+                    "pepjs": "^0.4.3",
+                    "deepmerge": "^2.1.1",
+                    "handlebars": "^4.0.11"
+                },
+                "peerDependencies": {
+                    "babylonjs-viewer-assets": true
+                }
+            }
+        }
+    ]
+}

+ 29 - 0
Tools/Publisher/config/template.package.json

@@ -0,0 +1,29 @@
+{
+    "author": {
+        "name": "David CATUHE"
+    },
+    "contributors": [
+        "David ROUSSET",
+        "Sebastien VANDENBERGHE",
+        "Raanan Weber"
+    ],
+    "name": "",
+    "description": "",
+    "version": "",
+    "repository": {
+        "type": "git",
+        "url": "https://github.com/BabylonJS/Babylon.js.git"
+    },
+    "main": "index.js",
+    "module": "index.js",
+    "esnext": "index.js",
+    "files": [],
+    "typings": "index.d.ts",
+    "keywords": [
+        "3D",
+        "javascript",
+        "html5",
+        "webgl"
+    ],
+    "license": "Apache-2.0"
+}

+ 21 - 283
Tools/Publisher/index.js

@@ -1,285 +1,23 @@
-let prompt = require('prompt');
-let shelljs = require('shelljs');
-let fs = require('fs-extra');
-let path = require('path');
-
-let basePath = '../../dist/preview release';
-
-// This can be changed when we have a new major release.
-let minimumDependency = '>=3.3.0-rc.4';
-
-process.env.PATH += (path.delimiter + path.join(__dirname, 'node_modules', '.bin'));
-
-let packages = [
-    {
-        name: 'core',
-        path: '../../'
-    },
-    {
-        name: 'gui',
-        path: basePath + '/gui/'
-    },
-    {
-        name: 'materials',
-        path: basePath + '/materialsLibrary/'
-    },
-    {
-        name: 'postProcess',
-        path: basePath + '/postProcessesLibrary/'
-    },
-    {
-        name: 'gltf2interface',
-        path: basePath + '/gltf2interface/'
-    },
-    {
-        name: 'loaders',
-        path: basePath + '/loaders/'
-    },
-    {
-        name: 'serializers',
-        path: basePath + '/serializers/'
-    },
-    {
-        name: 'proceduralTextures',
-        path: basePath + '/proceduralTexturesLibrary/'
-    },
-    {
-        name: 'inspector',
-        path: basePath + '/inspector/'
-    },
-    {
-        name: 'viewer',
-        path: basePath + '/../../Viewer/',
-        required: [
-            basePath + '/viewer/readme.md',
-            basePath + '/viewer/package.json',
-            basePath + '/viewer/babylon.viewer.js',
-            basePath + '/viewer/babylon.viewer.max.js'
-        ]
-    },
-    {
-        name: 'viewer-assets',
-        path: basePath + '/../../Viewer/build/assets/',
-        required: [
-            basePath + '/../../Viewer/assets/readme.md',
-            basePath + '/../../Viewer/assets/package.json',
-        ]
-    }
-];
-
-function updateEngineVersion(newVersion) {
-    console.log("updating version in babylon.engine.ts");
-    let engineContent = fs.readFileSync("../../src/Engine/babylon.engine.ts").toString();
-    let replaced = engineContent.replace(/(public static get Version\(\): string {\s*return ")(.*)(";\s*})/g, "$1" + newVersion + "$3");
-    fs.writeFileSync("../../src/Engine/babylon.engine.ts", replaced);
-}
-
-function runGulp() {
-    // run gulp typescript-all
-    console.log("Running gulp compilation");
-    let exec = shelljs.exec("gulp typescript-all --gulpfile ../Gulp/gulpfile.js");
-    if (exec.code) {
-        console.log("error during compilation, aborting");
-        process.exit(1);
-    }
-}
-
-function processPackages(version) {
-    packages.forEach((package) => {
-        if (package.name === "core") {
-            processCore(package, version);
-        } else if (package.name === "viewer") {
-            processViewer(package, version);
-        } else {
-
-            if (package.required) {
-                package.required.forEach(file => {
-                    fs.copySync(file, package.path + '/' + path.basename(file));
-                });
-            }
-
-            let packageJson = require(package.path + 'package.json');
-            packageJson.version = version;
-            if (packageJson.dependencies) {
-                Object.keys(packageJson.dependencies).forEach(key => {
-                    if (key.indexOf("babylonjs") !== -1) {
-                        packageJson.dependencies[key] = version;
-                    }
-                });
-            }
-            if (packageJson.peerDependencies) packageJson.peerDependencies.babylonjs = minimumDependency;
-            fs.writeFileSync(package.path + 'package.json', JSON.stringify(packageJson, null, 4));
-
-            publish(version, package.name, package.path);
-        }
-
-    });
-}
-
-//check if logged in
-console.log("Using npm user:");
-let loginCheck = shelljs.exec('npm whoami');
-if (loginCheck.code === 0) {
-    prompt.start();
-
-    prompt.get(['version'], function(err, result) {
-        let version = result.version;
-        updateEngineVersion(version);
-        if (process.argv.indexOf('--no-build') === -1) {
-            runGulp();
-        }
-        processPackages(version);
-
-        console.log("done, please tag git with " + version);
-    });
-} else {
-    console.log('not logged in.');
-}
-
-function processCore(package, version) {
-    let packageJson = require(package.path + 'package.json');
-
-    // make a temporary directory
-    fs.ensureDirSync(basePath + '/package/');
-
-    let files = [
-        {
-            path: basePath + "/babylon.d.ts",
-            objectName: "babylon.d.ts"
-        },
-        {
-            path: basePath + "/es6.js",
-            objectName: "es6.js"
-        },
-        {
-            path: basePath + "/babylon.js",
-            objectName: "babylon.js"
-        },
-        {
-            path: basePath + "/babylon.max.js",
-            objectName: "babylon.max.js"
-        },
-        {
-            path: basePath + "/babylon.worker.js",
-            objectName: "babylon.worker.js"
-        },
-        {
-            path: basePath + "/Oimo.js",
-            objectName: "Oimo.js"
-        },
-        {
-            path: package.path + "readme.md",
-            objectName: "readme.md"
-        }
-    ];
-
-    //copy them to the package path
-    files.forEach(file => {
-        fs.copySync(file.path, basePath + '/package/' + file.objectName);
-    });
-
-    // update package.json
-    packageJson.version = version;
-    console.log("generating file list");
-    let packageFiles = ["package.json"];
-    files.forEach(file => {
-        if (!file.isDir) {
-            packageFiles.push(file.objectName);
-        } else {
-            //todo is it better to read the content and add it? leave it like that ATM
-            packageFiles.push(file.objectName + "/index.js", file.objectName + "/index.d.ts", file.objectName + "/es6.js")
-        }
-    });
-    console.log("updating package.json");
-    packageJson.files = packageFiles;
-    packageJson.main = "babylon.js";
-    packageJson.typings = "babylon.d.ts";
-
-    fs.writeFileSync(basePath + '/package/' + 'package.json', JSON.stringify(packageJson, null, 4));
-
-    publish(version, package.name, basePath + '/package/');
-
-    // remove package directory
-    fs.removeSync(basePath + '/package/');
-
-    // now update the main package.json
-    packageJson.files = packageJson.files.map(file => {
-        if (file !== 'package.json' && file !== 'readme.md') {
-            return 'dist/preview release/' + file;
-        } else {
-            return file;
-        }
-    });
-    packageJson.main = "dist/preview release/babylon.js";
-    packageJson.typings = "dist/preview release/babylon.d.ts";
-
-    fs.writeFileSync(package.path + 'package.json', JSON.stringify(packageJson, null, 4));
-}
-
-function processViewer(package, version) {
-
-    let buildPath = package.path + "build/src/";
-    let projectPath = '../../Viewer';
-
-    if (package.required) {
-        package.required.forEach(file => {
-
-            fs.copySync(file, buildPath + '/' + path.basename(file));
-        });
-    }
-    // the viewer needs to be built using tsc on the viewer's main repository
-
-    // build the viewer
-    console.log("executing " + 'tsc -p ' + projectPath);
-
-    let tscCompile = shelljs.exec('tsc -p ' + projectPath);
-    if (tscCompile.code !== 0) {
-        throw new Error("tsc compilation failed");
+// Dependecies.
+const publisher = require('./publisher');
+
+// CMD Arguments Management.
+const doNotBuild = process.argv.indexOf('--no-build') === -1;
+const doNotPublish = process.argv.indexOf('--no-publish') === -1;
+
+/**
+ * Main function driving the publication.
+ */
+function main() {
+    // Gets the current npm user.
+    console.log("Using npm user:");
+    let loginCheck = shelljs.exec('npm whoami');
+    // If logged in process.
+    if (loginCheck.code === 0) {
+        publisher.process(doNotBuild, doNotPublish, true);
     }
-
-    let packageJson = require(buildPath + '/package.json');
-
-    let files = getFiles(buildPath).map(f => f.replace(buildPath + "/", "")).filter(f => f.indexOf("assets/") === -1);
-
-    packageJson.files = files;
-    packageJson.version = version;
-    packageJson.module = "index.js";
-    packageJson.main = "babylon.viewer.js";
-    packageJson.typings = "index.d.ts";
-
-    fs.writeFileSync(buildPath + '/package.json', JSON.stringify(packageJson, null, 4));
-
-    publish(version, package.name, buildPath);
-
-}
-
-function publish(version, packageName, basePath) {
-    console.log('Publishing ' + packageName + " from " + basePath);
-
-    let tagDef = "";
-    // check for alpha or beta
-    if (version.indexOf('alpha') !== -1 || version.indexOf('beta') !== -1 || version.indexOf('-rc.') !== -1) {
-        tagDef = '--tag preview';
-    }
-
-    //publish the respected package
-    console.log("executing " + 'npm publish \"' + basePath + "\"" + ' ' + tagDef);
-    if (process.argv.indexOf('--no-publish') === -1) {
-        shelljs.exec('npm publish \"' + basePath + "\"" + ' ' + tagDef);
-    }
-
-}
-
-function getFiles(dir, files_) {
-    files_ = files_ || [];
-    var files = fs.readdirSync(dir);
-    for (var i in files) {
-        var name = dir + '/' + files[i];
-        if (fs.statSync(name).isDirectory()) {
-            getFiles(name, files_);
-        } else {
-            files_.push(name);
-        }
+    // If not logged in error.
+    else {
+        console.log('Not logged in, please log in to npm.');
     }
-    return files_;
-}
+}();

+ 285 - 0
Tools/Publisher/index.js.bak

@@ -0,0 +1,285 @@
+let prompt = require('prompt');
+let shelljs = require('shelljs');
+let fs = require('fs-extra');
+let path = require('path');
+
+let basePath = '../../dist/preview release';
+
+// This can be changed when we have a new major release.
+let minimumDependency = '>=3.3.0-rc.4';
+
+process.env.PATH += (path.delimiter + path.join(__dirname, 'node_modules', '.bin'));
+
+let packages = [
+    {
+        name: 'core',
+        path: '../../'
+    },
+    {
+        name: 'gui',
+        path: basePath + '/gui/'
+    },
+    {
+        name: 'materials',
+        path: basePath + '/materialsLibrary/'
+    },
+    {
+        name: 'postProcess',
+        path: basePath + '/postProcessesLibrary/'
+    },
+    {
+        name: 'gltf2interface',
+        path: basePath + '/gltf2interface/'
+    },
+    {
+        name: 'loaders',
+        path: basePath + '/loaders/'
+    },
+    {
+        name: 'serializers',
+        path: basePath + '/serializers/'
+    },
+    {
+        name: 'proceduralTextures',
+        path: basePath + '/proceduralTexturesLibrary/'
+    },
+    {
+        name: 'inspector',
+        path: basePath + '/inspector/'
+    },
+    {
+        name: 'viewer',
+        path: basePath + '/../../Viewer/',
+        required: [
+            basePath + '/viewer/readme.md',
+            basePath + '/viewer/package.json',
+            basePath + '/viewer/babylon.viewer.js',
+            basePath + '/viewer/babylon.viewer.max.js'
+        ]
+    },
+    {
+        name: 'viewer-assets',
+        path: basePath + '/../../Viewer/build/assets/',
+        required: [
+            basePath + '/../../Viewer/assets/readme.md',
+            basePath + '/../../Viewer/assets/package.json',
+        ]
+    }
+];
+
+function updateEngineVersion(newVersion) {
+    console.log("updating version in babylon.engine.ts");
+    let engineContent = fs.readFileSync("../../src/Engine/babylon.engine.ts").toString();
+    let replaced = engineContent.replace(/(public static get Version\(\): string {\s*return ")(.*)(";\s*})/g, "$1" + newVersion + "$3");
+    fs.writeFileSync("../../src/Engine/babylon.engine.ts", replaced);
+}
+
+function runGulp() {
+    // run gulp typescript-all
+    console.log("Running gulp compilation");
+    let exec = shelljs.exec("gulp typescript-all --gulpfile ../Gulp/gulpfile.js");
+    if (exec.code) {
+        console.log("error during compilation, aborting");
+        process.exit(1);
+    }
+}
+
+function processPackages(version) {
+    packages.forEach((package) => {
+        if (package.name === "core") {
+            processCore(package, version);
+        } else if (package.name === "viewer") {
+            processViewer(package, version);
+        } else {
+
+            if (package.required) {
+                package.required.forEach(file => {
+                    fs.copySync(file, package.path + '/' + path.basename(file));
+                });
+            }
+
+            let packageJson = require(package.path + 'package.json');
+            packageJson.version = version;
+            if (packageJson.dependencies) {
+                Object.keys(packageJson.dependencies).forEach(key => {
+                    if (key.indexOf("babylonjs") !== -1) {
+                        packageJson.dependencies[key] = version;
+                    }
+                });
+            }
+            if (packageJson.peerDependencies) packageJson.peerDependencies.babylonjs = minimumDependency;
+            fs.writeFileSync(package.path + 'package.json', JSON.stringify(packageJson, null, 4));
+
+            publish(version, package.name, package.path);
+        }
+
+    });
+}
+
+//check if logged in
+console.log("Using npm user:");
+let loginCheck = shelljs.exec('npm whoami');
+if (loginCheck.code === 0) {
+    prompt.start();
+
+    prompt.get(['version'], function(err, result) {
+        let version = result.version;
+        updateEngineVersion(version);
+        if (process.argv.indexOf('--no-build') === -1) {
+            runGulp();
+        }
+        processPackages(version);
+
+        console.log("done, please tag git with " + version);
+    });
+} else {
+    console.log('not logged in.');
+}
+
+function processCore(package, version) {
+    let packageJson = require(package.path + 'package.json');
+
+    // make a temporary directory
+    fs.ensureDirSync(basePath + '/package/');
+
+    let files = [
+        {
+            path: basePath + "/babylon.d.ts",
+            objectName: "babylon.d.ts"
+        },
+        {
+            path: basePath + "/es6.js",
+            objectName: "es6.js"
+        },
+        {
+            path: basePath + "/babylon.js",
+            objectName: "babylon.js"
+        },
+        {
+            path: basePath + "/babylon.max.js",
+            objectName: "babylon.max.js"
+        },
+        {
+            path: basePath + "/babylon.worker.js",
+            objectName: "babylon.worker.js"
+        },
+        {
+            path: basePath + "/Oimo.js",
+            objectName: "Oimo.js"
+        },
+        {
+            path: package.path + "readme.md",
+            objectName: "readme.md"
+        }
+    ];
+
+    //copy them to the package path
+    files.forEach(file => {
+        fs.copySync(file.path, basePath + '/package/' + file.objectName);
+    });
+
+    // update package.json
+    packageJson.version = version;
+    console.log("generating file list");
+    let packageFiles = ["package.json"];
+    files.forEach(file => {
+        if (!file.isDir) {
+            packageFiles.push(file.objectName);
+        } else {
+            //todo is it better to read the content and add it? leave it like that ATM
+            packageFiles.push(file.objectName + "/index.js", file.objectName + "/index.d.ts", file.objectName + "/es6.js")
+        }
+    });
+    console.log("updating package.json");
+    packageJson.files = packageFiles;
+    packageJson.main = "babylon.js";
+    packageJson.typings = "babylon.d.ts";
+
+    fs.writeFileSync(basePath + '/package/' + 'package.json', JSON.stringify(packageJson, null, 4));
+
+    publish(version, package.name, basePath + '/package/');
+
+    // remove package directory
+    fs.removeSync(basePath + '/package/');
+
+    // now update the main package.json
+    packageJson.files = packageJson.files.map(file => {
+        if (file !== 'package.json' && file !== 'readme.md') {
+            return 'dist/preview release/' + file;
+        } else {
+            return file;
+        }
+    });
+    packageJson.main = "dist/preview release/babylon.js";
+    packageJson.typings = "dist/preview release/babylon.d.ts";
+
+    fs.writeFileSync(package.path + 'package.json', JSON.stringify(packageJson, null, 4));
+}
+
+function processViewer(package, version) {
+
+    let buildPath = package.path + "build/src/";
+    let projectPath = '../../Viewer';
+
+    if (package.required) {
+        package.required.forEach(file => {
+
+            fs.copySync(file, buildPath + '/' + path.basename(file));
+        });
+    }
+    // the viewer needs to be built using tsc on the viewer's main repository
+
+    // build the viewer
+    console.log("executing " + 'tsc -p ' + projectPath);
+
+    let tscCompile = shelljs.exec('tsc -p ' + projectPath);
+    if (tscCompile.code !== 0) {
+        throw new Error("tsc compilation failed");
+    }
+
+    let packageJson = require(buildPath + '/package.json');
+
+    let files = getFiles(buildPath).map(f => f.replace(buildPath + "/", "")).filter(f => f.indexOf("assets/") === -1);
+
+    packageJson.files = files;
+    packageJson.version = version;
+    packageJson.module = "index.js";
+    packageJson.main = "babylon.viewer.js";
+    packageJson.typings = "index.d.ts";
+
+    fs.writeFileSync(buildPath + '/package.json', JSON.stringify(packageJson, null, 4));
+
+    publish(version, package.name, buildPath);
+
+}
+
+function publish(version, packageName, basePath) {
+    console.log('Publishing ' + packageName + " from " + basePath);
+
+    let tagDef = "";
+    // check for alpha or beta
+    if (version.indexOf('alpha') !== -1 || version.indexOf('beta') !== -1 || version.indexOf('-rc.') !== -1) {
+        tagDef = '--tag preview';
+    }
+
+    //publish the respected package
+    console.log("executing " + 'npm publish \"' + basePath + "\"" + ' ' + tagDef);
+    if (process.argv.indexOf('--no-publish') === -1) {
+        shelljs.exec('npm publish \"' + basePath + "\"" + ' ' + tagDef);
+    }
+
+}
+
+function getFiles(dir, files_) {
+    files_ = files_ || [];
+    var files = fs.readdirSync(dir);
+    for (var i in files) {
+        var name = dir + '/' + files[i];
+        if (fs.statSync(name).isDirectory()) {
+            getFiles(name, files_);
+        } else {
+            files_.push(name);
+        }
+    }
+    return files_;
+}

+ 332 - 0
Tools/Publisher/publisher.js

@@ -0,0 +1,332 @@
+// Dependecies.
+const prompt = require('prompt');
+const shelljs = require('shelljs');
+const fs = require('fs-extra');
+const path = require('path');
+
+// This can be changed when we have a new major release.
+const minimumDependency = '>=3.4.0-alpha';
+
+// CMD Arguments Management.
+let doNotBuild = false;
+let doNotPublish = false;
+
+// Pathe management.
+process.env.PATH += (path.delimiter + path.join(__dirname, 'node_modules', '.bin'));
+
+// Global Variables.
+const config = require("./config/config.json");
+const basePath = config.basePath;
+const packages = config.packages;
+
+/**
+ * Remove a directory.
+ */
+const rmDir = function (dirPath) {
+    try { var files = fs.readdirSync(dirPath); }
+    catch (e) { return; }
+    if (files.length > 0)
+        for (var i = 0; i < files.length; i++) {
+            var filePath = dirPath + '/' + files[i];
+            if (fs.statSync(filePath).isFile())
+                fs.unlinkSync(filePath);
+            else
+                rmDir(filePath);
+        }
+    fs.rmdirSync(dirPath);
+};
+
+/**
+ * Get Files from folder.
+ */
+const getFiles = function(dir, files_) {
+    files_ = files_ || [];
+    var files = fs.readdirSync(dir);
+    for (var i in files) {
+        var name = dir + '/' + files[i];
+        if (fs.statSync(name).isDirectory()) {
+            getFiles(name, files_);
+        } else {
+            files_.push(name);
+        }
+    }
+    return files_;
+}
+
+/**
+ * Update the version in the engine class for Babylon
+ */
+function updateEngineVersion(newVersion) {
+    console.log("Updating version in babylon.engine.ts to: " + newVersion);
+    let engineContent = fs.readFileSync("../../src/Engine/babylon.engine.ts").toString();
+    let replaced = engineContent.replace(/(public static get Version\(\): string {\s*return ")(.*)(";\s*})/g, "$1" + newVersion + "$3");
+    fs.writeFileSync("../../src/Engine/babylon.engine.ts", replaced);
+}
+
+/**
+ * Get the version from the engine class for Babylon
+ */
+function getEngineVersion() {
+    console.log("Get version from babylon.engine.ts");
+    const engineContent = fs.readFileSync("../../src/Engine/babylon.engine.ts").toString();
+    var versionRegex = new RegExp(`public static get Version\(\): string {[\s\S]*return "([\s\S]*?)";[\s\S]*}`, "gm");
+    versionRegex.exec(engineContent);
+    if (match && match.length) {
+        const version = match[1];
+        console.log("Version found: " + version);
+        return version;
+    }
+
+    console.log("Version not found in engine.ts");
+    process.exit(1);
+}
+
+/**
+ * Publish a package to npm.
+ */
+function publish(version, packageName, basePath) {
+    console.log('Publishing ' + packageName + " from " + basePath);
+
+    let tag = "";
+    // check for alpha or beta
+    if (version.indexOf('alpha') !== -1 || version.indexOf('beta') !== -1) {
+        tag = '--tag preview';
+    }
+
+    //publish the respected package
+    if (doNotPublish) {
+        console.log("If publishing enabled: " + 'npm publish \"' + basePath + "\"" + ' ' + tag);
+    }
+    else {
+        console.log("Executing: " + 'npm publish \"' + basePath + "\"" + ' ' + tag);
+        shelljs.exec('npm publish \"' + basePath + "\"" + ' ' + tag);
+    }
+}
+
+/**
+ * Build the folder with Gulp.
+ */
+function buildBabylonJSAndDependencies() {
+    // run gulp typescript-all
+    console.log("Running gulp compilation");
+    let exec = shelljs.exec("gulp typescript-all --gulpfile ../Gulp/gulpfile.js");
+    if (exec.code) {
+        console.log("Error during compilation, aborting");
+        process.exit(1);
+    }
+}
+
+/**
+ * Process Legacy Packages.
+ */
+function processLegacyPackages(version) {
+    packages.forEach((package) => {
+        if (package.name === "core") {
+            processCore(package, version);
+        else {
+            if (package.required) {
+                package.required.forEach(file => {
+                    fs.copySync(basePath + file, basePath + package.path + '/' + path.basename(file));
+                });
+            }
+
+            let packageJson = require(basePath + package.path + 'package.json');
+            packageJson.version = version;
+            if (packageJson.dependencies) {
+                Object.keys(packageJson.dependencies).forEach(key => {
+                    if (key.indexOf("babylonjs") !== -1) {
+                        packageJson.dependencies[key] = version;
+                    }
+                });
+            }
+            if (packageJson.peerDependencies) packageJson.peerDependencies.babylonjs = minimumDependency;
+            fs.writeFileSync(basePath + package.path + 'package.json', JSON.stringify(packageJson, null, 4));
+
+            publish(version, package.name, basePath + package.path);
+        }
+    });
+}
+
+/**
+ * Process ES6 Packages.
+ */
+function processEs6Packages(version) {
+    let es6Packages = config.es6;
+
+    es6Packages.forEach(package => {
+        let projectPath = package.path;
+        let buildPath = path.normalize(basePath + projectPath + package.buildPath);
+
+        if (package.required) {
+            package.required.forEach(file => {
+                fs.copySync(file, basePath + '/' + path.basename(file));
+            });
+        }
+
+        console.log("Cleanup " + buildPath);
+        rmDir(buildPath);
+
+        console.log("Executing " + 'tsc -t es6 -m esNext -p ' + projectPath);
+
+        let tscCompile = shelljs.exec('tsc -t es6 -m esNext -p ' + projectPath);
+        if (tscCompile.code !== 0) {
+            throw new Error("Tsc compilation failed");
+        }
+
+        let packageJson = require("./config" + '/template.package.json');
+        let files = getFiles(buildPath).map(f => f.replace(buildPath + "/", "")).filter(f => f.indexOf("assets/") === -1);
+
+        packageJson.files = files;
+        packageJson.version = version;
+
+        Object.keys(package.payload).forEach(key => {
+            packageJson[key] = package.payload[key]
+        });
+
+        ["dependencies", "peerDependencies", "devDependencies"].forEach(key => {
+            if (package.payload[key]) {
+                packageJson[key] = {};
+                Object.keys(package.payload[key]).forEach(packageName => {
+                    if (package.payload[key][packageName] === true) {
+                        packageJson[key][packageName] = version;
+                    } else {
+                        packageJson[key][packageName] = package.payload[key][packageName];
+                    }
+                });
+            }
+        });
+
+        fs.writeFileSync(buildPath + '/package.json', JSON.stringify(packageJson, null, 4));
+
+        publish(version, package.name, buildPath);
+    });
+}
+
+/**
+ * Special treatment for core.
+ */
+function processCore(package, version) {
+    let packageJson = require(package.path + 'package.json');
+
+    // make a temporary directory
+    fs.ensureDirSync(basePath + 'package/');
+
+    let files = [
+        {
+            path: basePath + "babylon.d.ts",
+            objectName: "babylon.d.ts"
+        },
+        {
+            path: basePath + "es6.js",
+            objectName: "es6.js"
+        },
+        {
+            path: basePath + "babylon.js",
+            objectName: "babylon.js"
+        },
+        {
+            path: basePath + "babylon.max.js",
+            objectName: "babylon.max.js"
+        },
+        {
+            path: basePath + "babylon.worker.js",
+            objectName: "babylon.worker.js"
+        },
+        {
+            path: basePath + "Oimo.js",
+            objectName: "Oimo.js"
+        },
+        {
+            path: basePath + package.path + "readme.md",
+            objectName: "readme.md"
+        }
+    ];
+
+    //copy them to the package path
+    files.forEach(file => {
+        fs.copySync(file.path, basePath + 'package/' + file.objectName);
+    });
+
+    // update package.json
+    packageJson.version = version;
+    console.log("generating file list");
+    let packageFiles = ["package.json"];
+    files.forEach(file => {
+        if (!file.isDir) {
+            packageFiles.push(file.objectName);
+        } else {
+            //todo is it better to read the content and add it? leave it like that ATM
+            packageFiles.push(file.objectName + "/index.js", file.objectName + "/index.d.ts", file.objectName + "/es6.js")
+        }
+    });
+    console.log("updating package.json");
+    packageJson.files = packageFiles;
+    packageJson.main = "babylon.js";
+    packageJson.typings = "babylon.d.ts";
+
+    fs.writeFileSync(basePath + 'package/' + 'package.json', JSON.stringify(packageJson, null, 4));
+
+    publish(version, package.name, basePath + 'package/');
+
+    // remove package directory
+    fs.removeSync(basePath + 'package/');
+
+    // now update the main package.json
+    packageJson.files = packageJson.files.map(file => {
+        if (file !== 'package.json' && file !== 'readme.md') {
+            return 'dist/preview release/' + file;
+        } else {
+            return file;
+        }
+    });
+    packageJson.main = "dist/preview release/babylon.js";
+    packageJson.typings = "dist/preview release/babylon.d.ts";
+
+    fs.writeFileSync(package.path + 'package.json', JSON.stringify(packageJson, null, 4));
+}
+
+const createVersion = function(version) {
+    // Prevent to build for test Cases.
+    if (!doNotBuild) {
+        buildBabylonJSAndDependencies();
+    }
+
+    // Create the packages and publish if needed.
+    processLegacyPackages(version);
+    processEs6Packages(version);
+}
+
+/**
+ * Main function driving the publication.
+ */
+module.exports = function(noBuild, noPublish, askVersion) {
+    doNotBuild = noBuild;
+    doNotPublish = noPublish;
+
+    if (askVersion) {
+        prompt.start();
+
+        prompt.get(['version'], function (err, result) {
+            const version = result.version;
+            
+            // Update the engine version if needed.
+            if (!version || !version.length) {
+                console.log("New version required.");
+                Process.exit(1);
+                return;
+            }
+
+            updateEngineVersion(version);
+            createVersion(version);
+
+            // Invite user to tag with the new version.
+            if (newVersion) {
+                console.log("Done, please tag git with " + version);
+            }
+        });
+    }
+    else {
+        const version = getEngineVersion();
+        createVersion(version);
+    }
+}();

+ 13 - 0
Tools/Publisher/test.js

@@ -0,0 +1,13 @@
+// Dependecies.
+const publisher = require('./publisher');
+
+// CMD Arguments Management.
+const doNotBuild = true;
+const doNotPublish = true;
+
+/**
+ * Main function driving the publication.
+ */
+function main() {
+    publisher.process(doNotBuild, doNotPublish, false);
+}();

+ 2 - 122
Tools/WebpackShaderLoader/index.js

@@ -4,132 +4,12 @@
 var fs = require('fs');
 var path = require('path');
 
-
-function parse(loader, source, context, cb) {
-    var imports = [];
-    var importPattern = /@import ([.\/\w_-]+);/gi;
-    var match = importPattern.exec(source);
-
-    while (match != null) {
-        imports.push({
-            key: match[1],
-            target: match[0],
-            content: ''
-        });
-        match = importPattern.exec(source);
-    }
-
-    source = uncomment(source);
-
-    processImports(loader, source, context, imports, cb);
-}
-
-var singleComment = 1;
-var multiComment = 2;
-
-function uncomment(str) {
-
-    var currentChar;
-    var nextChar;
-    var insideString = false;
-    var insideComment = 0;
-    var offset = 0;
-    var ret = '';
-
-    str = str.replace(/\r\n/g, '\n');
-    str = str.replace(/[ \f\t\v]+/g, ' ');
-    str = str.replace(/^\s*\n/gm, '');
-    str = str.replace(/ \+ /g, '+');
-    str = str.replace(/ \- /g, '-');
-    str = str.replace(/ \/ /g, '/');
-    str = str.replace(/ \* /g, '*');
-    str = str.replace(/ > /g, '>');
-    str = str.replace(/ < /g, '<');
-    str = str.replace(/ >= /g, '>=');
-    str = str.replace(/ <= /g, '<=');
-    str = str.replace(/ \+= /g, '+=');
-    str = str.replace(/ \-= /g, '-=');
-    str = str.replace(/ \/= /g, '/=');
-    str = str.replace(/ \*= /g, '*=');
-    str = str.replace(/ = /g, '=');
-    str = str.replace(/, /g, ',');
-    str = str.replace(/\n\n/g, '\n');
-    str = str.replace(/\n /g, '\n');
-
-    for (var i = 0; i < str.length; i++) {
-        currentChar = str[i];
-        nextChar = str[i + 1];
-
-        if (!insideComment && currentChar === '"') {
-            var escaped = str[i - 1] === '\\' && str[i - 2] !== '\\';
-            if (!escaped) {
-                insideString = !insideString;
-            }
-        }
-
-        if (insideString) {
-            continue;
-        }
-
-        if (!insideComment && currentChar + nextChar === '//') {
-            ret += str.slice(offset, i);
-            offset = i;
-            insideComment = singleComment;
-            i++;
-        } else if (insideComment === singleComment && currentChar === '\n') {
-            insideComment = 0;
-            offset = i;
-        } else if (!insideComment && currentChar + nextChar === '/*') {
-            ret += str.slice(offset, i);
-            offset = i;
-            insideComment = multiComment;
-            i++;
-            continue;
-        } else if (insideComment === multiComment && currentChar + nextChar === '*/') {
-            i++;
-            insideComment = 0;
-            offset = i + 1;
-            continue;
-        }
-    }
-
-    return ret + (insideComment ? '' : str.substr(offset));
-}
-
-function processImports(loader, source, context, imports, cb) {
-    if (imports.length === 0) {
-        return cb(null, source);
-    }
-
-    var imp = imports.pop();
-
-    loader.resolve(context, imp.key + '.fx', function (err, resolved) {
-        if (err) {
-            return cb(err);
-        }
-
-        loader.addDependency(resolved);
-        fs.readFile(resolved, 'utf-8', function (err, src) {
-            if (err) {
-                return cb(err);
-            }
-
-            parse(loader, src, path.dirname(resolved), function (err, bld) {
-                if (err) {
-                    return cb(err);
-                }
-
-                source = source.replace(imp.target, bld);
-                processImports(loader, source, context, imports, cb);
-            });
-        });
-    });
-}
+let parser = require('./parser')
 
 module.exports = function (source) {
     this.cacheable();
     var cb = this.async();
-    parse(this, source, this.context, function (err, bld) {
+    parser(this, source, this.context, function (err, bld) {
         if (err) {
             return cb(err);
         }

+ 105 - 0
Tools/WebpackShaderLoader/parser.js

@@ -0,0 +1,105 @@
+var fs = require('fs');
+var path = require('path');
+ function parse(loader, source, context, cb) {
+    var imports = [];
+    var importPattern = /@import ([.\/\w_-]+);/gi;
+    var match = importPattern.exec(source);
+     while (match != null) {
+        imports.push({
+            key: match[1],
+            target: match[0],
+            content: ''
+        });
+        match = importPattern.exec(source);
+    }
+     source = uncomment(source);
+     processImports(loader, source, context, imports, cb);
+}
+ var singleComment = 1;
+var multiComment = 2;
+ function uncomment(str) {
+     var currentChar;
+    var nextChar;
+    var insideString = false;
+    var insideComment = 0;
+    var offset = 0;
+    var ret = '';
+     str = str.replace(/\r\n/g, '\n');
+    str = str.replace(/[ \f\t\v]+/g, ' ');
+    str = str.replace(/^\s*\n/gm, '');
+    str = str.replace(/ \+ /g, '+');
+    str = str.replace(/ \- /g, '-');
+    str = str.replace(/ \/ /g, '/');
+    str = str.replace(/ \* /g, '*');
+    str = str.replace(/ > /g, '>');
+    str = str.replace(/ < /g, '<');
+    str = str.replace(/ >= /g, '>=');
+    str = str.replace(/ <= /g, '<=');
+    str = str.replace(/ \+= /g, '+=');
+    str = str.replace(/ \-= /g, '-=');
+    str = str.replace(/ \/= /g, '/=');
+    str = str.replace(/ \*= /g, '*=');
+    str = str.replace(/ = /g, '=');
+    str = str.replace(/, /g, ',');
+    str = str.replace(/\n\n/g, '\n');
+    str = str.replace(/\n /g, '\n');
+     for (var i = 0; i < str.length; i++) {
+        currentChar = str[i];
+        nextChar = str[i + 1];
+         if (!insideComment && currentChar === '"') {
+            var escaped = str[i - 1] === '\\' && str[i - 2] !== '\\';
+            if (!escaped) {
+                insideString = !insideString;
+            }
+        }
+         if (insideString) {
+            continue;
+        }
+         if (!insideComment && currentChar + nextChar === '//') {
+            ret += str.slice(offset, i);
+            offset = i;
+            insideComment = singleComment;
+            i++;
+        } else if (insideComment === singleComment && currentChar === '\n') {
+            insideComment = 0;
+            offset = i;
+        } else if (!insideComment && currentChar + nextChar === '/*') {
+            ret += str.slice(offset, i);
+            offset = i;
+            insideComment = multiComment;
+            i++;
+            continue;
+        } else if (insideComment === multiComment && currentChar + nextChar === '*/') {
+            i++;
+            insideComment = 0;
+            offset = i + 1;
+            continue;
+        }
+    }
+     return ret + (insideComment ? '' : str.substr(offset));
+}
+ function processImports(loader, source, context, imports, cb) {
+    if (imports.length === 0) {
+        return cb(null, source);
+    }
+     var imp = imports.pop();
+     loader.resolve(context, imp.key + '.fx', function (err, resolved) {
+        if (err) {
+            return cb(err);
+        }
+         loader.addDependency(resolved);
+        fs.readFile(resolved, 'utf-8', function (err, src) {
+            if (err) {
+                return cb(err);
+            }
+             parse(loader, src, path.dirname(resolved), function (err, bld) {
+                if (err) {
+                    return cb(err);
+                }
+                 source = source.replace(imp.target, bld);
+                processImports(loader, source, context, imports, cb);
+            });
+        });
+    });
+}
+ module.exports = parse; 

+ 49 - 0
Tools/WebpackShaderLoader/processShaders.js

@@ -0,0 +1,49 @@
+let glob = require('glob');
+let path = require('path');
+let fs = require('fs');
+// Usage - node .\processShaders.js ../../gui/
+let shaderProcessor = require('./parser');
+let shadersPath = process.argv[2] || '../../';
+
+let tsTemplate = `import { Effect } from "babylonjs";
+
+let shader = '';
+let name = '';
+let registerShader = false;
+##PLACEHOLDER##
+if(registerShader && name && shader) {
+    Effect.ShadersStore[name] = shader;
+}
+
+export { shader, name };
+`;
+
+glob(shadersPath + '/**/*.fx', (err, shaderFiles) => {
+    if (err) {
+        console.log('error', err);
+    } else {
+        console.log('processing shaders');
+        shaderFiles.forEach(file => {
+            let filename = path.basename(file);
+            let normalized = path.normalize(file);
+            let directory = path.dirname(normalized);
+            let shaderName = getShaderName(filename);
+            let tsFilename = filename.replace('.fx', '.ts');
+             let shaderContent = fs.readFileSync(file).toString();
+             //TODO - take care of includes!!!
+             shaderProcessor(undefined, shaderContent, undefined, (err, data) => {
+                let tsContent = tsTemplate.replace('##PLACEHOLDER##', `name = '${shaderName}'; shader = \`${data}\`;  `);
+                fs.writeFileSync(directory + '/' + tsFilename, tsContent);
+            });
+        });
+    }
+})
+
+function getShaderName(filename) {
+    let parts = filename.split('.');
+    if (parts[1] !== 'fx') {
+        return parts[0] + (parts[1] === 'fragment' ? 'Pixel' : 'Vertex') + "Shader";
+    } else {
+        return parts[0];
+    }
+}

+ 1 - 0
package.json

@@ -61,6 +61,7 @@
         "chai": "^4.1.2",
         "color-support": "^1.1.3",
         "del": "3.0.0",
+        "glob": "^7.1.3",
         "gulp": "^4.0.0",
         "gulp-clean-ts-extends": "~0.1.1",
         "gulp-concat": "~2.6.1",