-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from brzpegasus/package-cmd
nw:package command
- Loading branch information
Showing
13 changed files
with
471 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var chalk = require('chalk'); | ||
var NwBuilder = require('node-webkit-builder'); | ||
|
||
module.exports = { | ||
name: 'nw:package', | ||
description: 'Packages your NW.js app', | ||
|
||
availableOptions: [ | ||
{ name: 'environment', type: String, default: 'production', aliases: ['e', { 'dev' : 'development' }, { 'prod' : 'production' }] }, | ||
{ name: 'output-path', type: String, default: 'dist/', aliases: ['o'] }, | ||
{ name: 'config-file', type: String, default: 'config/nw-package.js', aliases: ['f'] } | ||
], | ||
|
||
buildApp: function(options) { | ||
var buildTask = new this.tasks.Build({ | ||
ui: this.ui, | ||
analytics: this.analytics, | ||
project: this.project | ||
}); | ||
|
||
return buildTask.run(options); | ||
}, | ||
|
||
packageApp: function(options) { | ||
var ui = this.ui; | ||
|
||
ui.writeLine(chalk.green('Packaging...')); | ||
|
||
var config = this.nwConfig(options); | ||
var nw = new NwBuilder(config); | ||
nw.on('log', console.log); | ||
|
||
return nw.build().then(function() { | ||
ui.writeLine(chalk.green('Packaged project successfully.')); | ||
}); | ||
}, | ||
|
||
nwConfig: function(options) { | ||
var config = {}; | ||
|
||
var configFile = path.resolve(this.project.root, options.configFile); | ||
if (fs.existsSync(configFile)) { | ||
config = require(configFile); | ||
} | ||
|
||
if (!config.buildDir) { config.buildDir = 'build/app'; } | ||
if (!config.cacheDir) { config.cacheDir = 'build/cache'; } | ||
|
||
if (!config.files) { | ||
config.files = this.nwFiles(options); | ||
} | ||
|
||
if (!config.platforms) { | ||
var detectPlatform = require('../helpers/detect-platform'); | ||
var currentPlatform = detectPlatform(); | ||
if (currentPlatform) { | ||
config.platforms = [currentPlatform]; | ||
} | ||
} | ||
|
||
return config; | ||
}, | ||
|
||
nwFiles: function(options) { | ||
var nwFiles = ['package.json']; | ||
|
||
// Contents of the build output directory | ||
nwFiles.push(options.outputPath.replace(/\/?$/, '/**')); | ||
|
||
// Non-dev NPM modules | ||
var npmModulesRoot = 'node_modules'; | ||
var npmDependencies = this.project.pkg.dependencies || {}; | ||
|
||
Object.keys(npmDependencies).forEach(function(dependency) { | ||
nwFiles.push(npmModulesRoot + '/' + dependency + '/**'); | ||
}); | ||
|
||
return nwFiles; | ||
}, | ||
|
||
run: function(options) { | ||
var _this = this; | ||
|
||
return this.buildApp(options) | ||
.then(function() { | ||
return _this.packageApp(options); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
module.exports = function() { | ||
switch (process.platform) { | ||
case 'darwin': | ||
return process.arch === 'x64' ? 'osx64' : 'osx32'; | ||
|
||
case 'win32': | ||
return (process.arch === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432')) ? 'win64' : 'win32'; | ||
|
||
case 'linux': | ||
return process.arch === 'x64' ? 'linux64' : 'linux32'; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
buildDir: 'build', | ||
cacheDir: 'cache', | ||
files: ['package.json'], | ||
platforms: ['osx64', 'win64'], | ||
appName: 'foo', | ||
appVersion: '0.0.1' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
buildDir: 'build/release', | ||
platforms: ['win64'], | ||
appName: 'bar', | ||
appVersion: '0.0.1' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
var RSVP = require('rsvp'); | ||
|
||
function MockNodeWebkitBuilder(options) { | ||
this.options = options; | ||
} | ||
|
||
module.exports = MockNodeWebkitBuilder; | ||
|
||
MockNodeWebkitBuilder.prototype.on = function() { | ||
}; | ||
|
||
MockNodeWebkitBuilder.prototype.build = function() { | ||
return RSVP.resolve(this.options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
|
||
function MockProject(name, pkg) { | ||
this.name = name; | ||
this.pkg = pkg || {}; | ||
this.root = path.resolve(__dirname, '..', '..', 'fixtures', name); | ||
} | ||
|
||
module.exports = MockProject; | ||
|
||
MockProject.prototype.isEmberCLIProject = function() { | ||
return true; | ||
}; |
Oops, something went wrong.