Writing an automated build script for MV games

Intro

When working with custom tools (like my Cook Tool) it can be daunting to build the game before publishing. In this tutorial, I’ll show you how to build your own build script so you can automate the chores (and have a custom executable).

Requirements

  • PowerShell 7 or newer
  • Node.js (either LTS or Stable)
  • An MV project

Step 1: Build the exe script

  1. Download Node.js and PowerShell (or type winget install OpenJS.NodeJS and winget install Microsoft.PowerShell, if you have winget installed). If you are using Linux or MacOS, look up if your package manager provides these.
  2. After exporting the game, edit the package.json file and add the “app_name” and “version” tags.
  3. Find a folder that you’ll put the exported project on. The project should be on in a folder inside it.
  4. Create two files: One called buildPackage.ps1 and another called buildExecutable.js
  5. Open the ps1 file. Then write the following:
    Get-ChildItem -Path ‘.\<Game Folder>’ -Exclude “www”, “package.json” | Remove-Item -force -Recurse
    Remove-Item -Path “.\www\package.json”
    node buildExecutable.js
    Important! If you have any folders outside of the www folder (and need to keep), add it to the exclude list.
  6. Save the .ps1 file.
  7. Open the command line (or the terminal) on the folder, then type npm install nw-builder –save-dev.
  8. Once the nw-builder is installed, open the js file and put this script:
var gameName = '<Game Name>';
var gameVersion = '<Game Version>';
var gameTag = '<GameName>';

var NwBuilder = require('nw-builder');
var nw = new NwBuilder({
    files: '<Game Folder>/**', // use the glob format
    flavor: 'normal',
    version: '0.22.0', //Specifies the version of nwjs. Remove this to get the latest version.
    appVersion: gameVersion,
    platforms: ['win64', 'linux64'], //Change this if you want to target more or less platforms
    zip: false, //Only turn this to true. This may affect startup times on Windows
    appName: gameTag,
    winVersionString: {
        'FileVersion': gameVersion,
        'InternalName': gameTag,
        'ProductVersion': gameVersion,
        'CompanyName': '<Dev Name>',
        'FileDescription': gameName,
        'ProductName': '<Game or Series Name>',
        'OriginalFilename': '<GameName>.exe',
        'LegalCopyright': '<Insert copyright here>',
    },
    winIco: "Game.ico" //It should be at the same folder as this script
});

// Log stuff you want
nw.on('log', console.log);

nw.build().then(function () {
    console.log('all done!');
}).catch(function (error) {
    console.error(error);
});

That’s all. Save the file, run PowerShell and then execute the ps1 script (after you navigate to the folder where both scripts live) with .\buildPackage.ps1.

Step 2: Chaining the other tools

In order to get the tools working with the script, it’s a simple line add before or after the js line. In the ps1 script, add this line:

Start-Process <tool executable> -NoNewWindow -PassThru -Wait -Arguments ‘<Arguments for the tool go here>’

Step 3: Customizing and expanding the script

This step is left up to you. PowerShell is pretty powerful and you can do a lot of stuff with it. Want to create a zip file? You can. Want to edit a few files before creating? That too. Take a look at the documentation of PowerShell. Look on some tutorials. Experiment.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.