예제 #1
0
        /// <summary>
        ///     Exports TypeScript source according to settings
        /// </summary>
        public void Export()
        {
            _context.FileOperations.ClearTempRegistry();
            Initialize();

            _context.Lock();
            ReferenceProcessorBase refProc = null;

            if (_context.Global.ReferencesProcessorType != null)
            {
                refProc = (ReferenceProcessorBase)Activator.CreateInstance(_context.Global.ReferencesProcessorType);
            }
            if (!_context.Hierarchical)
            {
                var file = ExportTypes();
                file.ApplyReferenceProcessor(refProc);
                _context.FileOperations.Export(_context.TargetFile, file);
            }
            else
            {
                foreach (var kv in _context.TypesToFilesMap)
                {
                    var path = kv.Key;
                    var file = ExportTypes(kv.Key);
                    file.ApplyReferenceProcessor(refProc);
                    _context.FileOperations.Export(path, file);
                }
            }

            _context.Unlock();
            _context.FileOperations.DeployTempFiles();
        }
예제 #2
0
        internal void ApplyReferenceProcessor(ReferenceProcessorBase refProcessor = null)
        {
            if (refProcessor == null)
            {
                return;
            }

            var references = References.References;

            references = refProcessor.FilterReferences(references, this);
            if (references == null)
            {
                references = new RtReference[0];
            }
            _refinedReferences = references;

            var imports = References.Imports;

            imports = refProcessor.FilterImports(imports, this);
            if (imports == null)
            {
                imports = new RtImport[0];
            }

            _refinedImports = imports;
        }
예제 #3
0
 public void Export(string fileName, ExportedFile file, ReferenceProcessorBase refProcessor = null)
 {
     using (var fs = GetTmpFile(fileName))
     {
         using (var tw = new StreamWriter(fs))
         {
             ExportCore(tw, file, refProcessor);
         }
     }
 }
예제 #4
0
        public void Export(string fileName, ExportedFile file, ReferenceProcessorBase refProcessor = null)
        {
            StringBuilder sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                ExportCore(sw, file, refProcessor);
            }
            ExportedFiles[fileName] = sb.ToString();
        }
예제 #5
0
        protected virtual void ExportCore(StreamWriter tw, ExportedFile file, ReferenceProcessorBase refProcessor = null)
        {
            var visitor = Context.Global.ExportPureTypings
                ? new TypingsExportVisitor(tw, Context.Global.TabSymbol, Context.Global.ReorderMembers)
                : new TypeScriptExportVisitor(tw, Context.Global.TabSymbol, Context.Global.ReorderMembers);

            WriteWarning(tw);

            var references = file.References.References;

            if (refProcessor != null)
            {
                references = refProcessor.FilterReferences(references, file);
                if (references == null)
                {
                    references = new RtReference[0];
                }
            }
            bool hasReferences = false;

            foreach (var rtReference in references)
            {
                visitor.Visit(rtReference);
                hasReferences = true;
            }

            var imports = file.References.Imports;

            if (refProcessor != null)
            {
                imports = refProcessor.FilterImports(imports, file);
                if (imports == null)
                {
                    imports = new RtImport[0];
                }
            }
            bool hasImports = false;

            foreach (var rtImport in imports)
            {
                visitor.Visit(rtImport);
                hasImports = true;
            }
            if (hasReferences || hasImports)
            {
                tw.WriteLine();
            }

            foreach (var fileNamespace in file.Namespaces)
            {
                visitor.Visit(fileNamespace);
            }
        }