From 9568b4df0abe5fafe0e3123e83cd1f86dceefb87 Mon Sep 17 00:00:00 2001 From: Asmeili Date: Mon, 26 Jun 2023 17:43:00 +0200 Subject: [PATCH] Removed resources bundle --- NetworkDebugger.podspec | 5 +- Package.swift | 5 +- README.md | 2 +- .../Extensions/Bundle+NetworkDebugger.swift | 78 ------------------- Sources/NetworkDebugger/Resources/DataView.js | 37 --------- .../Resources/Highlightjs/Highlightjs.css | 9 --- .../Models/DataView/DataView.html.swift} | 39 +++++----- .../Views/Models/DataView/DataView.js.swift | 41 ++++++++++ .../Models/{ => DataView}/DataView.swift | 18 ++--- .../Highlightjs/Highlightjs.css.swift | 21 +++++ .../Highlightjs/Hightlightjs.js.swift} | 25 ++++-- .../Models/DataView}/Highlightjs/LICENSE | 0 12 files changed, 110 insertions(+), 170 deletions(-) delete mode 100644 Sources/NetworkDebugger/Extensions/Bundle+NetworkDebugger.swift delete mode 100644 Sources/NetworkDebugger/Resources/DataView.js delete mode 100644 Sources/NetworkDebugger/Resources/Highlightjs/Highlightjs.css rename Sources/NetworkDebugger/{Resources/DataView.html => UI/Views/Models/DataView/DataView.html.swift} (53%) create mode 100644 Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.js.swift rename Sources/NetworkDebugger/UI/Views/Models/{ => DataView}/DataView.swift (67%) create mode 100644 Sources/NetworkDebugger/UI/Views/Models/DataView/Highlightjs/Highlightjs.css.swift rename Sources/NetworkDebugger/{Resources/Highlightjs/Highlightjs.js => UI/Views/Models/DataView/Highlightjs/Hightlightjs.js.swift} (99%) rename Sources/NetworkDebugger/{Resources => UI/Views/Models/DataView}/Highlightjs/LICENSE (100%) diff --git a/NetworkDebugger.podspec b/NetworkDebugger.podspec index 1bd92c6..2560d84 100644 --- a/NetworkDebugger.podspec +++ b/NetworkDebugger.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "NetworkDebugger" - s.version = "1.0.1" + s.version = "1.0.2" s.summary = "A Swift package designed to view your App's networking activity with minimal setup." s.homepage = "https://github.com/schwarzit/swift-network-debugger" @@ -20,7 +20,4 @@ Pod::Spec.new do |s| s.swift_version = "5.0" s.source_files = "Sources/NetworkDebugger/**/*.{swift}" - s.resource_bundles = { - 'NetworkDebugger' => ['Sources/NetworkDebugger/Resources/**/*'] - } end diff --git a/Package.swift b/Package.swift index 1c8fbe9..893008c 100644 --- a/Package.swift +++ b/Package.swift @@ -21,10 +21,7 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "NetworkDebugger", - dependencies: [], - resources: [ - .process("Resources") - ] + dependencies: [] ), .testTarget( name: "NetworkDebuggerTests", diff --git a/README.md b/README.md index 64b9883..63d819f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Install through the Swift Package Manager using Xcode. ### Cocoa Pods Add to your `podfile` and install using `pod install`. ```ruby -pod 'NetworkDebugger', '1.0.1' +pod 'NetworkDebugger', '1.0.2' ``` ## Setup diff --git a/Sources/NetworkDebugger/Extensions/Bundle+NetworkDebugger.swift b/Sources/NetworkDebugger/Extensions/Bundle+NetworkDebugger.swift deleted file mode 100644 index 0e987f0..0000000 --- a/Sources/NetworkDebugger/Extensions/Bundle+NetworkDebugger.swift +++ /dev/null @@ -1,78 +0,0 @@ -// -// Bundle+NetworkDebugger.swift -// -// -// Created by Michael Artes on 26.04.23. -// Copyright © 2023 Schwarz IT KG. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Foundation - -extension Bundle { - private static let spmBundle: Bundle? = { - let bundleName = "NetworkDebugger_NetworkDebugger" - - let overrides: [URL] - #if DEBUG - if let override = ProcessInfo.processInfo.environment["PACKAGE_RESOURCE_BUNDLE_URL"] { - overrides = [URL(fileURLWithPath: override)] - } else { - overrides = [] - } - #else - overrides = [] - #endif - - let candidates = overrides + [ - // Bundle should be present here when the package is linked into an App. - Bundle.main.resourceURL, - - // Bundle should be present here when the package is linked into a framework. - Bundle(for: NetworkDebugger.self).resourceURL, - - // For command-line tools. - Bundle.main.bundleURL, - ] - - for candidate in candidates { - let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle") - if let bundle = bundlePath.flatMap(Bundle.init(url:)) { - return bundle - } - } - return nil - }() - - private static let podsBundle: Bundle? = { - guard let bundleUrl = Bundle(for: NetworkDebugger.self).url( - forResource: "NetworkDebugger", - withExtension: "bundle" - ), - let bundle = Bundle(url: bundleUrl) - else { return nil } - debugPrint("Debug: \(bundleUrl.absoluteString)") - return bundle - }() - - static let ndBundle: Bundle = { - if let spmBundle { - return spmBundle - } - if let podsBundle { - return podsBundle - } - fatalError("Unable to find bundle for NetworkDebugger.") - }() -} diff --git a/Sources/NetworkDebugger/Resources/DataView.js b/Sources/NetworkDebugger/Resources/DataView.js deleted file mode 100644 index d132c86..0000000 --- a/Sources/NetworkDebugger/Resources/DataView.js +++ /dev/null @@ -1,37 +0,0 @@ -// -// DataView.js -// NetworkDebugger -// -// Created by Michael Artes on 28.02.23. -// Copyright © 2023 Schwarz IT KG. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -function isJson(str) { - try { JSON.parse(str) } - catch(e) { return false; } - return true; -} - -function makeJSONPretty() { - const code = document.getElementById("code"); - const codeText = code.textContent; - if (!isJson(codeText)) return; - const codeJson = JSON.parse(codeText); - const prettyJson = JSON.stringify(codeJson, null, 4); - code.textContent = prettyJson; -} - -makeJSONPretty(); -hljs.highlightAll(); diff --git a/Sources/NetworkDebugger/Resources/Highlightjs/Highlightjs.css b/Sources/NetworkDebugger/Resources/Highlightjs/Highlightjs.css deleted file mode 100644 index 76274d6..0000000 --- a/Sources/NetworkDebugger/Resources/Highlightjs/Highlightjs.css +++ /dev/null @@ -1,9 +0,0 @@ -/*! - Theme: Default - Description: Original highlight.js style - Author: (c) Ivan Sagalaev - Maintainer: @highlightjs/core-team - Website: https://highlightjs.org/ - License: see project LICENSE - Touched: 2021 - */pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#f3f3f3;color:#444}.hljs-comment{color:#697070}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#ab5656}.hljs-literal{color:#695}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#38a}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700} diff --git a/Sources/NetworkDebugger/Resources/DataView.html b/Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.html.swift similarity index 53% rename from Sources/NetworkDebugger/Resources/DataView.html rename to Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.html.swift index e98aec3..b8eba72 100644 --- a/Sources/NetworkDebugger/Resources/DataView.html +++ b/Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.html.swift @@ -1,9 +1,9 @@ - - - - - - - - -
-            {CONTENT}
-        
- - +enum DataViewHtml { + static let source = #""" + + + + + + + +
+                {CONTENT}
+            
+ + + """# +} diff --git a/Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.js.swift b/Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.js.swift new file mode 100644 index 0000000..f499fe1 --- /dev/null +++ b/Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.js.swift @@ -0,0 +1,41 @@ +// +// DataView.js.swift +// +// +// Created by Michael Artes on 26.06.23. +// Copyright © 2023 Schwarz IT KG. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +enum DataViewJs { + static let source = #""" + function isJson(str) { + try { JSON.parse(str) } + catch(e) { return false; } + return true; + } + + function makeJSONPretty() { + const code = document.getElementById("code"); + const codeText = code.textContent; + if (!isJson(codeText)) return; + const codeJson = JSON.parse(codeText); + const prettyJson = JSON.stringify(codeJson, null, 4); + code.textContent = prettyJson; + } + + makeJSONPretty(); + hljs.highlightAll(); + """# +} diff --git a/Sources/NetworkDebugger/UI/Views/Models/DataView.swift b/Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.swift similarity index 67% rename from Sources/NetworkDebugger/UI/Views/Models/DataView.swift rename to Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.swift index b64cab7..0c31afa 100644 --- a/Sources/NetworkDebugger/UI/Views/Models/DataView.swift +++ b/Sources/NetworkDebugger/UI/Views/Models/DataView/DataView.swift @@ -40,23 +40,15 @@ struct DataView: View { return prettyData } - private func getFileContents(forResource: String, ofType: String) -> String { - let fileURL = Bundle.ndBundle.path(forResource: forResource, ofType: ofType)! - let fileManager = FileManager.default - let data = fileManager.contents(atPath: fileURL)! - let fileContents = String(data: data, encoding: .utf8) - return fileContents! - } - private func getHtmlContents() -> String { - let css = getFileContents(forResource: "Highlightjs", ofType: "css") - let html = getFileContents(forResource: "DataView", ofType: "html") + let css = HighlightjsCss.source + let html = DataViewHtml.source return html.replacingOccurrences(of: "{CSS}", with: css) } private func getScriptContents() -> String { - let highlightjs = getFileContents(forResource: "Highlightjs", ofType: "js") - let dataView = getFileContents(forResource: "DataView", ofType: "js") - return highlightjs.appending("\n\(dataView)") + let highlightjs = HighlightjsJs.source + let dataViewJs = DataViewJs.source + return highlightjs.appending("\n\(dataViewJs)") } } diff --git a/Sources/NetworkDebugger/UI/Views/Models/DataView/Highlightjs/Highlightjs.css.swift b/Sources/NetworkDebugger/UI/Views/Models/DataView/Highlightjs/Highlightjs.css.swift new file mode 100644 index 0000000..c4ffe3d --- /dev/null +++ b/Sources/NetworkDebugger/UI/Views/Models/DataView/Highlightjs/Highlightjs.css.swift @@ -0,0 +1,21 @@ +// +// Hightlightjs.css.swift +// +// +// Created by Michael Artes on 26.06.23. +// See license in the LICENSE file of this directory. +// + +enum HighlightjsCss { + static let source = #""" + /*! + Theme: Default + Description: Original highlight.js style + Author: (c) Ivan Sagalaev + Maintainer: @highlightjs/core-team + Website: https://highlightjs.org/ + License: see project LICENSE + Touched: 2021 + */pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#f3f3f3;color:#444}.hljs-comment{color:#697070}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#ab5656}.hljs-literal{color:#695}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#38a}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700} + """# +} diff --git a/Sources/NetworkDebugger/Resources/Highlightjs/Highlightjs.js b/Sources/NetworkDebugger/UI/Views/Models/DataView/Highlightjs/Hightlightjs.js.swift similarity index 99% rename from Sources/NetworkDebugger/Resources/Highlightjs/Highlightjs.js rename to Sources/NetworkDebugger/UI/Views/Models/DataView/Highlightjs/Hightlightjs.js.swift index 5181a45..676fbf9 100644 --- a/Sources/NetworkDebugger/Resources/Highlightjs/Highlightjs.js +++ b/Sources/NetworkDebugger/UI/Views/Models/DataView/Highlightjs/Hightlightjs.js.swift @@ -1,9 +1,19 @@ -/*! - Highlight.js v11.5.1 (git: b8f233c8e2) - (c) 2006-2022 Ivan Sagalaev and other contributors - License: BSD-3-Clause - */ -var hljs=function(){"use strict";var e={exports:{}};function n(e){ +// +// Hightlightjs.js.swift +// +// +// Created by Michael Artes on 26.06.23. +// See license in the LICENSE file of this directory. +// + +enum HighlightjsJs { + static let source = #""" + /*! + Highlight.js v11.5.1 (git: b8f233c8e2) + (c) 2006-2022 Ivan Sagalaev and other contributors + License: BSD-3-Clause + */ + var hljs=function(){"use strict";var e={exports:{}};function n(e){ return e instanceof Map?e.clear=e.delete=e.set=()=>{ throw Error("map is read-only")}:e instanceof Set&&(e.add=e.clear=e.delete=()=>{ throw Error("set is read-only") @@ -1171,3 +1181,6 @@ var hljs=function(){"use strict";var e={exports:{}};function n(e){ const n=e.replace("grmr_","").replace("_","-");je.registerLanguage(n,Ue[e])} return je}() ;"object"==typeof exports&&"undefined"!=typeof module&&(module.exports=hljs); + + """# +} diff --git a/Sources/NetworkDebugger/Resources/Highlightjs/LICENSE b/Sources/NetworkDebugger/UI/Views/Models/DataView/Highlightjs/LICENSE similarity index 100% rename from Sources/NetworkDebugger/Resources/Highlightjs/LICENSE rename to Sources/NetworkDebugger/UI/Views/Models/DataView/Highlightjs/LICENSE