@@ -16,31 +16,36 @@ package main
1616
1717import (
1818 "context"
19- "fmt"
2019)
2120
2221type NdthanhdevGithubIo struct {
22+ Dir * Directory
23+ Mode string
24+ GhToken * Secret
2325}
2426
25- // Returns a container that echoes whatever string argument is provided
26- func (m * NdthanhdevGithubIo ) ContainerEcho (stringArg string ) * Container {
27- return dag .Container ().From ("alpine:latest" ).WithExec ([]string {"echo" , stringArg })
27+ func New (
28+ // +required
29+ dir * Directory ,
30+ // +optional
31+ // +default="dev"
32+ mode string ,
33+ // +optional
34+ ghToken * Secret ,
35+ ) * NdthanhdevGithubIo {
36+ return & NdthanhdevGithubIo {
37+ Dir : dir ,
38+ Mode : mode ,
39+ GhToken : ghToken ,
40+ }
2841}
2942
30- type Con struct {
31- * Container
32- }
33-
34- func (c * Con ) MoonRun (command string ) * Container {
35- return c .Container .WithExec ([]string {fmt .Sprintf (`moon run %s` , command )})
36- }
37-
38- func (m * NdthanhdevGithubIo ) Init (ctx context.Context , dir * Directory ) * Container {
39- source := dag .Directory ().WithDirectory ("/" , dir , DirectoryWithDirectoryOpts {
43+ func (m * NdthanhdevGithubIo ) init (ctx context.Context ) * Con {
44+ source := dag .Directory ().WithDirectory ("/" , m .Dir , DirectoryWithDirectoryOpts {
4045 Exclude : []string {"node_modules" , ".cache" , "moon/.cache" },
4146 })
4247
43- return dag .
48+ con := dag .
4449 Container ().
4550 From ("node:22-bookworm" ).
4651 WithExec ([]string {"apt-get" , "install" , "-y" , "bash" , "curl" , "git" , "unzip" , "gzip" , "xz-utils" }).
@@ -50,7 +55,7 @@ func (m *NdthanhdevGithubIo) Init(ctx context.Context, dir *Directory) *Containe
5055 WithEnvVariable ("HOME" , "/root" ).
5156 WithUser ("root" ).
5257 // curl -fsSL https://moonrepo.dev/install/proto.sh | bash -s 0.35.3 --yes
53- WithExec ([]string {`curl -fsSL https://moonrepo.dev/install/proto.sh | bash -s -- 0.35.3 --yes` }).
58+ WithExec ([]string {`curl -fsSL https://moonrepo.dev/install/proto.sh | bash -s -- 0.35.5 --yes` }).
5459 // export PROTO_HOME="$HOME/.proto"
5560 WithEnvVariable ("PROTO_HOME" , "$HOME/.proto" , ContainerWithEnvVariableOpts {
5661 Expand : true ,
@@ -68,28 +73,30 @@ func (m *NdthanhdevGithubIo) Init(ctx context.Context, dir *Directory) *Containe
6873 // yarn install --immutable
6974 WithExec ([]string {"yarn install --immutable" })
7075
76+ return (& Con {con }).SetEnvs (ctx , m )
7177}
7278
73- func (m * NdthanhdevGithubIo ) Test (ctx context.Context , dir * Directory ) * Container {
74- return (& Con {m .Init (ctx , dir )}).
75- MoonRun ("scripts:test" )
79+ func (m * NdthanhdevGithubIo ) MoonRun (ctx context.Context , command string ) * Container {
80+ return m .
81+ init (ctx ).
82+ MoonRun (command ).
83+ Container
7684}
7785
78- func (m * NdthanhdevGithubIo ) Build (ctx context.Context , dir * Directory , mode string ) * Directory {
79- return (& Con {m .Init (ctx , dir ).
80- WithEnvVariable ("MODE" , mode )}).
81- MoonRun ("scripts:build" ).
82- Directory ("/mnt/app/public" )
86+ func (m * NdthanhdevGithubIo ) Test (ctx context.Context ) (string , error ) {
87+ return m .
88+ MoonRun (ctx , "scripts:test" ).
89+ Stdout (ctx )
8390}
8491
85- func (m * NdthanhdevGithubIo ) Publish (ctx context.Context , dir * Directory , mode string , token * Secret ) (string , error ) {
86-
87- tokenString , _ := token .Plaintext (ctx )
92+ func (m * NdthanhdevGithubIo ) Build (ctx context.Context ) * Directory {
93+ return m .
94+ MoonRun (ctx , "scripts:build" ).
95+ Directory ("/mnt/app/public" )
96+ }
8897
89- return (& Con {m .
90- Init (ctx , dir ).
91- WithEnvVariable ("GH_TOKEN" , tokenString ).
92- WithEnvVariable ("MODE" , mode )}).
93- MoonRun ("scripts:publish" ).
98+ func (m * NdthanhdevGithubIo ) Publish (ctx context.Context ) (string , error ) {
99+ return m .
100+ MoonRun (ctx , "scripts:publish" ).
94101 Stdout (ctx )
95102}
0 commit comments