Skip to content

Commit 0ce5d76

Browse files
authored
Merge pull request #419 from isleofcode/fix/open-app-xcode
fix(open-app): drops android support, defaults to xcworkspace vs xcproj
2 parents 226d473 + 74b7853 commit 0ce5d76

File tree

2 files changed

+92
-56
lines changed

2 files changed

+92
-56
lines changed

lib/targets/cordova/tasks/open-app.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,57 @@ const Task = require('../../../tasks/-task');
22
const Bash = require('../../../tasks/bash');
33
const Promise = require('rsvp').Promise;
44
const logger = require('../../../utils/logger');
5-
const fs = require('fs');
65

76
const path = require('path');
87
const getOpenCommand = require('../../../utils/open-app-command');
98
const cordovaPath = require('../utils/get-path');
9+
const getConfig = require('../utils/get-config');
10+
const fsUtils = require('../../../utils/fs-utils');
1011

1112
module.exports = Task.extend({
1213
application: undefined,
1314
platform: undefined,
1415
project: undefined,
1516

16-
run() {
17-
let projectPath, open, command;
18-
let cdvPath = cordovaPath(this.project);
19-
20-
if (this.platform === 'ios') {
21-
projectPath = path.join(cdvPath, 'platforms/ios/*.xcodeproj');
22-
} else if (this.platform === 'android') {
23-
let projectFile = path.join(cdvPath, 'platforms/android/.project');
17+
getProjectPath(platform, project) {
18+
let cdvPath = cordovaPath(project);
2419

25-
if (fs.existsSync(projectFile)) {
26-
projectPath = projectFile;
27-
} else {
28-
let docLink = 'http://embercordova.com/pages/cli#open';
20+
if (platform === 'ios') {
21+
return getConfig(project).then((config) => {
22+
let appName = config.widget.name[0];
2923

30-
logger.warn('Can\'t open IDE without a project being created. See ' +
31-
docLink +
32-
'for more info.'
24+
let workspacePath = path.join(
25+
cdvPath,
26+
`platforms/ios/${appName}.xcworkspace`
3327
);
34-
35-
projectPath = path.join(cdvPath, 'platforms/android/');
36-
}
28+
if (fsUtils.existsSync(workspacePath)) {
29+
return Promise.resolve(workspacePath);
30+
} else {
31+
return Promise.resolve(path.join(
32+
cdvPath,
33+
`platforms/ios/${appName}.xcodeproj`
34+
));
35+
}
36+
});
3737
} else {
38-
return Promise.reject(
39-
'The ' + this.platform +
40-
' platform is not supported. Please use \'ios\' or \'android\''
41-
);
38+
return Promise.reject(`Open is not supported for ${platform}`);
4239
}
40+
},
4341

44-
logger.success('Opening app for ' + this.platform);
45-
46-
command = getOpenCommand(projectPath, this.application);
47-
open = new Bash({
48-
command: command,
49-
options: {
50-
cwd: this.project.root
51-
}
52-
});
53-
54-
return open.run();
42+
run() {
43+
let open, command;
44+
45+
return this.getProjectPath(this.platform, this.project)
46+
.then((projectPath) => {
47+
logger.success('Opening app for ' + this.platform);
48+
command = getOpenCommand(projectPath, this.application);
49+
open = new Bash({
50+
command: command,
51+
options: {
52+
cwd: this.project.root
53+
}
54+
});
55+
return open.run();
56+
});
5557
}
5658
});
Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,86 @@
11
var td = require('testdouble');
22
var path = require('path');
33
var BashTask = require('../../../../../lib/tasks/bash');
4-
var OpenAppTask = require('../../../../../lib/targets/cordova/tasks/open-app');
4+
var fsUtils = require('../../../../../lib/utils/fs-utils');
55
var expect = require('../../../../helpers/expect');
66
var openCommand = require('../../../../../lib/utils/open-app-command');
77
var mockProject = require('../../../../fixtures/corber-mock/project');
88
var _merge = require('lodash').merge;
99
var isObject = td.matchers.isA(Object);
1010

11+
var setupOpenTask = function() {
12+
var OpenAppTask = require('../../../../../lib/targets/cordova/tasks/open-app');
13+
return new OpenAppTask(_merge(mockProject, { platform: 'ios' }));
14+
};
15+
1116
describe('Cordova Open App Task', function() {
12-
var bashDouble, openApp, cdvPath;
17+
var cdvPath;
1318

1419
beforeEach(function() {
15-
bashDouble = td.replace(BashTask.prototype, 'runCommand');
1620
cdvPath = path.resolve(
1721
__dirname, '../../../../',
1822
'fixtures',
1923
'corber-mock/corber/cordova'
2024
);
21-
22-
openApp = new OpenAppTask(_merge(mockProject, { platform: 'ios' }));
2325
});
2426

2527
afterEach(function() {
2628
td.reset();
2729
});
2830

29-
it('runs open command for ios', function() {
30-
openApp.run();
31-
var expectedPath = cdvPath + '/platforms/ios/*.xcodeproj';
32-
var expectedCmd = openCommand(expectedPath);
33-
td.verify(bashDouble(expectedCmd, isObject));
31+
it('runs openApp with the path from getProjectPath', function() {
32+
var bashDouble = td.replace(BashTask.prototype, 'runCommand');
33+
34+
var openApp = setupOpenTask();
35+
return openApp.run().then(function() {
36+
var expectedPath = cdvPath + '/platforms/ios/emberCordovaDummyApp.xcodeproj';
37+
var expectedCmd = openCommand(expectedPath);
38+
td.verify(bashDouble(expectedCmd, isObject));
39+
});
3440
});
3541

36-
it('runs open command for Android', function() {
37-
openApp.platform = 'android';
38-
openApp.run();
3942

40-
var expectedPath = cdvPath + '/platforms/android/';
41-
var expectedCmd = openCommand(expectedPath);
42-
td.verify(bashDouble(expectedCmd, isObject));
43-
}),
43+
context('getProjectPath', function() {
44+
it('ios returns xcworkspace if it exists', function() {
45+
td.replace(fsUtils, 'existsSync', function() {
46+
return true;
47+
});
4448

45-
it('outputs an error if no platform is specified', function() {
46-
openApp.platform = 'invalidPlatform';
49+
var openApp = setupOpenTask();
50+
return openApp.getProjectPath('ios', mockProject.project).then(function(projectPath) {
51+
var expectedPath = cdvPath + '/platforms/ios/emberCordovaDummyApp.xcworkspace';
52+
expect(projectPath).to.equal(expectedPath);
53+
});
54+
});
4755

48-
return expect(openApp.run()).to.eventually.be.rejectedWith(
49-
/platform is not supported/
50-
);
56+
it('ios returns xcodeproj if workspace does not exist', function() {
57+
td.replace(fsUtils, 'existsSync', function() {
58+
return false;
59+
});
60+
61+
var openApp = setupOpenTask();
62+
return openApp.getProjectPath('ios', mockProject.project).then(function(projectPath) {
63+
var expectedPath = cdvPath + '/platforms/ios/emberCordovaDummyApp.xcodeproj';
64+
expect(projectPath).to.equal(expectedPath);
65+
});
66+
});
67+
68+
it('rejects for android', function() {
69+
var openApp = setupOpenTask();
70+
openApp.platform = 'android';
71+
72+
return expect(openApp.run()).to.eventually.be.rejectedWith(
73+
/is not supported for android/
74+
);
75+
});
76+
77+
it('rejects if an invalid platform is specified', function() {
78+
var openApp = setupOpenTask();
79+
openApp.platform = 'invalidPlatform';
80+
81+
return expect(openApp.run()).to.eventually.be.rejectedWith(
82+
/is not supported/
83+
);
84+
});
5185
});
5286
});

0 commit comments

Comments
 (0)