Skip to content

Commit

Permalink
allow running app directly
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed Apr 3, 2014
1 parent b06225c commit b0d35f2
Showing 1 changed file with 67 additions and 3 deletions.
70 changes: 67 additions & 3 deletions lib/index.js
Expand Up @@ -24,7 +24,7 @@ function NwBuilder(options) {
buildDir: './build',
cacheDir: './cache',
downloadUrl: 'https://s3.amazonaws.com/node-webkit/',
buildType: 'default', // timestamped
buildType: 'default', // not timestamped
forceDownload: false,
checkVersions: true,
macCredits: false,
Expand Down Expand Up @@ -105,6 +105,33 @@ NwBuilder.prototype.build = function (callback) {
return hasCallback ? true : done.promise;
};

NwBuilder.prototype.run = function (callback) {
var hasCallback = (typeof callback === 'function'),
done = Promise.defer();

// Run the node Webkit app directly
this.checkFiles().bind(this)
.then(this.checkVersions)
.then(this.downloadNodeWebkit) // Todo: only download node-webkit for the current plattform
.then(this.runApp)
.then(function (info) {
if(hasCallback) {
callback(false, info);
} else {
done.resolve(info);
}
})
.catch(function (error) {
if(hasCallback) {
callback(true, error);
} else {
done.reject(error);
}
});

return hasCallback ? true : done.promise;
};

NwBuilder.prototype.checkFiles = function () {
var self = this;

Expand All @@ -113,7 +140,7 @@ NwBuilder.prototype.checkFiles = function () {
self._appPkg = data.json;
self._files = data.files;

if(!self.options.appName || self.options.appVersion) {
if(!self.options.appName || !self.options.appVersion) {
return Utils.getPackageInfo(self._appPkg).then(function (appPkg) {
self._appPkg = appPkg;
self.options.appName = appPkg.name;
Expand Down Expand Up @@ -143,7 +170,7 @@ NwBuilder.prototype.checkVersions = function (versions) {
}

// log something
self.emit('log', 'Using v' + self._version.version);
self.emit('log', 'Using node-webkit v' + self._version.version);

return self._version;
});
Expand Down Expand Up @@ -303,3 +330,40 @@ NwBuilder.prototype.handleMacApp = function () {
return Promise.all(allDone);

};

NwBuilder.prototype.runApp = function () {
var self = this;

var plattform = {
'darwin': 'osx',
'freebsd': 'linux32', //64?
'linux': 'linux32', //64?
'sunos': 'linux32', //64?
'win32': 'win'
}[process.platform];

var single_plattform = _.findWhere(self._plattforms, {'plattform':plattform});
var executable = single_plattform.files[0];
var executable_path = path.resolve(single_plattform.cache, executable)

var spawn = require('child_process').spawn;

self.emit('log', 'Launching App');

return new Promise(function(resolve, reject) {
var p = spawn(executable_path, [self.options.files.replace(/\*[\/\*]*/,"")]);

p.stdout.on('data', function(data) {
self.emit('stdout', data);
});

p.stderr.on('data', function(data) {
self.emit('stderr', data);
});

p.on('close', function(code) {
self.emit('log', 'App exited with code ' + code);
resolve();
});
});
};

0 comments on commit b0d35f2

Please sign in to comment.