Skip to content

Commit

Permalink
Merge 0fdf524 into 7f2a003
Browse files Browse the repository at this point in the history
  • Loading branch information
markmorris committed Oct 18, 2018
2 parents 7f2a003 + 0fdf524 commit bbb6de4
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 71 deletions.
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -50,7 +50,16 @@ const msiCreator = new MSICreator({
name: 'Kittens',
manufacturer: 'Kitten Technologies',
version: '1.1.2',
outputDirectory: '/path/to/output/folder'
outputDirectory: '/path/to/output/folder',
ui: {
enabled: true,
chooseDirectory: true,
images: {
background: 'path/to/background.jpg',
banner: 'path/to/banner.jpg'
}
},
extensions: ['WixUtilExtension'] // This is required for launch after install
});

// Step 2: Create a .wxs template file
Expand Down
4 changes: 2 additions & 2 deletions __tests__/creator-spec.ts
Expand Up @@ -103,9 +103,9 @@ testIncludes('an ApplicationProgramsFolder', '<Directory Id="ApplicationPrograms
testIncludes('a default appUserModelId', 'Key="System.AppUserModel.ID" Value="com.squirrel.Acme.acme"');

test('.wxs file has as many components as we have files', () => {
// Files + Shortcut
// Files + Shortcut + Desktop Shortcut
const count = wxsContent.split('</Component>').length - 1;
expect(count).toEqual(numberOfFiles + 1);
expect(count).toEqual(numberOfFiles + 2);
});

test('MSICreator create() creates Wix file with UI properties', async () => {
Expand Down
7 changes: 7 additions & 0 deletions src/creator.ts
Expand Up @@ -92,6 +92,7 @@ export class MSICreator {
private directories: Array<string> = [];
private tree: FileFolderTree | undefined;
private components: Array<Component> = [];
private exeComponentID: string = '';

constructor(options: MSICreatorOptions) {
this.appDirectory = path.normalize(options.appDirectory);
Expand Down Expand Up @@ -196,6 +197,7 @@ export class MSICreator {
'{{ApplicationDescription}}': this.description,
'{{ApplicationName}}': this.name,
'{{ApplicationShortcutGuid}}': uuid(),
'{{DesktopShortcutGuid}}': uuid(),
'{{ApplicationShortName}}': this.shortName,
'{{AppUserModelId}}': this.appUserModelId,
'{{Language}}': this.language.toString(10),
Expand All @@ -208,6 +210,7 @@ export class MSICreator {
'{{ProgramFilesFolder}}': this.arch === 'x86' ? 'ProgramFilesFolder' : 'ProgramFiles64Folder',
'{{ProcessorArchitecture}}' : this.arch,
'{{Win64YesNo}}' : this.arch === 'x86' ? 'no' : 'yes',
'{{exeComponentID}}' : this.exeComponentID,
};

const completeTemplate = replaceInString(this.wixTemplate, scaffoldReplacements);
Expand Down Expand Up @@ -443,6 +446,10 @@ export class MSICreator {
'{{SourcePath}}': file.path
});

if (file.name.includes(this.exe)) {
this.exeComponentID = componentId;
}

return { guid, componentId, xml, file };
}

Expand Down
15 changes: 11 additions & 4 deletions src/utils/walker.ts
Expand Up @@ -22,10 +22,17 @@ export function getDirectoryStructure(root: string): Promise <{ files: Array<str
// testing with mock-fs.
klaw(root, { fs: gfs })
.on('data', (item) => {
if (item.stats.isFile()) {
files.push(item.path);
} else if (item.stats.isDirectory() && item.path !== root) {
directories.push(item.path);
if (item.path.includes('.asar') && !item.path.includes('.asar.unpacked')) {
const itemPath = item.path.substring(0, (item.path.indexOf('.asar')) + 5);
if (!files.includes(itemPath)) {
files.push(itemPath);
}
} else {
if (item.stats.isFile()) {
files.push(item.path);
} else if (item.stats.isDirectory() && item.path !== root) {
directories.push(item.path);
}
}
})
.on('end', () => resolve({ files, directories }));
Expand Down
4 changes: 4 additions & 0 deletions static/ui-choose-dir.xml
Expand Up @@ -22,6 +22,10 @@
<Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="4"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>

<Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
<Publish Dialog="ExitDialog"
Control="Finish"
Event="DoAction"
Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>

<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg">NOT Installed</Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish>
Expand Down
4 changes: 4 additions & 0 deletions static/ui.xml
Expand Up @@ -14,6 +14,10 @@
<DialogRef Id="UserExit" />

<Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
<Publish Dialog="ExitDialog"
Control="Finish"
Event="DoAction"
Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="EndDialog" Value="Return" Order="2"></Publish>
</UI>
<UIRef Id="WixUI_Common" />
Expand Down
153 changes: 90 additions & 63 deletions static/wix.xml
@@ -1,71 +1,98 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<!-- http://wixtoolset.org/documentation/manual/v3/xsd/wix/product.html -->
<Product Id="*" UpgradeCode="{{UpgradeCode}}"
Name="{{ApplicationName}}"
Version="{{Version}}"
Manufacturer="{{Manufacturer}}"
Language="{{Language}}">
<!-- Only run this installer on Windows 7 or up (or if it's already installed, I guess) -->
<!-- <Condition Message="This application is only supported on Windows 7 or higher.">
<![CDATA[Installed OR (VersionNT >= 601)]]>
</Condition> -->
<!-- http://wixtoolset.org/documentation/manual/v3/xsd/wix/package.html -->
<Package InstallerVersion="405"
Compressed="yes"
InstallScope="perMachine"
Comments="Windows Installer Package"
Platform="{{Platform}}"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
<!-- http://wixtoolset.org/documentation/manual/v3/xsd/wix/product.html -->
<Product Id="*" UpgradeCode="{{UpgradeCode}}"
Name="{{ApplicationName}}"
Version="{{Version}}"
Manufacturer="{{Manufacturer}}"
Language="{{Language}}">
<!-- Only run this installer on Windows 7 or up (or if it's already installed, I guess) -->
<!-- <Condition Message="This application is only supported on Windows 7 or higher.">
<![CDATA[Installed OR (VersionNT >= 601)]]>
</Condition> -->
<!-- http://wixtoolset.org/documentation/manual/v3/xsd/wix/package.html -->
<Package InstallerVersion="405"
Compressed="yes"
InstallScope="perMachine"
Comments="Windows Installer Package"
Platform="{{Platform}}"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>

<!-- Handle Updates -->
<Upgrade Id="{{UpgradeCode}}">
<UpgradeVersion OnlyDetect="no" Property="PREVIOUSFOUND"
Minimum="0.0.0" IncludeMinimum="yes"
Maximum="{{Version}}" IncludeMaximum="no" />
</Upgrade>
<!-- Handle Updates -->
<Upgrade Id="{{UpgradeCode}}">
<UpgradeVersion OnlyDetect="no" Property="PREVIOUSFOUND"
Minimum="0.0.0" IncludeMinimum="yes"
Maximum="{{Version}}" IncludeMaximum="no" />
</Upgrade>

<InstallExecuteSequence>
<RemoveExistingProducts After="InstallInitialize" />
</InstallExecuteSequence>
<InstallExecuteSequence>
<RemoveExistingProducts After="InstallInitialize" />
</InstallExecuteSequence>

<!-- {{UI}} -->
<!-- {{UI}} -->

<!-- Step 2: Add files and directories -->
<Directory Id="TARGETDIR" Name="SourceDir">
<!-- Installation files to %PROGRAMFILES% -->
<Directory Id="{{ProgramFilesFolder}}">
<!-- {{Directories}} -->
</Directory>
<!-- Start Menu -->
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="{{ShortcutFolderName}}"/>
</Directory>
</Directory>
<!-- Step 2: Add files and directories -->
<Directory Id="TARGETDIR" Name="SourceDir">
<!-- Installation files to %PROGRAMFILES% -->
<Directory Id="{{ProgramFilesFolder}}">
<!-- {{Directories}} -->
</Directory>

<!-- Step 3: Add app to Start Menu -->
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="{{ApplicationShortcutGuid}}" Win64='{{Win64YesNo}}'>
<Shortcut Id="ApplicationStartMenuShortcut"
Name="{{ShortcutName}}"
Description="{{ApplicationDescription}}"
Target="[APPLICATIONROOTDIRECTORY]{{ApplicationBinary}}.exe"
WorkingDirectory="APPLICATIONROOTDIRECTORY">
<ShortcutProperty Key="System.AppUserModel.ID" Value="{{AppUserModelId}}" />
</Shortcut>
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
<RegistryValue Root="HKCU"
Key="Software\Microsoft\{{ApplicationShortName}}"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes"/>
</Component>
</DirectoryRef>
<!-- Desktop -->
<Directory Id="DesktopFolder" Name="Desktop" />

<!-- Step 4: Tell WiX to install the files -->
<Feature Id="MainApplication" Title="Main Application" Level="1">
<!-- {{ComponentRefs}} -->
<ComponentRef Id="ApplicationShortcut" />
</Feature>
</Product>
<!-- Start Menu -->
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="{{ShortcutFolderName}}"/>
</Directory>
</Directory>

<!-- Step 3: Add app to Start Menu -->
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="{{ApplicationShortcutGuid}}" Win64='{{Win64YesNo}}'>
<Shortcut Id="ApplicationStartMenuShortcut"
Name="{{ShortcutName}}"
Description="{{ApplicationDescription}}"
Target="[APPLICATIONROOTDIRECTORY]{{ApplicationBinary}}.exe"
WorkingDirectory="APPLICATIONROOTDIRECTORY">
<ShortcutProperty Key="System.AppUserModel.ID" Value="{{AppUserModelId}}" />
</Shortcut>
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
<RegistryValue Root="HKCU"
Key="Software\Microsoft\{{ApplicationShortName}}"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes" />
</Component>
</DirectoryRef>

<DirectoryRef Id="DesktopFolder">
<Component Id="DesktopShortcut" Guid="{{DesktopShortcutGuid}}" >
<Shortcut Id="MyDesktopShortcut"
Name="{{ShortcutName}}"
Description="{{ApplicationDescription}}"
Target="[APPLICATIONROOTDIRECTORY]{{ApplicationBinary}}.exe"
WorkingDirectory="INSTALLFOLDER"/>
<RegistryValue Root="HKCU"
Key="Software\Microsoft\{{ApplicationShortName}}"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes" />
</Component>
</DirectoryRef>

<!-- Step 4: Tell WiX to install the files -->
<Feature Id="MainApplication" Title="Main Application" Level="1">
<!-- {{ComponentRefs}} -->
<ComponentRef Id="ApplicationShortcut" />
<ComponentRef Id="DesktopShortcut" />
</Feature>

<!-- Optional Launch app feature -->
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1"/>
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch {{ApplicationName}}" />
<Property Id="WixShellExecTarget" Value="[#{{exeComponentID}}]" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
</Product>
</Wix>
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -4,7 +4,7 @@
"module": "commonjs",
"moduleResolution": "node",
"lib": [
"es2015"
"es2016"
],
"target": "es2015",
"strict": true,
Expand Down

0 comments on commit bbb6de4

Please sign in to comment.