<commit_before>package haxeshim;

import haxe.Resource;
import js.node.ChildProcess;
import js.Node.*;

using sys.io.File;
using sys.FileSystem;
using haxe.io.Path;
using StringTools;

class PostInstall { 
  
  static var exifier = Resource.getBytes('exify');
  
  static function exify(dir) {
    
    
    for (name in ['haxe', 'haxelib']) {
      var exe = '$dir/$name.exe';
      if (exe.exists() && !'$exe.bak'.exists())
        exe.rename('$exe.bak');
      exe.saveBytes(exifier);
    }
    
    if (!'$dir/CHANGES.txt'.exists())
      '$dir/CHANGES.txt'.saveContent("0: 0\nI'm only here to please FlashDevelop ... which I seem to fail at");
  }
  
  static function main() 
    switch Sys.systemName() {
      case 'Windows':
        for (path in Std.string(ChildProcess.spawnSync('where', ['haxe']).stdout).split('\n').map(StringTools.trim).map(Path.new)) {
          switch path {
            case { ext: 'cmd', dir: npm }:
              
              exify(npm);
              
            case { ext: 'exe', dir: std } if (Lambda.foreach(['CHANGES.txt', 'CONTRIB.txt', 'LICENSE.txt'], function (file) return '$std/$file'.exists())):
              
              exify(std);
              
            default: 
          }
        }
      default:
    }
  
}<commit_msg>Do not overwrite haxe binaries when not installed globally.<commit_after>package haxeshim;

import haxe.Resource;
import js.node.ChildProcess;
import js.Node.*;

using sys.io.File;
using sys.FileSystem;
using haxe.io.Path;
using StringTools;

class PostInstall { 
  
  static var exifier = Resource.getBytes('exify');
  
  static function exify(dir) {
    
    
    for (name in ['haxe', 'haxelib']) {
      var exe = '$dir/$name.exe';
      if (exe.exists() && !'$exe.bak'.exists())
        exe.rename('$exe.bak');
      exe.saveBytes(exifier);
    }
    
    if (!'$dir/CHANGES.txt'.exists())
      '$dir/CHANGES.txt'.saveContent("0: 0\nI'm only here to please FlashDevelop ... which I seem to fail at");
  }
  
  static function main() 
    switch Sys.systemName() {
      case 'Windows' if (!!(untyped process.env["npm_config_global"])): //wohooo \o/
        for (path in Std.string(ChildProcess.spawnSync('where', ['haxe']).stdout).split('\n').map(StringTools.trim).map(Path.new)) {
          switch path {
            case { ext: 'cmd', dir: npm }:
              
              exify(npm);
              
            case { ext: 'exe', dir: std } if (Lambda.foreach(['CHANGES.txt', 'CONTRIB.txt', 'LICENSE.txt'], function (file) return '$std/$file'.exists())):
              
              exify(std);
              
            default: 
          }
        }
      default:
    }
  
}
{'fraction_non_alphanumeric': 0.16, 'fraction_numerical': 0.0014953271028037382, 'mean_word_length': 2.1261682242990654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1753542', 'n_tokens_mistral': 909, 'n_tokens_neox': 865, 'n_words': 191}