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

Commit

Permalink
Merge branch 'brkp/auto-pwa-field' of github.com:deta/pc-cli into new…
Browse files Browse the repository at this point in the history
…-fields
  • Loading branch information
aavshr committed Oct 2, 2023
2 parents b8b307f + d339afe commit 8254475
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func push(projectID, projectDir, pushTag string, openInBrowser, skipLogs, experi
return fmt.Errorf("failed to zip your project, %w", 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 {
return fmt.Errorf("failed to start a build, %w", err)
}
Expand Down
28 changes: 12 additions & 16 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 {
return fmt.Errorf("failed to get Discovery data, %w", err)
}
Expand Down Expand Up @@ -137,9 +143,8 @@ func newCmdRelease() *cobra.Command {
}

utils.Logger.Printf(getCreatingReleaseMsg(listedRelease, useLatestRevision))

err = release(projectID, revisionID, releaseVersion,
listedRelease, releaseNotes, discoveryData)
err = release(projectDir, projectID, revisionID, releaseVersion,
listedRelease, releaseNotes, discoveryData, *spacefile.AutoPWA)
if err != nil {
return err
}
Expand Down Expand Up @@ -300,7 +305,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 @@ -335,11 +340,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 @@ -409,19 +409,15 @@ func selectRevision(projectID string, useLatestRevision bool) (*api.Revision, er
return revisionMap[tag], nil
}

// release xx
func release(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 @@ -38,6 +38,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 @@ -267,6 +268,10 @@ func LoadSpacefile(projectDir string) (*Spacefile, error) {
if err := yaml.Unmarshal(content, &spacefile); err != nil {
return nil, err
}
if spacefile.AutoPWA == nil {
spacefile.AutoPWA = new(bool)
*spacefile.AutoPWA = true
}

foundPrimaryMicro := false
micros := make(map[string]struct{})
Expand Down

0 comments on commit 8254475

Please sign in to comment.