Ejemplo n.º 1
0
        private void TransformOutputs()
        {
            if (this.Emitter.Outputs.Count == 0)
            {
                return;
            }

            if (this.Emitter.AssemblyInfo.OutputBy == OutputBy.Project)
            {
                var fileName = Path.GetFileNameWithoutExtension(this.Emitter.Outputs.First().Key) + Files.Extensions.DTS;
                var e        = new EmitterOutput(fileName);

                foreach (var item in this.Outputs)
                {
                    e.NonModuletOutput.Append(item.Value.ToString() + newLine);
                }

                this.Emitter.Outputs.Add(fileName, e);
            }
            else
            {
                foreach (var item in this.Outputs)
                {
                    var fileName = item.Key + Files.Extensions.DTS;
                    var e        = new EmitterOutput(fileName);
                    e.NonModuletOutput = item.Value;
                    this.Emitter.Outputs.Add(fileName, e);
                }
            }
        }
Ejemplo n.º 2
0
        private void TransformOutputs()
        {
            if (this.Emitter.Outputs.Count == 0)
            {
                return;
            }

            var withoutModuleOutputs = this.Outputs.Where(o => o.Key.Module == null).ToList();
            var withModuleOutputs    = this.Outputs.Where(o => o.Key.Module != null).ToList();

            var nonModuleOutputs = withoutModuleOutputs.GroupBy(o => o.Key.Key).ToDictionary(t => t.Key, t => string.Join(newLine.ToString(), t.Select(r => r.Value.ToString()).ToList()));
            var outputs          = withModuleOutputs.GroupBy(o => o.Key.Module).ToDictionary(t => t.Key, t => string.Join(newLine.ToString(), t.Select(r => r.Value.ToString()).ToList()));

            if (this.Emitter.AssemblyInfo.OutputBy == OutputBy.Project)
            {
                var fileName = Path.GetFileNameWithoutExtension(this.Emitter.Outputs.First().Key) + Files.Extensions.DTS;
                var e        = new EmitterOutput(fileName);

                foreach (var item in nonModuleOutputs)
                {
                    e.NonModuletOutput.Append(item.Value.ToString() + newLine);
                }

                foreach (var item in outputs)
                {
                    e.NonModuletOutput.Append(WrapModule(item) + newLine);
                }

                this.Emitter.Outputs.Add(fileName, e);
            }
            else
            {
                foreach (var item in nonModuleOutputs)
                {
                    var fileName = item.Key + Files.Extensions.DTS;
                    var e        = new EmitterOutput(fileName);
                    e.NonModuletOutput.Append(item.Value.ToString());
                    this.Emitter.Outputs.Add(fileName, e);
                }

                foreach (var item in outputs)
                {
                    var fileName = item.Key.ExportAsNamespace + Files.Extensions.DTS;
                    var e        = new EmitterOutput(fileName);
                    e.NonModuletOutput.Append(WrapModule(item));
                    this.Emitter.Outputs.Add(fileName, e);
                }
            }
        }
Ejemplo n.º 3
0
        private void TransformOutputs()
        {
            if (this.Emitter.AssemblyInfo.OutputBy == OutputBy.Project)
            {
                var fileName = Path.GetFileNameWithoutExtension(this.Emitter.Outputs.First().Key) + ".d.ts";
                var e = new EmitterOutput(fileName);

                foreach (var item in this.Outputs)
                {
                    e.NonModuletOutput.Append(item.Value.ToString() + newLine);
                }

                this.Emitter.Outputs.Add(fileName, e);
            }
            else
            {
                foreach (var item in this.Outputs)
                {
                    var fileName = item.Key + ".d.ts";
                    var e = new EmitterOutput(fileName);
                    e.NonModuletOutput = item.Value;
                    this.Emitter.Outputs.Add(fileName, e);
                }
            }
        }
Ejemplo n.º 4
0
        protected virtual StringBuilder GetOutputForType(ITypeInfo typeInfo)
        {
            string module = null;

            if (typeInfo.Module != null)
            {
                module = typeInfo.Module;
            }
            else if (this.Emitter.AssemblyInfo.Module != null)
            {
                module = this.Emitter.AssemblyInfo.Module;
            }

            var fileName = typeInfo.FileName;

            if (fileName.IsEmpty() && this.Emitter.AssemblyInfo.OutputBy != OutputBy.Project)
            {
                switch (this.Emitter.AssemblyInfo.OutputBy)
                {
                    case OutputBy.ClassPath:
                        fileName = typeInfo.Type.FullName;
                        break;

                    case OutputBy.Class:
                        fileName = this.GetIteractiveClassPath(typeInfo);
                        break;

                    case OutputBy.Module:
                        fileName = module;
                        break;

                    case OutputBy.NamespacePath:
                    case OutputBy.Namespace:
                        fileName = this.GetNamespaceFilename(typeInfo);
                        break;

                    default:
                        break;
                }

                var isPathRelated = this.Emitter.AssemblyInfo.OutputBy == OutputBy.ClassPath ||
                                    this.Emitter.AssemblyInfo.OutputBy == OutputBy.NamespacePath;

                if (fileName.IsNotEmpty() && isPathRelated)
                {
                    fileName = fileName.Replace('.', System.IO.Path.DirectorySeparatorChar);

                    if (this.Emitter.AssemblyInfo.StartIndexInName > 0)
                    {
                        fileName = fileName.Substring(this.Emitter.AssemblyInfo.StartIndexInName);
                    }
                }
            }

            if (fileName.IsEmpty() && this.Emitter.AssemblyInfo.FileName != null)
            {
                fileName = this.Emitter.AssemblyInfo.FileName;
            }

            if (fileName.IsEmpty())
            {
                fileName = AssemblyInfo.DEFAULT_FILENAME;
            }

            // Apply lowerCamelCase to filename if set up in bridge.json (or left default)
            if (this.Emitter.AssemblyInfo.FileNameCasing == FileNameCaseConvert.CamelCase)
            {
                var sepList = new string[] { ".", System.IO.Path.DirectorySeparatorChar.ToString(), "\\", "/" };

                // Populate list only with needed separators, as usually we will never have all four of them
                var neededSepList = new List<string>();

                foreach (var separator in sepList)
                {
                    if (fileName.Contains(separator.ToString()) && !neededSepList.Contains(separator))
                    {
                        neededSepList.Add(separator);
                    }
                }

                // now, separating the filename string only by the used separators, apply lowerCamelCase
                if (neededSepList.Count > 0)
                {
                    foreach (var separator in neededSepList)
                    {
                        var stringList = new List<string>();

                        foreach (var str in fileName.Split(separator[0]))
                        {
                            stringList.Add(str.ToLowerCamelCase());
                        }

                        fileName = stringList.Join(separator);
                    }
                }
                else
                {
                    fileName = fileName.ToLowerCamelCase();
                }
            }

            // Append '.js' extension to file name at translator.Outputs level: this aids in code grouping on files
            // when filesystem is not case sensitive.
            if (!fileName.ToLower().EndsWith("." + Bridge.Translator.AssemblyInfo.JAVASCRIPT_EXTENSION))
            {
                fileName += "." + Bridge.Translator.AssemblyInfo.JAVASCRIPT_EXTENSION;
            }

            switch (this.Emitter.AssemblyInfo.FileNameCasing)
            {
                case FileNameCaseConvert.Lowercase:
                    fileName = fileName.ToLower();
                    break;

                default:
                    var lcFileName = fileName.ToLower();

                    // Find a file name that matches (case-insensitive) and use it as file name (if found)
                    // The used file name will use the same casing of the existing one.
                    foreach (var existingFile in this.Emitter.Outputs.Keys)
                    {
                        if (lcFileName == existingFile.ToLower())
                        {
                            fileName = existingFile;
                        }
                    }

                    break;
            }

            IEmitterOutput output = null;

            if (this.Emitter.Outputs.ContainsKey(fileName))
            {
                output = this.Emitter.Outputs[fileName];
            }
            else
            {
                output = new EmitterOutput(fileName);
                this.Emitter.Outputs.Add(fileName, output);
            }

            this.Emitter.EmitterOutput = output;

            if (module == null)
            {
                return output.NonModuletOutput;
            }

            if (module == "")
            {
                module = Bridge.Translator.AssemblyInfo.DEFAULT_FILENAME;
            }

            if (output.ModuleOutput.ContainsKey(module))
            {
                this.Emitter.CurrentDependencies = output.ModuleDependencies[module];
                return output.ModuleOutput[module];
            }

            StringBuilder moduleOutput = new StringBuilder();
            output.ModuleOutput.Add(module, moduleOutput);
            var dependencies = new List<IPluginDependency>();
            output.ModuleDependencies.Add(module, dependencies);

            if (typeInfo.Dependencies.Count > 0)
            {
                dependencies.AddRange(typeInfo.Dependencies);
            }

            this.Emitter.CurrentDependencies = dependencies;

            return moduleOutput;
        }