Skip to content

Commit 2429728

Browse files
chore: automate set module version
1 parent e0b0ae6 commit 2429728

5 files changed

Lines changed: 71 additions & 4 deletions

File tree

packages/jsActions/mobile-resources-native/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"marketplace": {
1212
"name": "Native Mobile Resources",
1313
"description": "Download this module to access a rich set of widgets and nanoflow actions created for native mobile, including authentication, network, platform, and more. A must-have for native mobile development!",
14-
"minimumMXVersion": "11.12.0",
14+
"minimumMXVersion": "11.12.3",
1515
"marketplaceId": 109513
1616
},
1717
"testProject": {
@@ -51,4 +51,4 @@
5151
"mendix": "11.8.0",
5252
"rimraf": "^6.1.2"
5353
}
54-
}
54+
}

packages/jsActions/nanoflow-actions-native/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"marketplace": {
1212
"name": "Nanoflow Commons",
1313
"description": "The Nanoflow Commons module contains commonly used nanoflow actions that are usable across web, hybrid mobile, and native mobile apps, such as: client activities, geo location, local storage, & more.",
14-
"minimumMXVersion": "11.12.0",
14+
"minimumMXVersion": "11.12.3",
1515
"marketplaceId": 109515
1616
},
1717
"testProject": {
@@ -37,4 +37,4 @@
3737
"@mendix/pluggable-widgets-tools": "*",
3838
"mendix": "11.8.0"
3939
}
40-
}
40+
}

scripts/release/build-mpk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ async function createNativeMobileResourcesModule(): Promise<ArtifactResult> {
126126
log(`Native widget folders found: ${nativeWidgetFolders.length}`);
127127
const moduleInfo = {
128128
...(await getPackageInfo(moduleFolder)),
129+
version: inputs.version,
129130
moduleNameInModeler: "NativeMobileResources",
130131
moduleFolderNameInModeler: "nativemobileresources"
131132
};
@@ -157,6 +158,7 @@ async function createNanoflowCommonsModule(): Promise<ArtifactResult> {
157158
log(`Temp folder: ${tmpFolder}`);
158159
const moduleInfo = {
159160
...(await getPackageInfo(moduleFolder)),
161+
version: inputs.version,
160162
moduleNameInModeler: "NanoflowCommons",
161163
moduleFolderNameInModeler: "nanoflowcommons"
162164
};

scripts/release/module-automation/commons.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ async function cloneRepo(githubUrl, localFolder, branchName) {
219219

220220
async function createMPK(tmpFolder, moduleInfo, excludeFilesRegExp) {
221221
console.log("Creating module MPK..");
222+
// Required lazily: createWidgetRelease.js loads this module under plain node, which
223+
// cannot resolve a .ts file. Only the ts-node entry points reach createMPK.
224+
const { setModuleVersion } = require("./moduleVersion");
225+
await setModuleVersion(tmpFolder, moduleInfo.moduleNameInModeler, moduleInfo.version, moduleInfo.minimumMXVersion);
226+
222227
await createModuleMpkInDocker(
223228
tmpFolder,
224229
moduleInfo.moduleNameInModeler,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { basename, dirname } from "path";
2+
import { exec } from "child_process";
3+
import { readdir } from "fs/promises";
4+
import { join } from "path";
5+
6+
type CommandResult = {
7+
code: number | null;
8+
output: string;
9+
};
10+
11+
function runCommand(command: string, workingDirectory: string): Promise<CommandResult> {
12+
return new Promise(resolve => {
13+
exec(command, { cwd: workingDirectory }, (error, stdout, stderr) => {
14+
const output = `${stdout}${stderr}`.trim();
15+
resolve({ code: error ? (error as unknown as { code?: number }).code ?? 1 : 0, output });
16+
});
17+
});
18+
}
19+
20+
function dockerMxCommand(mendixVersion: string, projectFile: string, mxArguments: string): string {
21+
return (
22+
`docker run -t -v ${dirname(projectFile)}:/source --rm mxbuild:${mendixVersion} ` +
23+
`bash -c "mx ${mxArguments.replace("{project}", `/source/${basename(projectFile)}`)}"`
24+
);
25+
}
26+
27+
async function findProjectFile(projectDir: string): Promise<string> {
28+
const entries = await readdir(projectDir, { withFileTypes: true });
29+
const projectFile = entries.find(entry => entry.isFile() && entry.name.endsWith(".mpr"));
30+
if (!projectFile) {
31+
throw new Error(`No .mpr file found in ${projectDir}`);
32+
}
33+
return join(projectDir, projectFile.name);
34+
}
35+
36+
export async function setModuleVersion(
37+
projectDir: string,
38+
moduleName: string,
39+
version: string,
40+
mendixVersion: string
41+
): Promise<void> {
42+
if (!/^\d+\.\d+\.\d+$/.test(version ?? "")) {
43+
throw new Error(`Cannot set module version: "${version}" is not a SemVer major.minor.patch version`);
44+
}
45+
const projectFile = await findProjectFile(projectDir);
46+
47+
const command = dockerMxCommand(
48+
mendixVersion,
49+
projectFile,
50+
`set-module-version {project} ${moduleName} ${version}`
51+
);
52+
const { code, output } = await runCommand(command, dirname(projectFile));
53+
if (code === 0) {
54+
console.log(`Set module "${moduleName}" version to ${version} via mx set-module-version.`);
55+
} else {
56+
throw new Error(
57+
`Failed to set version ${version} of module "${moduleName}" in ${projectFile}. Error: ${output || "<none>"}`
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)