Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

spacefile: auto_pwa field #152

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -379,14 +380,15 @@ 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,
Version: releaseVersion,
ReleaseNotes: releaseNotes,
DiscoveryList: listedRelease,
Channel: ReleaseChannelExp, // always experimental release for now
AutoPWA: autoPWA,
})
if err != nil {
if errors.Is(err, auth.ErrNoAccessTokenFound) {
Expand Down
2 changes: 2 additions & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions internal/spacefile/schemas/spacefile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions internal/spacefile/spacefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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{})
Expand Down