-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
109 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/fatih/color" | ||
"github.com/manifoldco/promptui" | ||
"github.com/sst/ion/pkg/project" | ||
) | ||
|
||
func CmdInit(cli *Cli) error { | ||
color.New(color.FgYellow, color.Bold).Println(` __ | ||
__________/ /_ | ||
/ ___/ ___/ __/ | ||
(__ |__ ) /_ | ||
/____/____/\__/`) | ||
// color.New(color.FgYellow, color.Bold).Println(` ______ ______ ______ | ||
// /\ ___\ /\ ___\ /\__ _\ | ||
// \ \___ \ \ \___ \ \/_/\ \/ | ||
// \/\_____\ \/\_____\ \ \_\ | ||
// \/_____/ \/_____/ \/_/`) | ||
fmt.Println() | ||
if _, err := os.Stat("sst.config.ts"); err == nil { | ||
color.New(color.FgRed, color.Bold).Print("✗") | ||
color.New(color.FgWhite, color.Bold).Println(" sst.config.ts already exists") | ||
return nil | ||
} | ||
|
||
var template string | ||
if _, err := os.Stat("next.config.js"); err == nil { | ||
fmt.Println(" Next.js detected - initializing an sst project will") | ||
fmt.Println(" - create an sst.config.ts file") | ||
fmt.Println(" - add the sst sdk to your package.json") | ||
fmt.Println(" - modify your tsconfig.json") | ||
fmt.Println() | ||
template = "nextjs" | ||
} | ||
|
||
if template == "" { | ||
fmt.Println(" Creating a new sst project - this will") | ||
fmt.Println(" - create an sst.config.ts file") | ||
fmt.Println(" - install dependencies") | ||
fmt.Println() | ||
template = "vanilla" | ||
} | ||
|
||
p := promptui.Select{ | ||
Label: "Do you want to continue?", | ||
HideSelected: true, | ||
Items: []string{"Yes", "No"}, | ||
HideHelp: true, | ||
} | ||
|
||
_, confirm, err := p.Run() | ||
if err != nil { | ||
return err | ||
} | ||
if confirm == "No" { | ||
return nil | ||
} | ||
|
||
color.New(color.FgGreen, color.Bold).Print("✔") | ||
color.New(color.FgWhite).Println(" Using ", template, " template") | ||
|
||
p = promptui.Select{ | ||
Label: "Where do you want to store the state of your app?", | ||
HideSelected: true, | ||
Items: []string{"aws", "cloudflare"}, | ||
HideHelp: true, | ||
} | ||
_, home, err := p.Run() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
color.New(color.FgGreen, color.Bold).Print("✔") | ||
color.New(color.FgWhite).Println(" Setting home to " + home) | ||
|
||
err = project.Create(template, home) | ||
if err != nil { | ||
return err | ||
} | ||
initProject(cli) | ||
color.New(color.FgGreen, color.Bold).Print("✔") | ||
color.New(color.FgWhite).Println(" Created new project with '", template, "' template") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
/// <reference path="./.sst/platform/config.d.ts" /> | ||
|
||
export default $config({ | ||
app() { | ||
app(input) { | ||
return { | ||
name: "test", | ||
removal: "retain-all", | ||
removal: input?.stage === "production" ? "retain" : "remove", | ||
home: "aws", | ||
providers: {}, | ||
}; | ||
}, | ||
async run() { | ||
const fn = new sst.aws.Function("MyFunction2", { | ||
handler: "src/index.handler", | ||
url: true, | ||
}); | ||
const router = new sst.aws.Router("MyRouter", { | ||
routes: { | ||
"/*": fn.url, | ||
}, | ||
}); | ||
return { | ||
url: fn.url, | ||
router: router.url, | ||
}; | ||
}, | ||
async run() {}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters