discourse_theme 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -5
- data/.streerc +1 -1
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/bin/discourse_theme +1 -1
- data/discourse_theme.gemspec +1 -3
- data/lib/discourse_theme/cli.rb +21 -20
- data/lib/discourse_theme/cli_commands/rspec.rb +1 -1
- data/lib/discourse_theme/client.rb +10 -8
- data/lib/discourse_theme/uploader.rb +9 -32
- data/lib/discourse_theme/version.rb +1 -1
- data/lib/discourse_theme/watcher.rb +3 -25
- metadata +10 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 418652d7c45d966814257d956464454ae771dba99d94156a322ad38c76200580
|
4
|
+
data.tar.gz: 31ae03c9cc2ad4c858a2666bf59da8a38102078c77cb631fa612de8ef405dfe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baeefaa0afe4afd2b880a2f01235f004e4921185854d5bd35d92b032c2a69c680967a91fdd97164078cfff2ead4ad88caa55ed0ed23f547883b544c55839e876
|
7
|
+
data.tar.gz: f731b2771c1e225291dab344601e3aa5724094d3370e3600fd81cfb4df2f93cdf2775892008438b6edd609b1b9e080f5becbc98438f9c729101cef781e2ee0d9
|
data/.github/workflows/ci.yml
CHANGED
@@ -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@
|
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@
|
45
|
+
- uses: actions/checkout@v4
|
47
46
|
|
48
47
|
- name: Release Gem
|
49
|
-
uses: discourse/publish-rubygems-action@
|
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,
|
2
|
+
--plugins=plugin/trailing_comma,plugin/disable_auto_ternary
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,17 @@ 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
|
+
|
8
19
|
## [1.1.0] - 2024-01-10
|
9
20
|
|
10
21
|
### Added
|
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/
|
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
data/discourse_theme.gemspec
CHANGED
@@ -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
|
data/lib/discourse_theme/cli.rb
CHANGED
@@ -36,7 +36,7 @@ module DiscourseTheme
|
|
36
36
|
exit 1
|
37
37
|
end
|
38
38
|
|
39
|
-
def run(args
|
39
|
+
def run(args)
|
40
40
|
usage unless args[1]
|
41
41
|
|
42
42
|
reset = !!args.delete("--reset")
|
@@ -116,7 +116,7 @@ module DiscourseTheme
|
|
116
116
|
UI.progress "Uploading theme from #{dir}"
|
117
117
|
|
118
118
|
settings.theme_id =
|
119
|
-
theme_id = uploader.upload_full_theme(
|
119
|
+
theme_id = uploader.upload_full_theme(skip_migrations: skip_migrations(theme, dir))
|
120
120
|
|
121
121
|
UI.success "Theme uploaded (id:#{theme_id})"
|
122
122
|
UI.info "Preview: #{client.url}/?preview_theme_id=#{theme_id}"
|
@@ -131,7 +131,7 @@ module DiscourseTheme
|
|
131
131
|
|
132
132
|
watcher = DiscourseTheme::Watcher.new(dir: dir, uploader: uploader)
|
133
133
|
UI.progress "Watching for changes in #{dir}..."
|
134
|
-
watcher.watch
|
134
|
+
watcher.watch
|
135
135
|
elsif command == "download"
|
136
136
|
client = DiscourseTheme::Client.new(dir, settings, reset: reset)
|
137
137
|
downloader = DiscourseTheme::Downloader.new(dir: dir, client: client)
|
@@ -205,40 +205,41 @@ module DiscourseTheme
|
|
205
205
|
|
206
206
|
private
|
207
207
|
|
208
|
-
def
|
209
|
-
return
|
208
|
+
def skip_migrations(theme, dir)
|
209
|
+
return true unless theme && Dir.exist?(File.join(dir, "migrations"))
|
210
210
|
|
211
|
-
|
211
|
+
migrated_migrations =
|
212
212
|
theme
|
213
213
|
.dig("theme_fields")
|
214
214
|
&.filter_map do |theme_field|
|
215
|
-
theme_field["
|
215
|
+
if theme_field["target"] == "migrations" && theme_field["migrated"] == true
|
216
|
+
theme_field["name"]
|
217
|
+
end
|
216
218
|
end || []
|
217
219
|
|
218
|
-
|
220
|
+
pending_migrations =
|
219
221
|
Dir["#{dir}/migrations/**/*.js"]
|
220
222
|
.reject do |f|
|
221
|
-
|
223
|
+
migrated_migrations.any? do |existing_migration|
|
222
224
|
File.basename(f).include?(existing_migration)
|
223
225
|
end
|
224
226
|
end
|
225
227
|
.map { |f| Pathname.new(f).relative_path_from(Pathname.new(dir)).to_s }
|
226
228
|
|
227
|
-
if
|
228
|
-
|
229
|
+
return true if pending_migrations.empty?
|
230
|
+
|
231
|
+
options = { "No" => :no, "Yes" => :yes }
|
229
232
|
|
230
|
-
|
231
|
-
Would you like to
|
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).
|
232
236
|
TEXT
|
233
237
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
else
|
238
|
-
[]
|
239
|
-
end
|
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
|
240
241
|
else
|
241
|
-
|
242
|
+
false
|
242
243
|
end
|
243
244
|
end
|
244
245
|
|
@@ -73,7 +73,7 @@ module DiscourseTheme
|
|
73
73
|
success = exit_status.success?
|
74
74
|
|
75
75
|
unless success
|
76
|
-
UI.error "Error
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
|
@@ -1,20 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module DiscourseTheme
|
3
3
|
class Uploader
|
4
|
-
def self.upload_full_theme_callbacks
|
5
|
-
@upload_callbacks ||= []
|
6
|
-
end
|
7
|
-
|
8
|
-
# Used in the test environment to register a callback that is called with the directory of the theme being uploaded.
|
9
|
-
def self.register_upload_full_theme_callback(&block)
|
10
|
-
self.upload_full_theme_callbacks << block
|
11
|
-
end
|
12
|
-
|
13
|
-
# Used in the test environment to clear the registered callbacks.
|
14
|
-
def self.reset_upload_full_theme_callbacks
|
15
|
-
self.upload_full_theme_callbacks.clear
|
16
|
-
end
|
17
|
-
|
18
4
|
def initialize(dir:, client:, theme_id: nil, components: nil)
|
19
5
|
@dir = dir
|
20
6
|
@client = client
|
@@ -67,27 +53,19 @@ module DiscourseTheme
|
|
67
53
|
UI.error "(end of errors)" if diagnose_errors(json) != 0
|
68
54
|
end
|
69
55
|
|
70
|
-
def upload_full_theme(
|
56
|
+
def upload_full_theme(skip_migrations: false)
|
71
57
|
filename = "#{Pathname.new(Dir.tmpdir).realpath}/bundle_#{SecureRandom.hex}.tar.gz"
|
72
|
-
temp_dir = nil
|
73
|
-
|
74
|
-
theme_dir =
|
75
|
-
if !ignore_files.empty?
|
76
|
-
temp_dir = Dir.mktmpdir
|
77
|
-
FileUtils.copy_entry(@dir, temp_dir)
|
78
|
-
dir_pathname = Pathname.new(@dir)
|
79
|
-
ignore_files.each { |file| FileUtils.rm_f(File.join(temp_dir, file)) }
|
80
|
-
temp_dir
|
81
|
-
else
|
82
|
-
@dir
|
83
|
-
end
|
84
|
-
|
85
|
-
self.class.upload_full_theme_callbacks.each { |cb| cb.call(theme_dir) }
|
86
58
|
|
87
|
-
compress_dir(filename,
|
59
|
+
compress_dir(filename, @dir)
|
88
60
|
|
89
61
|
File.open(filename) do |tgz|
|
90
|
-
response =
|
62
|
+
response =
|
63
|
+
@client.upload_full_theme(
|
64
|
+
tgz,
|
65
|
+
theme_id: @theme_id,
|
66
|
+
components: @components,
|
67
|
+
skip_migrations: skip_migrations,
|
68
|
+
)
|
91
69
|
|
92
70
|
json = JSON.parse(response.body)
|
93
71
|
@theme_id = json["theme"]["id"]
|
@@ -95,7 +73,6 @@ module DiscourseTheme
|
|
95
73
|
@theme_id
|
96
74
|
end
|
97
75
|
ensure
|
98
|
-
FileUtils.rm_rf(temp_dir) if temp_dir
|
99
76
|
FileUtils.rm_f(filename)
|
100
77
|
end
|
101
78
|
end
|
@@ -1,33 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module DiscourseTheme
|
3
3
|
class Watcher
|
4
|
-
LISTEN_IGNORE_PATTERNS = [%r{migrations/.+/.+\.js}]
|
5
|
-
|
6
4
|
def self.return_immediately!
|
7
5
|
@return_immediately = true
|
8
6
|
end
|
9
7
|
|
10
|
-
def self.return_immediately=(val)
|
11
|
-
@return_immediately = val
|
12
|
-
end
|
13
|
-
|
14
8
|
def self.return_immediately?
|
15
9
|
!!@return_immediately
|
16
10
|
end
|
17
11
|
|
18
|
-
def self.subscribe_start(&block)
|
19
|
-
@subscribers ||= []
|
20
|
-
@subscribers << block
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.call_start_subscribers
|
24
|
-
@subscribers&.each(&:call)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.reset_start_subscribers
|
28
|
-
@subscribers = []
|
29
|
-
end
|
30
|
-
|
31
12
|
def initialize(dir:, uploader:)
|
32
13
|
@dir = dir
|
33
14
|
@uploader = uploader
|
@@ -35,9 +16,7 @@ module DiscourseTheme
|
|
35
16
|
|
36
17
|
def watch
|
37
18
|
listener =
|
38
|
-
Listen.to(@dir
|
39
|
-
yield(modified, added, removed) if block_given?
|
40
|
-
|
19
|
+
Listen.to(@dir) do |modified, added, removed|
|
41
20
|
begin
|
42
21
|
if modified.length == 1 && added.length == 0 && removed.length == 0 &&
|
43
22
|
(resolved = resolve_file(modified[0]))
|
@@ -60,7 +39,7 @@ module DiscourseTheme
|
|
60
39
|
UI.progress "Detected changes in #{filename.gsub(@dir, "")}, uploading theme"
|
61
40
|
end
|
62
41
|
|
63
|
-
@uploader.upload_full_theme
|
42
|
+
@uploader.upload_full_theme(skip_migrations: true)
|
64
43
|
end
|
65
44
|
UI.success "Done! Watching for changes..."
|
66
45
|
rescue DiscourseTheme::ThemeError => e
|
@@ -70,8 +49,7 @@ module DiscourseTheme
|
|
70
49
|
end
|
71
50
|
|
72
51
|
listener.start
|
73
|
-
self.class.
|
74
|
-
sleep 1 while !self.class.return_immediately?
|
52
|
+
sleep if !self.class.return_immediately?
|
75
53
|
end
|
76
54
|
|
77
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:
|
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: 2024-01-
|
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:
|
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:
|
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.
|
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: []
|