discourse_theme 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f330872d917c9b14b0e2ab7827f7fa16c41f5dce83ad4ec960888dc91e13a368
4
- data.tar.gz: e19bf6dfde320a3a616890abe72ff9a72021c25a5168dccada18824007540fcb
3
+ metadata.gz: 418652d7c45d966814257d956464454ae771dba99d94156a322ad38c76200580
4
+ data.tar.gz: 31ae03c9cc2ad4c858a2666bf59da8a38102078c77cb631fa612de8ef405dfe4
5
5
  SHA512:
6
- metadata.gz: fee66903932cf9fb014e7e5c637daf2995756f8a122219cb4e5616d87229eff1fba8ed20aa59bcd07b5d58773c5f3ee07fc1801d44f07506d28c767b2c2adb92
7
- data.tar.gz: bf7b0fd4078e802e0039daa8499fc369a7befbb15349208361dae8678093d4402c7f938779c91c760a2141ab4f64fcf93693708a21564f4f3fda08fca0a25f1b
6
+ metadata.gz: baeefaa0afe4afd2b880a2f01235f004e4921185854d5bd35d92b032c2a69c680967a91fdd97164078cfff2ead4ad88caa55ed0ed23f547883b544c55839e876
7
+ data.tar.gz: f731b2771c1e225291dab344601e3aa5724094d3370e3600fd81cfb4df2f93cdf2775892008438b6edd609b1b9e080f5becbc98438f9c729101cef781e2ee0d9
@@ -13,12 +13,12 @@ jobs:
13
13
  strategy:
14
14
  matrix:
15
15
  ruby:
16
- - "3.0"
17
16
  - "3.1"
18
17
  - "3.2"
18
+ - "3.3"
19
19
 
20
20
  steps:
21
- - uses: actions/checkout@v3
21
+ - uses: actions/checkout@v4
22
22
 
23
23
  - name: Setup ruby
24
24
  uses: ruby/setup-ruby@v1
@@ -33,7 +33,6 @@ jobs:
33
33
  run: |
34
34
  bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake') $(git ls-files '*.thor')
35
35
 
36
-
37
36
  - name: Tests
38
37
  run: bundle exec rake test
39
38
 
@@ -43,10 +42,10 @@ jobs:
43
42
  runs-on: ubuntu-latest
44
43
 
45
44
  steps:
46
- - uses: actions/checkout@v3
45
+ - uses: actions/checkout@v4
47
46
 
48
47
  - name: Release Gem
49
- uses: discourse/publish-rubygems-action@v2
48
+ uses: discourse/publish-rubygems-action@v3
50
49
  env:
51
50
  RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
52
51
  GIT_EMAIL: team@discourse.org
data/.streerc CHANGED
@@ -1,2 +1,2 @@
1
1
  --print-width=100
2
- --plugins=plugin/trailing_comma,disable_ternary
2
+ --plugins=plugin/trailing_comma,plugin/disable_auto_ternary
data/CHANGELOG.md CHANGED
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.0.0] - 2024-01-31
9
+
10
+ ### Added
11
+
12
+ - `watch` command for `discourse_theme` will prompt user if pending theme migrations should be run (#40)
13
+
14
+ ### Removed
15
+
16
+ - Remove upload theme migrations prompt to `watch` command for `discourse_theme` CLI previously added in #38. Theme migrations
17
+ files are always uploaded going forward.
18
+
19
+ ## [1.1.0] - 2024-01-10
20
+
21
+ ### Added
22
+
23
+ - Add upload theme migrations prompt to `watch` command for `discourse_theme` CLI (#38)
24
+
8
25
  ## [1.0.2] - 2023-12-08
9
26
 
10
27
  ### Fixed
data/README.md CHANGED
@@ -45,7 +45,7 @@ On the first run for the given directory, you will be asked if you'll like to us
45
45
  If you select 'Y' and proceeds to configure the path to the local Discourse repository, the tests will be ran using the local Discourse development environment provided by the local Discourse repository. Note that you'll have to set up the local test environment before
46
46
  the tests can be ran successfully.
47
47
 
48
- If the 'n' option is selected, the tests will run in a Docker container created using the [`discourse/discours_test:release`](https://hub.docker.com/r/discourse/discourse_test) Docker image. Note that this requires [Docker](https://docs.docker.com/engine/install/) to be installed.
48
+ If the 'n' option is selected, the tests will run in a Docker container created using the [`discourse/discourse_test:release`](https://hub.docker.com/r/discourse/discourse_test) Docker image. Note that this requires [Docker](https://docs.docker.com/engine/install/) to be installed.
49
49
 
50
50
  When the `--headless` option is used, a local installation of the [Google Chrome browser](https://www.google.com/chrome/) is required.
51
51
 
data/bin/discourse_theme CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../lib/discourse_theme'
4
+ require_relative "../lib/discourse_theme"
5
5
 
6
6
  DiscourseTheme::Cli.new.run(ARGV)
@@ -36,10 +36,8 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "guard"
37
37
  spec.add_development_dependency "guard-minitest"
38
38
  spec.add_development_dependency "webmock"
39
- spec.add_development_dependency "rubocop"
40
- spec.add_development_dependency "rubocop-discourse"
39
+ spec.add_development_dependency "rubocop-discourse", "~> 3.6.0"
41
40
  spec.add_development_dependency "m"
42
41
  spec.add_development_dependency "syntax_tree"
43
- spec.add_development_dependency "syntax_tree-disable_ternary"
44
42
  spec.add_development_dependency "mocha"
45
43
  end
@@ -66,9 +66,11 @@ module DiscourseTheme
66
66
  theme_list = client.get_themes_list
67
67
 
68
68
  options = {}
69
+
69
70
  if theme_id && theme = theme_list.find { |t| t["id"] == theme_id }
70
71
  options["Sync with existing theme: '#{theme["name"]}' (id:#{theme_id})"] = :default
71
72
  end
73
+
72
74
  options["Create and sync with a new theme"] = :create
73
75
  options["Select a different theme"] = :select
74
76
 
@@ -89,6 +91,7 @@ module DiscourseTheme
89
91
  rescue StandardError
90
92
  nil
91
93
  end
94
+
92
95
  already_uploaded = !!theme
93
96
  is_component = theme&.[]("component")
94
97
  component_count = about_json&.[]("components")&.length || 0
@@ -111,7 +114,9 @@ module DiscourseTheme
111
114
  )
112
115
 
113
116
  UI.progress "Uploading theme from #{dir}"
114
- settings.theme_id = theme_id = uploader.upload_full_theme
117
+
118
+ settings.theme_id =
119
+ theme_id = uploader.upload_full_theme(skip_migrations: skip_migrations(theme, dir))
115
120
 
116
121
  UI.success "Theme uploaded (id:#{theme_id})"
117
122
  UI.info "Preview: #{client.url}/?preview_theme_id=#{theme_id}"
@@ -200,6 +205,44 @@ module DiscourseTheme
200
205
 
201
206
  private
202
207
 
208
+ def skip_migrations(theme, dir)
209
+ return true unless theme && Dir.exist?(File.join(dir, "migrations"))
210
+
211
+ migrated_migrations =
212
+ theme
213
+ .dig("theme_fields")
214
+ &.filter_map do |theme_field|
215
+ if theme_field["target"] == "migrations" && theme_field["migrated"] == true
216
+ theme_field["name"]
217
+ end
218
+ end || []
219
+
220
+ pending_migrations =
221
+ Dir["#{dir}/migrations/**/*.js"]
222
+ .reject do |f|
223
+ migrated_migrations.any? do |existing_migration|
224
+ File.basename(f).include?(existing_migration)
225
+ end
226
+ end
227
+ .map { |f| Pathname.new(f).relative_path_from(Pathname.new(dir)).to_s }
228
+
229
+ return true if pending_migrations.empty?
230
+
231
+ options = { "No" => :no, "Yes" => :yes }
232
+
233
+ choice = UI.select(<<~TEXT, options.keys)
234
+ Would you like to run the following pending theme migration(s): #{pending_migrations.join(", ")}
235
+ Select 'No' if you are in the midst of adding or modifying theme migration(s).
236
+ TEXT
237
+
238
+ if options[choice] == :no
239
+ UI.warn "Pending theme migrations have not been run, run `discourse_theme upload #{dir}` if you wish to run the theme migrations."
240
+ true
241
+ else
242
+ false
243
+ end
244
+ end
245
+
203
246
  def command?(cmd)
204
247
  exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
205
248
  ENV["PATH"]
@@ -73,7 +73,7 @@ module DiscourseTheme
73
73
  success = exit_status.success?
74
74
 
75
75
  unless success
76
- UI.error "Error occured while running: `#{command}`:\n\n#{output}" unless stream
76
+ UI.error "Error occurred while running: `#{command}`:\n\n#{output}" unless stream
77
77
  exit 1 if exit_on_error
78
78
  end
79
79
  end
@@ -84,7 +84,7 @@ module DiscourseTheme
84
84
  request(put)
85
85
  end
86
86
 
87
- def upload_full_theme(tgz, theme_id:, components:)
87
+ def upload_full_theme(tgz, theme_id:, components:, skip_migrations: false)
88
88
  endpoint =
89
89
  root +
90
90
  (
@@ -95,13 +95,15 @@ module DiscourseTheme
95
95
  end
96
96
  )
97
97
 
98
- post =
99
- Net::HTTP::Post::Multipart.new(
100
- endpoint,
101
- "theme_id" => theme_id,
102
- "components" => components,
103
- "bundle" => UploadIO.new(tgz, "application/tar+gzip", "bundle.tar.gz"),
104
- )
98
+ params = {
99
+ "theme_id" => theme_id,
100
+ "components" => components,
101
+ "bundle" => UploadIO.new(tgz, "application/tar+gzip", "bundle.tar.gz"),
102
+ }
103
+
104
+ params["skip_migrations"] = true if skip_migrations
105
+
106
+ post = Net::HTTP::Post::Multipart.new(endpoint, params)
105
107
  request(post)
106
108
  end
107
109
 
@@ -28,6 +28,10 @@ module DiscourseTheme
28
28
  puts @@pastel.red("✘ #{message}")
29
29
  end
30
30
 
31
+ def self.warn(message)
32
+ puts @@pastel.yellow("⚠ #{message}")
33
+ end
34
+
31
35
  def self.success(message)
32
36
  puts @@pastel.green("✔ #{message}")
33
37
  end
@@ -53,12 +53,19 @@ module DiscourseTheme
53
53
  UI.error "(end of errors)" if diagnose_errors(json) != 0
54
54
  end
55
55
 
56
- def upload_full_theme
56
+ def upload_full_theme(skip_migrations: false)
57
57
  filename = "#{Pathname.new(Dir.tmpdir).realpath}/bundle_#{SecureRandom.hex}.tar.gz"
58
+
58
59
  compress_dir(filename, @dir)
59
60
 
60
61
  File.open(filename) do |tgz|
61
- response = @client.upload_full_theme(tgz, theme_id: @theme_id, components: @components)
62
+ response =
63
+ @client.upload_full_theme(
64
+ tgz,
65
+ theme_id: @theme_id,
66
+ components: @components,
67
+ skip_migrations: skip_migrations,
68
+ )
62
69
 
63
70
  json = JSON.parse(response.body)
64
71
  @theme_id = json["theme"]["id"]
@@ -66,7 +73,7 @@ module DiscourseTheme
66
73
  @theme_id
67
74
  end
68
75
  ensure
69
- FileUtils.rm_f filename
76
+ FileUtils.rm_f(filename)
70
77
  end
71
78
  end
72
79
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseTheme
3
- VERSION = "1.0.2"
3
+ VERSION = "2.0.0"
4
4
  end
@@ -31,13 +31,15 @@ module DiscourseTheme
31
31
  )
32
32
  else
33
33
  count = modified.length + added.length + removed.length
34
+
34
35
  if count > 1
35
36
  UI.progress "Detected changes in #{count} files, uploading theme"
36
37
  else
37
38
  filename = modified[0] || added[0] || removed[0]
38
39
  UI.progress "Detected changes in #{filename.gsub(@dir, "")}, uploading theme"
39
40
  end
40
- @uploader.upload_full_theme
41
+
42
+ @uploader.upload_full_theme(skip_migrations: true)
41
43
  end
42
44
  UI.success "Done! Watching for changes..."
43
45
  rescue DiscourseTheme::ThemeError => e
@@ -47,7 +49,7 @@ module DiscourseTheme
47
49
  end
48
50
 
49
51
  listener.start
50
- sleep unless self.class.return_immediately?
52
+ sleep if !self.class.return_immediately?
51
53
  end
52
54
 
53
55
  protected
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discourse_theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-08 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitar
@@ -178,34 +178,20 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: rubocop
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
181
  - !ruby/object:Gem::Dependency
196
182
  name: rubocop-discourse
197
183
  requirement: !ruby/object:Gem::Requirement
198
184
  requirements:
199
- - - ">="
185
+ - - "~>"
200
186
  - !ruby/object:Gem::Version
201
- version: '0'
187
+ version: 3.6.0
202
188
  type: :development
203
189
  prerelease: false
204
190
  version_requirements: !ruby/object:Gem::Requirement
205
191
  requirements:
206
- - - ">="
192
+ - - "~>"
207
193
  - !ruby/object:Gem::Version
208
- version: '0'
194
+ version: 3.6.0
209
195
  - !ruby/object:Gem::Dependency
210
196
  name: m
211
197
  requirement: !ruby/object:Gem::Requirement
@@ -234,20 +220,6 @@ dependencies:
234
220
  - - ">="
235
221
  - !ruby/object:Gem::Version
236
222
  version: '0'
237
- - !ruby/object:Gem::Dependency
238
- name: syntax_tree-disable_ternary
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - ">="
242
- - !ruby/object:Gem::Version
243
- version: '0'
244
- type: :development
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - ">="
249
- - !ruby/object:Gem::Version
250
- version: '0'
251
223
  - !ruby/object:Gem::Dependency
252
224
  name: mocha
253
225
  requirement: !ruby/object:Gem::Requirement
@@ -298,7 +270,7 @@ homepage: https://github.com/discourse/discourse_theme
298
270
  licenses:
299
271
  - MIT
300
272
  metadata: {}
301
- post_install_message:
273
+ post_install_message:
302
274
  rdoc_options: []
303
275
  require_paths:
304
276
  - lib
@@ -313,8 +285,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
313
285
  - !ruby/object:Gem::Version
314
286
  version: '0'
315
287
  requirements: []
316
- rubygems_version: 3.1.6
317
- signing_key:
288
+ rubygems_version: 3.5.3
289
+ signing_key:
318
290
  specification_version: 4
319
291
  summary: CLI helper for creating Discourse themes
320
292
  test_files: []