I am not sure if it is possible to generate source code for the entire project. However, you can pass the required model unit(microflow, pages, etc..) to serializeToJs() method that generates the source code for the same.
The below code snippet generates source code for the microflow. You can try retrieving the page model unit and give a try.
async function serializeToJs() {
try {
const client = new MendixPlatformClient();
const moduleName = "MyFirstModule";
const mfName = "IVK_TestSDKFlow";
const app = client.getApp("YOUR-APP-ID");
const workingCopy = await app.createTemporaryWorkingCopy("trunk");
const model = await workingCopy.openModel();
const module = model.findModuleByQualifiedName(moduleName);
const domainModelInterface = model
.allDomainModels()
.filter((dm) => dm.containerAsModule.name === moduleName)[0];
const domainModel = await domainModelInterface.load();
const mfInterface = model
.allMicroflows()
.filter((mf) => mf.qualifiedName === `${moduleName}.${mfName}`)[0];
const mf = await mfInterface.load();
// Redirect generated code to a file.
fs.writeFile(
"autogenerated/model-autogenerated.js",
JavaScriptSerializer.serializeToJs(mf),
(err) => {
if (err) {
console.error(`Exception while writing to a file. ${err}`);
}
}
);
console.log(
`Domain model source code generation for the module ${moduleName} completed.`
);
} catch (error) {
console.log(`error: ${error}`);
}
}
serializeToJs();