summaryrefslogtreecommitdiff
path: root/build/windows/build-installer.js
blob: e6199728af035ff6542c411d55b0b6ae72b41fe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// This script was started by copying MonoDevelop's, available at 
// https://github.com/mono/monodevelop/tree/master/setup/WixSetup

// HEAT manual: http://wix.sourceforge.net/manual-wix3/heat.htm

var bin = '..\\..\\bin';
var sh = new ActiveXObject("WScript.Shell");
var fs = new ActiveXObject("Scripting.FileSystemObject");
var env = sh.Environment("Process");
var heat = "\"" + env("WIX") + "bin\\heat.exe\"";

// Look for msbuild.exe
if (fs.FileExists (env("windir") + "\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe") == 1) {
  var msbuild = env("windir") + "\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe"
} else if (fs.FileExists(env("windir") + "\\Microsoft.NET\\Framework\\v3.5\\msbuild.exe") == 1) {
  var msbuild = env("windir") + "\\Microsoft.NET\\Framework\\v3.5\\msbuild.exe"
} else {
  WScript.Echo ('Build failed: Microsoft.NET MSBuild \(msbuild.exe\) not found');
  WScript.Quit (1);
}

// Could build Banshee from here, but atm at least I prefer to assume it's already built
//build ("..\\..\\Banshee.sln");

// Delete some files that might be created by running uninstalled
if (fs.FileExists (bin + "\\bin\\registry.bin")) fs.DeleteFile (bin + "\\bin\\registry.bin");
if (fs.FolderExists (bin + "\\bin\\addin-db-001")) fs.DeleteFolder (bin + "\\bin\\addin-db-001");

// We can't just heat the entire dir b/c it would include the .git/ directory
heatDir ("bin");
heatDir ("etc");
heatDir ("lib");
heatDir ("share");

// Create the installer, will be outputted to Banshee-1.9.3.msi in build/windows/
build ("Installer.wixproj")
WScript.Echo ("Setup successfully generated");

function heatDir (dir)
{
  var params = ' -cg ' + dir + ' -scom -sreg -ag -sfrag -indent 2 -var var.' + dir + 'Dir -dr INSTALLLOCATION ';
  if (dir == 'bin') {
    // Do not auto-generate ids for files in the bin directory
    params += '-suid '
  }
  // Generate the list of binary files (managed and native .dlls and .pdb and .config files)
  run (heat + ' dir ..\\..\\bin\\' + dir + params + ' -out obj\\generated_'+dir+'.wxi');

  // Heat has no option to output Include (wxi) files instead of Wix (wxs) ones, so do a little regex
  regexreplace ('obj\\generated_'+dir+'.wxi', /Wix xmlns/, 'Include xmlns');
  regexreplace ('obj\\generated_'+dir+'.wxi', /Wix>/, 'Include>');
}

function run (cmd)
{
  if (sh.run (cmd, 5, true) != 0) {
    WScript.Echo ("Failed to run cmd:\n" + cmd);
    WScript.Quit (1);
  }
}

function build (file)
{
  if (sh.run (msbuild + " " + file, 5, true) != 0) {
    WScript.Echo ("Build failed");
    WScript.Quit (1);
  }
}

function regexreplace (file, regex, replacement)
{
  var f = fs.OpenTextFile (file, 1);
  var content = f.ReadAll ();
  f.Close ();
  content = content.replace (regex, replacement);
  f = fs.CreateTextFile (file, true);
  f.Write (content);
  f.Close ();
}