Override app version and name when loading apps from default_app.

Fixes #346.
This commit is contained in:
Cheng Zhao 2014-05-24 11:18:06 +08:00
Родитель 3d2464c30e
Коммит 393d61b362
3 изменённых файлов: 19 добавлений и 3 удалений

Просмотреть файл

@ -1,5 +1,6 @@
var app = require('app');
var dialog = require('dialog');
var fs = require('fs');
var path = require('path');
var optimist = require('optimist');
@ -15,7 +16,21 @@ var argv = optimist(process.argv.slice(1)).boolean('ci').argv;
// start the default app.
if (argv._.length > 0) {
try {
require(path.resolve(argv._[0]));
// Override app name and version.
var packagePath = path.resolve(argv._[0]);
var packageJsonPath = path.join(packagePath, 'package.json');
if (fs.existsSync(packageJsonPath)) {
var packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
if (packageJson.version)
app.setVersion(packageJson.version);
if (packageJson.productName)
app.setName(packageJson.productName);
else if (packageJson.name)
app.setName(packageJson.name);
}
// Run the app.
require(packagePath);
} catch(e) {
if (e.code == 'MODULE_NOT_FOUND') {
app.focus();

Просмотреть файл

@ -15,11 +15,11 @@ describe 'app module', ->
describe 'app.getName()', ->
it 'returns the name field of package.json', ->
assert.equal app.getName(), 'Atom Shell Default App'
assert.equal app.getName(), 'Atom Shell Test App'
describe 'app.setName(name)', ->
it 'overrides the name', ->
assert.equal app.getName(), 'Atom Shell Default App'
assert.equal app.getName(), 'Atom Shell Test App'
app.setName 'test-name'
assert.equal app.getName(), 'test-name'
app.setName 'Atom Shell Default App'

Просмотреть файл

@ -1,5 +1,6 @@
{
"name": "atom-shell-specs",
"productName": "Atom Shell Test App",
"main": "static/main.js",
"version": "0.1.0",