Skip to content

Commit

Permalink
Use plain path.join to fix path handling #22
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Mar 8, 2016
1 parent 0d9ff43 commit a361160
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
2,
"always"
],
"no-console": 0
"no-console": 0,
"quotes": [2, "single", "avoid-escape"]
},
"env": {
"es6": true,
Expand Down
14 changes: 7 additions & 7 deletions spec/installer-spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import temp from 'temp';
import jetpack from 'fs-jetpack';
import sfs from 'fs';
import path from 'path';

import { createWindowsInstaller } from '../src/index.js';
import p from '../src/path-helper';

temp.track();

const d = require('debug')('electron-windows-installer:spec');

describe('create-windows-installer task', function() {
beforeEach(async function() {
let updateExePath = p`${__dirname}/fixtures/app/Update.exe`;
let updateExePath = path.join(__dirname, 'fixtures', 'app', 'Update.exe');
if (await jetpack.existsAsync(updateExePath)) {
// NB: Jetpack doesn't have unlink?
sfs.unlinkSync(updateExePath);
Expand All @@ -24,22 +24,22 @@ describe('create-windows-installer task', function() {
let outputDirectory = temp.mkdirSync('ei-');

let options = {
appDirectory: p`${__dirname}/fixtures/app`,
appDirectory: path.join(__dirname, 'fixtures/app'),
outputDirectory: outputDirectory
};

await createWindowsInstaller(options);

d(`Verifying assertions on ${outputDirectory}`);
d(JSON.stringify(sfs.readdirSync(outputDirectory)));
expect(await jetpack.existsAsync(p`${outputDirectory}/myapp-1.0.0-full.nupkg`)).to.be.ok;
expect(await jetpack.existsAsync(p`${outputDirectory}/MyAppSetup.exe`)).to.be.ok;
expect(await jetpack.existsAsync(path.join(outputDirectory, 'myapp-1.0.0-full.nupkg'))).to.be.ok;
expect(await jetpack.existsAsync(path.join(outputDirectory, 'MyAppSetup.exe'))).to.be.ok;

if (process.platform === 'win32') {
expect(await jetpack.existsAsync(p`${outputDirectory}/MyAppSetup.msi`)).to.be.ok;
expect(await jetpack.existsAsync(path.join(outputDirectory, 'MyAppSetup.msi'))).to.be.ok;
}

d('Verifying Update.exe');
expect(await jetpack.existsAsync(p`${__dirname}/fixtures/app/Update.exe`)).to.be.ok;
expect(await jetpack.existsAsync(path.join(__dirname, 'fixtures', 'app', 'Update.exe'))).to.be.ok;
});
});
49 changes: 26 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import path from 'path';
import temp from 'temp';
import jetpack from 'fs-jetpack';
import fs from 'fs';
import p from './path-helper';

const d = require('debug')('electron-windows-installer:main');

Expand Down Expand Up @@ -66,31 +65,33 @@ export async function createWindowsInstaller(options) {
if (process.platform !== 'win32') {
useMono = true;
if (!wineExe || !monoExe) {
throw new Error("You must install both Mono and Wine on non-Windows");
throw new Error('You must install both Mono and Wine on non-Windows');
}

d(`Using Mono: '${monoExe}'`);
d(`Using Wine: '${wineExe}'`);
}
let { appDirectory, outputDirectory, loadingGif } = options;
outputDirectory = p`${outputDirectory || 'installer'}`;
outputDirectory = path.resolve(outputDirectory || 'installer');

const vendorPath = path.join(__dirname, '..', 'vendor');
await jetpack.copyAsync(
p`${__dirname}/../vendor/Update.exe`,
p`${appDirectory}/Update.exe`,
path.join(vendorPath, 'Update.exe'),
path.join(appDirectory, 'Update.exe'),
{ overwrite: true });

let defaultLoadingGif = p`${__dirname}/../resources/install-spinner.gif`;
loadingGif = loadingGif ? p`${loadingGif}` : defaultLoadingGif;
let defaultLoadingGif = path.join(__dirname, '..', 'resources', 'install-spinner.gif');
loadingGif = loadingGif ? path.resolve(loadingGif) : defaultLoadingGif;

let {certificateFile, certificatePassword, remoteReleases, signWithParams, githubToken} = options;

let appMetadata = null;
let asarFile = p`${appDirectory}/resources/app.asar`;
const appResources = path.join(appDirectory, 'resources');
let asarFile = path.join(appResources, 'app.asar');
if (await jetpack.existsAsync(asarFile)) {
appMetadata = JSON.parse(asar.extractFile(asarFile, 'package.json'));
} else {
appMetadata = JSON.parse(await jetpack.readAsync(p`${appDirectory}/resources/app/package.json`, 'utf8'));
appMetadata = JSON.parse(await jetpack.readAsync(path.join(appResources, 'app', 'package.json'), 'utf8'));
}

let defaults = {
Expand All @@ -115,16 +116,16 @@ export async function createWindowsInstaller(options) {
metadata.copyright = metadata.copyright ||
`Copyright © ${new Date().getFullYear()} ${metadata.authors || metadata.owners}`;

let templateStamper = _.template(await jetpack.readAsync(p`${__dirname}/../template.nuspec`));
let templateStamper = _.template(await jetpack.readAsync(path.join(__dirname, '..', 'template.nuspec')));
let nuspecContent = templateStamper(metadata);

d(`Created NuSpec file:\n${nuspecContent}`);

let nugetOutput = temp.mkdirSync('si');
let targetNuspecPath = p`${nugetOutput}/${metadata.name}.nuspec`;
let targetNuspecPath = path.join(nugetOutput, metadata.name + '.nuspec');
await jetpack.writeAsync(targetNuspecPath, nuspecContent);

let cmd = p`${__dirname}/../vendor/nuget.exe`;
let cmd = path.join(vendorPath, 'nuget.exe');
let args = [
'pack', targetNuspecPath,
'-BasePath', appDirectory,
Expand All @@ -139,10 +140,10 @@ export async function createWindowsInstaller(options) {

// Call NuGet to create our package
d(await spawn(cmd, args));
let nupkgPath = p`${nugetOutput}/${metadata.name}.${metadata.version}.nupkg`;
let nupkgPath = path.join(nugetOutput, `${metadata.name}.${metadata.version}.nupkg`);

if (remoteReleases) {
cmd = p`${__dirname}/../vendor/SyncReleases.exe`;
cmd = path.join(vendorPath, 'SyncReleases.exe');
args = ['-u', remoteReleases, '-r', outputDirectory];

if (useMono) {
Expand All @@ -157,15 +158,15 @@ export async function createWindowsInstaller(options) {
d(await spawn(cmd, args));
}

cmd = p`${__dirname}/../vendor/Update.com`;
cmd = path.join(vendorPath, 'Update.com');
args = [
'--releasify', nupkgPath,
'--releaseDir', outputDirectory,
'--loadingGif', loadingGif
];

if (useMono) {
args.unshift(p`${__dirname}/../vendor/Update-Mono.exe`);
args.unshift(path.join(vendorPath, 'Update-Mono.exe'));
cmd = monoExe;
}

Expand All @@ -178,7 +179,7 @@ export async function createWindowsInstaller(options) {
}

if (options.setupIcon) {
let setupIconPath = p`${options.setupIcon}`;
let setupIconPath = path.resolve(options.setupIcon);
args.push('--setupIcon');
args.push(setupIconPath);
}
Expand All @@ -191,16 +192,18 @@ export async function createWindowsInstaller(options) {

if (metadata.productName) {
d('Fixing up paths');
let setupPath = p`${outputDirectory}/${metadata.productName}Setup.exe`;
let setupMsiPath = p`${outputDirectory}/${metadata.productName}Setup.msi`;
const setupPath = path.join(outputDirectory, `${metadata.productName}Setup.exe`);
const setupMsiPath = path.join(outputDirectory, `${metadata.productName}Setup.msi`);

// NB: When you give jetpack two absolute paths, it acts as if './' is appended
// to the target and mkdirps the entire path
d(`Renaming ${outputDirectory}/Setup.exe => ${setupPath}`);
fs.renameSync(p`${outputDirectory}/Setup.exe`, setupPath);
const unfixedSetupPath = path.join(outputDirectory, 'Setup.exe');
d(`Renaming ${unfixedSetupPath} => ${setupPath}`);
fs.renameSync(unfixedSetupPath, setupPath);

if (jetpack.exists(p`${outputDirectory}/Setup.msi`)) {
fs.renameSync(p`${outputDirectory}/Setup.msi`, setupMsiPath);
const msiPath = path.join(outputDirectory, 'Setup.msi');
if (jetpack.exists(msiPath)) {
fs.renameSync(msiPath, setupMsiPath);
}
}
}
13 changes: 0 additions & 13 deletions src/path-helper.js

This file was deleted.

0 comments on commit a361160

Please sign in to comment.