file_sv 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/file_sv +7 -0
- data/lib/file_sv/har_generator.rb +78 -0
- data/lib/file_sv/planned_endpoint.rb +3 -0
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv.rb +7 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c69a4a4dec09d95aa3ec0ef6aa3871c2f3d53b22a0ec265b8b270a2a940a8177
|
4
|
+
data.tar.gz: 0bad44a25fe5e26efc4145290d939b2298912c9b185def00b92a8fc57db2acb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fefabfaf7af9116e9ecdf160151dd081112aa591f28e5b231719732c079d4f6fbc4973afc964b4a8295611d19a3d798c085a5d50d173fbe188477fbf6dee8dc
|
7
|
+
data.tar.gz: 177338aca5865d57008934cea16600890048effa3ce33ace8fd36437df0855250d89d977702c683c57d4dfb6a5904fed3769b6a6eaf131a1b3340ce333a4435d
|
data/exe/file_sv
CHANGED
@@ -33,6 +33,13 @@ class Exe < Thor
|
|
33
33
|
ServiceLoader.inspect folder
|
34
34
|
end
|
35
35
|
|
36
|
+
desc "generate har_file_location mock_service_base", "Generate mock folder/file structure from recording"
|
37
|
+
def generate(har_file_location, mock_service_base, output_folder)
|
38
|
+
require "file_sv/har_generator"
|
39
|
+
generator = HarGenerator.new(har_file_location, mock_service_base, output_folder)
|
40
|
+
generator.generate
|
41
|
+
end
|
42
|
+
|
36
43
|
desc "version", "Version of FileSv"
|
37
44
|
def version
|
38
45
|
require "file_sv/version"
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative '../file_sv'
|
2
|
+
require 'json'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class HarGenerator
|
6
|
+
|
7
|
+
attr_accessor :har_file_location
|
8
|
+
|
9
|
+
attr_accessor :mock_service_base
|
10
|
+
|
11
|
+
attr_accessor :output_folder
|
12
|
+
# @return [String] Har file content
|
13
|
+
attr_accessor :content
|
14
|
+
|
15
|
+
attr_accessor :entries
|
16
|
+
|
17
|
+
def initialize(har_file_location, mock_service_base, output_folder)
|
18
|
+
self.har_file_location = har_file_location
|
19
|
+
self.mock_service_base = mock_service_base
|
20
|
+
self.output_folder = output_folder
|
21
|
+
self.content = File.read(har_file_location)
|
22
|
+
parse_har
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_har
|
26
|
+
parsed = JSON.parse(self.content)
|
27
|
+
pages = parsed['log']['pages']
|
28
|
+
self.entries = parsed['log']['entries']
|
29
|
+
puts "Found #{self.entries.count} entries in #{self.har_file_location}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate
|
33
|
+
self.entries.each do |entry|
|
34
|
+
request = entry['request']
|
35
|
+
response = entry['response']
|
36
|
+
|
37
|
+
request_url = request['url']
|
38
|
+
if (!request_url.include?(self.mock_service_base))
|
39
|
+
next;
|
40
|
+
end
|
41
|
+
|
42
|
+
path = request_url[self.mock_service_base.length..-1]
|
43
|
+
path_folder = path.split('.')[0]
|
44
|
+
|
45
|
+
method = request['method']
|
46
|
+
status_code = response['status']
|
47
|
+
content = response['content']
|
48
|
+
mime_type = content['mimeType']
|
49
|
+
extension = mime_type.split('/').last
|
50
|
+
|
51
|
+
extension = 'js' if (extension == 'javascript')
|
52
|
+
|
53
|
+
location = "#{self.output_folder}/#{path_folder}/#{method}_#{status_code}.#{extension}"
|
54
|
+
create_file_at "./#{location}", extension, content['text']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Create folder if there's not a file already there.
|
59
|
+
# Will create parent folder if necessary.
|
60
|
+
# @param [String] folder Folder to create
|
61
|
+
def create_folder(folder)
|
62
|
+
if File.exist? folder
|
63
|
+
warn "!! #{folder} already exists and is not a directory" unless File.directory? folder
|
64
|
+
else
|
65
|
+
FileUtils.mkdir_p folder
|
66
|
+
puts "Created folder: #{folder}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_file_at(file_path, extension, content)
|
71
|
+
file_path = file_path.gsub('//', '/')
|
72
|
+
folder_name = File.split(file_path).first
|
73
|
+
folder_name += ".#{extension}" if (extension == '.css' || extension == '.js')
|
74
|
+
create_folder folder_name
|
75
|
+
puts "Creating response at #{file_path}"
|
76
|
+
File.open("#{folder_name}/#{File.split(file_path).last}", 'w') { |f| f.puts content }
|
77
|
+
end
|
78
|
+
end
|
data/lib/file_sv/version.rb
CHANGED
data/lib/file_sv.rb
CHANGED
@@ -30,12 +30,18 @@ CONFIG_FILE = "file_sv.yaml"
|
|
30
30
|
|
31
31
|
# Set values in global settings based on config
|
32
32
|
def load_default_config(file_path)
|
33
|
-
|
33
|
+
unless File.exist? file_path
|
34
|
+
puts "No config found at #{file_path}" if ENV['debug'] == "true"
|
35
|
+
return
|
36
|
+
end
|
37
|
+
puts "Loading config from #{file_path}" if ENV['debug'] == "true"
|
34
38
|
|
35
39
|
config = YAML.load_file file_path
|
36
40
|
return unless config # Handle empty YAML file
|
37
41
|
|
42
|
+
puts "Config #{config}" if ENV['debug'] == "true"
|
38
43
|
config["global"]&.each do |key, value|
|
44
|
+
puts "Setting #{key} to #{value}" if ENV['debug'] == "true"
|
39
45
|
GlobalSettings.send("#{key}=", value)
|
40
46
|
end
|
41
47
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_sv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/file_sv/file_processor.rb
|
110
110
|
- lib/file_sv/file_sv.ico
|
111
111
|
- lib/file_sv/global_settings.rb
|
112
|
+
- lib/file_sv/har_generator.rb
|
112
113
|
- lib/file_sv/planned_endpoint.rb
|
113
114
|
- lib/file_sv/render_file.rb
|
114
115
|
- lib/file_sv/service_loader.rb
|