discourse_theme 0.5.0 → 0.7.0

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: 0a1f5b1cee83b53b139cb01af57e7e7ea7687cd1a97cc55ef293703d5500f17c
4
- data.tar.gz: c67b2363cba3ab789eb20f987775c90f0821105dbbf32ddf3a7e564e77d35d7f
3
+ metadata.gz: 97aee15a1f43095bc2c3ceb628dc56490f089b0e0aec4d30e724e2467d0ac7fa
4
+ data.tar.gz: 045d1945d862aa40a3f365552f9b4fccfa1e8164a263946414c6b12fb25af487
5
5
  SHA512:
6
- metadata.gz: a93ecd60d0cab2284697e183595fe5caf76c0a137e476551461ee189a81382ec9ea34480b1c3ac78058641aa4ca391d4fd567373bf81c700cc5843a90685aa6a
7
- data.tar.gz: eefffe552afaf7a461c55a04258714a2204be39b0190c4337f2ed928ffd8ed15e27fd09c9b6f5889fb1e5e4c0162810b850194819542daaa9cef7187072c731c
6
+ metadata.gz: f429459aaab31d0a3110552a50dcf9b804e9ff6e42dd2c18481882c238fe9b459744e206abcb6553b0df4c1241b0bd1b94282c0456a9c99ca994eaac8beb2a34
7
+ data.tar.gz: 45cda79f27c1415fe6f3671f42547432fc105ac911ebd9be9f90b4781459a303fe7f41f740cf05e5c22d75ddd84f7840fa28c00f208a9fc37a3e5d35932e2dad
data/README.md CHANGED
@@ -32,6 +32,10 @@ Downloads a theme from the server and stores in the designated directory.
32
32
 
33
33
  Monitors a theme or component for changes. When changed the program will synchronize the theme or component to your Discourse of choice.
34
34
 
35
+ ### `discourse_theme upload PATH`
36
+
37
+ Uploads a theme to the server. Requires the theme to have been previously synchronized via `watch`.
38
+
35
39
  ## Contributing
36
40
 
37
41
  Bug reports and pull requests are welcome at [Meta Discourse](https://meta.discourse.org). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -8,6 +8,7 @@ module DiscourseTheme
8
8
  puts
9
9
  puts "discourse_theme new DIR - Creates a new theme in the designated directory"
10
10
  puts "discourse_theme download DIR - Downloads a theme from the server and stores in the designated directory"
11
+ puts "discourse_theme upload DIR - Uploads the theme directory to Discourse"
11
12
  puts "discourse_theme watch DIR - Watches the theme directory and synchronizes with Discourse"
12
13
  puts
13
14
  puts "Use --reset to change the configuration for a directory"
@@ -29,7 +30,10 @@ module DiscourseTheme
29
30
  components = settings.components
30
31
 
31
32
  if command == "new"
32
- raise DiscourseTheme::ThemeError.new "'#{dir} is not empty" if Dir.exists?(dir) && !Dir.empty?(dir)
33
+ raise DiscourseTheme::ThemeError.new "'#{dir}' is not empty" if Dir.exists?(dir) && !Dir.empty?(dir)
34
+ raise DiscourseTheme::ThemeError.new "git is not installed" if !command?("git")
35
+ raise DiscourseTheme::ThemeError.new "yarn is not installed" if !command?("yarn")
36
+
33
37
  DiscourseTheme::Scaffold.generate(dir)
34
38
  watch_theme?(args)
35
39
  elsif command == "watch"
@@ -107,6 +111,28 @@ module DiscourseTheme
107
111
  UI.success "Theme downloaded"
108
112
 
109
113
  watch_theme?(args)
114
+ elsif command == "upload"
115
+ raise DiscourseTheme::ThemeError.new "'#{dir} does not exist" unless Dir.exists?(dir)
116
+ raise DiscourseTheme::ThemeError.new "No theme_id is set, please sync via the 'watch' command initially" if theme_id == 0
117
+ client = DiscourseTheme::Client.new(dir, settings, reset: reset)
118
+
119
+ theme_list = client.get_themes_list
120
+
121
+ theme = theme_list.find { |t| t["id"] == theme_id }
122
+ raise DiscourseTheme::ThemeError.new "theme_id is set, but the theme does not exist in Discourse" unless theme
123
+
124
+ uploader = DiscourseTheme::Uploader.new(dir: dir, client: client, theme_id: theme_id, components: components)
125
+
126
+ UI.progress "Uploading theme (id:#{theme_id}) from #{dir} "
127
+ settings.theme_id = theme_id = uploader.upload_full_theme
128
+
129
+ UI.success "Theme uploaded (id:#{theme_id})"
130
+ UI.info "Preview: #{client.root}/?preview_theme_id=#{theme_id}"
131
+ if client.is_theme_creator
132
+ UI.info "Manage: #{client.root}/my/themes"
133
+ else
134
+ UI.info "Manage: #{client.root}/admin/customize/themes/#{theme_id}"
135
+ end
110
136
  else
111
137
  usage
112
138
  end
@@ -120,6 +146,18 @@ module DiscourseTheme
120
146
 
121
147
  private
122
148
 
149
+ def command?(cmd)
150
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
151
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
152
+ exts.each do |ext|
153
+ exe = File.join(path, "#{cmd}#{ext}")
154
+ return true if File.executable?(exe) && !File.directory?(exe)
155
+ end
156
+ end
157
+
158
+ false
159
+ end
160
+
123
161
  def watch_theme?(args)
124
162
  if UI.yes?("Would you like to start 'watching' this theme?")
125
163
  args[0] = "watch"
@@ -105,7 +105,7 @@ module DiscourseTheme
105
105
  end
106
106
 
107
107
  def root
108
- @url
108
+ URI.parse(@url).path
109
109
  end
110
110
 
111
111
  def is_theme_creator
@@ -116,6 +116,12 @@ module DiscourseTheme
116
116
 
117
117
  def request(request, never_404: false)
118
118
  uri = URI.parse(@url)
119
+
120
+ if uri.userinfo
121
+ username, password = uri.userinfo.split(":", 2)
122
+ request.basic_auth username, password
123
+ end
124
+
119
125
  http = Net::HTTP.new(uri.host, uri.port)
120
126
  http.use_ssl = URI::HTTPS === uri
121
127
  add_headers(request)
@@ -60,21 +60,37 @@ module DiscourseTheme
60
60
 
61
61
  EN_YML = <<~YAML
62
62
  en:
63
- #my_locale_key: My Translation
64
63
  theme_metadata:
65
64
  description: "#DESCRIPTION"
66
- settings:
67
- # my_setting_name: My Setting Description
68
65
  YAML
69
66
 
70
67
  def self.generate(dir)
71
68
  UI.progress "Generating a scaffold theme at #{dir}"
72
69
 
73
- name = UI.ask("What would you like to call your theme?").strip
70
+ name = loop do
71
+ input = UI.ask("What would you like to call your theme?").to_s.strip
72
+ if input.empty?
73
+ UI.error("Theme name cannot be empty")
74
+ else
75
+ break input
76
+ end
77
+ end
78
+
74
79
  is_component = UI.yes?("Is this a component?")
75
80
 
76
81
  FileUtils.mkdir_p dir
77
82
  Dir.chdir dir do
83
+ author = loop do
84
+ input = UI.ask("Who is authoring the theme?", default: ENV['USER']).to_s.strip
85
+ if input.empty?
86
+ UI.error("Author cannot be empty")
87
+ else
88
+ break input
89
+ end
90
+ end
91
+
92
+ description = UI.ask("How would you describe this theme?").to_s.strip
93
+
78
94
  UI.info "Creating about.json"
79
95
  about_template = ABOUT_JSON.dup
80
96
  about_template[:name] = name
@@ -89,7 +105,6 @@ module DiscourseTheme
89
105
  File.write('HELP', HELP)
90
106
 
91
107
  UI.info "Creating package.json"
92
- author = UI.ask("Who is authoring the theme?").strip
93
108
  File.write('package.json', PACKAGE_JSON.sub("#AUTHOR", author))
94
109
 
95
110
  UI.info "Creating .template-lintrc.js"
@@ -104,10 +119,10 @@ module DiscourseTheme
104
119
  locale = "locales/en.yml"
105
120
  UI.info "Creating #{locale}"
106
121
  FileUtils.mkdir_p(File.dirname(locale))
107
- description = UI.ask("How would you describe this theme?").strip
108
122
  File.write(locale, EN_YML.sub("#DESCRIPTION", description))
109
123
 
110
- initializer = "javascripts/discourse/api-initializers/#{name}.js"
124
+ encoded_name = name.downcase.gsub(/[^\w_-]+/, '_')
125
+ initializer = "javascripts/discourse/api-initializers/#{encoded_name}.js"
111
126
  UI.info "Creating #{initializer}"
112
127
  FileUtils.mkdir_p(File.dirname(initializer))
113
128
  File.write(initializer, API_INITIALIZER)
@@ -119,7 +134,7 @@ module DiscourseTheme
119
134
  end
120
135
 
121
136
  UI.info "Initializing git repo"
122
- puts `git init .`
137
+ puts `git init . --initial-branch=main`
123
138
 
124
139
  UI.info "Installing dependencies"
125
140
  puts `yarn`
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseTheme
3
- VERSION = "0.5.0"
3
+ VERSION = "0.7.0"
4
4
  end
@@ -14,15 +14,15 @@ require 'json'
14
14
  require 'yaml'
15
15
  require 'tty/prompt'
16
16
 
17
- require 'discourse_theme/version'
18
- require 'discourse_theme/config'
19
- require 'discourse_theme/ui'
20
- require 'discourse_theme/cli'
21
- require 'discourse_theme/client'
22
- require 'discourse_theme/downloader'
23
- require 'discourse_theme/uploader'
24
- require 'discourse_theme/watcher'
25
- require 'discourse_theme/scaffold'
17
+ require_relative 'discourse_theme/version'
18
+ require_relative 'discourse_theme/config'
19
+ require_relative 'discourse_theme/ui'
20
+ require_relative 'discourse_theme/cli'
21
+ require_relative 'discourse_theme/client'
22
+ require_relative 'discourse_theme/downloader'
23
+ require_relative 'discourse_theme/uploader'
24
+ require_relative 'discourse_theme/watcher'
25
+ require_relative 'discourse_theme/scaffold'
26
26
 
27
27
  module DiscourseTheme
28
28
  class ThemeError < StandardError; end
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: 0.5.0
4
+ version: 0.7.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: 2021-05-18 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitar
@@ -225,7 +225,7 @@ homepage: https://github.com/discourse/discourse_theme
225
225
  licenses:
226
226
  - MIT
227
227
  metadata: {}
228
- post_install_message:
228
+ post_install_message:
229
229
  rdoc_options: []
230
230
  require_paths:
231
231
  - lib
@@ -240,8 +240,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  - !ruby/object:Gem::Version
241
241
  version: '0'
242
242
  requirements: []
243
- rubygems_version: 3.0.3
244
- signing_key:
243
+ rubygems_version: 3.1.6
244
+ signing_key:
245
245
  specification_version: 4
246
246
  summary: CLI helper for creating Discourse themes
247
247
  test_files: []