Implement basic flavor support

This commit is contained in:
Tom Wiesing 2023-11-02 20:06:09 +01:00
parent 9a3e508ce8
commit d6c0c465e4
No known key found for this signature in database
24 changed files with 246 additions and 82 deletions

View file

@ -1,6 +1,9 @@
package manager
import (
"maps"
"slices"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel/composer"
@ -27,8 +30,81 @@ type Manager struct {
}
}
// profiles contains the list of default profiles
var (
defaultProfile = "Drupal 10"
profiles = map[string]Profile{
"Drupal 9": {
Description: "Legacy Version of Drupal with default packages",
Drupal: "^9",
WissKI: "",
InstallModules: []string{
"drupal/inline_entity_form:^1.0@RC",
"drupal/imagemagick",
"drupal/image_effects",
"drupal/colorbox",
},
EnableModules: []string{
"drupal/devel:^4.1",
"drupal/geofield:^1.40",
"drupal/geofield_map:^2.85",
"drupal/imce:^2.4",
"drupal/remove_generator:^2.0",
},
},
"Drupal 10": {
Description: "Current Version of Drupal with default packages",
Drupal: "^10",
WissKI: "",
InstallModules: []string{
"drupal/inline_entity_form:^1.0@RC",
"drupal/imagemagick",
"drupal/image_effects",
"drupal/colorbox",
},
EnableModules: []string{
"drupal/devel:^5.0",
"drupal/geofield:^1.56",
"drupal/geofield_map:^3.0",
"drupal/imce:^3.0",
"drupal/remove_generator:^2.0",
},
},
}
)
// TODO: All of these should move to the config
func LoadDefaultProfile() Profile {
return LoadProfile(DefaultProfile())
}
func Profiles() map[string]Profile {
return maps.Clone(profiles)
}
func LoadProfile(name string) Profile {
return profiles[name]
}
func HasProfile(name string) bool {
_, ok := profiles[name]
return ok
}
func DefaultProfile() string {
return defaultProfile
}
// Profile represents a profile applied to a WissKI instance of the Distillery.
type Profile struct {
// Description is a human-readable description for this profile.
// It is only used by the frontend.
Description string
Drupal string // Version of Drupal to use
WissKI string // Version of WissKI to use
@ -36,29 +112,25 @@ type Profile struct {
EnableModules []string // Modules to be installed and enabled
}
// DefaultDrupalVersion is the default drupal version
const DefaultDrupalVersion = "^9.0.0"
// ApplyDefaults applies the default settings to missing profile settings.
func (profile *Profile) ApplyDefaults() {
// Apply copies over defaults from the other profile to this one.
// If a field is already set, no defaults are copied.
func (profile *Profile) Apply(other Profile) {
if profile.Drupal == "" {
profile.Drupal = DefaultDrupalVersion
profile.Drupal = other.Drupal
}
if profile.WissKI == "" {
profile.WissKI = other.WissKI
}
if profile.InstallModules == nil {
profile.InstallModules = []string{
"drupal/inline_entity_form:^1.0@RC",
"drupal/imagemagick",
"drupal/image_effects",
"drupal/colorbox",
}
profile.InstallModules = slices.Clone(other.InstallModules)
}
if profile.EnableModules == nil {
profile.EnableModules = []string{
"drupal/devel:^4.1",
"drupal/geofield:^1.40",
"drupal/geofield_map:^2.85",
"drupal/imce:^2.4",
"drupal/remove_generator:^2.0",
}
profile.EnableModules = slices.Clone(profile.EnableModules)
}
}
// ApplyDefaults loads some set of defaults.
// If all fields are set, no defaults are applied.
func (profile *Profile) ApplyDefaults() {
profile.Apply(profiles[defaultProfile])
}

View file

@ -57,8 +57,6 @@ func (manager *Manager) Provision(ctx context.Context, progress io.Writer, syste
manager.dependencies.Barrel.Stack().DownAll(anyways, progress)
}()
// Apply the defaults to the flags
flags.ApplyDefaults()
return manager.bootstrap(ctx, progress, flags)
}
@ -71,7 +69,6 @@ var drushVariants = []string{
// Applies defaults to the flags.
func (provision *Manager) bootstrap(ctx context.Context, progress io.Writer, flags Profile) error {
// TODO: Check if we can remove the easyrdf patch!
flags.ApplyDefaults()
logging.LogMessage(progress, "Creating Composer Project")

View file

@ -10,7 +10,7 @@ function get_setting($name) {
/** sets a setting in 'settings.php' */
function set_setting(string $name, mixed $value): bool {
// find settings.php
$filename = DRUPAL_ROOT . "/" . \Drupal::service("site.path") . "/settings.php";
$filename = DRUPAL_ROOT . "/" . \Drupal::getContainer()->getParameter("site.path") . "/settings.php";
// setup user write permissions for the file
$old = fileperms($filename);

View file

@ -0,0 +1,37 @@
package extras
import (
"context"
"github.com/FAU-CDI/wisski-distillery/internal/phpx"
"github.com/FAU-CDI/wisski-distillery/internal/status"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
_ "embed"
)
// Version implements reading the current drupal version
type Version struct {
ingredient.Base
dependencies struct {
PHP *php.PHP
}
}
// Get returns the currently active theme
func (v *Version) Get(ctx context.Context, server *phpx.Server) (version string, err error) {
err = v.dependencies.PHP.EvalCode(
ctx, server, &version, "return Drupal::VERSION; ",
)
return
}
func (v *Version) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
if flags.Quick {
return
}
info.DrupalVersion, _ = v.Get(flags.Context, flags.Server)
return
}

View file

@ -1 +0,0 @@
package wisski

View file

@ -144,6 +144,7 @@ func (wisski *WissKI) allIngredients(context *lifetime.RegisterContext[ingredien
lifetime.Place[*extras.Requirements](context)
lifetime.Place[*extras.Adapters](context)
lifetime.Place[*extras.Theme](context)
lifetime.Place[*extras.Version](context)
lifetime.Place[*users.Users](context)
lifetime.Place[*users.UserPolicy](context)