예제 #1
0
        private void CleanDirsAndFiles(string directory, ResourceMapping resourceMapping)
        {
            var files = FindFiles(directory, resourceMapping.Clean.ToArray());

            foreach (var file in files)
            {
                if (File.Exists(file.Path))
                {
                    File.Delete(file.Path);
                }
            }

            foreach (var directoryInfo in Directory.GetDirectories(Path.Combine(directory, resourceMapping.Clean.First()), "*", SearchOption.AllDirectories).Reverse())
            {
                if (!Directory.EnumerateFileSystemEntries(directoryInfo).Any())
                {
                    Directory.Delete(directoryInfo);
                }
            }
        }
예제 #2
0
        private void CopyResourcesToLibs(string fileDirectory, ResourceMapping resourceMapping)
        {
            foreach (var mapping in resourceMapping.Mappings)
            {
                var destPath = Path.Combine(fileDirectory, mapping.Value);
                var files    = FindFiles(fileDirectory, mapping.Key);

                foreach (var file in files)
                {
                    var destFilePath = Path.Combine(destPath, file.Stem);
                    if (File.Exists(destFilePath))
                    {
                        continue;
                    }

                    Directory.CreateDirectory(Path.GetDirectoryName(destFilePath));
                    File.Copy(file.Path, destFilePath);
                }
            }
        }
예제 #3
0
        private async Task CleanAndCopyResources(string fileDirectory)
        {
            var mappingFiles    = Directory.GetFiles(fileDirectory, "abp.resourcemapping.js", SearchOption.AllDirectories);
            var resourceMapping = new ResourceMapping
            {
                Clean = new List <string> {
                    LibsDirectory
                }
            };

            foreach (var mappingFile in mappingFiles)
            {
                using (var reader = File.OpenText(mappingFile))
                {
                    var mappingFileContent = await reader.ReadToEndAsync();

                    var mapping = _jsonSerializer.Deserialize <ResourceMapping>(mappingFileContent
                                                                                .Replace("module.exports", string.Empty)
                                                                                .Replace("=", string.Empty).Trim().TrimEnd(';'));

                    mapping.ReplaceAliases();

                    mapping.Clean.ForEach(c => resourceMapping.Clean.AddIfNotContains(c));
                    mapping.Aliases.ToList().ForEach(x =>
                    {
                        resourceMapping.Aliases.AddIfNotContains(new KeyValuePair <string, string>(x.Key, x.Value));
                    });
                    mapping.Mappings.ToList().ForEach(x =>
                    {
                        resourceMapping.Mappings.AddIfNotContains(new KeyValuePair <string, string>(x.Key, x.Value));
                    });
                }
            }

            EnsureLibsFolderExists(fileDirectory, LibsDirectory);

            CleanDirsAndFiles(fileDirectory, resourceMapping);
            CopyResourcesToLibs(fileDirectory, resourceMapping);
        }