Skip to content

Commit 099cef3

Browse files
committed
organize scripting extensions
1 parent 4c5eb79 commit 099cef3

File tree

18 files changed

+319
-199
lines changed

18 files changed

+319
-199
lines changed

lib/app/ChecksumVerificationState.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
//go:generate go-enum --marshal
21
package app
32

43
import (
54
"errors"
65
"fmt"
7-
8-
"github.com/stackup-app/stackup/lib/utils"
96
)
107

118
// ENUM(not verified, pending, verified, mismatch, error)
@@ -105,32 +102,44 @@ func ParseChecksumVerificationState(name string) (ChecksumVerificationState, err
105102
}
106103

107104
func (x *ChecksumVerificationState) IsInFinalState() bool {
108-
return utils.ArrayContains(AllFinalCHecksumVerificationStates, *x)
105+
for _, finalState := range AllFinalCHecksumVerificationStates {
106+
if *x == finalState {
107+
return true
108+
}
109+
}
110+
111+
return false
109112
}
110113

111-
func (x *ChecksumVerificationState) TransitionToNext(err error, matched bool) bool {
114+
func (x *ChecksumVerificationState) TransitionToNext(err error, matched bool) *ChecksumVerificationState {
112115
possibleStates := _ChecksumVerificationStateTransitionMap[*x]
113116

114117
if len(possibleStates) == 0 {
115-
return false
118+
return x
116119
}
117120

118121
if len(possibleStates) == 1 {
119122
*x = possibleStates[0]
120-
return true
123+
return x
121124
}
122125

123-
if err != nil && utils.ArrayContains(possibleStates, ChecksumVerificationStateError) {
124-
*x = ChecksumVerificationStateError
125-
return true
126+
for _, state := range possibleStates {
127+
if state == ChecksumVerificationStateError {
128+
*x = ChecksumVerificationStateError
129+
return x
130+
}
126131
}
127132

128-
if utils.ArrayContains(possibleStates, NonErrorFinalChecksumVerificationStates) {
129-
x.SetVerified(matched)
130-
return true
133+
for _, state := range possibleStates {
134+
for _, finalState := range AllFinalCHecksumVerificationStates {
135+
if state == finalState {
136+
x.SetVerified(matched)
137+
return x
138+
}
139+
}
131140
}
132141

133-
return false
142+
return x
134143
}
135144

136145
// MarshalText implements the text marshaller method.

lib/app/WorkflowInclude.go

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ func (wi *WorkflowInclude) ValidateChecksum() bool {
143143
return true
144144
}
145145

146-
wi.ValidationState.TransitionToNext(nil, false)
147-
// wi.ValidationState = ChecksumVerificationStatePending
146+
// wi.TransitionToNext(nil, false)
147+
wi.ValidationState = ChecksumVerificationStatePending
148148
found := false
149149

150150
for _, url := range GetChecksumUrls(wi.FullUrl()) {
@@ -161,14 +161,28 @@ func (wi *WorkflowInclude) ValidateChecksum() bool {
161161
found = true
162162
wi.ChecksumUrl = url
163163
wi.UpdateChecksumFromChecksumsFile(url, urlText)
164-
wi.ValidationState.TransitionToNext(wi.HashAlgorithm.UnsupportedError(), false)
164+
// wi.TransitionToNext(wi.HashAlgorithm.UnsupportedError(), false)
165165
// wi.ValidationState = ChecksumVerificationStateError
166+
// test
167+
//wi.ValidationState =
166168

167169
break
168170
}
169171

170-
wi.ValidationState.TransitionToNext(nil, found && !wi.ValidationState.IsError() && checksums.HashesMatch(wi.Hash, wi.FoundChecksum))
171-
// wi.ValidationState.SetVerified(found && !wi.ValidationState.IsError() && checksums.HashesMatch(wi.Hash, wi.FoundChecksum))
172+
matched := found && !wi.ValidationState.IsError() && checksums.HashesMatch(wi.Hash, wi.FoundChecksum)
173+
174+
if !found {
175+
wi.ValidationState = ChecksumVerificationStateError
176+
}
177+
if matched {
178+
wi.ValidationState = ChecksumVerificationStateVerified
179+
}
180+
181+
// wi.TransitionToNext(nil, matched)
182+
//
183+
wi.ValidationState.SetVerified(matched)
184+
185+
fmt.Printf("wi.ValidationState: %v\n", wi.ValidationState)
172186

173187
return wi.ValidationState.IsVerified()
174188
}
@@ -233,3 +247,32 @@ func (wi *WorkflowInclude) NewCacheEntry() *cache.CacheEntry {
233247
cache.CreateCarbonNowPtr(),
234248
)
235249
}
250+
251+
func (wi *WorkflowInclude) TransitionToNext(err error, matched bool) {
252+
possibleStates := _ChecksumVerificationStateTransitionMap[wi.ValidationState]
253+
254+
if len(possibleStates) == 0 {
255+
return
256+
}
257+
258+
if len(possibleStates) == 1 {
259+
wi.ValidationState = possibleStates[0]
260+
return
261+
}
262+
263+
for _, state := range possibleStates {
264+
if state == ChecksumVerificationStateError {
265+
wi.ValidationState = ChecksumVerificationStateError
266+
return
267+
}
268+
}
269+
270+
for _, state := range possibleStates {
271+
for _, finalState := range AllFinalCHecksumVerificationStates {
272+
if state == finalState {
273+
wi.ValidationState.SetVerified(true)
274+
return
275+
}
276+
}
277+
}
278+
}

lib/app/WorkflowState.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (ws *WorkflowState) SetCurrent(task *Task) CleanupCallback {
3232
ws.CurrentTask = nil
3333

3434
value, ok := ws.Stack.Pop()
35-
if ok {
35+
if ok && value != nil {
3636
ws.CurrentTask = value.(*Task)
3737
}
3838
}

lib/app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ func (a *Application) Run() {
357357
a.runInitScript()
358358
a.runPreconditions()
359359
a.runStartupTasks()
360-
a.runServerTasks()
361-
a.createScheduledTasks()
360+
// a.runServerTasks()
361+
// a.createScheduledTasks()
362362

363363
a.runEventLoop()
364364
}

lib/scripting/ScriptRegistry.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

lib/scripting/scriptApp.go renamed to lib/scripting/extensions/app_extension/scriptApp.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
package scripting
1+
package appextension
22

33
import (
44
"github.com/stackup-app/stackup/lib/support"
5-
"github.com/stackup-app/stackup/lib/version"
5+
"github.com/stackup-app/stackup/lib/types"
6+
appvers "github.com/stackup-app/stackup/lib/version"
67
)
78

9+
const name = "app"
10+
11+
// const version = "0.0.1"
12+
// const description = "Provides access to application methods."
13+
814
type ScriptApp struct {
915
}
1016

11-
func CreateScriptAppObject(e *JavaScriptEngine) {
12-
obj := &ScriptApp{}
13-
e.Vm.Set("app", obj)
17+
func Create() *ScriptApp {
18+
return &ScriptApp{}
19+
}
20+
21+
func (app *ScriptApp) GetName() string {
22+
return name
23+
}
24+
25+
func (ex *ScriptApp) OnInstall(engine types.JavaScriptEngineContract) {
26+
engine.GetVm().Set(ex.GetName(), ex)
1427
}
1528

1629
func (app *ScriptApp) StatusMessage(message string) {
@@ -34,5 +47,5 @@ func (app *ScriptApp) WarningMessage(message string) {
3447
}
3548

3649
func (app *ScriptApp) Version() string {
37-
return version.APP_VERSION
50+
return appvers.APP_VERSION
3851
}

lib/scripting/scriptComposerJson.go renamed to lib/scripting/extensions/dev_extension/scriptComposerJson.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package scripting
1+
package devextension
22

33
import (
44
"encoding/json"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package devextension
2+
3+
import (
4+
"github.com/stackup-app/stackup/lib/types"
5+
)
6+
7+
const name = "dev"
8+
9+
// const version = "0.0.1"
10+
// const description = "Provides access to development tools."
11+
12+
type ScriptDev struct {
13+
types.ScriptExtensionContract
14+
}
15+
16+
func Create() *ScriptDev {
17+
return &ScriptDev{}
18+
}
19+
20+
func (ex *ScriptDev) OnInstall(engine types.JavaScriptEngineContract) {
21+
engine.GetVm().Set(ex.GetName(), ex)
22+
}
23+
24+
func (dev *ScriptDev) GetName() string {
25+
return name
26+
}
27+
28+
func (dev *ScriptDev) ComposerJson(filename string) *Composer {
29+
result, _ := LoadComposerJson(filename)
30+
return result
31+
}
32+
33+
func (dev *ScriptDev) PackageJson(filename string) *PackageJSON {
34+
result, _ := LoadPackageJson(filename)
35+
return result
36+
}
37+
38+
func (dev *ScriptDev) RequirementsTxt(filename string) *RequirementsTxt {
39+
result, _ := LoadRequirementsTxt(filename)
40+
return result
41+
}

lib/scripting/scriptPackageJson.go renamed to lib/scripting/extensions/dev_extension/scriptPackageJson.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package scripting
1+
package devextension
22

33
import (
44
"encoding/json"

lib/scripting/scriptRequirementsTxt.go renamed to lib/scripting/extensions/dev_extension/scriptRequirementsTxt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package scripting
1+
package devextension
22

33
import (
44
"bufio"

0 commit comments

Comments
 (0)