Skip to content

Commit

Permalink
Improve instructions and tested on windows 11
Browse files Browse the repository at this point in the history
  • Loading branch information
xiwenc committed Mar 26, 2024
1 parent 806e33c commit 539d9b3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 69 deletions.
60 changes: 9 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,19 @@ See each Mendix document/object as a separate file in the output directory. And

## pre-commit hook setup

> As of this writing, Mendix Studio Pro does not support Git hooks. You can use the following workaround to automatically export your Mendix model to Yaml before each commit. Make sure you have git-bash installed on your system. Download it from [here](https://git-scm.com/download/win).
> As of this writing, Mendix Studio Pro does not support Git hooks. You can use the following workaround to automatically export your Mendix model to Yaml before each commit. Make sure you have git-bash installed on your system. It is already present if you use Mendix 10. If you don't have it, download from [here](https://git-scm.com/download/win).
After you open your `git` project in Mendix Studio Pro, navigate to the root of the project. Create a new file named `.git/hooks/pre-commit` and add the following content:

```bash
#!/bin/sh

# Program name and download URL
PROGRAM_NAME="mendix-model-exporter"
## might need to change the version. See for latest version at https://github.com/cinaq/mendix-model-exporter/releases
VERSION="v1.0.0"

# Path to the program in the hooks directory
PROGRAM_PATH="$(dirname $0)/$PROGRAM_NAME"

# Check if the program exists, download it if it does not
if [ ! -f "$PROGRAM_PATH" ]; then
echo "Program not found, downloading..."
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m | tr '[:upper:]' '[:lower:]')"
if [ "$OS" = "windows" ]; then
EXT=".exe"
else
EXT=""
fi
if [ "$ARCH" = "aarch64" ]; then
ARCH="arm64"
fi
DOWNLOAD_URL="https://github.com/cinaq/mendix-model-exporter/releases/download/$VERSION/mendix-model-exporter-$VERSION-$OS-$ARCH$EXT"
curl -L -sf "$DOWNLOAD_URL" -o "$PROGRAM_PATH"
chmod +x "$PROGRAM_PATH"
fi

# Execute the program
"$PROGRAM_PATH"

# Check program execution result
if [ $? -ne 0 ]; then
echo "Program failed, aborting commit."
exit 1
fi

# Automatically stage changes made by your program
git add modelsource

# Exit with 0 to continue the commit process
exit 0
```

Set the executable bit on the file:
Open git-bash inside of your project directory (use `cd Mendix/project-name` if needed) and run the following commands:

```bash
curl https://github.com/cinaq/mendix-model-exporter/raw/main/pre-commit -o .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

# try it out
.git/hooks/pre-commit
```

Now whenever you commit using git-bash, the Mendix model will be exported to Yaml before the commit. The changes will be staged automatically.
Now whenever you commit using git-bash, the Mendix model will be exported to Yaml before the commit. The changes will be included automatically.

## Contribute

Expand All @@ -91,8 +48,9 @@ make test
## TODO

- [x] Export Mendix model to Yaml
- [x] Improve output human readability
- [ ] Expand test coverage
- [ ] Support incremental changes
- [ ] Improve performance for large models
- [ ] Improve error handling
- [ ] Improve output human readability
- [ ] Transform flows (activities, decisions, etc.) to pseudo code
1 change: 0 additions & 1 deletion cmd/mendix-model-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/cinaq/mendix-model-exporter/mpr"
_ "github.com/mattn/go-sqlite3"
"github.com/sirupsen/logrus"
)

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ go 1.22.0

require (
github.com/ghodss/yaml v1.0.0
github.com/mattn/go-sqlite3 v1.14.22
github.com/glebarez/go-sqlite v1.22.0
github.com/sirupsen/logrus v1.9.3
go.mongodb.org/mongo-driver v1.14.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ github.com/glebarez/go-sqlite v1.22.0 h1:uAcMJhaA6r3LHMTFgP0SifzgXg46yJkgxqyuyec
github.com/glebarez/go-sqlite v1.22.0/go.mod h1:PlBIdHe0+aUEFn+r2/uthrWq4FxbzugL0L8Li6yQJbc=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
Expand All @@ -26,7 +26,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
Expand Down
16 changes: 9 additions & 7 deletions mpr/mpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@ import (
"reflect"

"github.com/ghodss/yaml"
_ "github.com/mattn/go-sqlite3"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"

_ "github.com/glebarez/go-sqlite"
)

func ExportMetadata(MPRFilePath string, outputDirectory string) error {
db, err := sql.Open("sqlite3", MPRFilePath)

db, err := sql.Open("sqlite", MPRFilePath)
if err != nil {
return fmt.Errorf("error opening database: %v", err)
return err
}
defer db.Close()

log.Debugf("Exporting metadata")
rows, err := db.Query("SELECT _ProductVersion, _BuildVersion FROM _MetaData")
if err != nil {
return fmt.Errorf("error querying metadata: %v", err)
return fmt.Errorf("error querying units: %v", err)
}

log.Debugf("Exporting metadata")
defer rows.Close()

if !rows.Next() {
return fmt.Errorf("no metadata found")
}

log.Debugf("Reading metadata")
var productVersion, buildVersion string
if err := rows.Scan(&productVersion, &buildVersion); err != nil {
return fmt.Errorf("error scanning metadata: %v", err)
Expand Down Expand Up @@ -215,7 +217,7 @@ func getMxDocuments(units []MxUnit, folders []MxFolder) ([]MxDocument, error) {
}

func exportUnits(MPRFilePath string, outputDirectory string) error {
db, err := sql.Open("sqlite3", MPRFilePath)
db, err := sql.Open("sqlite", MPRFilePath)
if err != nil {
return fmt.Errorf("error opening database: %v", err)
}
Expand Down
4 changes: 0 additions & 4 deletions mpr/types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package mpr

import (
_ "github.com/mattn/go-sqlite3"
)

type MxMetadata struct {
ProductVersion string `yaml:"ProductVersion"`
BuildVersion string `yaml:"BuildVersion"`
Expand Down
1 change: 0 additions & 1 deletion mpr/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mpr

import (
_ "github.com/mattn/go-sqlite3"
"github.com/sirupsen/logrus"
)

Expand Down

0 comments on commit 539d9b3

Please sign in to comment.