Ver código fonte

Color publisher and federate node tools

sebavan 7 anos atrás
pai
commit
142dada196

+ 5 - 67
Tools/Gulp/helpers/gulp-validateTypedoc.js

@@ -4,74 +4,12 @@ var fs = require('fs');
 var Vinyl = require('vinyl');
 var Vinyl = require('vinyl');
 var through = require('through2');
 var through = require('through2');
 var PluginError = require('plugin-error');
 var PluginError = require('plugin-error');
-var supportsColor = require('color-support');
+var nodeColorConsole = require('../../NodeHelpers/colorConsole');
 
 
-// ______________________________________________ LOGS ______________________________________________
-
-var hasColors = supportsColor();
-
-var red = hasColors ? '\x1b[31m' : '';
-var yellow = hasColors ? '\x1b[33m' : '';
-var green = hasColors ? '\x1b[32m' : '';
-var gray = hasColors ? '\x1b[90m' : '';
-var white = hasColors ? '\x1b[97m' : '';
-var clear = hasColors ? '\x1b[0m' : '';
-
-var currentColor = undefined;
-
-function getTimestamp() {
-    var time = new Date();
-    var timeInString = ("0" + time.getHours()).slice(-2) + ":" +
-        ("0" + time.getMinutes()).slice(-2) + ":" +
-        ("0" + time.getSeconds()).slice(-2);
-
-    if (currentColor) {
-        return white + '[' + currentColor + timeInString + clear + white + ']';
-    }
-    else {
-        return white + '[' + gray + timeInString + white + ']';
-    }
-}
-
-function log() {
-    currentColor = gray;
-    var time = getTimestamp();
-    process.stdout.write(time + ' ');
-    currentColor = undefined;
-
-    console.log.apply(console, arguments);
-    return this;
-}
-
-function warn() {
-    currentColor = yellow;
-    var time = getTimestamp();
-    process.stdout.write(time + ' ');
-    currentColor = undefined;
-
-    console.warn.apply(console, arguments);
-    return this;
-}
-
-function err() {
-    currentColor = red;
-    var time = getTimestamp();
-    process.stderr.write(time + ' ');
-    currentColor = undefined;
-
-    console.error.apply(console, arguments);
-    return this;
-}
-
-function success() {
-    currentColor = green;
-    var time = getTimestamp();
-    process.stdout.write(time + ' ');
-    currentColor = undefined;
-
-    console.log.apply(console, arguments);
-    return this;
-}
+const log = nodeColorConsole.log;
+const warn = nodeColorConsole.warn;
+const err = nodeColorConsole.error;
+const success = nodeColorConsole.success;
 
 
 // ______________________________________________ VALIDATION ____________________________________________
 // ______________________________________________ VALIDATION ____________________________________________
 
 

+ 1 - 1
Tools/Gulp/tasks/gulpTasks-tests.js

@@ -8,7 +8,7 @@ var webpackStream = require("webpack-stream");
 var rename = require("gulp-rename");
 var rename = require("gulp-rename");
 
 
 // Import Helpers.
 // Import Helpers.
-var rmDir = require("../helpers/gulp-rmDir");
+var rmDir = require("../../NodeHelpers/rmDir");
 
 
 // Read the full config.
 // Read the full config.
 var config = require("../config.json");
 var config = require("../config.json");

+ 1 - 1
Tools/Gulp/tasks/gulpTasks-watchCore.js

@@ -6,7 +6,7 @@ var del = require("del");
 // Import Helpers.
 // Import Helpers.
 var processShaders = require("../helpers/gulp-processShaders");
 var processShaders = require("../helpers/gulp-processShaders");
 var uncommentShaders = require('../helpers/gulp-removeShaderComments');
 var uncommentShaders = require('../helpers/gulp-removeShaderComments');
-var rmDir = require('../helpers/gulp-rmDir');
+var rmDir = require("../../NodeHelpers/rmDir");
 
 
 // Read the full config.
 // Read the full config.
 var config = require("../config.json");
 var config = require("../config.json");

+ 109 - 0
Tools/NodeHelpers/colorConsole.js

@@ -0,0 +1,109 @@
+var supportsColor = require('color-support');
+
+var hasColors = supportsColor();
+
+var styles = {
+    black: hasColors ? '\x1b[30m' : '',
+    red: hasColors ? '\x1b[31m' : '',
+    green: hasColors ? '\x1b[32m' : '',
+    yellow: hasColors ? '\x1b[33m' : '',
+    blue: hasColors ? '\x1b[34m' : '',
+    magenta: hasColors ? '\x1b[35m' : '',
+    cyan: hasColors ? '\x1b[36m' : '',
+    gray: hasColors ? '\x1b[90m' : '',
+    white: hasColors ? '\x1b[97m' : '',
+
+    bgBlack: hasColors ? '\x1b[40m' : '',
+    bgRed: hasColors ? '\x1b[41m' : '',
+    bgGreen: hasColors ? '\x1b[42m' : '',
+    bgYellow: hasColors ? '\x1b[43m' : '',
+    bgBlue: hasColors ? '\x1b[44m' : '',
+    bgMagenta: hasColors ? '\x1b[45m' : '',
+    bgCyan: hasColors ? '\x1b[46m' : '',
+    bgWhite: hasColors ? '\x1b[47m' : '',
+
+    bold: hasColors ? '\x1b[1m' : '',
+    italic: hasColors ? '\x1b[3m' : '',
+    underline: hasColors ? '\x1b[4m' : '',
+    strikethrough: hasColors ? '\x1b[9m' : '',
+}
+
+var clear = hasColors ? '\x1b[0m' : '';
+
+var currentColor = undefined;
+
+function getTimestamp() {
+    var time = new Date();
+    var timeInString = ("0" + time.getHours()).slice(-2) + ":" +
+        ("0" + time.getMinutes()).slice(-2) + ":" +
+        ("0" + time.getSeconds()).slice(-2);
+
+    if (currentColor) {
+        return styles.white + '[' + currentColor + timeInString + clear + styles.white + ']';
+    }
+    else {
+        return styles.white + '[' + styles.gray + timeInString + styles.white + ']';
+    }
+}
+
+function log() {
+    currentColor = styles.gray;
+    var time = getTimestamp();
+    process.stdout.write(time + ' ');
+    currentColor = undefined;
+
+    console.log.apply(console, arguments);
+    return this;
+}
+
+function warn() {
+    currentColor = styles.yellow;
+    var time = getTimestamp();
+    process.stdout.write(time + ' ');
+    currentColor = undefined;
+
+    console.warn.apply(console, arguments);
+    return this;
+}
+
+function err() {
+    currentColor = styles.red;
+    var time = getTimestamp();
+    process.stderr.write(time + ' ');
+    currentColor = undefined;
+
+    console.error.apply(console, arguments);
+    return this;
+}
+
+function success() {
+    currentColor = styles.green;
+    var time = getTimestamp();
+    process.stdout.write(time + ' ');
+    currentColor = undefined;
+
+    console.log.apply(console, arguments);
+    return this;
+}
+
+function emptyLine() {
+    console.log();
+}
+
+for (let style in styles) {
+    Object.defineProperty(String.prototype, style, {
+        get: function() {
+            return styles[style] + this + clear;
+        },
+        enumerable: true,
+        configurable: true
+    });
+}
+
+module.exports = {
+    log,
+    warn,
+    error: err,
+    success,
+    emptyLine
+};

Tools/Gulp/helpers/gulp-rmDir.js → Tools/NodeHelpers/rmDir.js


+ 33 - 43
Tools/Publisher/publisher.js

@@ -3,6 +3,8 @@ const prompt = require('prompt');
 const shelljs = require('shelljs');
 const shelljs = require('shelljs');
 const fs = require('fs-extra');
 const fs = require('fs-extra');
 const path = require('path');
 const path = require('path');
+const rmDir = require("../NodeHelpers/rmDir");
+const colorConsole = require("../NodeHelpers/colorConsole");
 
 
 // CMD Arguments Management.
 // CMD Arguments Management.
 let doNotBuild = false;
 let doNotBuild = false;
@@ -20,23 +22,6 @@ const coreSrc = config.core.build.srcDirectory;
 const enginePath = coreSrc + "Engines/engine.ts";
 const enginePath = coreSrc + "Engines/engine.ts";
 
 
 /**
 /**
- * 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.
  * Get Files from folder.
  */
  */
 const getFiles = function(dir, files_) {
 const getFiles = function(dir, files_) {
@@ -57,28 +42,30 @@ const getFiles = function(dir, files_) {
  * Update the version in the engine class for Babylon
  * Update the version in the engine class for Babylon
  */
  */
 function updateEngineVersion(newVersion) {
 function updateEngineVersion(newVersion) {
-    console.log("Updating version in engine.ts to: " + newVersion);
+    colorConsole.log("Updating version in engine.ts to: " + newVersion.green);
     let engineContent = fs.readFileSync(enginePath).toString();
     let engineContent = fs.readFileSync(enginePath).toString();
     let replaced = engineContent.replace(/(public static get Version\(\): string {\s*return ")(.*)(";\s*})/g, "$1" + newVersion + "$3");
     let replaced = engineContent.replace(/(public static get Version\(\): string {\s*return ")(.*)(";\s*})/g, "$1" + newVersion + "$3");
-    fs.writeFileSync(enginePath, replaced);
+    fs.writeFileSync(enginePath, replaced);    
+    colorConsole.emptyLine();
 }
 }
 
 
 /**
 /**
  * Get the version from the engine class for Babylon
  * Get the version from the engine class for Babylon
  */
  */
 function getEngineVersion() {
 function getEngineVersion() {
-    console.log("Get version from engine.ts");
+    colorConsole.log("Get version from engine.ts");
     const engineContent = fs.readFileSync(enginePath).toString();
     const engineContent = fs.readFileSync(enginePath).toString();
 
 
     const versionRegex = new RegExp(`public static get Version\\(\\): string {[\\s\\S]*return "([\\s\\S]*?)";[\\s\\S]*}`, "gm");
     const versionRegex = new RegExp(`public static get Version\\(\\): string {[\\s\\S]*return "([\\s\\S]*?)";[\\s\\S]*}`, "gm");
     const match = versionRegex.exec(engineContent);
     const match = versionRegex.exec(engineContent);
     if (match && match.length) {
     if (match && match.length) {
         const version = match[1];
         const version = match[1];
-        console.log("Version found: " + version);
+        colorConsole.log("Version found: " + version.green);
+        colorConsole.emptyLine();
         return version;
         return version;
     }
     }
 
 
-    console.log("Version not found in engine.ts");
+    colorConsole.error("Version not found in engine.ts");
     process.exit(1);
     process.exit(1);
 }
 }
 
 
@@ -86,7 +73,7 @@ function getEngineVersion() {
  * Publish a package to npm.
  * Publish a package to npm.
  */
  */
 function publish(version, packageName, basePath) {
 function publish(version, packageName, basePath) {
-    console.log('    Publishing ' + packageName + " from " + basePath);
+    colorConsole.log('    Publishing ' + packageName.blue.bold + " from " + basePath.cyan);
 
 
     let tag = "";
     let tag = "";
     // check for alpha or beta
     // check for alpha or beta
@@ -96,22 +83,24 @@ function publish(version, packageName, basePath) {
 
 
     //publish the respected package
     //publish the respected package
     if (doNotPublish) {
     if (doNotPublish) {
-        console.log("    If publishing enabled: " + 'npm publish \"' + basePath + "\"" + ' ' + tag);
+        colorConsole.log("    If publishing enabled: " + ('npm publish \"' + basePath + "\"" + ' ' + tag).yellow);
     }
     }
     else {
     else {
-        console.log("    Executing: " + 'npm publish \"' + basePath + "\"" + ' ' + tag);
+        colorConsole.log("    Executing: " + ('npm publish \"' + basePath + "\"" + ' ' + tag).bold);
         shelljs.exec('npm publish \"' + basePath + "\"" + ' ' + tag);
         shelljs.exec('npm publish \"' + basePath + "\"" + ' ' + tag);
     }
     }
+
+    colorConsole.success('    Publishing ' + "OK".green);
 }
 }
 
 
 /**
 /**
  * Build the folder with Gulp.
  * Build the folder with Gulp.
  */
  */
 function buildBabylonJSAndDependencies() {
 function buildBabylonJSAndDependencies() {
-    console.log("Running gulp compilation");
+    colorConsole.log("Running gulp compilation");
     let exec = shelljs.exec("gulp typescript-libraries --gulpfile ../Gulp/gulpfile.js");
     let exec = shelljs.exec("gulp typescript-libraries --gulpfile ../Gulp/gulpfile.js");
     if (exec.code) {
     if (exec.code) {
-        console.log("Error during compilation, aborting");
+        colorConsole.error("Error during compilation, aborting");
         process.exit(1);
         process.exit(1);
     }
     }
 }
 }
@@ -120,7 +109,6 @@ function buildBabylonJSAndDependencies() {
  * Process ES6 Packages.
  * Process ES6 Packages.
  */
  */
 function processEs6Packages(version) {
 function processEs6Packages(version) {
-    console.log("Process ES6 Packages...");
     modules.forEach(moduleName => {
     modules.forEach(moduleName => {
         let module = config[moduleName];
         let module = config[moduleName];
         let es6Config = module.build.es6;
         let es6Config = module.build.es6;
@@ -128,17 +116,17 @@ function processEs6Packages(version) {
             return;
             return;
         }
         }
 
 
-        console.log("Process ES6 Package: " + moduleName);
+        colorConsole.log("Process " + "UMD".magenta + " Package: " + moduleName.blue.bold);
 
 
         let projectPath = es6Config.tsFolder;
         let projectPath = es6Config.tsFolder;
         let buildPath = path.normalize(tempPath + moduleName);
         let buildPath = path.normalize(tempPath + moduleName);
         let legacyPackageJson = require(module.build.packageJSON || basePath + module.build.distOutputDirectory + 'package.json');
         let legacyPackageJson = require(module.build.packageJSON || basePath + module.build.distOutputDirectory + 'package.json');
 
 
-        console.log("    Cleanup " + buildPath);
+        colorConsole.log("    Cleanup " + buildPath.cyan);
         rmDir(buildPath);
         rmDir(buildPath);
 
 
         let command = 'tsc -t es5 -m esNext -p ' + projectPath + ' --outDir ' + buildPath;
         let command = 'tsc -t es5 -m esNext -p ' + projectPath + ' --outDir ' + buildPath;
-        console.log("    Executing " + command);
+        colorConsole.log("    Executing " + command.yellow);
 
 
         let tscCompile = shelljs.exec(command);
         let tscCompile = shelljs.exec(command);
         if (tscCompile.code !== 0) {
         if (tscCompile.code !== 0) {
@@ -179,18 +167,17 @@ function processEs6Packages(version) {
 
 
         // Do not publish yet.
         // Do not publish yet.
         // publish(version, es6Config.packageName, buildPath);
         // publish(version, es6Config.packageName, buildPath);
+        colorConsole.emptyLine();
     });
     });
-    console.log();
 }
 }
 
 
 /**
 /**
  * Process Legacy Packages.
  * Process Legacy Packages.
  */
  */
 function processLegacyPackages(version) {
 function processLegacyPackages(version) {
-    console.log("Process Legacy Packages...");
     modules.forEach(moduleName => {
     modules.forEach(moduleName => {
         let module = config[moduleName];
         let module = config[moduleName];
-        console.log("Process Package: " + moduleName);
+        colorConsole.log("Process " + "UMD".magenta + " Package: " + moduleName.blue.bold);
 
 
         if (moduleName === "core") {
         if (moduleName === "core") {
             processLegacyCore(version);
             processLegacyCore(version);
@@ -203,14 +190,14 @@ function processLegacyPackages(version) {
 
 
             if (module.build.requiredFiles) {
             if (module.build.requiredFiles) {
                 module.build.requiredFiles.forEach(file => {
                 module.build.requiredFiles.forEach(file => {
-                    console.log("    Copy required file: ", file, outputDirectory + '/' + path.basename(file));
+                    colorConsole.log("    Copy required file: ", file.cyan, (outputDirectory + '/' + path.basename(file)).cyan);
                     fs.copySync(file, outputDirectory + '/' + path.basename(file));
                     fs.copySync(file, outputDirectory + '/' + path.basename(file));
                 });
                 });
             }
             }
 
 
             let packageJson = require(outputDirectory + 'package.json');
             let packageJson = require(outputDirectory + 'package.json');
             packageJson.version = version;
             packageJson.version = version;
-            console.log("    Update package version to: " + version);
+            colorConsole.log("    Update package version to: " + version.green);
 
 
             if (packageJson.dependencies) {
             if (packageJson.dependencies) {
                 Object.keys(packageJson.dependencies).forEach(key => {
                 Object.keys(packageJson.dependencies).forEach(key => {
@@ -222,9 +209,10 @@ function processLegacyPackages(version) {
             fs.writeFileSync(outputDirectory + 'package.json', JSON.stringify(packageJson, null, 4));
             fs.writeFileSync(outputDirectory + 'package.json', JSON.stringify(packageJson, null, 4));
 
 
             publish(version, moduleName, outputDirectory);
             publish(version, moduleName, outputDirectory);
+
+            colorConsole.emptyLine();
         }
         }
     });
     });
-    console.log();
 }
 }
 
 
 /**
 /**
@@ -237,14 +225,14 @@ function processLegacyViewer(module, version) {
 
 
     if (module.build.requiredFiles) {
     if (module.build.requiredFiles) {
         module.build.requiredFiles.forEach(file => {
         module.build.requiredFiles.forEach(file => {
-            console.log("    Copy required file: ", file, buildPath + path.basename(file));
+            colorConsole.log("    Copy required file: ", file.cyan, (buildPath + path.basename(file)).cyan);
             fs.copySync(file, buildPath + path.basename(file));
             fs.copySync(file, buildPath + path.basename(file));
         });
         });
     }
     }
 
 
     // The viewer needs to be built using tsc on the viewer's main repository
     // The viewer needs to be built using tsc on the viewer's main repository
     // build the viewer.
     // build the viewer.
-    console.log("    Executing " + 'tsc -p ' + projectPath);
+    colorConsole.log("    Executing " + ('tsc -p ' + projectPath).yellow);
 
 
     let tscCompile = shelljs.exec('tsc -p ' + projectPath);
     let tscCompile = shelljs.exec('tsc -p ' + projectPath);
     if (tscCompile.code !== 0) {
     if (tscCompile.code !== 0) {
@@ -264,6 +252,7 @@ function processLegacyViewer(module, version) {
     fs.writeFileSync(buildPath + '/package.json', JSON.stringify(packageJson, null, 4));
     fs.writeFileSync(buildPath + '/package.json', JSON.stringify(packageJson, null, 4));
 
 
     publish(version, "viewer", buildPath);
     publish(version, "viewer", buildPath);
+    colorConsole.emptyLine();
 }
 }
 
 
 /**
 /**
@@ -313,7 +302,7 @@ function processLegacyCore(version) {
 
 
     // update package.json
     // update package.json
     packageJson.version = version;
     packageJson.version = version;
-    console.log("    Generating file list");
+    colorConsole.log("    Generating file list");
     let packageFiles = ["package.json"];
     let packageFiles = ["package.json"];
     files.forEach(file => {
     files.forEach(file => {
         if (!file.isDir) {
         if (!file.isDir) {
@@ -323,7 +312,7 @@ function processLegacyCore(version) {
             packageFiles.push(file.objectName + "/index.js", file.objectName + "/index.d.ts", file.objectName + "/es6.js")
             packageFiles.push(file.objectName + "/index.js", file.objectName + "/index.d.ts", file.objectName + "/es6.js")
         }
         }
     });
     });
-    console.log("    Updating package.json");
+    colorConsole.log("    Updating package.json");
     packageJson.files = packageFiles;
     packageJson.files = packageFiles;
     packageJson.main = "babylon.js";
     packageJson.main = "babylon.js";
     packageJson.typings = "babylon.d.ts";
     packageJson.typings = "babylon.d.ts";
@@ -347,6 +336,7 @@ function processLegacyCore(version) {
     packageJson.typings = "dist/preview release/babylon.d.ts";
     packageJson.typings = "dist/preview release/babylon.d.ts";
 
 
     fs.writeFileSync('../../package.json', JSON.stringify(packageJson, null, 4));
     fs.writeFileSync('../../package.json', JSON.stringify(packageJson, null, 4));
+    colorConsole.emptyLine();
 }
 }
 
 
 const createVersion = function(version) {
 const createVersion = function(version) {
@@ -378,7 +368,7 @@ module.exports = function(noBuild, noPublish, askVersion) {
             
             
             // Update the engine version if needed.
             // Update the engine version if needed.
             if (!version || !version.length) {
             if (!version || !version.length) {
-                console.log("New version required.");
+                colorConsole.error("New version required.");
                 Process.exit(1);
                 Process.exit(1);
                 return;
                 return;
             }
             }
@@ -388,7 +378,7 @@ module.exports = function(noBuild, noPublish, askVersion) {
 
 
             // Invite user to tag with the new version.
             // Invite user to tag with the new version.
             if (newVersion) {
             if (newVersion) {
-                console.log("Done, please tag git with " + version);
+                colorConsole.log("Done, please tag git with " + version);
             }
             }
         });
         });
     }
     }