Automatic build numbering, versioning, and starting

I use vscode and have a terminal window always open in it, and so I can just run the same command over and over again to build and play the game when I make changes.

I also like it to automatically create the pdxinfo file and add versioning and build information.

My project tree has a src/ directory which contains all of the items that will go into the app build. I have separate directories for things like promotional materials and original artwork that `src/images/ is derived from.

in the root of the directory is a file called baseConfig.json that looks like this:

{
  "name": "ElfFactory",
  "author": "Robert Kohr",
  "description": "Help the elves put together Christmas presents to save Christmas",
  "bundleID": "com.robkohr.elffactory",
  "majorVersion": 1,
  "imagePath": "images/gameCard"
}

When it is ready for launch, I change majorVersion from 0 to 1.

I also have a start.js script like so (requires node.js to be installed on the computer):

#!/usr/bin/env node
const { execSync } = require('child_process');
const baseConfig = require('./baseConfig.json');
const fs = require('fs');
const pdxInfoFields = [
  'name',
  'author',
  'description',
  'bundleID',
  'imagePath',
  'version',
  'buildNumber',
];
const config = {};
for (const key in baseConfig) {
  config[key] = baseConfig[key];
}
let date = new Date();
const minorVersion = new Date()
  .toISOString()
  .replaceAll('-', '')
  .replaceAll('T', '')
  .replace(':', '')
  .split(':')[0];
config.buildNumber = Number(minorVersion);
config.version = baseConfig.majorVersion + '.' + minorVersion.substr(0, 8);

let pdxinfo = '';
for (let field of pdxInfoFields) {
  pdxinfo += `${field}=${config[field]}\n`;
}
fs.writeFileSync('src/pdxinfo', pdxinfo);
fs.writeFileSync('src/config.json', JSON.stringify(config, null, 5));

try {
  execSync(
    `rm -rf ${config.name}.pdx.zip; pdc -q ./src ./${config.name}.pdx && open ./${config.name}.pdx/ && zip  -qr ${config.name}.pdx.zip ${config.name}.pdx`
  );
} catch (e) {
  // do nothing. lua errors already go to the console.
}

This does all the work of building, running, and zipping the end result. It also creates a pdxinfo file that looks like this:

name=ElfFactory
author=Robert Kohr
description=Help the elves put together Christmas presents to save Christmas
bundleID=com.robkohr.elffactory
imagePath=images/gameCard
version=1.20221229
buildNumber=202212292025

and a config.json that looks like this:

{
     "name": "ElfFactory",
     "author": "Robert Kohr",
     "description": "Help the elves put together Christmas presents to save Christmas",
     "bundleID": "com.robkohr.elffactory",
     "majorVersion": 1,
     "imagePath": "images/gameCard",
     "buildNumber": 202212292025,
     "version": "1.20221229"
}

Which is handy if the lua code wants to output info about the build.

Note that the config.json is basically everything in baseConfig.json plus anything that went into pdxinfo, so the baseConfig.json can have some extra stuff in it for config.json that isn't relevant to the pdxinfo file.

With this setup, I run chmod a+x ./start.js to make it executable, and from then on I can just run:

./start.js

to build and run the game.

The start.js script is totally generic, so I just copy it into whatever project I am working on, and it grabs the names from the config file. Also, the build and version numbers are always increasing as it is based on the date.

Feel free to use it on your own project if it helps you, and sorry to through in node.js into the mix. It is really what I am most familiar with, but you shouldn't have to make any changes other than installing node.js on your local enviornment.

This should work on mac and linux, and probably windows with some tweaks.

6 Likes