Pārlūkot izejas kodu

append loose dts to the output

sebavan 6 gadi atpakaļ
vecāks
revīzija
66b53b6893

+ 1 - 1
Tools/Gulp/helpers/gulp-processImportsToEs6.js

@@ -17,7 +17,7 @@ function processImports(sourceCode, replacements) {
 }
 
 /**
- * Generate a ts file per shader file.
+ * Replaces all imports by their es6 peers.
  */
 function main(replacements) {
     return through.obj(function (file, enc, cb) {

+ 44 - 0
Tools/Gulp/helpers/gulp-processLooseDeclarationEs6.js

@@ -0,0 +1,44 @@
+// Dependencies.
+var through = require('through2');
+var PluginError = require('plugin-error');
+let fs = require('fs');
+
+/**
+ * Encapsulates types in declare global { }
+ */
+function processLooseDeclarations(sourceCode) {
+    // To replace if that causes issue (defining start point of the concat
+    // as interface like the first code line of the first mixin)
+    sourceCode = sourceCode.replace(/declare /g, "");
+    sourceCode = sourceCode.replace(/interface /, `declare global {
+interface `);
+    sourceCode += `
+}`;
+
+    return sourceCode;
+}
+
+/**
+ * Prepare loose declarations to be added to the package.
+ */
+function main(replacements) {
+    return through.obj(function (file, enc, cb) {
+            if (file.isNull()) {
+                cb(null, file);
+                return;
+            }
+            if (file.isStream()) {
+                cb(new PluginError("Process Shader", "Streaming not supported."));
+            }
+
+            let data = file.contents.toString();
+            data = processLooseDeclarations(data, replacements);
+
+            file.contents = Buffer.from(data);
+            this.push(file);
+
+            return cb();
+        });
+}
+
+module.exports = main;

+ 18 - 1
Tools/Gulp/tasks/gulpTasks-librariesES6.js

@@ -3,10 +3,12 @@ var gulp = require("gulp");
 var path = require("path");
 var fs = require("fs-extra");
 var shelljs = require("shelljs");
+var concat = require('gulp-concat');
 
 // Gulp Helpers
 var rmDir = require("../../NodeHelpers/rmDir");
 var processImports = require("../helpers/gulp-processImportsToEs6");
+var processLooseDeclaration = require("../helpers/gulp-processLooseDeclarationEs6");
 
 // Import Build Config
 var config = require("../../Config/config.js");
@@ -151,6 +153,20 @@ var modifyTsConfig = function(settings, cb) {
 }
 
 /**
+ * Append Lose DTS Files allowing isolated Modules build
+ */
+var appendLoseDTSFiles = function(settings) {
+    if (settings.build.loseDTSFiles) {
+        const indexDTS = path.join(settings.computed.ES6PackageDirectory, "index.d.ts");
+        return gulp.src([indexDTS, path.join(settings.computed.srcDirectory, settings.build.loseDTSFiles)])
+            .pipe(concat("index.d.ts"))
+            .pipe(processLooseDeclaration())
+            .pipe(gulp.dest(settings.computed.ES6PackageDirectory));
+    }
+    return Promise.resolve();
+}
+
+/**
  * Dynamic es 6 module creation.
  */
 function buildES6Library(settings) {
@@ -163,8 +179,9 @@ function buildES6Library(settings) {
     var adaptSourceImportPaths = function() { return modifySources(settings); };
     var adaptTsConfigImportPaths = function(cb) { return modifyTsConfig(settings, cb); };
     var buildes6 = function(cb) { return build(settings, cb) };
+    var appendLoseDTS = function() { return appendLoseDTSFiles(settings) };
 
-    tasks.push(cleanup, copySource, dependencies, adaptSourceImportPaths, adaptTsConfigImportPaths, buildes6);
+    tasks.push(cleanup, copySource, dependencies, adaptSourceImportPaths, adaptTsConfigImportPaths, buildes6, appendLoseDTS);
 
     return gulp.series.apply(this, tasks);
 }