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

Commit

Permalink
bundle components
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Nov 22, 2023
1 parent 043db6b commit 6099b4a
Show file tree
Hide file tree
Showing 13 changed files with 1,702 additions and 94 deletions.
40 changes: 28 additions & 12 deletions cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"log/slog"
"os"
"strings"
"time"

"github.com/briandowns/spinner"
Expand All @@ -16,6 +17,8 @@ import (
cli "github.com/urfave/cli/v2"
)

var version = "dev"

func main() {
app := &cli.App{
Name: "sst",
Expand Down Expand Up @@ -43,7 +46,8 @@ func main() {
return err
}
}
fmt.Println(color.CyanString("SST ❍ Ion "), color.HiBlackString("ready!"))
color.New(color.FgCyan, color.Bold).Print("SST ❍ Ion " + version + " ")
color.New(color.FgHiBlack).Print("ready!\n")
return nil
},
Commands: []*cli.Command{
Expand All @@ -69,27 +73,29 @@ func main() {
timing := make(map[string]time.Time)
outputs := make(map[string]interface{})
for evt := range events {
s.Disable()
if evt.ResourcePreEvent != nil {
if evt.ResourcePreEvent.Metadata.Type == "pulumi:pulumi:Stack" {
continue
}
if evt.ResourcePreEvent.Metadata.Op == apitype.OpSame {
s.Disable()
color.New(color.FgHiBlack, color.Bold).Print("| ")
color.New(color.FgHiBlack).Println("Skipping ", evt.ResourcePreEvent.Metadata.URN)
color.New(color.FgHiBlack).Println("Skipping ", prettyResourceName(evt.ResourcePreEvent.Metadata.URN))
continue
}

timing[evt.ResourcePreEvent.Metadata.URN] = time.Now()
if evt.ResourcePreEvent.Metadata.Op == apitype.OpCreate {
s.Disable()
color.New(color.FgYellow, color.Bold).Print("| ")
color.New(color.FgHiBlack).Println("Creating ", evt.ResourcePreEvent.Metadata.URN)
color.New(color.FgHiBlack).Println("Creating ", prettyResourceName(evt.ResourcePreEvent.Metadata.URN))
continue
}

if evt.ResourcePreEvent.Metadata.Op == apitype.OpUpdate {
s.Disable()
color.New(color.FgYellow, color.Bold).Print("| ")
color.New(color.FgHiBlack).Println("Updating ", evt.ResourcePreEvent.Metadata.URN)
color.New(color.FgHiBlack).Println("Updating ", prettyResourceName(evt.ResourcePreEvent.Metadata.URN))
continue
}
}
Expand All @@ -104,12 +110,14 @@ func main() {
}
duration := time.Since(timing[evt.ResOutputsEvent.Metadata.URN]).Milliseconds()
if evt.ResOutputsEvent.Metadata.Op == apitype.OpCreate {
s.Disable()
color.New(color.FgGreen, color.Bold).Print("| ")
color.New(color.FgHiBlack).Println("Created ", evt.ResOutputsEvent.Metadata.URN, " in ", duration, "ms")
color.New(color.FgHiBlack).Println("Created ", prettyResourceName(evt.ResOutputsEvent.Metadata.URN), " in ", duration, "ms")
}
if evt.ResOutputsEvent.Metadata.Op == apitype.OpUpdate {
s.Disable()
color.New(color.Bold, color.FgGreen).Print("| ")
color.New(color.FgHiBlack).Println("Updated ", evt.ResOutputsEvent.Metadata.URN, " in ", duration, "ms")
color.New(color.FgHiBlack).Println("Updated ", prettyResourceName(evt.ResOutputsEvent.Metadata.URN), " in ", duration, "ms")
}
}
s.Enable()
Expand All @@ -119,8 +127,7 @@ func main() {
color.New(color.FgWhite, color.Bold).Println(" Deployed:")
for k, v := range outputs {
color.New(color.FgHiBlack).Print(" ")
color.New(color.FgWhite).Print(k)
color.New(color.FgHiBlack).Print(" = ")
color.New(color.FgHiBlack, color.Bold).Print(k + ": ")
color.New(color.FgWhite).Println(v)
}

Expand Down Expand Up @@ -195,8 +202,8 @@ func main() {
}

func initProject() (*project.Project, error) {
slog.Info("initializing project")
p, err := project.New()
slog.Info("initializing project", "version", version)
p, err := project.New(version)
if err != nil {
return nil, err
}
Expand All @@ -219,7 +226,7 @@ func initProject() (*project.Project, error) {
}
}
}
slog.Info("using", "stage", p.Stage())
slog.Info("loaded cnfig", "app", p.Name(), "stage", p.Stage(), "region", p.Region())

_, err = p.AWS.Config()
if err != nil {
Expand Down Expand Up @@ -259,3 +266,12 @@ func printHeader(p *project.Project) {

fmt.Println()
}

func prettyResourceName(input string) string {
splits := strings.Split(input, "::")
// take last two
splits = splits[len(splits)-2:]
splits[0] = strings.ReplaceAll(splits[0], "bucket:", "")
joined := strings.Join(splits, "::")
return joined
}
1 change: 0 additions & 1 deletion examples/nextjs/components/SsrSite.ts

This file was deleted.

9 changes: 5 additions & 4 deletions examples/test-old/sst.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SSTConfig } from "sst";
import { Bucket } from "sst/constructs";
import { Tags } from "aws-cdk-lib";
import { CfnBucket } from "aws-cdk-lib/aws-s3";

export default {
config() {
Expand All @@ -12,8 +11,10 @@ export default {
},
stacks(app) {
app.stack(function Default(ctx) {
const b = new Bucket(ctx.stack, "MyBucket");
Tags.of(b).add("foo", "1000");
// const b = new CfnBucket(ctx.stack, "MyBucket");
ctx.stack.addOutputs({
// url: b.attrDomainName,
});
});
},
} satisfies SSTConfig;
4 changes: 0 additions & 4 deletions examples/test/Pulumi.yaml

This file was deleted.

1 change: 1 addition & 0 deletions examples/test/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default {
foo: "1123",
},
});

return {
url: util.interpolate`https://${a.bucketDomainName}`,
};
Expand Down
3 changes: 1 addition & 2 deletions pkg/project/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ func (p *projectAws) Config() (aws.Config, error) {
var err error

p.Do(func() {
slog.Info("using", "profile", p.project.Profile())
slog.Info("getting aws credentials", "profile", p.project.Profile())
ctx := context.Background()
slog.Info("getting aws credentials")
cfg, e := config.LoadDefaultConfig(
ctx,
config.WithSharedConfigProfile(p.project.Profile()),
Expand Down
8 changes: 8 additions & 0 deletions pkg/project/components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "sst",
"dependencies": {
"@pulumi/aws": "5.43.0",
"@pulumi/pulumi": "3.94.2"
}
}
Loading

0 comments on commit 6099b4a

Please sign in to comment.