electron-windows-installer
Version:
Build Windows installers for Electron apps using Squirrel. Works with Gulp!
131 lines (117 loc) • 5.42 kB
JavaScript
// Generated by CoffeeScript 1.10.0
var InstallerFactory, Promise, fs, path, temp, utils,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Promise = require('bluebird');
fs = require('fs-extra');
path = require('path');
temp = require('temp');
utils = require('./utils');
InstallerFactory = (function() {
function InstallerFactory(opts) {
this.renameSetupFile = bind(this.renameSetupFile, this);
this.packRelease = bind(this.packRelease, this);
this.syncReleases = bind(this.syncReleases, this);
var appMetadata;
if (!opts.appDirectory) {
throw new Error('Please provide the "appDirectory" config parameter.');
}
appMetadata = utils.getPackageJson(opts.appDirectory);
this.appDirectory = opts.appDirectory;
this.outputDirectory = path.resolve(opts.outputDirectory || 'installer');
this.loadingGif = opts.loadingGif ? path.resolve(opts.loadingGif) : path.resolve(__dirname, '..', 'resources', 'install-spinner.gif');
this.authors = opts.authors || appMetadata.author || '';
this.owners = opts.owners || this.authors;
this.copyright = opts.copyright || ("Copyright © " + (new Date().getFullYear()) + " " + (this.authors || this.owners));
this.name = appMetadata.name;
this.productName = appMetadata.productName || this.name;
this.exe = opts.exe || this.productName + '.exe';
this.setupExe = opts.setupExe || this.productName + 'Setup.exe';
this.setupMsi = opts.setupMsi || this.productName + 'Setup.msi';
this.iconUrl = opts.iconUrl || '';
this.description = opts.description || appMetadata.description || '';
this.version = utils.convertVersion(opts.version || appMetadata.version || '');
this.title = opts.title || this.productName || this.name;
this.certificateFile = opts.certificateFile;
this.certificatePassword = opts.certificatePassword;
this.signWithParams = opts.signWithParams;
this.setupIcon = opts.setupIcon;
this.remoteReleases = opts.remoteReleases && opts.remoteReleases.replace('.git', '');
this.noMsi = opts.noMsi;
this.arch = opts.arch || process.arch;
this.name = utils.escapeEntities(this.name);
this.title = utils.escapeEntities(this.title);
this.version = utils.escapeEntities(this.version);
this.authors = utils.escapeEntities(this.authors);
this.owners = utils.escapeEntities(this.owners);
this.iconUrl = utils.escapeEntities(this.iconUrl);
this.description = utils.escapeEntities(this.description);
this.copyright = utils.escapeEntities(this.copyright);
this.exe = utils.escapeEntities(this.exe);
if (!this.authors) {
throw new Error('Authors required: set "authors" in options or "author" in package.json');
}
}
InstallerFactory.prototype.syncReleases = function() {
var args, cmd;
if (this.remoteReleases) {
cmd = path.resolve(__dirname, '..', 'vendor', 'SyncReleases.exe');
args = ['-u', this.remoteReleases, '-r', this.outputDirectory];
return utils.exec(cmd, args);
} else {
return Promise.resolve();
}
};
InstallerFactory.prototype.packRelease = function() {
var args, cmd, nupkgPath;
nupkgPath = path.join(this.nugetOutput, this.name + "." + this.version + ".nupkg");
cmd = path.resolve(__dirname, '..', 'vendor', 'Squirrel.exe');
args = ['--releasify', nupkgPath, '--releaseDir', this.outputDirectory, '--loadingGif', this.loadingGif];
if (this.signWithParams) {
args.push('--signWithParams');
args.push(this.signWithParams);
} else if (this.certificateFile && this.certificatePassword) {
args.push('--signWithParams');
args.push("/a\ /f\ " + this.certificateFile + "\ /p\ " + this.certificatePassword);
}
if (this.noMsi) {
args.push('--no-msi');
}
if (this.setupIcon) {
args.push('--setupIcon');
args.push(path.resolve(this.setupIcon));
}
return utils.exec(cmd, args);
};
InstallerFactory.prototype.renameSetupFile = function() {
var newSetupMsiPath, newSetupPath, oldSetupMsiPath, oldSetupPath;
oldSetupPath = path.join(this.outputDirectory, 'Setup.exe');
newSetupPath = path.join(this.outputDirectory, this.setupExe);
oldSetupMsiPath = path.join(this.outputDirectory, 'Setup.msi');
newSetupMsiPath = path.join(this.outputDirectory, this.setupMsi);
fs.renameSync(oldSetupPath, newSetupPath);
if (fs.existsSync(oldSetupMsiPath)) {
fs.renameSync(oldSetupMsiPath, newSetupMsiPath);
}
return Promise.resolve();
};
InstallerFactory.prototype.createInstaller = function() {
var args, cmd, targetNuspecPath;
temp.track();
this.nugetOutput = temp.mkdirSync('squirrel-installer-');
targetNuspecPath = path.join(this.nugetOutput, this.name + '.nuspec');
fs.writeFileSync(targetNuspecPath, utils.getNuSpec(this));
cmd = path.resolve(__dirname, '..', 'vendor', 'nuget.exe');
args = ['pack', targetNuspecPath, '-BasePath', path.resolve(this.appDirectory), '-OutputDirectory', this.nugetOutput, '-NoDefaultExcludes'];
return utils.exec(cmd, args).then(this.syncReleases).then(this.packRelease).then(this.renameSetupFile);
};
return InstallerFactory;
})();
module.exports = function(opts) {
var error, error1;
try {
return new InstallerFactory(opts).createInstaller();
} catch (error1) {
error = error1;
return Promise.reject(error);
}
};