Explorar o código

Prepare remap tools

sebavan %!s(int64=6) %!d(string=hai) anos
pai
achega
7015cd3689

+ 1 - 0
Tools/Gulp/gulpfile.js

@@ -13,6 +13,7 @@ require("./tasks/gulpTasks-watch");
 require("./tasks/gulpTasks-typedoc");
 require("./tasks/gulpTasks-intellisense");
 require("./tasks/gulpTasks-tests");
+require("./tasks/gulpTasks-remapPaths");
 
 // Import Build Config
 var config = require("./config.json");

+ 66 - 0
Tools/Gulp/helpers/gulp-remapPaths.js

@@ -0,0 +1,66 @@
+'use strict';
+
+var through = require('through2');
+var PluginError = require('plugin-error');
+
+function modifyPath(str, opts) {
+    // opts = opts || {};
+
+    // str += "";
+
+    // // Start process by extracting all lines.
+    // let lines = str.split('\n');
+
+    // // Let's go line by line and replace the imports sources by their resolved locations
+    // for (let index = 0; index < lines.length; index++) {
+    //     let line = lines[index];
+
+    //     // Replace Static Readonly declaration for Legacy TS Version compat
+    //     var regexVar = /(.*)import .*"(.*)";/g;
+    //     var match = regexVar.exec(line);
+    //     if (!match) {
+    //         continue;
+    //     }
+
+    //     // Extract the typescript node based import location
+    //     const location = match[2];
+    //     const newLocation = location;
+
+    //     // Adds file relative path
+    //     if (!location.startsWith(".")) {
+
+    //     }
+
+    //     // Adds Extension
+
+
+    //     // Replace the location by the new one
+    //     line = line.replace('"' + location + '"', '"' + newLocation + '"');
+    //     lines[index] = line;
+    // }
+
+    // // Recreate the file.
+    // str = lines.join('\n');
+    return Date.now() + str;
+}
+
+function main(options, func) {
+    return through.obj(function (file, enc, cb) {
+        if (file.isNull()) {
+            cb(null, file);
+            return;
+        }
+        if (file.isStream()) {
+            cb(new PluginError("Modify Import Paths", "Streaming not supported."));
+        }
+        file.contents = Buffer.from(func(file.contents.toString(), options));
+        this.push(file);
+        return cb();
+    });
+}
+
+function gulpModifyPath(options) {
+    return main(options, modifyPath);
+}
+
+module.exports = gulpModifyPath;

+ 22 - 0
Tools/Gulp/tasks/gulpTasks-remapPaths.js

@@ -0,0 +1,22 @@
+// Gulp Tools
+var gulp = require("gulp");
+var minimist = require("minimist");
+
+// Helpers
+var remapPaths = require("../helpers/gulp-remapPaths");
+
+// Parse Command Line.
+var commandLineOptions = minimist(process.argv.slice(2), {
+    string: ["path"]
+});
+
+/**
+ * This tasks remaps all the import path of a typescript project to their relative paths.
+ */
+gulp.task("remapPaths", function() {
+    const path = commandLineOptions.path;
+
+    return gulp.src(path + "/**/*.ts", { base: path })
+        .pipe(remapPaths())
+        .pipe(gulp.dest(path));
+});