github.com/sapplications/sb@v0.0.0-20240116135441-1a13cafe3497/readme.txt (about) 1 package sb // import "github.com/sapplications/sb" 2 Package sb implements a Smart Builder application. It is the next generation of 3 building applications using independent bussiness components. 4 CONSTANTS 5 const ( 6 // application 7 AppName string = "sb" 8 AppVersion string = "1.0" 9 AppVersionString string = AppName + " version " + AppVersion 10 AppsItemName string = "apps" 11 DefaultModuleName string = "apps" 12 // errors 13 ErrorMessageF string = "Error: %v\n" 14 AppIsExistF string = "the specified %s application is exist" 15 AppIsMissing string = "does not found any application in the apps" 16 AppIsMissingF string = "the selected \"%s\" application is not found" 17 AppIsMissingInSystemF string = "the system cannot find the \"%s\" application" 18 AppIsNotSpecified string = "the application is not specified" 19 ItemIsMissingF string = "the %s item is not found" 20 AttrIsMissingF string = "the \"%s\" attribute is missing for \"%s\" application" 21 ModuleFilesMissingF string = "no .%s files in \"" 22 ) 23 VARIABLES 24 var ModKind = struct { 25 SA string 26 SB string 27 SP string 28 }{ 29 "sa", 30 "sb", 31 "sp", 32 } 33 TYPES 34 type Logger interface { 35 Trace(msg string, args ...interface{}) 36 Debug(msg string, args ...interface{}) 37 Info(msg string, args ...interface{}) 38 Warn(msg string, args ...interface{}) 39 Error(msg string, args ...interface{}) 40 IsTrace() bool 41 IsDebug() bool 42 IsInfo() bool 43 IsWarn() bool 44 IsError() bool 45 } 46 Logger describes methods for logging messages. 47 type ModHelper struct { 48 Manager ModManager 49 } 50 ModHelper performs usuful methods. 51 func (h *ModHelper) Apps() ([]string, error) 52 type ModManager interface { 53 AddItem(moduleName, itemName string) error 54 AddDependency(itemName, dependencyName, resolver string, update bool) error 55 DeleteItem(itemName string) error 56 DeleteDependency(itemName, dependencyName string) error 57 ReadAll() (ModReader, error) 58 SetLogger(logger Logger) 59 } 60 ModManager describes methods for managing a module. 61 type ModReader interface { 62 Items() map[string][][]string 63 Dependency(itemName, dependencyName string) string 64 } 65 ModReader describes methods for getting module attributes. 66 type SmartBuilder struct { 67 Builder interface{} 68 ModManager ModManager 69 PluginHandshake plugin.HandshakeConfig 70 Logger Logger 71 } 72 SmartBuilder manages modules and builds the application. 73 func (b *SmartBuilder) AddDependency(item, dependency, resolver string, update bool) error 74 AddDependency adds a dependency to the item. 75 func (b *SmartBuilder) AddItem(module, item string) error 76 AddItem adds an item to the module. 77 func (b *SmartBuilder) Build(application string) error 78 Build builds an application using the generated items. 79 func (b *SmartBuilder) Clean(application string) error 80 Clean removes generated/compiled files. 81 func (b *SmartBuilder) DeleteDependency(item, dependency string) error 82 DeleteDependency deletes the dependency from the item. 83 func (b *SmartBuilder) DeleteItem(item string) error 84 DeleteItem deletes the item from the module. 85 func (b *SmartBuilder) Generate(application string) error 86 Generate generates smart builder unit (.sb) using smart application unit. 87 func (b *SmartBuilder) Init() error 88 Init creates a apps.sb module and initialize it with the apps item. If the 89 apps item is exist then do nothing. 90 func (b *SmartBuilder) ReadAll(kind string) (ModReader, error) 91 ReadAll loads modules. 92 func (b *SmartBuilder) Run(application string) error 93 Run runs the application. 94 func (b *SmartBuilder) Version() string 95 Version displays a version of the application. 96 type SmartCreator struct { 97 ModManager ModManager 98 Logger Logger 99 } 100 SmartCreator creates a new application. 101 func (c *SmartCreator) Create(application string) error 102 Create creates an application by generating smart application unit (.sa 103 file). 104 type SmartGenerator struct{} 105 SmartGenerator generates smart builder unit (.sb) using smart application 106 unit. 107 func (b *SmartGenerator) Generate(application string) error 108 Generate generates smart builder unit (.sb) using smart application unit.