Remove Version requirment from mod folder names

Things that we aren't going to implement
eduran
Filter Inserter
Filter Inserter
Posts: 261
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Allow uncompressed mod folders without version

Post by eduran » Mon Apr 15, 2019 2:14 pm

danielbrauer wrote:
Sat Apr 13, 2019 12:22 pm
Like many modders, I'm using git to version my work. This works nicely except when I have to bump the version number. The process is:
  • Close the VSCode workspace
  • Close the repo in SourceTree
  • Rename the folder
  • Open the workspace again
  • Change the info file to match
  • Open the repo again
  • Commit
If Factorio allowed mod folders without a version number (as a special case: it should still check that they match if they're there), the process would look like this:
  • Change the info file
  • Commit
Ooh, that would be so satisfying...
Your git repo resides inside the Factorio mod folder? No offense, but that is a bad idea. What if Factorio decides to remove the mod (say because your little brother clicked the delete mod button)? Hope your remote repo is up-to-date...
Instead, have your repo in a separate location and use a deploy script and/or symlinks. It is a bit more work to get going, but worth the effort. You will never have to worry about folder names again. If you are on windows, I can share my powershell script if you are interested.

mrvn
Smart Inserter
Smart Inserter
Posts: 3085
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Allow uncompressed mod folders without version

Post by mrvn » Mon Apr 15, 2019 3:03 pm

eduran wrote:
Mon Apr 15, 2019 2:14 pm
danielbrauer wrote:
Sat Apr 13, 2019 12:22 pm
Like many modders, I'm using git to version my work. This works nicely except when I have to bump the version number. The process is:
  • Close the VSCode workspace
  • Close the repo in SourceTree
  • Rename the folder
  • Open the workspace again
  • Change the info file to match
  • Open the repo again
  • Commit
If Factorio allowed mod folders without a version number (as a special case: it should still check that they match if they're there), the process would look like this:
  • Change the info file
  • Commit
Ooh, that would be so satisfying...
Your git repo resides inside the Factorio mod folder? No offense, but that is a bad idea. What if Factorio decides to remove the mod (say because your little brother clicked the delete mod button)? Hope your remote repo is up-to-date...
Instead, have your repo in a separate location and use a deploy script and/or symlinks. It is a bit more work to get going, but worth the effort. You will never have to worry about folder names again. If you are on windows, I can share my powershell script if you are interested.
Up until recently if you had a symlink then factorio would delete the git repository you link to.

What I do at the moment is "cd mods; git clone ../../MyMod MyMod-0.0.1". Then I can pull and push and if I loose the clone nothing big is lost.

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Allow uncompressed mod folders without version

Post by danielbrauer » Mon Apr 15, 2019 3:31 pm

eduran wrote:
Mon Apr 15, 2019 2:14 pm
Your git repo resides inside the Factorio mod folder? No offense, but that is a bad idea. What if Factorio decides to remove the mod (say because your little brother clicked the delete mod button)? Hope your remote repo is up-to-date...
Instead, have your repo in a separate location and use a deploy script and/or symlinks. It is a bit more work to get going, but worth the effort. You will never have to worry about folder names again. If you are on windows, I can share my powershell script if you are interested.
Thanks! I’m on macOS but I’d like to see your scripts anyway.

The symlink still needs to be renamed, right? Have you automated that?

eduran
Filter Inserter
Filter Inserter
Posts: 261
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Remove Version requirment from mod folder names

Post by eduran » Mon Apr 15, 2019 4:25 pm

danielbrauer wrote:
Mon Apr 15, 2019 3:31 pm
The symlink still needs to be renamed, right? Have you automated that?
Yes, it would need to be renamed. I am not using symlinks, but copying the dev folder. This is the powershell script I am using:

Code: Select all

param(
	[string]$version,      # defaults to version specified in info.json
	[switch]$zip = $false, # creates zip archive instead of directory
	[string]$mod_folder = "C:\Users\edura\AppData\Roaming\Factorio\mods\"
)
$ErrorActionPreference = "Stop"
# Current folder is assumed to be mod root folder
$dev_folder = (Get-Location).tostring() 
$info_file = $dev_folder + "\info.json"

if (Test-Path -Path $info_file){
	# find name
	$regex = '"name": "(\w*)"'
	Get-Content $info_file | Where-Object {$_ -Match $regex}
	$mod_name = $Matches[1]

	if(!($version)){
		# find version
		$regex = '"version": "([^"]+)'
		Get-Content $info_file | Where-Object {$_ -Match $regex}
		$version = $Matches[1]
	}
	else{
		# replace version
		$regex = '(?<="version": ")[^"]*'
		(Get-Content $info_file) -replace $regex, $version | Set-Content $info_file
	}
	# build destination path
	$destination = $mod_folder + $mod_name + "_" + $version + "\"
	
	# this section deletes all other versions of the mod (zipped and unzipped) in $mod_folder
	$fileNames = Get-ChildItem -Path $mod_folder -Recurse -Include ($mod_name + "*")
	"Deleting files: " + $fileNames
	foreach ($f in $fileNames){
		if(Test-Path -Path $f){Remove-Item $f -Recurse -force}
	}
	
	"Copying files from " + $dev_folder
	"to " + $destination
	
	# copy files, exclude some files and folder
	$excludeFiles = @(".gitignore", "*.md")
	$excludeFolders = @(".git", ".vscode")
	New-Item -ItemType directory -Path $destination | out-null
	[regex] $excludeRegEx = '(?i)' + (($excludeFolders |foreach {[regex]::escape($_)}) -join "|") + ''
	Get-ChildItem -Path $dev_folder -Recurse -Exclude $excludeFiles | 
	  where { $excludeFolders -eq $null -or $_.FullName.Replace($dev_folder, "") -notmatch $excludeRegEx } | 
		  Copy-Item -Destination {
			  Join-Path $destination $_.FullName.Substring($dev_folder.length)
		   } -Force -Exclude $excludeFiles

	
	# create zip file if requested
	if ($zip) {
		$zip_file = $mod_folder + "\" + $mod_name + "_" + $version + ".zip"
		Compress-Archive -Path $destination -DestinationPath $zip_file		
		}
}else{"info.json not found."}
It could be simplified if you don't care about exluding files/folder. And a bash script would probably do the same with half of the code.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2030
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Remove Version requirment from mod folder names

Post by Optera » Mon Apr 15, 2019 5:06 pm

With VSCode I moved all my projects outside the factorio mod folder and use a script to read current version from info.json and update directory junctions into factorio mods folder.

tasks.json

Code: Select all

    "tasks": [
        {
            "label": "mklink",
            "type": "shell",
            "command": "powershell",
            "args": [
                "-ExecutionPolicy",
                "Unrestricted",
                "-NoProfile",
                "-File",
                "${workspaceFolder}\\..\\makelink.ps1"
            ],
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
makelink.ps1

Code: Select all

$source_path = (Get-Item -Path ".\").FullName

$mod_name = (Get-Content 'info.json' | ConvertFrom-Json).name
$mod_version = (Get-Content 'info.json' | ConvertFrom-Json).version
$factorio_version = (Get-Content 'info.json' | ConvertFrom-Json).factorio_version
$factorio_mod_path = "D:/Factorio_$factorio_version/mods - dev/"
$dest_path = $factorio_mod_path + $mod_name + "_" + $mod_version

#remove existing version(s)
 Get-ChildItem  $factorio_mod_path | Where{$_.Name -Match $mod_name + "_\d*\.\d*\.\d*"} | Remove-Item -Force

cmd /c mklink /J $dest_path $source_path
Running build will remove old junction(s) and directories and place an updated one.

Post Reply

Return to “Won't implement”

Who is online

Users browsing this forum: No registered users