예제 #1
0
        /// <summary>
        /// Parses the manifest file
        /// </summary>
        /// <param name="json">Contents of the file</param>
        /// <returns>Parsed Webpack assets</returns>
        public WebpackAssets ParseManifest(string json)
        {
            var manifest = JsonConvert.DeserializeObject <IDictionary <string, IDictionary <string, dynamic> > >(json);

            var output = new Dictionary <string, WebpackAssets.EntryPoint>();

            foreach (var(entryPoint, filesByExtension) in manifest)
            {
                var outputFiles = new Dictionary <string, ImmutableArray <string> >();
                foreach (var(extension, files) in filesByExtension)
                {
                    // This can be either an array (for multiple files), or a string (for one file)
                    switch (files)
                    {
                    case JArray array:
                        outputFiles[extension] = array.Select(x => FormatPath(x.ToString())).ToImmutableArray();
                        break;

                    case string str:
                        outputFiles[extension] = ImmutableArray.Create(FormatPath(str));
                        break;

                    default:
                        throw new ArgumentException("Unrecognised webpack-assets format");
                    }
                }

                output[entryPoint] = new WebpackAssets.EntryPoint(outputFiles.ToImmutableDictionary());
            }

            return(new WebpackAssets(output.ToImmutableDictionary()));
        }
예제 #2
0
        /// <summary>
        /// Parses the manifest file
        /// </summary>
        /// <param name="json">Contents of the file</param>
        /// <returns>Parsed Webpack assets</returns>
        public WebpackAssets ParseManifest(string json)
        {
            var manifest = JsonSerializer.Deserialize <IDictionary <string, IDictionary <string, object> > >(json);

            var output = new Dictionary <string, WebpackAssets.EntryPoint>();

            foreach (var(entryPoint, filesByExtension) in manifest)
            {
                var outputFiles = new Dictionary <string, ImmutableArray <string> >();
                foreach (var(extension, files) in filesByExtension)
                {
                    if (files is JsonElement filesElement)
                    {
                        // This can be either an array (for multiple files), or a string (for one file)
                        switch (filesElement.ValueKind)
                        {
                        case JsonValueKind.Array:
                            outputFiles[extension] = JsonSerializer.Deserialize <List <string> >(filesElement.GetRawText())
                                                     .Select(x => FormatPath(x.ToString())).ToImmutableArray();
                            break;

                        case JsonValueKind.String:
                            outputFiles[extension] = ImmutableArray.Create(FormatPath(filesElement.GetString()));
                            break;

                        default:
                            throw new ArgumentException("Unrecognised webpack-assets format");
                        }
                    }
                }

                output[entryPoint] = new WebpackAssets.EntryPoint(outputFiles.ToImmutableDictionary());
            }

            return(new WebpackAssets(output.ToImmutableDictionary()));
        }