tailwind_dsl 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 932f3c5eab101600bca4bda271cff007b4bee1145fc248c3f2fa06d7ad2152f9
4
- data.tar.gz: fb033d87faeb2e2b56888de2f02bd75ac4214a01bb1d4ff955ab163a8feb8cc5
3
+ metadata.gz: b8465b256d515f8ecb6c81cb2e0c499a5ca3b0a3ab3e5d2ba614c55ef12049ec
4
+ data.tar.gz: a9f9bbbad156fefd8f7d04e43ab7cc4ac2b4634912ac7ef34cbd27a64236e4f1
5
5
  SHA512:
6
- metadata.gz: 6246a2e48781d1a59407231d46340429cf46ea42fa854e16378acb89f7fc1f69b4ae69113417752006eafcd5655d762a890df058ea64132f3bddf3f4f887dd0a
7
- data.tar.gz: bc9da3edcaf0e1e297f0fe89b62b5434d5252b3c80e1dc4790bb69b5d0a853fdcd832da19f24edddbfdff9818db8ea7352c5fbc71d9d7666588dcde6db48db61
6
+ metadata.gz: bba87ff679f1dde5650731005021e5c7061a6146eb47c4e0370325f330cbefb264604a6d320c3b34d9b8d2030a5011796d6d3e46330b1528189f94dc591a873d
7
+ data.tar.gz: b5379fe421463db2fea7672bf570e7fedf100c39e6259e98ad3d67099fe0873fe831d3700dad4dfdb68f16a0099f432ff5c25e8aeff033cc691f3ffa554d8eea
@@ -216,6 +216,7 @@ KManager.action :domain_model do
216
216
  .field(:tailwind_config_file , type: :string)
217
217
  .field(:settings_file , type: :string)
218
218
  .field(:data_file , type: :string)
219
+ .field(:model_file , type: :string)
219
220
  .field(:astro_file , type: :string)
220
221
  end
221
222
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## [0.0.18](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.17...v0.0.18) (2022-10-20)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * minor refactor on long extensions ([70615ad](https://github.com/klueless-io/tailwind_dsl/commit/70615adc3bb37267e930ac36b92472f8b054f2d7))
7
+ * resetting root path will remove transient files and empty directories, but not custom files ([07ef5ae](https://github.com/klueless-io/tailwind_dsl/commit/07ef5ae71fda4a92b9a9312f3f4de2bca7151505))
8
+ * resetting root path will remove transient files and empty directories, but not custom files ([e546bed](https://github.com/klueless-io/tailwind_dsl/commit/e546bed751f4e996802340a6573b68663224d555))
9
+
10
+ ## [0.0.17](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.16...v0.0.17) (2022-10-19)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * refactor component record shape ([8d9bd9a](https://github.com/klueless-io/tailwind_dsl/commit/8d9bd9ab7ab8a47db30f1916f289dba24040c988))
16
+
1
17
  ## [0.0.16](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.15...v0.0.16) (2022-10-19)
2
18
 
3
19
 
@@ -3,6 +3,16 @@
3
3
  module TailwindDsl
4
4
  module Etl
5
5
  module ComponentModels
6
+ class Gpt3Extractor
7
+ def extract_data(component)
8
+ puts "extract data for #{component} using GPT3"
9
+ end
10
+
11
+ def extract_model(component)
12
+ puts "extract model for #{component} using GPT3"
13
+ end
14
+ end
15
+
6
16
  # Extract component models by reading the cleansed component HTML and then using GPT3 to infer both the data/model structure.
7
17
  class Extractor
8
18
  attr_reader :components
@@ -11,7 +21,7 @@ module TailwindDsl
11
21
  attr_reader :batch_left
12
22
  attr_reader :use_prompt
13
23
  attr_reader :filter_design_system
14
- attr_reader :dry_run
24
+ attr_reader :extract_handler
15
25
 
16
26
  def initialize(components, target_root_path, **args)
17
27
  @components = components
@@ -20,7 +30,7 @@ module TailwindDsl
20
30
  @batch_left = batch_size
21
31
  @use_prompt = args[:use_prompt] || false
22
32
  @filter_design_system = args[:filter_design_system] || nil
23
- @dry_run = args[:dry_run] || false
33
+ @extract_handler = (args[:extract_handler] || Gpt3Extractor).new
24
34
  end
25
35
 
26
36
  # Goal: Extract the next (batch_size) component models using GPT3 and save them to target_root_path
@@ -28,14 +38,21 @@ module TailwindDsl
28
38
  # Create a model file at: design_system.name -> group-hierarchy -> component-name.model.rb
29
39
 
30
40
  # Process: Collect all components and optionally filter them by design system name.
41
+ # Also filter by other keys (to be determined)
42
+ # Only process files that have not been processed before.
31
43
  # Look for the next component to be processed, if it does not exist in the target folder then process it.
32
44
  # decrement the batch_left counter and continue until batch_left is 0.
33
45
  # if :use_prompt is true then display the input/output files and ask if you wish to process the component or skip.
34
46
  # process the component by calling the GPT3 API and save the results to the target folder.
35
47
 
48
+ # rubocop:disable Metrics/AbcSize
36
49
  def extract
50
+ guards
51
+
37
52
  filter_components.each do |component|
38
53
  puts "Processing: #{component.design_system.name} -> #{component.group.key} -> #{component.name} -> remaining#: #{batch_left}"
54
+
55
+ component.debug
39
56
  # component_model_path = File.join(target_root_path, component.design_system.name, component.group_hierarchy, "#{component.name}.model.rb")
40
57
  # next if File.exist?(component_model_path)
41
58
 
@@ -47,15 +64,29 @@ module TailwindDsl
47
64
  # end
48
65
 
49
66
  # puts "Processing: #{component_model_path}"
50
- @batch_left -= 1
51
- break if batch_left.zero?
52
67
 
53
- next if dry_run
68
+ # next if extract_handler
54
69
 
55
70
  # model = Gpt3::ComponentModel.new(component.cleansed_html_path)
56
71
  # model.save(component_model_path)
72
+
73
+ extract_handler.extract_data(component)
74
+ extract_handler.extract_model(component)
75
+
76
+ @batch_left -= 1
77
+ break if batch_left.zero?
57
78
  end
58
79
  end
80
+ # rubocop:enable Metrics/AbcSize
81
+
82
+ private
83
+
84
+ def guards
85
+ raise "Batch size must be greater than 0, got: #{batch_size}" if batch_size <= 0
86
+ raise 'Extract handler is required' unless extract_handler
87
+ raise 'Extract handler must implement extract_data method' unless extract_handler.respond_to?(:extract_data)
88
+ raise 'Extract handler must implement extract_model method' unless extract_handler.respond_to?(:extract_model)
89
+ end
59
90
 
60
91
  def filter_components
61
92
  return components unless filter_design_system
@@ -18,7 +18,8 @@ module TailwindDsl
18
18
  BLANK_LINE_REGEX = /(\n\s*\n)+/.freeze
19
19
  TAILWIND_CONFIG_REGEX = /```(?<tailwind>\n[\s\S]+?)```/.freeze
20
20
 
21
- # .gsub(/(\n\s*\n)+/, "\n")
21
+ TRANSIENT_FILE_EXTENSIONS = %w[.clean.html .html .settings.json .tailwind.config.js].freeze
22
+
22
23
  attr_reader :uikit
23
24
  attr_reader :components
24
25
  # Location for raw components
@@ -37,7 +38,7 @@ module TailwindDsl
37
38
  def generate
38
39
  assert_target_root_path_exists
39
40
 
40
- delete_target_root_path if reset_root_path
41
+ clear_root_path if reset_root_path
41
42
 
42
43
  @components = query_components
43
44
 
@@ -50,10 +51,6 @@ module TailwindDsl
50
51
  raise 'Target path does not exist' unless Dir.exist?(target_root_path)
51
52
  end
52
53
 
53
- def delete_target_root_path
54
- FileUtils.rm_rf(Dir.glob("#{target_root_path}/*"))
55
- end
56
-
57
54
  def query_components
58
55
  RawComponentQuery.query(uikit,
59
56
  source_root_path: source_root_path,
@@ -201,6 +198,24 @@ module TailwindDsl
201
198
  }
202
199
  }
203
200
  end
201
+
202
+ def clear_root_path
203
+ Dir.glob("#{target_root_path}/**/*")
204
+ .select { |path| transient_file?(path) }
205
+ .each { |path| File.delete(path) }
206
+
207
+ Dir.glob("#{target_root_path}/**/")
208
+ .reverse_each { |d| Dir.rmdir d if Dir.entries(d).size == 2 }
209
+ end
210
+
211
+ def transient_file?(path)
212
+ return false if File.directory?(path)
213
+
214
+ ext = File.basename(path).split('.', 2)[1]
215
+ ext = ext.nil? ? '' : ".#{ext}"
216
+
217
+ TRANSIENT_FILE_EXTENSIONS.include?(ext)
218
+ end
204
219
  end
205
220
  end
206
221
  end
@@ -7,22 +7,29 @@ module TailwindDsl
7
7
  #
8
8
  # This is a two pass process:
9
9
  # 1. Query the raw component folder for all files that match the pattern and build up a graph with required information
10
+
11
+ # puts '%-20s %s' % ['name', name]
12
+ # puts '%-20s %s' % ['source_path', source_path]
13
+ # puts '%-20s %s' % ['target_path', target_path]
10
14
  # 2. Flatten the graph into a list of rows
11
15
  class RawComponentQuery
12
- DesignSystem = Struct.new(
13
- :name,
14
- :source_path,
15
- :target_path,
16
- keyword_init: true
17
- )
16
+ DesignSystem = Struct.new(:name, :source_path, :target_path, keyword_init: true) do
17
+ def debug
18
+ puts format('%-30<key>s : %<value>s', key: 'Design system', value: name)
19
+ puts format('%-30<key>s : %<value>s', key: 'Source path', value: source_path)
20
+ puts format('%-30<key>s : %<value>s', key: 'Target path', value: target_path)
21
+ end
22
+ end
23
+
24
+ Group = Struct.new(:key, :type, :sub_keys, :folder, keyword_init: true) do
25
+ def debug
26
+ puts format('%-30<key>s : %<value>s', key: 'Group key', value: key)
27
+ puts format('%-30<key>s : %<value>s', key: 'Group type', value: type)
28
+ puts format('%-30<key>s : %<value>s', key: 'Group sub keys', value: sub_keys)
29
+ puts format('%-30<key>s : %<value>s', key: 'Group folder', value: folder)
30
+ end
31
+ end
18
32
 
19
- Group = Struct.new(
20
- :key,
21
- :type,
22
- :sub_keys,
23
- :folder,
24
- keyword_init: true
25
- )
26
33
  FilePath = Struct.new(
27
34
  :source_file,
28
35
  :target_html_file,
@@ -30,8 +37,23 @@ module TailwindDsl
30
37
  :target_tailwind_config_file,
31
38
  :target_settings_file,
32
39
  :target_data_file,
33
- :target_astro_file, keyword_init: true
34
- )
40
+ :target_model_file,
41
+ :target_astro_file,
42
+ keyword_init: true
43
+ ) do
44
+ # rubocop:disable Metrics/AbcSize
45
+ def debug
46
+ puts format('%-30<key>s : %<value>s', key: 'Source file', value: source_file)
47
+ puts format('%-30<key>s : %<value>s', key: 'Target html file', value: target_html_file)
48
+ puts format('%-30<key>s : %<value>s', key: 'Target clean html file', value: target_clean_html_file)
49
+ puts format('%-30<key>s : %<value>s', key: 'Target tailwind config file', value: target_tailwind_config_file)
50
+ puts format('%-30<key>s : %<value>s', key: 'Target settings file', value: target_settings_file)
51
+ puts format('%-30<key>s : %<value>s', key: 'Target data file', value: target_data_file)
52
+ puts format('%-30<key>s : %<value>s', key: 'Target model file', value: target_model_file)
53
+ puts format('%-30<key>s : %<value>s', key: 'Target astro file', value: target_astro_file)
54
+ end
55
+ # rubocop:enable Metrics/AbcSize
56
+ end
35
57
 
36
58
  class Component
37
59
  attr_reader :name
@@ -62,6 +84,16 @@ module TailwindDsl
62
84
  relative: relative.to_h
63
85
  }
64
86
  end
87
+
88
+ def debug
89
+ puts format('%-30<key>s : %<value>s', key: 'Component', value: name)
90
+ design_system.debug
91
+ group.debug
92
+ puts ':: Absolute paths'
93
+ absolute.debug
94
+ puts '::Relative paths'
95
+ relative.debug
96
+ end
65
97
  end
66
98
 
67
99
  attr_reader :uikit
@@ -155,6 +187,7 @@ module TailwindDsl
155
187
  target_tailwind_config_file: file.target.tailwind_config_file,
156
188
  target_settings_file: file.target.settings_file,
157
189
  target_data_file: file.target.data_file,
190
+ target_model_file: file.target.model_file,
158
191
  target_astro_file: file.target.astro_file
159
192
  }
160
193
  end
@@ -168,6 +201,7 @@ module TailwindDsl
168
201
  target_tailwind_config_file: File.join(target_path, file.target.tailwind_config_file),
169
202
  target_settings_file: File.join(target_path, file.target.settings_file),
170
203
  target_data_file: File.join(target_path, file.target.data_file),
204
+ target_model_file: File.join(target_path, file.target.model_file),
171
205
  target_astro_file: File.join(target_path, file.target.astro_file)
172
206
  }
173
207
  end
@@ -12,6 +12,7 @@ module TailwindDsl
12
12
  attr_accessor :tailwind_config_file
13
13
  attr_accessor :settings_file
14
14
  attr_accessor :data_file
15
+ attr_accessor :model_file
15
16
  attr_accessor :astro_file
16
17
 
17
18
  def initialize(**args)
@@ -20,6 +21,7 @@ module TailwindDsl
20
21
  @tailwind_config_file = grab_arg(args, :tailwind_config_file, guard: 'Missing tailwind_config_file')
21
22
  @settings_file = grab_arg(args, :settings_file, guard: 'Missing settings_file')
22
23
  @data_file = grab_arg(args, :data_file, guard: 'Missing data_file')
24
+ @model_file = grab_arg(args, :model_file) # , guard: 'Missing model_file')
23
25
  @astro_file = grab_arg(args, :astro_file, guard: 'Missing astro_file')
24
26
  end
25
27
 
@@ -30,6 +32,7 @@ module TailwindDsl
30
32
  tailwind_config_file: tailwind_config_file,
31
33
  settings_file: settings_file,
32
34
  data_file: data_file,
35
+ model_file: model_file,
33
36
  astro_file: astro_file
34
37
  }
35
38
  end
@@ -108,6 +108,7 @@ module TailwindDsl
108
108
  tailwind_config_file: "#{key}.tailwind.config.js",
109
109
  settings_file: "#{key}.settings.json",
110
110
  data_file: "#{key}.data.json",
111
+ model_file: "#{key}.model.rb",
111
112
  astro_file: "#{key}.astro"
112
113
  )
113
114
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TailwindDsl
4
- VERSION = '0.0.17'
4
+ VERSION = '0.0.19'
5
5
  end
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "tailwind_dsl",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "tailwind_dsl",
9
- "version": "0.0.17",
9
+ "version": "0.0.19",
10
10
  "devDependencies": {
11
11
  "@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
12
12
  "@semantic-release/changelog": "^6.0.1",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind_dsl",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "Tailwind DSL will build tailwind websites useing Domain Specific Language conventions",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailwind_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-19 00:00:00.000000000 Z
11
+ date: 2022-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdlet