public void Generate() { var lessPath = Path.Combine(_pathToThemeBuilderDataFolder, "less"); if (!Directory.Exists(lessPath)) { Directory.CreateDirectory(lessPath); } if (!Directory.Exists(_pathToThemeBuilderMetadata)) { Directory.CreateDirectory(_pathToThemeBuilderMetadata); } var allMetadata = new ConcurrentDictionary <string, string>(); var allLessTemplates = new ConcurrentDictionary <string, string>(); var tasks = new List <Task>(); foreach (var theme in THEMES) { var task = new Task(delegate() { var paths = ThemeBuilderLessFilesReader.GetLessPaths(_sourcePath, theme); var bag = PersistentCache.Instance.Get(new[] { "tb-asset-gen", theme.FullName }, paths, delegate() { var themeItem = ThemeBuilderItem.Get(_sourcePath, theme, paths); return(new Dictionary <string, string> { { "meta", PrepareMetadata(themeItem.Metadata, theme) }, { "less", themeItem.LessTemplate } }); }); allMetadata[theme.FullName] = bag["meta"]; allLessTemplates[theme.FullName] = bag["less"]; }); task.Start(); tasks.Add(task); } Task.WaitAll(tasks.ToArray()); foreach (var theme in THEMES) { File.WriteAllText(Path.Combine(lessPath, "theme-builder-" + theme.FullName + ".less"), allLessTemplates[theme.FullName]); } using (var stream = File.Open(Path.Combine(_pathToThemeBuilderMetadata, "dx-theme-builder-metadata.js"), FileMode.Create)) using (var writer = new StreamWriter(stream)) { writer.WriteLine("module.exports = {"); foreach (var theme in THEMES) { writer.WriteLine(allMetadata[theme.FullName]); } writer.Write(GetMetadataVersionScript()); writer.WriteLine("}"); } }
public static ThemeBuilderItem Get(string sourcePath, ThemeId theme, string[] lessPaths) { var lessParser = new ThemeBuilderLessParser(ThemeBuilderLessFilesReader.ReadPaths(lessPaths)); var meta = lessParser.GenerateThemeBuilderMetadata(); string lessData = ThemeBuilderLessFilesReader.ReadPaths(lessPaths); lessData = ImageInliner.InlineImages(lessData, sourcePath); lessData = ThemeBuilderLessParser.MinifyLess(lessData); return(new ThemeBuilderItem { Metadata = meta, LessTemplate = lessData }); }
public static void Generate(string sourcePath, ThemeId baseThemeId, string customMetaFilePath, string outputPath) { var baseThemeBuilderItem = ThemeBuilderItem.Get(sourcePath, baseThemeId, ThemeBuilderLessFilesReader.GetLessPaths(sourcePath, baseThemeId)); var baseThemeBuilderMeta = baseThemeBuilderItem.Metadata.ToDictionary(item => item.Key, item => item); var customThemeMeta = JsonConvert.DeserializeObject <CustomThemeMeta>(File.ReadAllText(customMetaFilePath)); var additionalConstants = new StringBuilder(); if (customThemeMeta.HighlightColor != null) { foreach (var entry in baseThemeBuilderMeta) { var isAccent = entry.Value.PaletteColorOpacity != null; if (isAccent) { additionalConstants.AppendFormat( LESS_VAR_FORMAT, entry.Key, ApplyOpacity(customThemeMeta.HighlightColor, double.Parse(entry.Value.PaletteColorOpacity, CultureInfo.InvariantCulture)) ); } } } foreach (var item in customThemeMeta.Items) { additionalConstants.AppendFormat(LESS_VAR_FORMAT, item.Key, item.Value); } var css = NodeRunner.CompileLess(baseThemeBuilderItem.LessTemplate + additionalConstants); var outputDir = Path.GetDirectoryName(outputPath); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } File.WriteAllText(outputPath, THEME_BUILDER_PROMO + css); }
public void Generate() { if (!Directory.Exists(_pathToThemeBuilderJSDataFolder)) { Directory.CreateDirectory(_pathToThemeBuilderJSDataFolder); } var lessPath = Path.Combine(_pathToThemeBuilderDataFolder, "LESS"); if (!Directory.Exists(lessPath)) { Directory.CreateDirectory(lessPath); } var allMetadata = new ConcurrentDictionary <string, string>(); var allLessTemplates = new ConcurrentDictionary <string, string>(); var tasks = new List <Task>(); foreach (var theme in THEMES) { var task = new Task(delegate() { var paths = ThemeBuilderLessFilesReader.GetLessPaths(_sourcePath, theme); var bag = PersistentCache.Instance.Get(new[] { "tb-asset-gen", theme.FullName }, paths, delegate() { var themeItem = ThemeBuilderItem.Get(_sourcePath, theme, paths); GenerateMissingDataForWidgetsPreview(themeItem.Metadata); return(new Dictionary <string, string> { { "meta", PrepareMetadata(themeItem.Metadata, theme) }, { "less", GetLessTemplateScript(themeItem.LessTemplate) } }); }); allMetadata[theme.FullName] = bag["meta"]; allLessTemplates[theme.FullName] = bag["less"]; }); task.Start(); tasks.Add(task); } Task.WaitAll(tasks.ToArray()); foreach (var theme in THEMES) { File.WriteAllText(Path.Combine(lessPath, "theme-builder-" + theme.FullName + ".less.js"), allLessTemplates[theme.FullName]); } using (var stream = File.Open(Path.Combine(_pathToThemeBuilderDataFolder, "JS", "dx-theme-builder-metadata.js"), FileMode.Create)) using (var writer = new StreamWriter(stream)) { foreach (var theme in THEMES) { writer.WriteLine(allMetadata[theme.FullName]); } writer.Write(GetMetadataVersionScript()); } GenerateCombinedDataForWidgetsPreview(); string bootstrapMetadataContent = File.ReadAllText(Path.Combine(_pathToBootstrapVariableFolder, BOOTSTRAP_METADATA_FILENAME)); StringBuilder content = new StringBuilder(); content.Append(String.Concat( "ThemeBuilder.__bootstrap_metadata", " = function() { return ", bootstrapMetadataContent, ";};\n" )); File.WriteAllText(Path.Combine(_pathToThemeBuilderJSDataFolder, "dx-theme-builder-bootstrap-metadata.js"), content.ToString()); string variablesMigrationMetadataContent = File.ReadAllText(Path.Combine(_pathToBootstrapVariableFolder, VARIABLES_MIGRATION_METADATA_FILENAME)); StringBuilder newContent = new StringBuilder(); newContent.Append(String.Concat( "ThemeBuilder.__variables_migration_metadata", " = function() { return ", variablesMigrationMetadataContent, ";};\n" )); File.WriteAllText(Path.Combine(_pathToThemeBuilderJSDataFolder, "dx-theme-builder-variables-migration-metadata.js"), newContent.ToString()); string additionalMigrationMetadataContent = File.ReadAllText(Path.Combine(_pathToBootstrapVariableFolder, ADDITIONAL_MIGRATION_METADATA_FILENAME)); StringBuilder dataContent = new StringBuilder(); dataContent.Append(String.Concat( "ThemeBuilder.__additional_migration_metadata", " = function() { return ", additionalMigrationMetadataContent, ";};\n" )); File.WriteAllText(Path.Combine(_pathToThemeBuilderJSDataFolder, "dx-theme-builder-additional-migration-metadata.js"), dataContent.ToString()); }