I’m not 100% sure if this will work but you could make a plugin that implements an EditorExportPlugin implementing the callback EditorExportPlugin._export_begin() that copies the js file to the path
I tested the following code and seems to work fine:
@tool
extends EditorPlugin
var export_plugin:ExportPlugin
func _enter_tree() -> void:
export_plugin = ExportPlugin.new()
add_export_plugin(export_plugin)
func _exit_tree() -> void:
if is_instance_valid(export_plugin):
remove_export_plugin(export_plugin)
export_plugin = null
class ExportPlugin extends EditorExportPlugin:
func _get_name() -> String:
return "My export plugin"
func _export_begin(features: PackedStringArray, is_debug: bool, path: String, flags: int) -> void:
print("Export begin")
var dir = DirAccess.open("res://")
if dir:
var err = dir.copy("my_script.js", path.get_base_dir().path_join("my_script.js"))
print("File copied: " + error_string(err))
else:
print("Error opening directory: " + error_string(dir.get_open_error()))