Skip to content

Commit

Permalink
introduce mode for export to hide advanced beta features
Browse files Browse the repository at this point in the history
  • Loading branch information
xiwenc committed Jun 7, 2024
1 parent 25df811 commit b8a182c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion cmd/mendix-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {
inputDirectory, _ := cmd.Flags().GetString("input")
outputDirectory, _ := cmd.Flags().GetString("output")
raw, _ := cmd.Flags().GetBool("raw")
mode, _ := cmd.Flags().GetString("mode")
verbose, _ := cmd.Flags().GetBool("verbose")

log := logrus.New()
Expand All @@ -32,12 +33,13 @@ func main() {
}

mpr.SetLogger(log)
mpr.ExportModel(inputDirectory, outputDirectory, raw)
mpr.ExportModel(inputDirectory, outputDirectory, raw, mode)
},
}

cmdExportModel.Flags().StringP("input", "i", ".", "Path to directory or mpr file to export. If it's a directory, all mpr files will be exported")
cmdExportModel.Flags().StringP("output", "o", "modelsource", "Path to directory to write the yaml files. If it doesn't exist, it will be created")
cmdExportModel.Flags().StringP("mode", "m", "basic", "Export mode. Valid options: basic, advanced")
cmdExportModel.Flags().Bool("raw", false, "If set, the output yaml will include all attributes as they are in the model. Otherwise, only the relevant attributes are included. You should never need this. Only useful when you are developing new functionalities for this tool.")
cmdExportModel.Flags().Bool("verbose", false, "Turn on for debug logs")
rootCmd.AddCommand(cmdExportModel)
Expand Down
6 changes: 3 additions & 3 deletions mpr/microflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestMPRMicroflow(t *testing.T) {
t.Run("microflow-simple", func(t *testing.T) {
if err := exportUnits("./../resources/app/App.mpr", "./../tmp", true); err != nil {
if err := exportUnits("./../resources/app/App.mpr", "./../tmp", true, "advanced"); err != nil {
t.Errorf("Failed to export units from MPR file")
}

Expand All @@ -38,7 +38,7 @@ func TestMPRMicroflow(t *testing.T) {
}
})
t.Run("microflow-with-split", func(t *testing.T) {
if err := exportUnits("./../resources/app/App.mpr", "./../tmp", true); err != nil {
if err := exportUnits("./../resources/app/App.mpr", "./../tmp", true, "advanced"); err != nil {
t.Errorf("Failed to export units from MPR file")
}

Expand All @@ -63,7 +63,7 @@ func TestMPRMicroflow(t *testing.T) {
}
})
t.Run("microflow-split-then-merge", func(t *testing.T) {
if err := exportUnits("./../resources/app/App.mpr", "./../tmp", true); err != nil {
if err := exportUnits("./../resources/app/App.mpr", "./../tmp", true, "advanced"); err != nil {
t.Errorf("Failed to export units from MPR file")
}

Expand Down
16 changes: 8 additions & 8 deletions mpr/mpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
_ "github.com/glebarez/go-sqlite"
)

func ExportModel(inputDirectory string, outputDirectory string, raw bool) error {
func ExportModel(inputDirectory string, outputDirectory string, raw bool, mode string) error {
err := filepath.Walk(inputDirectory, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && strings.HasSuffix(info.Name(), ".mpr") {
exportMPR(path, outputDirectory, raw)
exportMPR(path, outputDirectory, raw, mode)
}
return nil
})
Expand Down Expand Up @@ -162,7 +162,7 @@ func getMxDocumentPath(containerID string, folders []MxFolder) string {
return ""
}

func getMxDocuments(units []MxUnit, folders []MxFolder) ([]MxDocument, error) {
func getMxDocuments(units []MxUnit, folders []MxFolder, mode string) ([]MxDocument, error) {
var documents []MxDocument
documentTypes := []string{"ProjectDocuments", "DomainModel", "ModuleSettings", "ModuleSecurity", "Documents"}

Expand All @@ -180,7 +180,7 @@ func getMxDocuments(units []MxUnit, folders []MxFolder) ([]MxDocument, error) {
Path: getMxDocumentPath(unit.ContainerID, folders),
Attributes: unit.Contents,
}
if unit.Contents["$Type"] == "Microflows$Microflow" {
if unit.Contents["$Type"] == "Microflows$Microflow" && mode == "advanced" {
myDocument = transformMicroflow(myDocument)
}
documents = append(documents, myDocument)
Expand Down Expand Up @@ -232,7 +232,7 @@ func getMxUnits(MPRFilePath string) ([]MxUnit, error) {
return units, nil
}

func exportUnits(MPRFilePath string, outputDirectory string, raw bool) error {
func exportUnits(MPRFilePath string, outputDirectory string, raw bool, mode string) error {

units, err := getMxUnits(MPRFilePath)
if err != nil {
Expand All @@ -242,7 +242,7 @@ func exportUnits(MPRFilePath string, outputDirectory string, raw bool) error {
if err != nil {
return fmt.Errorf("error getting folders: %v", err)
}
documents, err := getMxDocuments(units, folders)
documents, err := getMxDocuments(units, folders, mode)
if err != nil {
return fmt.Errorf("error getting documents: %v", err)
}
Expand Down Expand Up @@ -284,13 +284,13 @@ func writeFile(filepath string, contents map[string]interface{}) error {
return nil
}

func exportMPR(MPRFilePath string, outputDirectory string, raw bool) error {
func exportMPR(MPRFilePath string, outputDirectory string, raw bool, mode string) error {
log.Infof("Exporting %s to %s", MPRFilePath, outputDirectory)
if err := exportMetadata(MPRFilePath, outputDirectory); err != nil {
return fmt.Errorf("error exporting metadata: %v", err)
}

if err := exportUnits(MPRFilePath, outputDirectory, raw); err != nil {
if err := exportUnits(MPRFilePath, outputDirectory, raw, mode); err != nil {
return fmt.Errorf("error exporting units: %v", err)
}
log.Infof("Completed %s", MPRFilePath)
Expand Down
2 changes: 1 addition & 1 deletion mpr/mpr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestMPRMetadata(t *testing.T) {

func TestMPRUnits(t *testing.T) {
t.Run("single-mpr", func(t *testing.T) {
if err := exportUnits("./../resources/full-app-v2.mpr", "./../tmp", false); err != nil {
if err := exportUnits("./../resources/full-app-v2.mpr", "./../tmp", false, "basic"); err != nil {
t.Errorf("Failed to export units from MPR file")
}
})
Expand Down

0 comments on commit b8a182c

Please sign in to comment.