A quick batch file I use for 'compiling' my mod when testing

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Zillo7
Inserter
Inserter
Posts: 22
Joined: Sun May 14, 2017 10:45 pm
Contact:

A quick batch file I use for 'compiling' my mod when testing

Post by Zillo7 »

I've written this simple batch file that packs the mod I'm working on into a .zip file and moves it into the mod directory before launching factorio. This makes testing a lot faster when I'm fixing bugs. (I'm using 7zip to make the .zip file)

Code: Select all

cd "C:\Program Files\7-Zip"
7z.exe a "C:\Users\USERNAME\Documents\My Games\MYMODSTUFF\MYMOD_0.1.0.zip" "C:\Users\USERNAME\Documents\My Games\MYMODSTUFF\MYMOD_0.1.0"
move "C:\Users\USERNAME\Documents\My Games\MYMODSTUFF\MYMOD_0.1.0.zip" "C:\Users\USERNAME\AppData\Roaming\Factorio\mods"

cd "C:\Program Files (x86)\Steam\steamapps\common\Factorio\bin\x64"
start factorio.exe

malventano
Filter Inserter
Filter Inserter
Posts: 340
Joined: Thu Apr 27, 2017 4:31 pm
Contact:

Re: A quick batch file I use for 'compiling' my mod when testing

Post by malventano »

I'm not sure if you are aware of this, but mods do not need to be zipped. You can have a working copy of a mod in the mods folder - in an extracted state, edit it directly, and then you only have to relaunch Factorio to re-load the changes.
Allyn Malventano
---
Want to improve fluid flow between pumps / across longer distances? Try my Manifolds mod.

User avatar
theRustyKnife
Filter Inserter
Filter Inserter
Posts: 259
Joined: Thu Feb 26, 2015 9:26 pm
Contact:

Re: A quick batch file I use for 'compiling' my mod when testing

Post by theRustyKnife »

Also a useful thing to do is to have a link (junction) in the mods folder into your git repo or whatever you use. This has a couple advantages:
- No need for copying things around to and from the repo
- The path to your working directory is always the same, even between versions (depending on your workflow, this can be really helpful)
- Packaging a new version for release is as simple as renaming the link and zipping it.

Seeing you're on windows, you might find Link Shell Extension helpful for creating the links. What you want to do is right-click on the source and select 'Pick link source' and then right-click in the destination and select 'Drop as' -> 'Junction'.
Hope this is helpful ;).

Cheers TRK

doc
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Mon Mar 28, 2016 3:52 pm
Contact:

Re: A quick batch file I use for 'compiling' my mod when testing

Post by doc »

Personally I use "gulp" (a node.js build system) for this - you can see my gulpfile.js here: https://github.com/chucksellick/factori ... ulpfile.js

Some cool features:
  • Continually watches for file changes, automatically rebuilds every time you change anything
  • Parses the version number and mod name from your info.json, and uses them to correctly name the mod folder. All you normally have to do to increase the version is change info.json and restart Factorio. (Note: occasionally this breaks for some unknown reason, if it stops updating you might need to manually restart gulp. Also if you fall back to an older version number for any reason then unfortunately you will need to manually delete the newer folders for now.)
  • Also detects whether you are on Windows or OSX and locates the mod folder for you. Should be easy to add Unix support too but I never got around to it.
  • Only copies specific file types to your build; I find this really useful so I can have psd sources lying around in my graphics folder but they won't end up bloating the build.
It doesn't yet create the zip for you but I will probably do this at some point, but it doesn't take long to manually zip the mod folder when I want to release.

To use it you need to install node.js: https://nodejs.org/en/

Then fork the repository and clone it. It's MIT license so you can freely redistribute. Delete everything from /src and copy your own mod code in there. Or if you already have a repo, all you should need is gulpfile.js and package.json in the root, and move your entire mod into /src, or edit gulpfile.js to specify a different source folder.

Then in command prompt cd into your project and run:

Code: Select all

npm install
npm install --global gulp-cli
This will install package dependencies into node_modules (add node_modules into your .gitignore if needed, there's no point in pushing all those modules into your repo). The second line installs the gulp client globally. You only need to do this once.

Now to start up the build process:

Code: Select all

gulp
That's it - you have now fully automated your build process!

Please let me know if you have any problems, and do let me know if you're using this for your mod - this might encourage me to add some new features ;) Some things I would like to get around to eventually are:
  • Delete old mod versions when you change info.json
  • Maybe optionally - actually generate most of info.json using properties from package.json
  • Some kind of sprite sheet generator, with automatic code for prototypes
  • Lua syntax checking / linting, maybe even a Lua test runner
  • Some code generators to perform common tasks like adding new entities
  • png crushing
  • And loads of other stuff could be done...

Post Reply

Return to “Modding discussion”