Преглед изворни кода

adding dts-bundle to our gulp process
dts-bundle is the only ts bundler that actually worked creating a proper d.ts for the viewer

Raanan Weber пре 7 година
родитељ
комит
41a6cc188d
4 измењених фајлова са 45 додато и 6 уклоњено
  1. 6 0
      Tools/Gulp/config.json
  2. 32 0
      Tools/Gulp/gulpfile.js
  3. 4 0
      Tools/Gulp/package.json
  4. 3 6
      Viewer/tsconfig-gulp.json

+ 6 - 0
Tools/Gulp/config.json

@@ -1746,6 +1746,12 @@
         ],
         "build": {
             "srcOutputDirectory": "../../Viewer/",
+            "dtsBundle": {
+                "name": "babylonjs-viewer",
+                "main": "../../Viewer/src/index.d.ts",
+                "out": "../../dist/preview release/viewer/babylon.viewer.module.d.ts",
+                "appendText": "/// <reference path=\"./babylon.d.ts\"/>"
+            },
             "outputs": [
                 {
                     "destination": [

+ 32 - 0
Tools/Gulp/gulpfile.js

@@ -29,6 +29,8 @@ var typedoc = require("gulp-typedoc");
 var validateTypedoc = require("./gulp-validateTypedoc");
 var request = require('request');
 var fs = require("fs");
+var dtsBundle = require('dts-bundle');
+const through = require('through2');
 var karmaServer = require('karma').Server;
 
 var config = require("./config.json");
@@ -440,7 +442,37 @@ var buildExternalLibrary = function (library, settings, watch) {
             let sequence = [waitAll];
             let wpBuild = webpack(require(library.webpack));
             if (settings.build.outputs) {
+                //shoud dtsBundle create the declaration?
+                if (settings.build.dtsBundle) {
+                    let event = wpBuild
+                        .pipe(through.obj(function (file, enc, cb) {
+                            // only declaration files
+                            const isdts = /\.d\.ts$/.test(file.path);
+                            if (isdts) this.push(file);
+                            cb();
+                        }))
+                        .pipe(gulp.dest('.'));
+                    // dts-bundle does NOT support (gulp) streams, so files have to be saved and reloaded, 
+                    // until I fix it
+                    event.on("end", function () {
+                        // create the file
+                        dtsBundle.bundle(settings.build.dtsBundle);
+                        // prepend the needed reference
+                        fs.readFile(settings.build.dtsBundle.out, function (err, data) {
+                            if (err) throw err;
+                            data = settings.build.dtsBundle.appendText + data.toString();
+                            fs.writeFile(settings.build.dtsBundle.out, data);
+                        });
+                    });
+                }
+
                 let build = wpBuild
+                    .pipe(through.obj(function (file, enc, cb) {
+                        // only pipe js files
+                        const isJs = /\.js$/.test(file.path);
+                        if (isJs) this.push(file);
+                        cb();
+                    }))
                     .pipe(addModuleExports(library.moduleDeclaration, { subModule: false, extendsRoot: false, externalUsingBabylon: true, noBabylonInit: library.babylonIncluded }));
 
                 let unminifiedOutpus = [];

+ 4 - 0
Tools/Gulp/package.json

@@ -62,5 +62,9 @@
     },
     "scripts": {
         "install": "npm --prefix ../../Playground/ install ../../Playground/ && npm --prefix ../../tests/unit/ install ../../tests/unit/ && gulp deployLocalDev"
+    },
+    "dependencies": {
+        "dts-bundle": "^0.7.3",
+        "gulp-clean": "^0.4.0"
     }
 }

+ 3 - 6
Viewer/tsconfig-gulp.json

@@ -3,14 +3,14 @@
         "target": "es5",
         "module": "commonjs",
         "noResolve": false,
-        "noImplicitAny": false, //mainly due to usage of external libs without typings.
+        "noImplicitAny": false,
         "strictNullChecks": true,
-        "removeComments": true,
+        "removeComments": false,
         "preserveConstEnums": true,
         "sourceMap": false,
         "experimentalDecorators": true,
         "isolatedModules": false,
-        "declaration": false,
+        "declaration": true,
         "lib": [
             "dom",
             "es2015.promise",
@@ -26,9 +26,6 @@
             ],
             "babylonjs-loaders": [
                 "../dist/preview release/loaders/babylonjs.loaders.d.ts"
-            ],
-            "babylonjs-gltf2interface": [
-                "../dist/babylon.glTF2Interface.d.ts"
             ]
         }
     },