void FillProjectOptionsFromPackageJson(JObject parsed) { ProjectOptions.Localize = Dependencies?.Contains("bobril-g11n") ?? false; ProjectOptions.TestSourcesRegExp = "^.*?(?:\\.s|S)pec\\.ts(?:x)?$"; var publishConfigSection = parsed.GetValue("publishConfig") as JObject; if (publishConfigSection != null) { ProjectOptions.NpmRegistry = publishConfigSection.Value <string>("registry"); } var bobrilSection = parsed.GetValue("bobril") as JObject; ProjectOptions.TypeScriptVersion = GetStringProperty(bobrilSection, "tsVersion", DefaultTypeScriptVersion); ProjectOptions.Title = GetStringProperty(bobrilSection, "title", "Bobril Application"); ProjectOptions.HtmlHead = GetStringProperty(bobrilSection, "head", "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />"); ProjectOptions.PrefixStyleNames = GetStringProperty(bobrilSection, "prefixStyleDefs", ""); ProjectOptions.Example = GetStringProperty(bobrilSection, "example", ""); ProjectOptions.AdditionalResourcesDirectory = GetStringProperty(bobrilSection, "additionalResourcesDirectory", null); ProjectOptions.BobrilJsx = true; ProjectOptions.CompilerOptions = bobrilSection != null?TSCompilerOptions.Parse(bobrilSection.GetValue("compilerOptions") as JObject) : null; ProjectOptions.DependencyUpdate = String2DependencyUpdate(GetStringProperty(bobrilSection, "dependencies", "install")); if (bobrilSection == null) { return; } }
public void FillProjectOptionsFromPackageJson(JObject parsed) { Localize = Owner.Dependencies?.Contains("bobril-g11n") ?? false; TestSourcesRegExp = "^.*?(?:\\.s|S)pec(?:\\.d)?\\.ts(?:x)?$"; if (parsed?.GetValue("publishConfig") is JObject publishConfigSection) { NpmRegistry = publishConfigSection.Value <string>("registry"); } var bobrilSection = parsed?.GetValue("bobril") as JObject; TypeScriptVersion = GetStringProperty(bobrilSection, "tsVersion", ""); if (TypeScriptVersion != "") { TypeScriptVersionOverride = true; } else { TypeScriptVersionOverride = false; TypeScriptVersion = TSProject.DefaultTypeScriptVersion; } Variant = GetStringProperty(bobrilSection, "variant", ""); JasmineVersion = GetStringProperty(bobrilSection, "jasmineVersion", "330"); NoHtml = bobrilSection?["nohtml"]?.Value <bool>() ?? Variant != ""; Title = GetStringProperty(bobrilSection, "title", "Bobril Application"); HtmlHead = GetStringProperty(bobrilSection, "head", "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />"); PrefixStyleNames = GetStringProperty(bobrilSection, "prefixStyleDefs", ""); Example = GetStringProperty(bobrilSection, "example", ""); AdditionalResourcesDirectory = GetStringProperty(bobrilSection, "additionalResourcesDirectory", null); BobrilJsx = true; CompilerOptions = bobrilSection != null ? TSCompilerOptions.Parse(bobrilSection.GetValue("compilerOptions") as JObject) : null; DependencyUpdate = String2DependencyUpdate(GetStringProperty(bobrilSection, "dependencies", "install")); var includeSources = bobrilSection?.GetValue("includeSources") as JArray; IncludeSources = includeSources?.Select(i => i.ToString()).ToArray(); if (bobrilSection?.GetValue("ignoreDiagnostic") is JArray ignoreDiagnostic) { IgnoreDiagnostic = new HashSet <int>(ignoreDiagnostic.Select(i => i.Value <int>()).ToArray()); } var pluginsSection = bobrilSection?.GetValue("plugins") as JObject; GenerateSpritesTs = pluginsSection?["bb-assets-generator-plugin"]?["generateSpritesFile"]?.Value <bool>() ?? false; WarningsAsErrors = bobrilSection?["warningsAsErrors"]?.Value <bool>() ?? false; ObsoleteMessage = GetStringProperty(bobrilSection, "obsolete", null); TestDirectories = bobrilSection?["testDirectories"]?.Values <string>().ToList(); Localize = bobrilSection?["localize"]?.Value <bool>() ?? Localize; PathToTranslations = GetStringProperty(bobrilSection, "pathToTranslations", null); TsconfigUpdate = bobrilSection?["tsconfigUpdate"]?.Value <bool>() ?? true; BuildOutputDir = GetStringProperty(bobrilSection, "buildOutputDir", null); }
public TSCompilerOptions Merge(TSCompilerOptions with) { if (with == null) { return(this); } if (with.allowJs != null) { allowJs = with.allowJs; } if (with.allowSyntheticDefaultImports != null) { allowSyntheticDefaultImports = with.allowSyntheticDefaultImports; } if (with.allowUnreachableCode != null) { allowUnreachableCode = with.allowUnreachableCode; } if (with.allowUnusedLabels != null) { allowUnusedLabels = with.allowUnusedLabels; } if (with.alwaysStrict != null) { alwaysStrict = with.alwaysStrict; } if (with.baseUrl != null) { baseUrl = with.baseUrl; } if (with.charset != null) { charset = with.charset; } if (with.checkJs != null) { checkJs = with.checkJs; } if (with.declaration != null) { declaration = with.declaration; } if (with.declarationDir != null) { declarationDir = with.declarationDir; } if (with.disableSizeLimit != null) { disableSizeLimit = with.disableSizeLimit; } if (with.downlevelIteration != null) { downlevelIteration = with.downlevelIteration; } if (with.emitBOM != null) { emitBOM = with.emitBOM; } if (with.emitDecoratorMetadata != null) { emitDecoratorMetadata = with.emitDecoratorMetadata; } if (with.experimentalDecorators != null) { experimentalDecorators = with.experimentalDecorators; } if (with.forceConsistentCasingInFileNames != null) { forceConsistentCasingInFileNames = with.forceConsistentCasingInFileNames; } if (with.importHelpers != null) { importHelpers = with.importHelpers; } if (with.inlineSourceMap != null) { inlineSourceMap = with.inlineSourceMap; } if (with.inlineSources != null) { inlineSources = with.inlineSources; } if (with.isolatedModules != null) { isolatedModules = with.isolatedModules; } if (with.jsx != null) { jsx = with.jsx; } if (with.jsxFactory != null) { jsxFactory = with.jsxFactory; } if (with.lib != null) { lib = with.lib; } if (with.locale != null) { locale = with.locale; } if (with.mapRoot != null) { mapRoot = with.mapRoot; } if (with.maxNodeModuleJsDepth != null) { maxNodeModuleJsDepth = with.maxNodeModuleJsDepth; } if (with.module != null) { module = with.module; } if (with.moduleResolution != null) { moduleResolution = with.moduleResolution; } if (with.newLine != null) { newLine = with.newLine; } if (with.noEmit != null) { noEmit = with.noEmit; } if (with.noEmitHelpers != null) { noEmitHelpers = with.noEmitHelpers; } if (with.noEmitOnError != null) { noEmitOnError = with.noEmitOnError; } if (with.noErrorTruncation != null) { noErrorTruncation = with.noErrorTruncation; } if (with.noFallthroughCasesInSwitch != null) { noFallthroughCasesInSwitch = with.noFallthroughCasesInSwitch; } if (with.noImplicitAny != null) { noImplicitAny = with.noImplicitAny; } if (with.noImplicitReturns != null) { noImplicitReturns = with.noImplicitReturns; } if (with.noImplicitThis != null) { noImplicitThis = with.noImplicitThis; } if (with.noImplicitUseStrict != null) { noImplicitUseStrict = with.noImplicitUseStrict; } if (with.noLib != null) { noLib = with.noLib; } if (with.noResolve != null) { noResolve = with.noResolve; } if (with.noStrictGenericChecks != null) { noStrictGenericChecks = with.noStrictGenericChecks; } if (with.noUnusedLocals != null) { noUnusedLocals = with.noUnusedLocals; } if (with.noUnusedParameters != null) { noUnusedParameters = with.noUnusedParameters; } if (with.outDir != null) { outDir = with.outDir; } if (with.outFile != null) { outFile = with.outFile; } if (with.paths != null) { paths = with.paths; } if (with.preserveConstEnums != null) { preserveConstEnums = with.preserveConstEnums; } if (with.project != null) { project = with.project; } if (with.reactNamespace != null) { reactNamespace = with.reactNamespace; } if (with.removeComments != null) { removeComments = with.removeComments; } if (with.rootDir != null) { rootDir = with.rootDir; } if (with.rootDirs != null) { rootDirs = with.rootDirs; } if (with.skipDefaultLibCheck != null) { skipDefaultLibCheck = with.skipDefaultLibCheck; } if (with.skipLibCheck != null) { skipLibCheck = with.skipLibCheck; } if (with.sourceMap != null) { sourceMap = with.sourceMap; } if (with.sourceRoot != null) { sourceRoot = with.sourceRoot; } if (with.strict != null) { strict = with.strict; } if (with.strictFunctionTypes != null) { strictFunctionTypes = with.strictFunctionTypes; } if (with.strictNullChecks != null) { strictNullChecks = with.strictNullChecks; } if (with.strictPropertyInitialization != null) { strictPropertyInitialization = with.strictPropertyInitialization; } if (with.suppressExcessPropertyErrors != null) { suppressExcessPropertyErrors = with.suppressExcessPropertyErrors; } if (with.suppressImplicitAnyIndexErrors != null) { suppressImplicitAnyIndexErrors = with.suppressImplicitAnyIndexErrors; } if (with.target != null) { target = with.target; } if (with.traceResolution != null) { traceResolution = with.traceResolution; } if (with.typeRoots != null) { typeRoots = with.typeRoots; } if (with.types != null) { types = with.types; } return(this); }
public void UpdateTSConfigJson() { var fsAbstration = Owner.DiskCache.FsAbstraction; var tsConfigPath = PathUtils.Join(Owner.Owner.FullPath, "tsconfig.json"); if (_originalContent == null && fsAbstration.FileExists(tsConfigPath)) { try { _originalContent = fsAbstration.ReadAllUtf8(tsConfigPath); } catch { } } var newConfigObject = new TSConfigJson { compilerOptions = GetDefaultTSCompilerOptions() .Merge(new TSCompilerOptions { allowJs = false }) .Merge(CompilerOptions), files = new List <string>(2 + IncludeSources?.Length ?? 0), include = new List <string> { "**/*" } }; if (BobrilJsx) { newConfigObject.files.Add(PathUtils.Subtract(BobrilJsxDts, Owner.Owner.FullPath)); } if (TestSources.Count > 0) { newConfigObject.files.Add(Tools.JasmineDtsPath); } if (IncludeSources != null) { newConfigObject.files.AddRange(IncludeSources); } var newContent = JsonConvert.SerializeObject(newConfigObject, Formatting.Indented, TSCompilerOptions.GetSerializerSettings()); if (newContent != _originalContent) { try { File.WriteAllText(tsConfigPath, newContent, new UTF8Encoding(false)); } catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Writting to " + tsConfigPath + " failed"); Console.ForegroundColor = ConsoleColor.Gray; } _originalContent = newContent; } }
public void Build(BuildCtx buildCtx, BuildResult buildResult, int iterationId) { var tryDetectChanges = !buildCtx.ProjectStructureChanged; buildResult.HasError = false; if (!buildResult.Incremental || !tryDetectChanges) { buildResult.RecompiledIncrementaly.Clear(); } var buildModuleCtx = new BuildModuleCtx() { BuildCtx = buildCtx, Owner = this, Result = buildResult, ToCheck = new OrderedHashSet <string>(), IterationId = iterationId }; try { ProjectOptions.BuildCache.StartTransaction(); ITSCompiler compiler = null; try { if (!tryDetectChanges) { if (!ProjectOptions.TypeScriptVersionOverride && DevDependencies != null && DevDependencies.Contains("typescript")) { ProjectOptions.Tools.SetTypeScriptPath(Owner.FullPath); } else { ProjectOptions.Tools.SetTypeScriptVersion(ProjectOptions.TypeScriptVersion); } } compiler = buildCtx.CompilerPool.GetTs(DiskCache, buildCtx.CompilerOptions); var trueTSVersion = compiler.GetTSVersion(); buildCtx.ShowTsVersion(trueTSVersion); ProjectOptions.ConfigurationBuildCacheId = ProjectOptions.BuildCache.MapConfiguration(trueTSVersion, JsonConvert.SerializeObject(buildCtx.CompilerOptions, Formatting.None, TSCompilerOptions.GetSerializerSettings())); } finally { if (compiler != null) { buildCtx.CompilerPool.ReleaseTs(compiler); } } if (buildModuleCtx.Result.CommonSourceDirectory == null) { buildModuleCtx.Result.CommonSourceDirectory = Owner.FullPath; } buildResult.TaskForSemanticCheck = buildCtx.StartTypeCheck().ContinueWith((task) => { if (task.IsCompletedSuccessfully) { buildResult.SemanticResult = task.Result; buildResult.NotifySemanticResult(task.Result); } }); if (tryDetectChanges) { if (!buildModuleCtx.CrawlChanges()) { buildResult.Incremental = true; goto noDependencyChangeDetected; } buildCtx.ProjectStructureChanged = true; buildResult.Incremental = false; buildModuleCtx.Result.JavaScriptAssets.Clear(); foreach (var info in buildModuleCtx.Result.Path2FileInfo) { info.Value.IterationId = iterationId - 1; } } buildModuleCtx.CrawledCount = 0; buildModuleCtx.ToCheck.Clear(); ProjectOptions.HtmlHeadExpanded = buildModuleCtx.ExpandHtmlHead(ProjectOptions.HtmlHead); if (buildCtx.MainFile != null) { buildModuleCtx.CheckAdd(PathUtils.Join(Owner.FullPath, buildCtx.MainFile), FileCompilationType.Unknown); } if (buildCtx.ExampleSources != null) { foreach (var src in buildCtx.ExampleSources) { buildModuleCtx.CheckAdd(PathUtils.Join(Owner.FullPath, src), FileCompilationType.Unknown); } } if (buildCtx.TestSources != null) { foreach (var src in buildCtx.TestSources) { buildModuleCtx.CheckAdd(PathUtils.Join(Owner.FullPath, src), FileCompilationType.Unknown); } } if (ProjectOptions.IncludeSources != null) { foreach (var src in ProjectOptions.IncludeSources) { buildModuleCtx.CheckAdd(PathUtils.Join(Owner.FullPath, src), FileCompilationType.Unknown); } } buildModuleCtx.Crawl(); noDependencyChangeDetected :; ProjectOptions.CommonSourceDirectory = buildModuleCtx.Result.CommonSourceDirectory; if (ProjectOptions.SpriteGeneration) { ProjectOptions.SpriteGenerator.ProcessNew(); } var hasError = false; foreach (var item in buildModuleCtx.Result.Path2FileInfo) { if (item.Value.HasError) { hasError = true; break; } } buildModuleCtx.Result.HasError = hasError; if (ProjectOptions.BuildCache.IsEnabled) { buildModuleCtx.StoreResultToBuildCache(buildModuleCtx.Result); } } finally { ProjectOptions.BuildCache.EndTransaction(); } }