Skip to content

Commit

Permalink
feat: extension zip allow to modify version, and app backend before f…
Browse files Browse the repository at this point in the history
…inal zipping
  • Loading branch information
shyim committed Sep 20, 2024
1 parent 0741ecc commit e0ea2fc
Show file tree
Hide file tree
Showing 9 changed files with 796 additions and 236 deletions.
15 changes: 15 additions & 0 deletions cmd/extension/extension_zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ var extensionZipCmd = &cobra.Command{
}
}

if err := extension.BuildModifier(ext, extDir, extension.BuildModifierConfig{
AppBackendUrl: getStringOnStringError(cmd.Flags().GetString("overwrite-app-backend-url")),
AppBackendSecret: getStringOnStringError(cmd.Flags().GetString("overwrite-app-backend-secret")),
Version: getStringOnStringError(cmd.Flags().GetString("overwrite-version")),
}); err != nil {
return fmt.Errorf("build modifier: %w", err)
}

fileName := fmt.Sprintf("%s-%s.zip", name, tag)
if len(tag) == 0 {
fileName = fmt.Sprintf("%s.zip", name)
Expand Down Expand Up @@ -197,10 +205,17 @@ func init() {
extensionRootCmd.AddCommand(extensionZipCmd)
extensionZipCmd.Flags().BoolVar(&disableGit, "disable-git", false, "Use the source folder as it is")
extensionZipCmd.Flags().BoolVar(&extensionReleaseMode, "release", false, "Release mode (remove app secrets)")
extensionZipCmd.Flags().String("overwrite-app-backend-url", "", "Change all URLs in manifest.xml to this URL")
extensionZipCmd.Flags().String("overwrite-app-backend-secret", "", "Change the secret to this value")
extensionZipCmd.Flags().String("overwrite-version", "", "Change the extension version to this value")
extensionZipCmd.Flags().String("output-directory", "", "Output directory for the zip file")
extensionZipCmd.Flags().String("git-commit", "", "Commit Hash / Tag to use")
}

func getStringOnStringError(val string, _ error) string {
return val
}

func executeHooks(ext extension.Extension, hooks []string, extDir string) error {
env := []string{
fmt.Sprintf("EXTENSION_DIR=%s", extDir),
Expand Down
91 changes: 91 additions & 0 deletions extension/_fixtures/istorier.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/Framework/App/Manifest/Schema/manifest-1.0.xsd">
<meta>
<name>InstoImmersiveElements</name>
<label>Immersive Elements</label>
<description>Transform your online store into an unforgettable brand experience. As an incredibly cost-effective alternative to external resources, the app is engineered to boost conversions.</description>
<author>Instorier AS</author>
<copyright>(c) by Instorier AS</copyright>
<version>1.1.0</version>
<icon>Resources/config/plugin.png</icon>
<license>Proprietary</license>
</meta>

<setup>
<registrationUrl>https://instorier.apps.shopware.io/app/lifecycle/register</registrationUrl>
</setup>

<admin>
<base-app-url>https://instorier.apps.shopware.io/iframe</base-app-url>
</admin>
<permissions>
<read>cms_slot</read>
<read>cms_slot_translation</read>
<read>language</read>
<read>sales_channel</read>
<read>sales_channel_domain</read>
<read>customer</read>
<read>newsletter_recipient</read>
<read>order</read>
<read>category_translation</read>
<read>country_state_translation</read>
<read>country_translation</read>
<read>currency_translation</read>
<read>customer_group_translation</read>
<read>locale_translation</read>
<read>media</read>
<read>media_default_folder</read>
<read>media_translation</read>
<read>payment_method_translation</read>
<read>product_manufacturer_translation</read>
<read>product_translation</read>
<read>shipping_method_translation</read>
<read>unit_translation</read>
<read>property_group_translation</read>
<read>property_group_option_translation</read>
<read>sales_channel_translation</read>
<read>sales_channel_type_translation</read>
<read>salutation_translation</read>
<read>plugin_translation</read>
<read>product_stream_translation</read>
<read>state_machine_translation</read>
<read>state_machine_state_translation</read>
<read>cms_page_translation</read>
<read>mail_template_translation</read>
<read>mail_header_footer_translation</read>
<read>document_type_translation</read>
<read>number_range_type_translation</read>
<read>delivery_time_translation</read>
<read>product_search_keyword</read>
<read>product_keyword_dictionary</read>
<read>mail_template_type_translation</read>
<read>promotion_translation</read>
<read>number_range_translation</read>
<read>product_review</read>
<read>seo_url</read>
<read>tax_rule_type_translation</read>
<read>product_cross_selling_translation</read>
<read>import_export_profile_translation</read>
<read>product_sorting_translation</read>
<read>product_feature_set_translation</read>
<read>app_translation</read>
<read>app_action_button_translation</read>
<read>landing_page_translation</read>
<read>app_cms_block_translation</read>
<read>app_script_condition_translation</read>
<read>app_flow_action_translation</read>
<read>tax_provider_translation</read>
<read>theme_translation</read>

<create>cms_slot</create>
<create>cms_slot_translation</create>
<create>media</create>
<create>media_translation</create>

<update>cms_slot</update>
<update>cms_slot_translation</update>

<delete>cms_slot</delete>
<delete>cms_slot_translation</delete>
</permissions>
</manifest>
187 changes: 6 additions & 181 deletions extension/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,184 +11,9 @@ import (
"github.com/FriendsOfShopware/shopware-cli/version"
)

type translatedXmlNode []struct {
Text string `xml:",chardata"`
Lang string `xml:"lang,attr"`
}

type appManifest struct {
XMLName xml.Name `xml:"manifest"`
Text string `xml:",chardata"`
Xsi string `xml:"xsi,attr"`
NoNamespaceSchemaLocation string `xml:"noNamespaceSchemaLocation,attr"`
Meta appManifestMeta `xml:"meta"`
Setup struct {
Text string `xml:",chardata"`
RegistrationUrl string `xml:"registrationUrl"`
Secret string `xml:"secret"`
} `xml:"setup"`
Permissions struct {
Text string `xml:",chardata"`
Read string `xml:"read"`
Create string `xml:"create"`
Update string `xml:"update"`
Delete string `xml:"delete"`
} `xml:"permissions"`
Webhooks struct {
Text string `xml:",chardata"`
Webhook struct {
Text string `xml:",chardata"`
Name string `xml:"name,attr"`
URL string `xml:"url,attr"`
Event string `xml:"event,attr"`
} `xml:"webhook"`
} `xml:"webhooks"`
Admin struct {
Text string `xml:",chardata"`
Module []struct {
Text string `xml:",chardata"`
Name string `xml:"name,attr"`
Parent string `xml:"parent,attr"`
Position string `xml:"position,attr"`
Source string `xml:"source,attr"`
Label []struct {
Text string `xml:",chardata"`
Lang string `xml:"lang,attr"`
} `xml:"label"`
} `xml:"module"`
MainModule struct {
Text string `xml:",chardata"`
Source string `xml:"source,attr"`
} `xml:"main-module"`
ActionButton []struct {
Text string `xml:",chardata"`
Action string `xml:"action,attr"`
Entity string `xml:"entity,attr"`
View string `xml:"view,attr"`
URL string `xml:"url,attr"`
Label string `xml:"label"`
} `xml:"action-button"`
} `xml:"admin"`
CustomFields struct {
Text string `xml:",chardata"`
CustomFieldSet struct {
Text string `xml:",chardata"`
Name string `xml:"name"`
Label []struct {
Text string `xml:",chardata"`
Lang string `xml:"lang,attr"`
} `xml:"label"`
RelatedEntities struct {
Text string `xml:",chardata"`
Order string `xml:"order"`
} `xml:"related-entities"`
Fields struct {
Chardata string `xml:",chardata"`
Text struct {
Text string `xml:",chardata"`
Name string `xml:"name,attr"`
Label string `xml:"label"`
Position string `xml:"position"`
Required string `xml:"required"`
HelpText string `xml:"help-text"`
} `xml:"text"`
Float struct {
Text string `xml:",chardata"`
Name string `xml:"name,attr"`
Label []struct {
Text string `xml:",chardata"`
Lang string `xml:"lang,attr"`
} `xml:"label"`
HelpText string `xml:"help-text"`
Position string `xml:"position"`
Placeholder string `xml:"placeholder"`
Min string `xml:"min"`
Max string `xml:"max"`
Steps string `xml:"steps"`
} `xml:"float"`
} `xml:"fields"`
} `xml:"custom-field-set"`
} `xml:"custom-fields"`
Cookies struct {
Text string `xml:",chardata"`
Cookie struct {
Text string `xml:",chardata"`
Cookie string `xml:"cookie"`
SnippetName string `xml:"snippet-name"`
SnippetDescription string `xml:"snippet-description"`
Value string `xml:"value"`
Expiration string `xml:"expiration"`
} `xml:"cookie"`
Group struct {
Text string `xml:",chardata"`
SnippetName string `xml:"snippet-name"`
SnippetDescription string `xml:"snippet-description"`
Entries struct {
Text string `xml:",chardata"`
Cookie struct {
Text string `xml:",chardata"`
Cookie string `xml:"cookie"`
SnippetName string `xml:"snippet-name"`
SnippetDescription string `xml:"snippet-description"`
Value string `xml:"value"`
Expiration string `xml:"expiration"`
} `xml:"cookie"`
} `xml:"entries"`
} `xml:"group"`
} `xml:"cookies"`
Payments struct {
Text string `xml:",chardata"`
PaymentMethod struct {
Text string `xml:",chardata"`
Identifier string `xml:"identifier"`
Name []struct {
Text string `xml:",chardata"`
Lang string `xml:"lang,attr"`
} `xml:"name"`
Description []struct {
Text string `xml:",chardata"`
Lang string `xml:"lang,attr"`
} `xml:"description"`
PayURL string `xml:"pay-url"`
FinalizeURL string `xml:"finalize-url"`
Icon string `xml:"icon"`
} `xml:"payment-method"`
} `xml:"payments"`
}

type appManifestMeta struct {
Text string `xml:",chardata"`
Name string `xml:"name"`
Label translatedXmlNode `xml:"label"`
Description translatedXmlNode `xml:"description"`
Author string `xml:"author"`
Copyright string `xml:"copyright"`
Version string `xml:"version"`
License string `xml:"license"`
Icon string `xml:"icon"`
Privacy string `xml:"privacy"`
Compatibility string `xml:"compatibility"`
PrivacyPolicyExtensions []struct {
Text string `xml:",chardata"`
Lang string `xml:"lang,attr"`
} `xml:"privacyPolicyExtensions"`
}

func getTranslatedTextFromXmlNode(node translatedXmlNode, keys []string) string {
for _, n := range node {
for _, key := range keys {
if n.Lang == key {
return n.Text
}
}
}

return ""
}

type App struct {
path string
manifest appManifest
manifest Manifest
config *Config
}

Expand All @@ -212,7 +37,7 @@ func newApp(path string) (*App, error) {
return nil, fmt.Errorf("newApp: %v", err)
}

var manifest appManifest
var manifest Manifest
err = xml.Unmarshal(appFile, &manifest)

if err != nil {
Expand Down Expand Up @@ -294,12 +119,12 @@ func (a App) GetMetaData() *extensionMetadata {

return &extensionMetadata{
Label: extensionTranslated{
German: getTranslatedTextFromXmlNode(a.manifest.Meta.Label, german),
English: getTranslatedTextFromXmlNode(a.manifest.Meta.Label, english),
German: a.manifest.Meta.Label.GetValueByLanguage(german),
English: a.manifest.Meta.Label.GetValueByLanguage(english),
},
Description: extensionTranslated{
German: getTranslatedTextFromXmlNode(a.manifest.Meta.Description, german),
English: getTranslatedTextFromXmlNode(a.manifest.Meta.Description, english),
German: a.manifest.Meta.Description.GetValueByLanguage(german),
English: a.manifest.Meta.Description.GetValueByLanguage(english),
},
}
}
Expand Down
12 changes: 6 additions & 6 deletions extension/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestConvertApp(t *testing.T) {
app := App{
path: t.TempDir(),
config: &Config{},
manifest: appManifest{
Meta: appManifestMeta{
manifest: Manifest{
Meta: Meta{
Name: "TestApp",
},
},
Expand All @@ -50,8 +50,8 @@ func TestConvertApp(t *testing.T) {
func TestConvertExtraBundlesOfConfig(t *testing.T) {
app := App{
path: t.TempDir(),
manifest: appManifest{
Meta: appManifestMeta{
manifest: Manifest{
Meta: Meta{
Name: "TestApp",
},
},
Expand Down Expand Up @@ -83,8 +83,8 @@ func TestConvertExtraBundlesOfConfig(t *testing.T) {
func TestConvertExtraBundlesOfConfigWithOverride(t *testing.T) {
app := App{
path: t.TempDir(),
manifest: appManifest{
Meta: appManifestMeta{
manifest: Manifest{
Meta: Meta{
Name: "TestApp",
},
},
Expand Down
Loading

0 comments on commit e0ea2fc

Please # to comment.