-
-
Notifications
You must be signed in to change notification settings - Fork 733
Expand file tree
/
Copy pathfetch-external-content.rb
More file actions
268 lines (229 loc) · 9.77 KB
/
Copy pathfetch-external-content.rb
File metadata and controls
268 lines (229 loc) · 9.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# frozen_string_literal: true
require "fileutils"
require "csv"
require_relative "lib/repo_manager"
require_relative "lib/jfrog_fetcher"
require_relative "lib/addon_processor"
require_relative "lib/thing_types_processor"
require_relative "lib/process_utils"
require_relative "lib/iconset_processor"
BASE_DIR = File.expand_path("..", File.dirname(__FILE__))
RESOURCE_FOLDER = File.join(BASE_DIR, ".external-resources")
def copy_file_safe(src, dst, source_url = nil)
if File.exist?(src)
FileUtils.mkdir_p(File.dirname(dst))
if File.extname(src).downcase == ".md" && source_url
process_markdown(File.dirname(src), File.basename(src), File.dirname(dst), source_url, File.basename(dst))
puts " ✔ Processed #{File.basename(src)} -> #{dst}"
else
FileUtils.cp(src, dst)
puts " ✔ Copied #{File.basename(src)} -> #{dst}"
end
else
warn " ⚠️ Source file does not exist: #{src}"
end
end
def copy_dir_safe(src, dst)
if Dir.exist?(src)
FileUtils.mkdir_p(dst)
FileUtils.cp_r(File.join(src, "."), dst)
puts " ✔ Copied directory #{src} -> #{dst}"
else
warn " ⚠️ Source directory does not exist: #{src}"
end
end
def copy_glob_safe(pattern, dst_dir, exclude_fn = nil, source_url_fn = nil)
Dir.glob(pattern).each do |file|
next if File.directory?(file)
next if exclude_fn && exclude_fn.call(file)
relative_path = File.basename(file)
target_file = File.join(dst_dir, relative_path)
FileUtils.mkdir_p(File.dirname(target_file))
if File.extname(file).downcase == ".md" && source_url_fn
source_url = source_url_fn.call(relative_path)
process_markdown(File.dirname(file), File.basename(file), File.dirname(target_file), source_url, File.basename(target_file))
puts " ✔ Processed #{File.basename(file)} -> #{target_file}"
else
FileUtils.cp(file, target_file)
puts " ✔ Copied #{File.basename(file)} -> #{target_file}"
end
end
puts " ✔ Copied glob #{pattern} -> #{dst_dir}"
end
def update_external_repositories
FileUtils.mkdir_p(RESOURCE_FOLDER)
readme_path = File.join(RESOURCE_FOLDER, "README.md")
unless File.exist?(readme_path)
File.write(readme_path, "# About\n\nUsed to temporarily store repository clones from related openHAB projects for 'fetch-external-docs.rb'.\n")
end
repos = [
["openhab-distro", "openhab/openhab-distro.git", "main"],
["openhab-addons", "openhab/openhab-addons.git", "main"],
["openhabian", "openhab/openhabian.git", "main"],
["openhab-alexa", "openhab/openhab-alexa.git", "main"],
["openhab-android", "openhab/openhab-android.git", "main"],
["openhab-google-assistant", "openhab/openhab-google-assistant.git", "main"],
["openhab-webui", "openhab/openhab-webui.git", "main"],
["openhab-addons/bundles/org.openhab.binding.zigbee", "openhab/org.openhab.binding.zigbee.git", "main"],
["openhab-addons/bundles/org.openhab.binding.zwave", "openhab/org.openhab.binding.zwave.git", "main"],
["openhab-garmin", "openhab/openhab-garmin.git", "main"],
["openhab-sailfishos", "openhab/openhab-sailfishos.git", "main"]
]
repos.each do |name, repo_path, branch|
RepoManager.pull_or_clone_repo(File.join(RESOURCE_FOLDER, name), repo_path, branch)
end
# Copy zigbee readme to where the addon processor expects it
zigbee_readme = File.join(RESOURCE_FOLDER, "openhab-addons/bundles/org.openhab.binding.zigbee/org.openhab.binding.zigbee/README.md")
zigbee_target = File.join(RESOURCE_FOLDER, "openhab-addons/bundles/org.openhab.binding.zigbee/README.md")
if File.exist?(zigbee_readme)
FileUtils.cp(zigbee_readme, zigbee_target)
puts " ✔ Copied Zigbee README to expected location."
end
end
def fetch_openhab_js_types
pom_path = File.join(RESOURCE_FOLDER, "openhab-addons/bundles/org.openhab.automation.jsscripting/pom.xml")
unless File.exist?(pom_path)
warn " ⚠️ JS Scripting POM not found at #{pom_path}"
return
end
pom_content = File.read(pom_path)
version_match = pom_content.match(/<ohjs.version>(.*?)<\/ohjs.version>/)
unless version_match
warn " ⚠️ Could not find <ohjs.version> in JS Scripting POM"
return
end
ohjs_version = version_match[1].strip
puts " Found openhab-js version in POM: #{ohjs_version}"
dest_path = File.join(BASE_DIR, "addons/automation/jsscripting/res/openhab.d.ts")
download_github_release_asset("openhab/openhab-js", ohjs_version, "openhab.d.ts", dest_path)
end
def main
puts "Starting fetch external content pipeline..."
# 1. Update/clone external git repos
update_external_repositories
# 2. Fetch feature.xml from JFrog snapshot repository
JfrogFetcher.fetch_features_xml(File.join(RESOURCE_FOLDER, "jfrog-files/feature.xml"))
# 3. Generate thing-types JSON
ThingTypesProcessor.collect_thing_types(RESOURCE_FOLDER, File.join(BASE_DIR, ".vuepress/thing-types.json"))
# 4. Process add-on markdown files
AddonProcessor.process_all(
File.join(RESOURCE_FOLDER, "openhab-distro/features/addons/src/main/feature/feature.xml"),
File.join(RESOURCE_FOLDER, "jfrog-files/feature.xml"),
File.join(RESOURCE_FOLDER, "openhab-addons/bundles"),
File.join(RESOURCE_FOLDER, "openhab-webui/bundles"),
File.join(BASE_DIR, "addons"),
File.join(BASE_DIR, "images")
)
# Preprocess all generated addon readme files
puts " Processing add-on readme files..."
Dir.glob(File.join(BASE_DIR, "addons/**/*.md")).each do |file|
next if File.basename(file) != "readme.md"
dir = File.dirname(file)
temp_readme = File.join(dir, "readme_raw.md")
FileUtils.mv(file, temp_readme)
process_markdown(dir, "readme_raw.md", dir, nil, "readme.md")
File.delete(temp_readme)
end
puts " ✔ Processed add-on readme files"
# 4b. Fetch openhab.d.ts definitions based on JS Scripting POM version
fetch_openhab_js_types
# 5. Inline Ecosystem and Apps copying/renaming
puts " Copying ecosystem & apps documentation..."
# HABPanel Config Docs
copy_file_safe(
File.join(RESOURCE_FOLDER, "openhab-webui/bundles/org.openhab.ui.habpanel/doc/habpanel.md"),
File.join(BASE_DIR, "docs/ui/habpanel/habpanel.md"),
"https://github.com/openhab/openhab-webui/blob/main/bundles/org.openhab.ui.habpanel/doc/habpanel.md"
)
copy_dir_safe(
File.join(RESOURCE_FOLDER, "openhab-webui/bundles/org.openhab.ui.habpanel/doc/images"),
File.join(BASE_DIR, "docs/ui/habpanel/images")
)
# openHABian Install Docs (excluding NEWSLOG.md)
copy_glob_safe(
File.join(RESOURCE_FOLDER, "openhabian/docs/*.md"),
File.join(BASE_DIR, "docs/installation"),
lambda { |f| File.basename(f) == "NEWSLOG.md" },
lambda { |fn| "https://github.com/openhab/openhabian/blob/main/docs/#{fn}" }
)
copy_dir_safe(
File.join(RESOURCE_FOLDER, "openhabian/docs/images"),
File.join(BASE_DIR, "docs/installation/images")
)
# Android Docs
copy_file_safe(
File.join(RESOURCE_FOLDER, "openhab-android/docs/USAGE.md"),
File.join(BASE_DIR, "docs/apps/android.md"),
"https://github.com/openhab/openhab-android/blob/main/docs/USAGE.md"
)
copy_dir_safe(
File.join(RESOURCE_FOLDER, "openhab-android/docs/images"),
File.join(BASE_DIR, "docs/apps/images")
)
# Garmin Docs
copy_file_safe(
File.join(RESOURCE_FOLDER, "openhab-garmin/docs/USAGE.md"),
File.join(BASE_DIR, "docs/apps/garmin/readme.md"),
"https://github.com/openhab/openhab-garmin/blob/main/docs/USAGE.md"
)
copy_dir_safe(
File.join(RESOURCE_FOLDER, "openhab-garmin/docs/images"),
File.join(BASE_DIR, "docs/apps/garmin/images")
)
# SailfishOS Docs
copy_file_safe(
File.join(RESOURCE_FOLDER, "openhab-sailfishos/docs/USAGE.md"),
File.join(BASE_DIR, "docs/apps/sailfishos/readme.md"),
"https://github.com/openhab/openhab-sailfishos/blob/main/docs/USAGE.md"
)
copy_dir_safe(
File.join(RESOURCE_FOLDER, "openhab-sailfishos/docs/images"),
File.join(BASE_DIR, "docs/apps/sailfishos/images")
)
# Alexa Docs
copy_file_safe(
File.join(RESOURCE_FOLDER, "openhab-alexa/docs/USAGE.md"),
File.join(BASE_DIR, "docs/ecosystem/alexa/readme.md"),
"https://github.com/openhab/openhab-alexa/blob/main/docs/USAGE.md"
)
copy_dir_safe(
File.join(RESOURCE_FOLDER, "openhab-alexa/docs/images"),
File.join(BASE_DIR, "docs/ecosystem/alexa/images")
)
# Google Assistant Docs
copy_file_safe(
File.join(RESOURCE_FOLDER, "openhab-google-assistant/docs/USAGE.md"),
File.join(BASE_DIR, "docs/ecosystem/google-assistant/readme.md"),
"https://github.com/openhab/openhab-google-assistant/blob/main/docs/USAGE.md"
)
copy_dir_safe(
File.join(RESOURCE_FOLDER, "openhab-google-assistant/docs/images"),
File.join(BASE_DIR, "docs/ecosystem/google-assistant/images")
)
puts " ✔ Copied ecosystem & apps documentation"
# UI Components Reference Docs
puts " Copying UI components reference documentation..."
ui_components_src = File.join(RESOURCE_FOLDER, "openhab-webui/bundles/org.openhab.ui/doc/components")
ui_components_dst = File.join(BASE_DIR, "docs/ui/components")
if Dir.exist?(ui_components_src)
process_directory(
src: ui_components_src,
dst: ui_components_dst,
source_root: "https://github.com/openhab/openhab-webui/blob/main/bundles/org.openhab.ui/doc/components",
) { |path| !path.to_s.split(File::SEPARATOR).include?("src") }
puts " ✔ Copied UI components reference documentation"
else
warn " ⚠️ UI components source directory does not exist: #{ui_components_src}"
end
# Classic Iconset
IconsetProcessor.process_iconset(
src: File.join(RESOURCE_FOLDER, "openhab-webui/bundles"),
dst: File.join(BASE_DIR, "docs/configuration/iconsets"),
data: File.join(BASE_DIR, "classic_iconset_data")
)
puts " ✔ Copied ecosystem & apps documentation"
puts "✔ External content pipeline completed successfully!"
end
if __FILE__ == $0
main
end