improvement: eliminate need for spark mix config

This commit is contained in:
Zach Daniel 2024-01-12 12:17:33 -05:00
parent 844f1ced17
commit 87546cc7ca
13 changed files with 396 additions and 92 deletions

View file

@ -21,8 +21,6 @@ defmodule AshHq.Docs.Dsl do
doc_attribute :doc
load_for_search [
:extension_name,
:extension_target,
:extension_module,
:library_name
]
@ -137,9 +135,7 @@ defmodule AshHq.Docs.Dsl do
calculations do
calculate :extension_type, :string, expr(extension.type)
calculate :extension_order, :integer, expr(extension.order)
calculate :extension_name, :string, expr(extension.name)
calculate :extension_module, :string, expr(extension.module)
calculate :extension_target, :string, expr(extension.target)
calculate :version_name, :string, expr(library_version.version)
calculate :library_name, :string, expr(library_version.library.name)
calculate :library_id, :string, expr(library_version.library.id)

View file

@ -2,8 +2,7 @@ defmodule AshHq.Docs.Extension do
@moduledoc false
use Ash.Resource,
data_layer: AshSqlite.DataLayer,
extensions: [AshHq.Docs.Extensions.Search, AshHq.Docs.Extensions.RenderMarkdown]
data_layer: AshSqlite.DataLayer
sqlite do
table "extensions"
@ -14,15 +13,6 @@ defmodule AshHq.Docs.Extension do
end
end
search do
doc_attribute :doc
load_for_search library_version: [:library_display_name, :library_name]
end
render_markdown do
render_attributes doc: :doc_html
end
actions do
defaults [:update, :destroy]
@ -52,35 +42,6 @@ defmodule AshHq.Docs.Extension do
attributes do
uuid_primary_key :id
attribute :name, :string do
allow_nil? false
end
attribute :target, :string
attribute :default_for_target, :boolean do
default false
end
attribute :doc, :string do
allow_nil? false
constraints trim?: false, allow_empty?: true
default ""
end
attribute :doc_html, :string do
constraints trim?: false, allow_empty?: true
writable? false
end
attribute :type, :string do
allow_nil? false
end
attribute :order, :integer do
allow_nil? false
end
attribute :module, :string
timestamps()
@ -104,8 +65,4 @@ defmodule AshHq.Docs.Extension do
resource do
description "An Ash DSL extension."
end
identities do
identity :unique_name_by_library_version, [:name, :library_version_id]
end
end

View file

@ -19,9 +19,7 @@ defmodule AshHq.Docs.Option do
doc_attribute :doc
load_for_search [
:extension_name,
:extension_module,
:extension_target,
:library_name
]
@ -126,9 +124,7 @@ defmodule AshHq.Docs.Option do
calculations do
calculate :extension_type, :string, expr(dsl.extension.type)
calculate :extension_name, :string, expr(dsl.extension.name)
calculate :extension_order, :integer, expr(dsl.extension.order)
calculate :extension_target, :string, expr(dsl.extension.target)
calculate :extension_module, :string, expr(dsl.extension.module)
calculate :version_name, :string, expr(library_version.version)
calculate :library_name, :string, expr(library_version.library.name)

View file

@ -1,19 +0,0 @@
defmodule AshHqWeb.DslRedirectController do
use AshHqWeb, :controller
def show(conn, %{"library" => library, "extension" => extension_name, "dsl_path" => dsl_path}) do
library = AshHq.Docs.Library.by_name!(library, load: [latest_library_version: :extensions])
extension =
library.latest_library_version.extensions
|> Enum.find(fn extension ->
AshHqWeb.DocRoutes.sanitize_name(extension.module) == extension_name ||
AshHqWeb.DocRoutes.sanitize_name(extension.name) == extension_name
end)
|> Kernel.||(raise Ash.Error.Query.NotFound)
target = AshHqWeb.DocRoutes.sanitize_name(extension.target)
redirect(conn, to: "/docs/dsl/#{target}##{Enum.join(dsl_path, "-")}")
end
end

View file

@ -66,8 +66,6 @@ defmodule AshHqWeb.Router do
live("/forum/:channel", AppViewLive, :forum)
live("/forum/:channel/:id", AppViewLive, :forum)
get("/docs/dsl/:library/:version/:extension/*dsl_path", DslRedirectController, :show)
get("/unsubscribe", MailingListController, :unsubscribe)
end

View file

@ -4,7 +4,7 @@
"appsignal": {:hex, :appsignal, "2.7.9", "efc11601a848f153752778356bc86f9af03e925f15a961f714cd702a83cee434", [:make, :mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:decorator, "~> 1.2.3 or ~> 1.3", [hex: :decorator, repo: "hexpm", optional: false]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, ">= 1.3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "84fff1dcba3d3fcf542c528ffb0f4eba891da0f68125fcf57e9b30d1a1a4a6e9"},
"appsignal_phoenix": {:hex, :appsignal_phoenix, "2.3.4", "c83a8e15a51456db7d722a21bfe9a45e23618b550219caa8fb6d4853f61b5734", [:mix], [{:appsignal, ">= 2.7.6 and < 3.0.0", [hex: :appsignal, repo: "hexpm", optional: false]}, {:appsignal_plug, ">= 2.0.15 and < 3.0.0", [hex: :appsignal_plug, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.11 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.9", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1ca040fbfa653bdda25735031d8b89c81ebb50c475bc35d5ac0e13236e5f6600"},
"appsignal_plug": {:hex, :appsignal_plug, "2.0.15", "758a8a78944878e8461bbc77ca86219121a56f4299c6d79940ab083cf9afea00", [:mix], [{:appsignal, ">= 2.7.6 and < 3.0.0", [hex: :appsignal, repo: "hexpm", optional: false]}, {:plug, ">= 1.1.0", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1c6059049e2081e808aaef04e2b9917e06277f61a35a0e103db860d08cbc41f1"},
"ash": {:git, "https://github.com/ash-project/ash.git", "8ce6e065ce7f37cbd0c15a9054502059215571ad", []},
"ash": {:git, "https://github.com/ash-project/ash.git", "6c5cd551ff16f01a707cbd49c689899b9366aa8b", []},
"ash_admin": {:git, "https://github.com/ash-project/ash_admin.git", "3002af9ec69dc475582ef5f445064e4594bf45ac", []},
"ash_appsignal": {:hex, :ash_appsignal, "0.1.2", "a6eb1927a13c11006aad0d9ffaa011143344dd04c9b07ab94f459498b8ddc6d4", [:mix], [{:appsignal, "~> 2.0", [hex: :appsignal, repo: "hexpm", optional: false]}, {:ash, ">= 2.14.14", [hex: :ash, repo: "hexpm", optional: false]}], "hexpm", "dae3158337d2a36b76f04519ebe6d08ef5296823831993cef6069eeb879c5b94"},
"ash_authentication": {:hex, :ash_authentication, "3.11.15", "7834446cdd13bb471bded630aa0e0e4fb8795ffffe0c294dc22448d3778ff035", [:mix], [{:ash, ">= 2.5.11 and < 3.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:assent, "~> 0.2", [hex: :assent, repo: "hexpm", optional: false]}, {:bcrypt_elixir, "~> 3.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: false]}, {:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:finch, "~> 0.16.0", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.5", [hex: :joken, repo: "hexpm", optional: false]}, {:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: false]}, {:spark, ">= 1.1.39 and < 2.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "931926d8dd3fc5ac54a354d69aad6aed30438977d7971bf3fdfae4c563557d21"},
@ -15,8 +15,8 @@
"ash_json_api": {:git, "https://github.com/ash-project/ash_json_api.git", "31ece4fad9920c7e45c600d38ac82218296c4612", []},
"ash_oban": {:git, "https://github.com/ash-project/ash_oban.git", "36a441f78195f4f4e656f6a0cf268084704ff174", []},
"ash_phoenix": {:git, "https://github.com/ash-project/ash_phoenix.git", "35e4d2931e1664383c9a085a90f846e58986c8c8", []},
"ash_postgres": {:git, "https://github.com/ash-project/ash_postgres.git", "54908395ebcd8e9a5f8e7e30c1cee3f57e233448", []},
"ash_sqlite": {:git, "https://github.com/ash-project/ash_sqlite.git", "55bdce140f7ba9df9479923de2ab276be3e28588", []},
"ash_postgres": {:git, "https://github.com/ash-project/ash_postgres.git", "40c1a13652dc65406692ffbcaf6d78d1d8aa07c4", []},
"ash_sqlite": {:git, "https://github.com/ash-project/ash_sqlite.git", "75ffda1076a81cf1793fe0a170c1df73021e83c9", []},
"assent": {:hex, :assent, "0.2.7", "aa68f68e577077c091ce722bff8fe1ae56b95b274bb8107f7a5406cc15a65da7", [:mix], [{:certifi, ">= 0.0.0", [hex: :certifi, repo: "hexpm", optional: true]}, {:finch, "~> 0.15", [hex: :finch, repo: "hexpm", optional: true]}, {:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: true]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:ssl_verify_fun, ">= 0.0.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: true]}], "hexpm", "08106af439de4f9de114c0334de4c848de7cfbe53a5a52d342a784c4f6bc86f3"},
"bcrypt_elixir": {:hex, :bcrypt_elixir, "3.1.0", "0b110a9a6c619b19a7f73fa3004aa11d6e719a67e672d1633dc36b6b2290a0f7", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "2ad2acb5a8bc049e8d5aa267802631912bb80d5f4110a178ae7999e69dca1bf7"},
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},

View file

@ -0,0 +1,112 @@
{
"attributes": [
{
"default": "nil",
"size": null,
"type": "text",
"source": "sanitized_name",
"references": null,
"allow_nil?": false,
"primary_key?": false,
"generated?": false
},
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "id",
"references": null,
"allow_nil?": false,
"primary_key?": true,
"generated?": false
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "doc",
"references": null,
"allow_nil?": false,
"primary_key?": false,
"generated?": false
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "doc_html",
"references": null,
"allow_nil?": true,
"primary_key?": false,
"generated?": false
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "module",
"references": null,
"allow_nil?": true,
"primary_key?": false,
"generated?": false
},
{
"default": "nil",
"size": null,
"type": "utc_datetime_usec",
"source": "inserted_at",
"references": null,
"allow_nil?": false,
"primary_key?": false,
"generated?": false
},
{
"default": "nil",
"size": null,
"type": "utc_datetime_usec",
"source": "updated_at",
"references": null,
"allow_nil?": false,
"primary_key?": false,
"generated?": false
},
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "library_version_id",
"references": {
"name": "extensions_library_version_id_fkey",
"table": "library_versions",
"multitenancy": {
"global": null,
"strategy": null,
"attribute": null
},
"destination_attribute": "id",
"primary_key?": true,
"deferrable": false,
"destination_attribute_default": null,
"destination_attribute_generated": null,
"on_delete": "delete",
"on_update": null
},
"allow_nil?": true,
"primary_key?": false,
"generated?": false
}
],
"table": "extensions",
"hash": "D5A8C840F686B00B4BBF777766E090ABF33DF738E31C4B55C9A74021F6DE5F93",
"repo": "Elixir.AshHq.SqliteRepo",
"custom_indexes": [],
"custom_statements": [],
"multitenancy": {
"global": null,
"strategy": null,
"attribute": null
},
"identities": [],
"base_filter": null,
"has_create_action": true
}

View file

@ -0,0 +1,102 @@
{
"attributes": [
{
"default": "nil",
"size": null,
"type": "text",
"source": "sanitized_name",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "id",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": true
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "doc",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "module",
"references": null,
"allow_nil?": true,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "utc_datetime_usec",
"source": "inserted_at",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "utc_datetime_usec",
"source": "updated_at",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "library_version_id",
"references": {
"name": "extensions_library_version_id_fkey",
"table": "library_versions",
"on_delete": "delete",
"destination_attribute": "id",
"on_update": null,
"primary_key?": true,
"multitenancy": {
"global": null,
"attribute": null,
"strategy": null
},
"deferrable": false,
"destination_attribute_default": null,
"destination_attribute_generated": null
},
"allow_nil?": true,
"generated?": false,
"primary_key?": false
}
],
"table": "extensions",
"hash": "434F994CE5D27E22BB6C339D676EE91C369BF6EB4A229A3572FB0E63F9C1D585",
"repo": "Elixir.AshHq.SqliteRepo",
"identities": [],
"multitenancy": {
"global": null,
"attribute": null,
"strategy": null
},
"custom_indexes": [],
"base_filter": null,
"custom_statements": [],
"has_create_action": true
}

View file

@ -0,0 +1,82 @@
{
"attributes": [
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "id",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": true
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "module",
"references": null,
"allow_nil?": true,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "utc_datetime_usec",
"source": "inserted_at",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "utc_datetime_usec",
"source": "updated_at",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "library_version_id",
"references": {
"name": "extensions_library_version_id_fkey",
"table": "library_versions",
"multitenancy": {
"global": null,
"strategy": null,
"attribute": null
},
"on_delete": "delete",
"on_update": null,
"deferrable": false,
"destination_attribute": "id",
"primary_key?": true,
"destination_attribute_default": null,
"destination_attribute_generated": null
},
"allow_nil?": true,
"generated?": false,
"primary_key?": false
}
],
"table": "extensions",
"hash": "1AC8484F12B89285D069CA667A143EAEAE254A3242DF31B11951A459DCC23E10",
"repo": "Elixir.AshHq.SqliteRepo",
"multitenancy": {
"global": null,
"strategy": null,
"attribute": null
},
"base_filter": null,
"identities": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true
}

View file

@ -104,16 +104,11 @@ defmodule Utils do
default
end
def build(extension, all_extensions, order) do
def build(extension, all_extensions, _order) do
%{
name: extension.name,
target: extension[:target],
module: inspect(extension.module),
default_for_target: extension[:default_for_target?] || false,
type: extension[:type],
order: order,
doc: module_docs(extension.module) || "No documentation",
dsls: build_sections(extension.module.sections(), extension.module, all_extensions)
module: inspect(extension),
doc: module_docs(extension) || "No documentation",
dsls: build_sections(extension.sections(), extension, all_extensions)
}
end
@ -126,13 +121,13 @@ defmodule Utils do
entities =
all_extensions
|> Enum.flat_map(fn extension ->
extension.module.dsl_patches()
extension.dsl_patches()
|> Enum.filter(&match?(%Spark.Dsl.Patch.AddEntity{section_path: ^section_path}, &1))
|> Enum.map(fn %{entity: entity} ->
if extension.module == this_extension_module do
if extension == this_extension_module do
entity
else
Map.put(entity, :__requires_extension__, inspect(extension.module))
Map.put(entity, :__requires_extension__, inspect(extension))
end
end)
end)
@ -741,19 +736,21 @@ acc = %{
mix_tasks: []
}
extensions =
mix_project.project[:docs][:spark][:extensions] || mix_project.project[:docs][:spark_extensions]
{:ok, all_modules} =
name
|> String.to_atom()
|> :application.get_key(:modules)
extensions =
Enum.filter(all_modules, fn module ->
Spark.implements_behaviour?(module, Spark.Dsl.Extension)
end)
all_modules =
all_modules
|> Kernel.||([])
|> Enum.reject(fn module ->
Enum.find(extensions || [], &(&1.module == module))
Enum.find(extensions || [], &(&1 == module))
end)
all_modules =

View file

@ -0,0 +1,38 @@
defmodule AshHq.SqliteRepo.Migrations.MigrateResources2 do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_sqlite.generate_migrations`
"""
use Ecto.Migration
def up do
drop_if_exists unique_index(:extensions, [:library_version_id, :name],
name: "extensions_unique_name_by_library_version_index"
)
alter table(:extensions) do
remove :order
remove :type
remove :default_for_target
remove :target
remove :name
end
end
def down do
create unique_index(:extensions, [:library_version_id, :name],
name: "extensions_unique_name_by_library_version_index"
)
alter table(:extensions) do
add :name, :text, null: false
add :target, :text
add :default_for_target, :boolean
add :type, :text, null: false
add :order, :bigint, null: false
end
end
end

View file

@ -0,0 +1,21 @@
defmodule AshHq.SqliteRepo.Migrations.MigrateResources3 do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_sqlite.generate_migrations`
"""
use Ecto.Migration
def up do
alter table(:extensions) do
remove :doc_html
end
end
def down do
alter table(:extensions) do
add :doc_html, :text
end
end
end

View file

@ -0,0 +1,24 @@
defmodule AshHq.SqliteRepo.Migrations.RemoveExtensionFields do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_sqlite.generate_migrations`
"""
use Ecto.Migration
def up do
alter table(:extensions) do
remove :doc
remove :sanitized_name
end
end
def down do
alter table(:extensions) do
add :sanitized_name, :text, null: false
add :doc, :text, null: false
end
end
end