diff --git a/cmd/push.go b/cmd/push.go index 7ae4eee..d9968e2 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -88,7 +88,7 @@ func push(projectID, projectDir, pushTag string, openInBrowser, skipLogs, experi return err } - build, err := utils.Client.CreateBuild(&api.CreateBuildRequest{AppID: projectID, Tag: pushTag, Experimental: experimental}) + build, err := utils.Client.CreateBuild(&api.CreateBuildRequest{AppID: projectID, Tag: pushTag, Experimental: experimental, AutoPWA: *s.AutoPWA}) if err != nil { utils.Logger.Printf("%s Failed to push project: %s", emoji.ErrorExclamation, err) return err diff --git a/cmd/release.go b/cmd/release.go index f23bb01..06ac194 100644 --- a/cmd/release.go +++ b/cmd/release.go @@ -87,7 +87,13 @@ func newCmdRelease() *cobra.Command { } } - discoveryData, err := getDiscoveryData(projectDir) + spacefile, err := spacefile.LoadSpacefile(projectDir) + if err != nil { + utils.Logger.Printf("Failed to load Spacefile: %v", err) + return err + } + + discoveryData, err := getDiscoveryData(projectDir, spacefile) if err != nil { utils.Logger.Printf("Failed to get discovery data: %v", err) return err @@ -127,7 +133,7 @@ func newCmdRelease() *cobra.Command { utils.Logger.Printf(getCreatingReleaseMsg(listedRelease, useLatestRevision)) err = release(projectDir, projectID, revisionID, releaseVersion, - listedRelease, releaseNotes, discoveryData) + listedRelease, releaseNotes, discoveryData, *spacefile.AutoPWA) if err != nil { return err } @@ -266,7 +272,7 @@ func compareDiscoveryData(discoveryData *shared.DiscoveryData, latestRelease *ap return nil } -func getDiscoveryData(projectDir string) (*shared.DiscoveryData, error) { +func getDiscoveryData(projectDir string, spacefile *spacefile.Spacefile) (*shared.DiscoveryData, error) { discoveryPath := filepath.Join(projectDir, discovery.DiscoveryFilename) if _, err := os.Stat(discoveryPath); os.IsNotExist(err) { if !utils.IsOutputInteractive() { @@ -303,11 +309,6 @@ func getDiscoveryData(projectDir string) (*shared.DiscoveryData, error) { discoveryData.ContentRaw = string(rest) if discoveryData.AppName == "" { - spacefile, err := spacefile.LoadSpacefile(projectDir) - if err != nil { - return nil, err - } - utils.Logger.Printf("\nNo app name found in Discovery file. Using the app name from your Spacefile: %s", styles.Code(spacefile.AppName)) utils.Logger.Printf("Using the app name from your Spacefile is deprecated and will be removed in a future version.\n\n") @@ -379,7 +380,7 @@ func selectRevision(projectID string, useLatestRevision bool) (*api.Revision, er return revisionMap[tag], nil } -func release(projectDir string, projectID string, revisionID string, releaseVersion string, listedRelease bool, releaseNotes string, discoveryData *shared.DiscoveryData) (err error) { +func release(projectDir string, projectID string, revisionID string, releaseVersion string, listedRelease bool, releaseNotes string, discoveryData *shared.DiscoveryData, autoPWA bool) (err error) { cr, err := utils.Client.CreateRelease(&api.CreateReleaseRequest{ RevisionID: revisionID, AppID: projectID, @@ -387,6 +388,7 @@ func release(projectDir string, projectID string, revisionID string, releaseVers ReleaseNotes: releaseNotes, DiscoveryList: listedRelease, Channel: ReleaseChannelExp, // always experimental release for now + AutoPWA: autoPWA, }) if err != nil { if errors.Is(err, auth.ErrNoAccessTokenFound) { diff --git a/internal/api/api.go b/internal/api/api.go index 9740b5b..8f1ace1 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -124,6 +124,7 @@ type CreateReleaseRequest struct { Description string `json:"description"` Channel string `json:"channel"` DiscoveryList bool `json:"discovery_list"` + AutoPWA bool `json:"auto_pwa"` } type CreateReleaseResponse struct { @@ -292,6 +293,7 @@ type CreateBuildRequest struct { AppID string `json:"app_id"` Tag string `json:"tag"` Experimental bool `json:"experimental"` + AutoPWA bool `json:"auto_pwa"` } type CreateBuildResponse struct { diff --git a/internal/spacefile/schemas/spacefile.schema.json b/internal/spacefile/schemas/spacefile.schema.json index 3351d92..6da72dc 100644 --- a/internal/spacefile/schemas/spacefile.schema.json +++ b/internal/spacefile/schemas/spacefile.schema.json @@ -26,6 +26,11 @@ "type": "string", "maxLength": 12 }, + "auto_pwa": { + "description": "Turn the application into a PWA by default", + "type": "boolean", + "default": true + }, "micros": { "description": "List of Micros in the app", "type": "array", diff --git a/internal/spacefile/spacefile.go b/internal/spacefile/spacefile.go index 1162c73..4ac99c5 100644 --- a/internal/spacefile/spacefile.go +++ b/internal/spacefile/spacefile.go @@ -43,6 +43,7 @@ type Spacefile struct { V int `yaml:"v"` Icon string `yaml:"icon,omitempty"` AppName string `yaml:"app_name,omitempty"` + AutoPWA *bool `yaml:"auto_pwa,omitempty"` Micros []*shared.Micro `yaml:"micros,omitempty"` } @@ -272,6 +273,10 @@ func LoadSpacefile(projectDir string) (*Spacefile, error) { if err := yaml.Unmarshal(content, &spacefile); err != nil { return nil, ErrInvalidSpacefile } + if spacefile.AutoPWA == nil { + spacefile.AutoPWA = new(bool) + *spacefile.AutoPWA = true + } foundPrimaryMicro := false micros := make(map[string]struct{})