discourse_theme 2.0.0 → 2.1.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: 418652d7c45d966814257d956464454ae771dba99d94156a322ad38c76200580
4
- data.tar.gz: 31ae03c9cc2ad4c858a2666bf59da8a38102078c77cb631fa612de8ef405dfe4
3
+ metadata.gz: 202bc4483d1d73df24eb1674c2d2e1f8920c3f73a7ffbf6d0a69d0fd9bc0fce8
4
+ data.tar.gz: 47e22597abb662a1fff0ba8f1678ea7533d8daa84eb63879d9dcb2c8a79e8dbf
5
5
  SHA512:
6
- metadata.gz: baeefaa0afe4afd2b880a2f01235f004e4921185854d5bd35d92b032c2a69c680967a91fdd97164078cfff2ead4ad88caa55ed0ed23f547883b544c55839e876
7
- data.tar.gz: f731b2771c1e225291dab344601e3aa5724094d3370e3600fd81cfb4df2f93cdf2775892008438b6edd609b1b9e080f5becbc98438f9c729101cef781e2ee0d9
6
+ metadata.gz: 14f195165983249d04b48c8e80427176ba1d673541fb87054a9e1f24f64e8f59897d88e2b11612be93996aee9c6122d6772ce141485674167cf793a8c41bb818
7
+ data.tar.gz: 2b6c59248aaac23b12744c89eb83ee886326cbff563a8156cba494e372c9b5b3ccf5cd2ede58c193ae0acb17c72ebeeafec10f35767448bb3e91d64029107c37
@@ -7,7 +7,27 @@ on:
7
7
  - main
8
8
 
9
9
  jobs:
10
- build:
10
+ lint:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Setup ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: "3.3"
20
+ bundler-cache: true
21
+
22
+ - name: Lint
23
+ run: bundle exec rubocop
24
+
25
+ - name: syntax_tree
26
+ if: ${{ !cancelled() }}
27
+ run: |
28
+ bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake') $(git ls-files '*.thor')
29
+
30
+ test:
11
31
  runs-on: ubuntu-latest
12
32
 
13
33
  strategy:
@@ -20,25 +40,23 @@ jobs:
20
40
  steps:
21
41
  - uses: actions/checkout@v4
22
42
 
43
+ - name: Setup Git
44
+ run: |
45
+ git config --global user.email "ci@ci.invalid"
46
+ git config --global user.name "Discourse CI"
47
+
23
48
  - name: Setup ruby
24
49
  uses: ruby/setup-ruby@v1
25
50
  with:
26
51
  ruby-version: ${{ matrix.ruby }}
27
52
  bundler-cache: true
28
53
 
29
- - name: Lint
30
- run: bundle exec rubocop
31
-
32
- - name: syntax_tree
33
- run: |
34
- bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake') $(git ls-files '*.thor')
35
-
36
54
  - name: Tests
37
55
  run: bundle exec rake test
38
56
 
39
57
  publish:
40
58
  if: github.event_name == 'push' && github.ref == 'refs/heads/main'
41
- needs: build
59
+ needs: [lint, test]
42
60
  runs-on: ubuntu-latest
43
61
 
44
62
  steps:
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ 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.1.0] - 2024-02-28
9
+
10
+ ### Changed
11
+
12
+ - `new` command now uses discourse-theme-skeleton repo (#44)
13
+
8
14
  ## [2.0.0] - 2024-01-31
9
15
 
10
16
  ### Added
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_runtime_dependency "listen", "~> 3.1"
28
28
  spec.add_runtime_dependency "multipart-post", "~> 2.0"
29
29
  spec.add_runtime_dependency "tty-prompt", "~> 0.18"
30
- spec.add_runtime_dependency "rubyzip", "~> 1.2"
30
+ spec.add_runtime_dependency "rubyzip", "~> 2.3"
31
31
  spec.add_runtime_dependency "selenium-webdriver", "> 4.11"
32
32
 
33
33
  spec.add_development_dependency "bundler"
@@ -57,7 +57,7 @@ module DiscourseTheme
57
57
  raise DiscourseTheme::ThemeError.new "git is not installed" if !command?("git")
58
58
  raise DiscourseTheme::ThemeError.new "yarn is not installed" if !command?("yarn")
59
59
 
60
- DiscourseTheme::Scaffold.generate(dir)
60
+ DiscourseTheme::Scaffold.generate(dir, name: args[1])
61
61
  watch_theme?(args)
62
62
  elsif command == "watch"
63
63
  raise DiscourseTheme::ThemeError.new "'#{dir} does not exist" unless Dir.exist?(dir)
@@ -2,159 +2,111 @@
2
2
 
3
3
  require "date"
4
4
  require "json"
5
+ require "yaml"
6
+ require "resolv"
5
7
 
6
8
  module DiscourseTheme
7
9
  class Scaffold
8
- ABOUT_JSON = {
9
- about_url: "TODO: Put your theme's public repo or Meta topic URL here",
10
- license_url: "TODO: Put your theme's LICENSE URL here",
11
- assets: {
12
- },
13
- }
14
-
15
- HELP = <<~STR
16
- Are you a bit lost? Be sure to read https://meta.discourse.org/t/how-to-develop-custom-themes/60848
17
- STR
18
-
19
- LICENSE = <<~STR
20
- Copyright #YEAR #AUTHOR
21
-
22
- Permission is hereby granted, free of charge, to any person obtaining a copy
23
- of this software and associated documentation files (the "Software"), to deal
24
- in the Software without restriction, including without limitation the rights
25
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
- copies of the Software, and to permit persons to whom the Software is
27
- furnished to do so, subject to the following conditions:
28
-
29
- The above copyright notice and this permission notice shall be included in all
30
- copies or substantial portions of the Software.
31
-
32
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
- SOFTWARE.
39
- STR
40
-
41
- GIT_IGNORE = <<~STR
42
- .discourse-site
43
- node_modules
44
- HELP
45
- STR
46
-
47
- API_INITIALIZER = <<~STR
48
- import { apiInitializer } from "discourse/lib/api";
49
-
50
- export default apiInitializer("1.8.0", (api) => {
51
- console.log("hello world from api initializer!");
52
- });
53
- STR
54
-
55
- PACKAGE_JSON = <<~STR
56
- {
57
- "author": "#AUTHOR",
58
- "license": "MIT",
59
- "devDependencies": {
60
- "eslint-config-discourse": "latest"
61
- }
62
- }
63
- STR
64
-
65
- ESLINT_RC = <<~STR
66
- {
67
- "extends": "eslint-config-discourse",
68
- "globals": {
69
- "settings": "readonly",
70
- "themePrefix": "readonly"
71
- }
72
- }
73
- STR
74
-
75
- TEMPLATE_LINT_RC = <<~STR
76
- module.exports = {
77
- plugins: ["ember-template-lint-plugin-discourse"],
78
- extends: "discourse:recommended",
79
- };
80
- STR
81
-
82
- EN_YML = <<~YAML
83
- en:
84
- theme_metadata:
85
- description: "#DESCRIPTION"
86
- YAML
87
-
88
- SETTINGS_YML = <<~YAML
89
- todo_rename_and_use_setting:
90
- default: ""
91
- YAML
92
-
93
- def self.generate(dir)
10
+ def self.generate(dir, name:)
94
11
  UI.progress "Generating a scaffold theme at #{dir}"
95
12
 
96
- name =
97
- loop do
98
- input = UI.ask("What would you like to call your theme?").to_s.strip
99
- if input.empty?
100
- UI.error("Theme name cannot be empty")
101
- else
102
- break input
103
- end
104
- end
105
-
13
+ name = UI.ask("What would you like to call your theme?", default: name).to_s.strip
106
14
  is_component = UI.yes?("Is this a component?")
107
15
 
108
- FileUtils.mkdir_p dir
109
- Dir.chdir dir do
110
- author =
111
- loop do
112
- input = UI.ask("Who is authoring the theme?", default: ENV["USER"]).to_s.strip
113
- if input.empty?
114
- UI.error("Author cannot be empty")
115
- else
116
- break input
117
- end
118
- end
16
+ get_theme_skeleton(dir)
119
17
 
18
+ Dir.chdir dir do
19
+ author = UI.ask("Who is authoring the theme?", default: "Discourse").to_s.strip
120
20
  description = UI.ask("How would you describe this theme?").to_s.strip
121
21
 
122
- about_template = ABOUT_JSON.dup
123
- about_template[:name] = name
124
- if is_component
125
- about_template[:component] = true
126
- else
127
- about_template[:color_schemes] = {}
22
+ about = JSON.parse(File.read("about.json"))
23
+ about["name"] = name
24
+ about["authors"] = author
25
+ if !is_component
26
+ about.delete("component")
27
+ about["color_schemes"] = {}
128
28
  end
29
+ File.write("about.json", JSON.pretty_generate(about))
30
+
31
+ if author != "Discourse"
32
+ license = File.read("LICENSE")
33
+ license.sub!(/^(Copyright\s\(c\))\s(.+)/, "\\1 #{author}")
34
+ File.write("LICENSE", license)
35
+ end
36
+
37
+ readme = File.read("README.md")
38
+ readme.sub!("**Theme Name**", name)
39
+ File.write("README.md", readme)
129
40
 
130
- encoded_name = name.downcase.gsub(/[^a-zA-Z0-9_-]+/, "_")
41
+ encoded_name = name.downcase.gsub(/[^a-zA-Z0-9_-]+/, "-")
42
+ FileUtils.mv(
43
+ "javascripts/discourse/api-initializers/todo.js",
44
+ "javascripts/discourse/api-initializers/#{encoded_name}.js",
45
+ )
131
46
 
132
- write("about.json", JSON.pretty_generate(about_template))
133
- write("HELP", HELP)
134
- write("LICENSE", LICENSE.sub("#YEAR", "#{Date.today.year}").sub("#AUTHOR", author))
135
- write(".eslintrc", ESLINT_RC)
136
- write(".gitignore", GIT_IGNORE)
137
- write(".template-lintrc.js", TEMPLATE_LINT_RC)
138
- write("package.json", PACKAGE_JSON.sub("#AUTHOR", author))
139
- write("settings.yml", SETTINGS_YML)
140
- write("common/common.scss", "")
141
- write("javascripts/discourse/api-initializers/#{encoded_name}.js", API_INITIALIZER)
142
- write("locales/en.yml", EN_YML.sub("#DESCRIPTION", description))
47
+ i18n = YAML.safe_load(File.read("locales/en.yml"))
48
+ i18n["en"]["theme_metadata"]["description"] = description
49
+ File.write("locales/en.yml", YAML.safe_dump(i18n).sub(/\A---\n/, ""))
143
50
 
144
51
  UI.info "Initializing git repo"
145
- puts `git init && git symbolic-ref HEAD refs/heads/main`
52
+ FileUtils.rm_rf(".git")
53
+ FileUtils.rm_rf("**/.gitkeep")
54
+ system "git", "init", exception: true
55
+ system "git", "symbolic-ref", "HEAD", "refs/heads/main", exception: true
56
+ root_files = Dir.glob("*").select { |f| File.file?(f) }
57
+ system "git", "add", *root_files, exception: true
58
+ system "git", "add", ".*", exception: true
59
+ system "git", "add", "locales", exception: true
60
+ system "git",
61
+ "commit",
62
+ "-m",
63
+ "Initial commit by `discourse_theme` CLI",
64
+ "--quiet",
65
+ exception: true
146
66
 
147
67
  UI.info "Installing dependencies"
148
- puts `yarn`
68
+ system "yarn", exception: true
149
69
  end
70
+
71
+ puts "✅ Done!"
72
+ puts "See https://meta.discourse.org/t/how-to-develop-custom-themes/60848 for more information!"
150
73
  end
151
74
 
152
75
  private
153
76
 
154
- def self.write(filename, contents)
155
- UI.info "Creating #{filename}"
156
- FileUtils.mkdir_p(File.dirname(filename))
157
- File.write(filename, contents)
77
+ def self.get_theme_skeleton(dir)
78
+ if online?
79
+ puts "Downloading discourse-theme-skeleton"
80
+ tmp = Dir.mktmpdir
81
+ system "git",
82
+ "clone",
83
+ "https://github.com/discourse/discourse-theme-skeleton",
84
+ tmp,
85
+ "--depth",
86
+ "1",
87
+ "--quiet",
88
+ exception: true
89
+ FileUtils.rm_rf(skeleton_dir)
90
+ # Store the local copy for offline use
91
+ FileUtils.cp_r(tmp, skeleton_dir)
92
+
93
+ FileUtils.cp_r(skeleton_dir, dir)
94
+ elsif Dir.exist?(skeleton_dir)
95
+ puts "⚠️ No internet connection detected, using the local copy of discourse-theme-skeleton"
96
+ FileUtils.cp_r(skeleton_dir, dir)
97
+ else
98
+ raise "🛑 Couldn't download discourse-theme-skeleton"
99
+ end
100
+ end
101
+
102
+ def self.online?
103
+ !!Resolv::DNS.new.getaddress("github.com")
104
+ rescue Resolv::ResolvError => e
105
+ false
106
+ end
107
+
108
+ def self.skeleton_dir
109
+ File.expand_path("~/.discourse_theme_skeleton")
158
110
  end
159
111
  end
160
112
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseTheme
3
- VERSION = "2.0.0"
3
+ VERSION = "2.1.0"
4
4
  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: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-31 00:00:00.000000000 Z
11
+ date: 2024-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitar
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.2'
75
+ version: '2.3'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.2'
82
+ version: '2.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: selenium-webdriver
85
85
  requirement: !ruby/object:Gem::Requirement