mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-24 11:34:26 +08:00
To simplify our repository architecture, we're moving the admin panel from a separate package(/ember-addon) to a directory inside the main app package. This will make future configuration of tools like typescript/glint, and Vite, much easier. It also means that the admin panel is now transpiled via Webpack, and can internally make use of async-imports and bundle-splitting. Admin modules will now be referenced like `discourse/admin/...`. Backwards-compatibility is maintained for the old import paths via a custom babel transform. A 'compatModules' technique is used to keep all of the admin invokables and routes/controllers/templates available to Ember's resolver.
71 lines
2.4 KiB
Ruby
Executable file
Vendored
71 lines
2.4 KiB
Ruby
Executable file
Vendored
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
require "pathname"
|
|
require "json"
|
|
|
|
Dir.chdir("#{__dir__}/..") # rubocop:disable Discourse/NoChdir because this is not part of the app
|
|
|
|
CORE_NAMESPACES = {
|
|
"discourse/admin/*" => ["app/assets/javascripts/discourse/admin"],
|
|
"discourse/*" => ["app/assets/javascripts/discourse/app"],
|
|
"discourse/tests/*" => ["app/assets/javascripts/discourse/tests"],
|
|
"admin/*" => ["app/assets/javascripts/discourse/admin"], # TODO: remove once all core code is migrated to new import path
|
|
"pretty-text/*" => ["app/assets/javascripts/pretty-text/addon"],
|
|
"select-kit/*" => ["app/assets/javascripts/select-kit/addon"],
|
|
"float-kit/*" => ["app/assets/javascripts/float-kit/addon"],
|
|
"truth-helpers/*" => ["app/assets/javascripts/truth-helpers/addon"],
|
|
"dialog-holder/*" => ["app/assets/javascripts/dialog-holder/addon"],
|
|
}
|
|
|
|
def relative(from, to)
|
|
relative_path = Pathname.new(to).relative_path_from(from).to_s
|
|
relative_path = "./#{relative_path}" if !relative_path.start_with?(".")
|
|
relative_path
|
|
end
|
|
|
|
def write_config(package_dir, extras: {})
|
|
package_dir = Pathname.new(package_dir)
|
|
namespaces = { **CORE_NAMESPACES, **extras }
|
|
config = {
|
|
"compilerOptions" => {
|
|
"target" => "es2021",
|
|
"module" => "esnext",
|
|
"moduleResolution" => "bundler",
|
|
"experimentalDecorators" => true,
|
|
"allowJs" => true,
|
|
"paths" => {
|
|
**namespaces
|
|
.map { |ns, paths| [ns, paths.map { |p| "#{relative(package_dir, p)}/*" }] }
|
|
.to_h,
|
|
},
|
|
},
|
|
"include" => namespaces.flat_map { |ns, paths| paths.map { |p| relative(package_dir, p) } },
|
|
"exclude" => [
|
|
"app/assets/javascripts/discourse/tests/unit/utils/decorators-test.js", # Native class decorators - unsupported by ts/glint
|
|
],
|
|
}
|
|
|
|
output = <<~JSON
|
|
// This file was generated by script/build_jsconfig.rb
|
|
#{JSON.pretty_generate(config)}
|
|
JSON
|
|
|
|
File.write("#{package_dir}/jsconfig.json", output)
|
|
end
|
|
|
|
plugin_configs =
|
|
`git ls-files plugins/*/plugin.rb`.lines
|
|
.map { File.dirname(_1) }
|
|
.map do |path|
|
|
["discourse/#{path}/*", ["#{path}/assets/javascripts", "#{path}/test/javascripts"]]
|
|
end
|
|
.to_h
|
|
|
|
theme_configs =
|
|
`git ls-files themes/*/about.json`.lines
|
|
.map { File.dirname(_1) }
|
|
.map { |path| ["discourse/#{path}/*", ["#{path}/javascripts", "#{path}/test"]] }
|
|
.to_h
|
|
|
|
write_config ".", extras: plugin_configs.merge(theme_configs)
|