Skip to content

Commit

Permalink
init command creates gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Mar 16, 2024
1 parent afbaaec commit cebbca5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.sst
12 changes: 12 additions & 0 deletions examples/test/sst.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path="./.sst/platform/config.d.ts" />

export default $config({
app(input) {
return {
name: "test",
removal: input?.stage === "production" ? "retain" : "remove",
home: "aws",
};
},
async run() {},
});
23 changes: 23 additions & 0 deletions pkg/project/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,28 @@ func Create(templateName string, home string) error {
}
}

gitignoreFilename := ".gitignore"
file, err := os.OpenFile(gitignoreFilename, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return err
}
defer file.Close()

bytes, err := os.ReadFile(gitignoreFilename)
if err != nil {
panic(err)
}
content := string(bytes)

if !strings.Contains(content, ".sst") {
if content != "" && !strings.HasSuffix(content, "\n") {
file.WriteString("\n")
}
_, err := file.WriteString(".sst\n")
if err != nil {
return err
}
}

return nil
}

0 comments on commit cebbca5

Please sign in to comment.