Пример #1
0
        public override bool Execute()
        {
            var success = true;

#if DEBUG
            if (AttachDebugger)
            {
                System.Diagnostics.Debugger.Launch();
            }
            ;
#endif

            Bridge.Translator.Translator translator = null;
            try
            {
                translator = new Bridge.Translator.Translator(this.ProjectPath);
                translator.Configuration  = this.Configuration;
                translator.BridgeLocation = Path.Combine(this.AssembliesPath, "Bridge.dll");
                translator.Rebuild        = false;
                translator.ChangeCase     = this.ChangeCase;
                translator.Log            = this.LogMessage;
                translator.Translate();

                string fileName = Path.GetFileNameWithoutExtension(this.Assembly.ItemSpec);

                string outputPath = !string.IsNullOrWhiteSpace(translator.AssemblyInfo.Output)
                    ? Path.Combine(Path.GetDirectoryName(this.ProjectPath), translator.AssemblyInfo.Output)
                    : this.OutputPath;

                translator.SaveTo(outputPath, fileName);

                if (!this.NoCore)
                {
                    Bridge.Translator.Translator.ExtractCore(translator, outputPath);
                }
            }
            catch (EmitterException e)
            {
                this.Log.LogError(null, null, null, e.FileName, e.StartLine + 1, e.StartColumn + 1, e.EndLine + 1, e.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                success = false;
            }
            catch (Exception e)
            {
                var ee = translator != null?translator.CreateExceptionFromLastNode() : null;

                if (ee != null)
                {
                    this.Log.LogError(null, null, null, ee.FileName, ee.StartLine + 1, ee.StartColumn + 1, ee.EndLine + 1, ee.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                }
                else
                {
                    this.Log.LogError("Error: {0} {1}", e.Message, e.StackTrace);
                }

                success = false;
            }

            return(success);
        }
Пример #2
0
        public string Translate()
        {
            var outputLocation = Path.ChangeExtension(ProjectLocation, "js");

            var translator = new Bridge.Translator.Translator(ProjectLocation);

            translator.Log     = this.Logger;
            translator.Rebuild = true;

            this.Logger.Info("\t\tProjectLocation: " + ProjectLocation);

            string configuration;

            translator.BridgeLocation = FindBridgeDllPath(out configuration);

            if (translator.BridgeLocation == null)
            {
                Bridge.Translator.Exception.Throw("Unable to determine Bridge project output path by configuration " + configuration);
            }

            translator.BuildArguments = WrapBuildArguments(configuration);
            translator.Configuration  = configuration;

            this.Logger.Info("\t\tBuildArguments: " + translator.BuildArguments);
            this.Logger.Info("\t\tConfiguration: " + translator.Configuration);
            this.Logger.Info("\t\tBridgeLocation: " + translator.BridgeLocation);

            translator.Translate();

            string path = Path.GetDirectoryName(outputLocation);

            string outputDir = !string.IsNullOrWhiteSpace(translator.AssemblyInfo.Output) ?
                               Path.Combine(Path.GetDirectoryName(ProjectLocation), translator.AssemblyInfo.Output) :
                               path;

            this.Logger.Info("\t\toutputDir: " + outputDir);
            translator.SaveTo(outputDir, Path.GetFileNameWithoutExtension(outputLocation));

            return(outputDir);
        }
Пример #3
0
        public override bool Execute()
        {
            var success = true;

            try
            {
                var translator = new Bridge.Translator.Translator(this.ProjectPath);
                translator.Configuration  = this.Configuration;
                translator.BridgeLocation = Path.Combine(this.AssembliesPath, "Bridge.dll");
                translator.Rebuild        = false;
                translator.ChangeCase     = this.ChangeCase;
                translator.Log            = this.LogMessage;
                translator.Translate();

                string fileName = Path.GetFileNameWithoutExtension(this.Assembly.ItemSpec);

                string outputPath = !string.IsNullOrWhiteSpace(translator.AssemblyInfo.Output) ?
                                    Path.Combine(Path.GetDirectoryName(this.ProjectPath), translator.AssemblyInfo.Output) :
                                    this.OutputPath;

                translator.SaveTo(outputPath, fileName);

                if (!this.NoCore)
                {
                    Bridge.Translator.Translator.ExtractCore(translator.BridgeLocation, outputPath);
                }

                if (!string.IsNullOrWhiteSpace(translator.AssemblyInfo.AfterBuild))
                {
                    translator.RunEvent(translator.AssemblyInfo.AfterBuild);
                }
            }
            catch (Exception e)
            {
                this.Log.LogError("Error: {0}", e.Message);
                success = false;
            }

            return(success);
        }
Пример #4
0
        public override bool Execute()
        {
            var success = true;

            #if DEBUG
            if (AttachDebugger)
            {
                System.Diagnostics.Debugger.Launch();
            };
            #endif

            Bridge.Translator.Translator translator = null;
            try
            {
                translator = new Bridge.Translator.Translator(this.ProjectPath, true);
                translator.Configuration = this.Configuration;

                if (this.DefineConstants != null)
                {
                    translator.DefineConstants.AddRange(this.DefineConstants.Split(';').Select(s => s.Trim()).Where(s => s != ""));
                    translator.DefineConstants = translator.DefineConstants.Distinct().ToList();
                }

                translator.BridgeLocation = Path.Combine(this.AssembliesPath, "Bridge.dll");
                translator.Rebuild = false;
                translator.Log = this.LogMessage;
                translator.Translate();

                string fileName = Path.GetFileNameWithoutExtension(this.Assembly.ItemSpec);

                string outputPath = !string.IsNullOrWhiteSpace(translator.AssemblyInfo.Output)
                    ? Path.Combine(Path.GetDirectoryName(this.ProjectPath), translator.AssemblyInfo.Output)
                    : this.OutputPath;

                if (translator.AssemblyInfo != null && translator.AssemblyInfo.CleanOutputFolderBeforeBuild)
                {
                    Console.WriteLine("Cleaning output folder before extracting scripts...");
                    CleanDirectory(outputPath);
                }

                if (!this.NoCore)
                {
                    translator.ExtractCore(outputPath);
                }
                translator.SaveTo(outputPath, fileName);
                translator.Flush(outputPath, fileName);
                translator.Plugins.AfterOutput(translator, outputPath, this.NoCore);
            }
            catch (EmitterException e)
            {
                this.Log.LogError(null, null, null, e.FileName, e.StartLine + 1, e.StartColumn + 1, e.EndLine + 1, e.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                success = false;
            }
            catch (Exception e)
            {
                var ee = translator != null ? translator.CreateExceptionFromLastNode() : null;

                if (ee != null)
                {
                    this.Log.LogError(null, null, null, ee.FileName, ee.StartLine + 1, ee.StartColumn + 1, ee.EndLine + 1, ee.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                }
                else
                {
                    this.Log.LogError("Error: {0} {1}", e.Message, e.StackTrace);
                }

                success = false;
            }

            return success;
        }
Пример #5
0
        static void Main(string[] args)
        {
            string projectLocation = null;
            string outputLocation  = null;
            string bridgeLocation  = null;
            bool   rebuild         = false;
            bool   extractCore     = true;
            bool   changeCase      = true;
            string cfg             = null;

            if (args.Length == 0)
            {
                Console.WriteLine("Bridge.Builder commands:");
                Console.WriteLine("-p or -project           Path to csproj file (required)");
                Console.WriteLine("-o or -output            Output directory for generated script");
                Console.WriteLine("-cfg or -configuration   Configuration name, typically Debug/Release");
                Console.WriteLine("-r or -rebuild           Force assembly rebuilding");
                Console.WriteLine("-nocore                  Do not extract core javascript files");
                Console.WriteLine("-c or -case              Do not change case of members");
#if DEBUG
                // This code and logic is only compiled in when building bridge.net in Debug configuration
                Console.WriteLine("-d or -debug             Attach the builder to an visual studio debugging instance.");
                Console.WriteLine("                         Use this to attach the process to an open Bridge.NET solution.");
#endif
                Console.WriteLine("");
                return;
            }

            int i = 0;

            while (i < args.Length)
            {
                switch (args[i])
                {
                case "-p":
                case "-project":
                    projectLocation = args[++i];
                    break;

                case "-b":
                case "-bridge":
                    bridgeLocation = args[++i];
                    break;

                case "-o":
                case "-output":
                    outputLocation = args[++i];
                    break;

                case "-cfg":
                case "-configuration":
                    cfg = args[++i];
                    break;

                case "-rebuild":
                case "-r":
                    rebuild = true;
                    break;

                case "-case":
                case "-c":
                    changeCase = false;
                    break;

                case "-nocore":
                    extractCore = false;
                    break;

#if DEBUG
                case "-debug":
                case "-d":
                    System.Diagnostics.Debugger.Launch();
                    break;
#endif
                default:
                    Console.WriteLine("Unknown command: " + args[i]);
                    return;
                }

                i++;
            }

            if (string.IsNullOrEmpty(projectLocation))
            {
                Console.WriteLine("Project location is empty, please define argument with -p command");
                return;
            }

            if (!File.Exists(projectLocation))
            {
                Console.WriteLine("Project file doesn't exist: " + projectLocation);
                return;
            }

            if (string.IsNullOrEmpty(outputLocation))
            {
                outputLocation = Path.GetFileNameWithoutExtension(projectLocation);
            }

            try
            {
                Console.WriteLine("Generating script...");
                var translator = new Bridge.Translator.Translator(projectLocation);

                bridgeLocation = !string.IsNullOrEmpty(bridgeLocation) ? bridgeLocation : Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Bridge.dll");

                translator.BridgeLocation = bridgeLocation;
                translator.Rebuild        = rebuild;
                translator.ChangeCase     = changeCase;
                translator.Log            = LogMessage;
                translator.Configuration  = cfg;
                translator.Translate();

                string path       = string.IsNullOrWhiteSpace(Path.GetFileName(outputLocation)) ? outputLocation : Path.GetDirectoryName(outputLocation);
                string outputPath = Path.Combine(Path.GetDirectoryName(projectLocation), !string.IsNullOrWhiteSpace(translator.AssemblyInfo.Output) ? translator.AssemblyInfo.Output : path);

                translator.SaveTo(outputPath, Path.GetFileName(outputLocation));

                if (extractCore)
                {
                    Console.WriteLine("Extracting core scripts...");
                    Bridge.Translator.Translator.ExtractCore(translator.BridgeLocation, outputPath);
                }

                Console.WriteLine("Done.");

                if (!string.IsNullOrWhiteSpace(translator.AssemblyInfo.AfterBuild))
                {
                    translator.RunEvent(translator.AssemblyInfo.AfterBuild);
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: {0}", e.Message);
                Console.ResetColor();
                Console.ReadLine();
            }
        }
Пример #6
0
        public override bool Execute()
        {
            var success = true;

#if DEBUG
            if (AttachDebugger)
            {
                System.Diagnostics.Debugger.Launch();
            };
#endif

            Bridge.Translator.Translator translator = null;
            try
            {
                translator = new Bridge.Translator.Translator(this.ProjectPath, true);
                translator.Configuration = this.Configuration;

                if (this.DefineConstants != null)
                {
                    translator.DefineConstants.AddRange(this.DefineConstants.Split(';').Select(s => s.Trim()).Where(s => s != ""));
                    translator.DefineConstants = translator.DefineConstants.Distinct().ToList();
                }

                translator.BridgeLocation = Path.Combine(this.AssembliesPath, "Bridge.dll");
                translator.Rebuild = false;
                translator.Log = new Translator.Logging.Logger("Bridge.Build.Task", true, new SimpleFileLoggerWriter());

                translator.Log.Info("Translator properties:");
                translator.Log.Info("\tBridgeLocation:" + translator.BridgeLocation ?? "");
                translator.Log.Info("\tBuildArguments:" + translator.BuildArguments ?? "");
                translator.Log.Info("\tConfiguration:" + translator.Configuration ?? "");
                translator.Log.Info("\tDefineConstants:" + (translator.DefineConstants != null ? string.Join(" ", translator.DefineConstants) : ""));
                translator.Log.Info("\tRebuild:" + translator.Rebuild);

                translator.Translate();

                string fileName = Path.GetFileNameWithoutExtension(this.Assembly.ItemSpec);

                string outputPath = !string.IsNullOrWhiteSpace(translator.AssemblyInfo.Output)
                    ? Path.Combine(Path.GetDirectoryName(this.ProjectPath), translator.AssemblyInfo.Output)
                    : this.OutputPath;

                translator.CleanOutputFolderIfRequired(outputPath);

                if (!this.NoCore)
                {
                    translator.ExtractCore(outputPath);
                }

                translator.SaveTo(outputPath, fileName);
                translator.Flush(outputPath, fileName);
                translator.Plugins.AfterOutput(translator, outputPath, this.NoCore);
            }
            catch (EmitterException e)
            {
                this.Log.LogError(null, null, null, e.FileName, e.StartLine + 1, e.StartColumn + 1, e.EndLine + 1, e.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                success = false;
            }
            catch (Exception e)
            {
                var ee = translator != null ? translator.CreateExceptionFromLastNode() : null;

                if (ee != null)
                {
                    this.Log.LogError(null, null, null, ee.FileName, ee.StartLine + 1, ee.StartColumn + 1, ee.EndLine + 1, ee.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                }
                else
                {
                    this.Log.LogError("Error: {0} {1}", e.Message, e.StackTrace);
                }

                success = false;
            }

            translator = null;

            return success;
        }
Пример #7
0
        public string Translate()
        {
            var outputLocation = Path.ChangeExtension(ProjectLocation, "js");

            var translator = new Bridge.Translator.Translator(ProjectLocation);

            translator.Log = LogMessage;
            translator.Rebuild = true;

            LogInfo("\t\tProjectLocation: " + ProjectLocation);

            string configuration;
            translator.BridgeLocation = FindBridgeDllPath(out configuration);
            if (translator.BridgeLocation == null)
            {
                Bridge.Translator.Exception.Throw("Unable to determine Bridge project output path");
            }

            translator.BuildArguments = WrapBuildArguments(configuration);
            translator.Configuration = configuration;

            LogInfo("\t\tBuildArguments: " + translator.BuildArguments);
            LogInfo("\t\tConfiguration: " + translator.Configuration);
            LogInfo("\t\tBridgeLocation: " + translator.BridgeLocation);

            translator.Translate();

            string path = Path.GetDirectoryName(outputLocation);

            string outputDir = !string.IsNullOrWhiteSpace(translator.AssemblyInfo.Output) ?
                                    Path.Combine(Path.GetDirectoryName(ProjectLocation), translator.AssemblyInfo.Output) :
                                    path;

            LogInfo("\t\toutputDir: " + outputDir);
            translator.SaveTo(outputDir, Path.GetFileNameWithoutExtension(outputLocation));

            return outputDir;
        }
Пример #8
0
        public override bool Execute()
        {
            var success = true;

#if DEBUG
            if (AttachDebugger)
            {
                System.Diagnostics.Debugger.Launch();
            }
            ;
#endif

            Bridge.Translator.Translator translator = null;
            try
            {
                translator = new Bridge.Translator.Translator(this.ProjectPath, true);
                translator.Configuration = this.Configuration;

                if (this.DefineConstants != null)
                {
                    translator.DefineConstants.AddRange(this.DefineConstants.Split(';').Select(s => s.Trim()).Where(s => s != ""));
                    translator.DefineConstants = translator.DefineConstants.Distinct().ToList();
                }

                translator.BridgeLocation = Path.Combine(this.AssembliesPath, "Bridge.dll");
                translator.Rebuild        = false;
                translator.Log            = new Translator.Logging.Logger("Bridge.Build.Task", true, new ConsoleLoggerWriter(), SimpleFileLoggerWriter.Instance);
                translator.Translate();

                string fileName = Path.GetFileNameWithoutExtension(this.Assembly.ItemSpec);

                string outputPath = !string.IsNullOrWhiteSpace(translator.AssemblyInfo.Output)
                    ? Path.Combine(Path.GetDirectoryName(this.ProjectPath), translator.AssemblyInfo.Output)
                    : this.OutputPath;

                if (translator.AssemblyInfo != null && translator.AssemblyInfo.CleanOutputFolderBeforeBuild)
                {
                    Console.WriteLine("Cleaning output folder before extracting scripts...");
                    CleanDirectory(outputPath);
                }

                if (!this.NoCore)
                {
                    translator.ExtractCore(outputPath);
                }
                translator.SaveTo(outputPath, fileName);
                translator.Flush(outputPath, fileName);
                translator.Plugins.AfterOutput(translator, outputPath, this.NoCore);
            }
            catch (EmitterException e)
            {
                this.Log.LogError(null, null, null, e.FileName, e.StartLine + 1, e.StartColumn + 1, e.EndLine + 1, e.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                success = false;
            }
            catch (Exception e)
            {
                var ee = translator != null?translator.CreateExceptionFromLastNode() : null;

                if (ee != null)
                {
                    this.Log.LogError(null, null, null, ee.FileName, ee.StartLine + 1, ee.StartColumn + 1, ee.EndLine + 1, ee.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                }
                else
                {
                    this.Log.LogError("Error: {0} {1}", e.Message, e.StackTrace);
                }

                success = false;
            }

            return(success);
        }
Пример #9
0
        public override bool Execute()
        {
            var success = true;

            #if DEBUG
            if (AttachDebugger)
            {
                System.Diagnostics.Debugger.Launch();
            };
            #endif

            Bridge.Translator.Translator translator = null;
            try
            {
                translator = new Bridge.Translator.Translator(this.ProjectPath);
                translator.Configuration = this.Configuration;
                translator.BridgeLocation = Path.Combine(this.AssembliesPath, "Bridge.dll");
                translator.Rebuild = false;
                translator.ChangeCase = this.ChangeCase;
                translator.Log = this.LogMessage;
                translator.Translate();

                string fileName = Path.GetFileNameWithoutExtension(this.Assembly.ItemSpec);

                string outputPath = !string.IsNullOrWhiteSpace(translator.AssemblyInfo.Output)
                    ? Path.Combine(Path.GetDirectoryName(this.ProjectPath), translator.AssemblyInfo.Output)
                    : this.OutputPath;

                translator.SaveTo(outputPath, fileName);

                if (!this.NoCore)
                {
                    Bridge.Translator.Translator.ExtractCore(translator, outputPath);
                }
            }
            catch (EmitterException e)
            {
                this.Log.LogError(null, null, null, e.FileName, e.StartLine + 1, e.StartColumn + 1, e.EndLine + 1, e.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                success = false;
            }
            catch (Exception e)
            {
                var ee = translator != null ? translator.CreateExceptionFromLastNode() : null;

                if (ee != null)
                {
                    this.Log.LogError(null, null, null, ee.FileName, ee.StartLine + 1, ee.StartColumn + 1, ee.EndLine + 1, ee.EndColumn + 1, "Error: {0} {1}", e.Message, e.StackTrace);
                }
                else
                {
                    this.Log.LogError("Error: {0} {1}", e.Message, e.StackTrace);
                }

                success = false;
            }

            return success;
        }