Skip to content

Commit 72b74c0

Browse files
authored
Merge pull request #110 from isleofcode/develop
Develop
2 parents d854431 + a2d1aaf commit 72b74c0

19 files changed

+310
-101
lines changed

blueprints/ember-cordova/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
var CreateTask = require('../../lib/tasks/create-cordova-project');
4-
var VerifyCordovaTask = require('../../lib/tasks/verify-cordova-installed');
54
var camelize = require('../../lib/utils/string.js').camelize;
65

76
module.exports = {
@@ -33,19 +32,13 @@ module.exports = {
3332
afterInstall: function(options) {
3433
var projectName = this.project.name();
3534

36-
var check = new VerifyCordovaTask({
37-
command: 'ember g ember-cordova',
38-
ui: this.ui
39-
});
40-
4135
var create = new CreateTask({
4236
id: options.cordovaid || camelize(projectName),
4337
name: options.name || camelize(projectName),
4438
project: this.project,
4539
ui: this.ui
4640
});
4741

48-
return check.run()
49-
.then(function() { return create.run(); });
42+
return create.run();
5043
}
5144
};

index.js

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

33
var commands = require('./lib/commands');
4-
var cordovaPath = require('./lib/utils/cordova-path');
54
var getNetworkIp = require('./lib/utils/get-network-ip');
5+
var getPlatformAssets = require('./lib/utils/get-platform-assets');
66

7+
var fs = require('fs');
8+
var path = require('path');
79
var chalk = require('chalk');
810
var mergeTrees = require('broccoli-merge-trees');
911
var Funnel = require('broccoli-funnel');
10-
var path = require('path');
11-
var fs = require('fs');
1212

1313
module.exports = {
1414
name: 'ember-cordova',
@@ -42,43 +42,32 @@ module.exports = {
4242
return commands;
4343
},
4444

45-
treeForPublic: function(tree) {
46-
if (this.project.targetIsCordova) {
47-
var platform = this.project.CORDOVA_PLATFORM;
48-
49-
var platformsPath = path.join(cordovaPath(this.project), 'platforms');
50-
var pluginsPath;
45+
cordovaAssetTree: function(tree, assets) {
46+
var pluginsTree = new Funnel(this.treeGenerator(assets.path), {
47+
srcDir: '/',
48+
include: assets.files,
49+
destDir: '/'
50+
});
5151

52-
if (platform === 'ios') {
53-
pluginsPath = path.join(platformsPath, 'ios', 'www');
54-
} else if (platform === 'android') {
55-
pluginsPath = path.join(platformsPath, 'android', 'assets', 'www');
56-
} else if (platform === 'browser') {
57-
pluginsPath = path.join(platformsPath, 'browser', 'www');
58-
}
52+
return mergeTrees([tree, pluginsTree]);
53+
},
5954

60-
var files = ['cordova_plugins.js'];
55+
treeForPublic: function(tree) {
56+
if (this.project.targetIsCordova) {
57+
var platformAssets = getPlatformAssets(this.project);
6158

62-
files.forEach(function (file) {
63-
var filePath = path.join(pluginsPath, file);
64-
if (!fs.existsSync(filePath)) {
65-
var err = new Error('ember-cordova: ' + filePath + ' did not exist. It is required for Device LiveReload to work.');
66-
err.stack = null;
67-
throw err;
68-
}
69-
});
59+
if (platformAssets.path === undefined) {
60+
throw new Error('ember-cordova: Did not receive platform asset path, canot not build');
61+
};
7062

71-
if (fs.existsSync(path.join(pluginsPath, 'plugins'))) {
72-
files.push('plugins/**');
63+
var filePath = path.join(platformAssets.path, 'cordova_plugins.js');
64+
if (!fs.existsSync(filePath)) {
65+
var err = new Error('ember-cordova: cordova_plugins did not exist. It is required for Device LiveReload to work.');
66+
err.stack = null;
67+
throw err;
7368
}
7469

75-
var pluginsTree = new Funnel(this.treeGenerator(pluginsPath), {
76-
srcDir: '/',
77-
include: files,
78-
destDir: '/'
79-
});
80-
81-
return mergeTrees([tree, pluginsTree]);
70+
return this.cordovaAssetTree(tree, platformAssets);
8271
}
8372

8473
return tree;

lib/commands/platform.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ module.exports = {
2626

2727
var platformTask = new CordovaRawTask({
2828
project: this.project,
29-
rawApi: 'platform',
29+
rawApi: 'platforms',
3030
ui: this.ui
3131
});
3232

33-
return platformTask.run(validated.command, validated.args, options.save);
33+
return platformTask.run(validated.command, validated.args, {
34+
save: options.save
35+
});
3436
}
3537
};
3638

lib/commands/plugin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ module.exports = {
2626

2727
var pluginTask = new CordovaRawTask({
2828
project: this.project,
29-
rawApi: 'platform',
29+
rawApi: 'plugins',
3030
ui: this.ui
3131
});
3232

33-
return pluginTask.run(validated.command, validated.args, options.save);
33+
return pluginTask.run(validated.command, validated.args, {
34+
save: options.save
35+
});
3436
}
3537
};
3638

lib/commands/serve.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var CdvBuildTask = require('../tasks/cordova-build');
44
var HookTask = require('../tasks/run-hook');
5+
var BuildTask = require('../tasks/ember-build');
56
var ServeTask = require('../tasks/ember-build-serve');
67
var getPlatform = require('../utils/get-platform');
78

@@ -54,7 +55,7 @@ module.exports = {
5455

5556
run: function(options) {
5657
var hook, serve, cordovaBuild, validateCordovaConfig, validatePlugin,
57-
validatePlatform;
58+
validatePlatform, emberBuild;
5859

5960
var platform = getPlatform(this.project.config(), options);
6061
this.project.CORDOVA_PLATFORM = platform;
@@ -93,6 +94,19 @@ module.exports = {
9394
ui: this.ui
9495
});
9596

97+
/*
98+
TODO - rm me. Serve builds directly to outputPath anyway
99+
This is required to init the cordova-build
100+
101+
cordova-builds can not be run while serve is
102+
*/
103+
emberBuild = new BuildTask({
104+
ui: this.ui,
105+
project: this.project,
106+
environment: options.environment,
107+
outputPath: options.outputPath
108+
});
109+
96110
cordovaBuild = new CdvBuildTask({
97111
project: this.project,
98112
ui: this.ui
@@ -108,19 +122,20 @@ module.exports = {
108122
.then(validatePlatform.prepare())
109123
.then(validatePlugin.prepare())
110124
.then(hook.prepare('beforeBuild'))
125+
.then(emberBuild.prepare())
126+
.then(cordovaBuild.prepare(platform))
127+
.then(hook.prepare('afterBuild'))
111128
.then(this._autoFindLiveReloadPort.bind(this, options))
112129
.then(function(serveOpts) {
113-
var baseURL = this.project.config.baseURL;
114-
if (baseURL === undefined) { baseURL = '/'; }
130+
var config = this.project.config();
115131

116132
_merge(serveOpts, {
117-
baseURL: this.project.config().baseURL,
133+
baseURL: config.baseURL || '/',
134+
rootURL: config.rootURL || '/',
118135
project: this.project
119136
});
120137

121138
return serve.run(serveOpts)
122-
.then(cordovaBuild.prepare(platform))
123-
.then(hook.prepare('afterBuild'))
124139
.then(function() {
125140
this.ui.writeLine(chalk.green(
126141
'ember-cordova: Device LiveReload is enabled'

lib/tasks/cordova-build.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
'use strict';
22

33
var Task = require('./-task');
4-
var Promise = require('ember-cli/lib/ext/promise');
4+
var CordovaRawTask = require('../tasks/cordova-raw');
55

6-
var cordovaRun = require('../utils/cordova-run');
7-
var cordovaBuild = require('cordova-lib/src/cordova/build');
8-
var buildPromise = Promise.denodeify(cordovaBuild);
96

107
module.exports = Task.extend({
118
run: function(platform, release) {
129
var buildType = release ? '--release' : '--debug';
13-
var opts = [{platforms: [platform], options: [buildType]}];
10+
var opts = { platforms: [platform], options: [buildType] };
1411

15-
return cordovaRun(buildPromise, this.project, opts);
12+
var build = new CordovaRawTask({
13+
project: this.project,
14+
rawApi: 'build',
15+
ui: this.ui
16+
});
17+
18+
return build.run(opts);
1619
}
1720
});

lib/tasks/cordova-raw.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
var Task = require('./-task');
44
var cordovaRun = require('../utils/cordova-run');
55
var cordovaProj = require('cordova-lib').cordova;
6+
var easyError = require('../utils/easy-error');
67

7-
var pluginPromise = function() {
8-
return cordovaProj.raw[this.rawApi].apply(this, arguments);
8+
var cordovaRawPromise = function() {
9+
return cordovaProj.raw[this.rawApi].apply(this, arguments)
10+
.catch(function(err) {
11+
easyError('ERROR ember-cordova with cordova raw \n' + err);
12+
});
913
};
1014

1115
module.exports = Task.extend({
12-
run: function(command, pluginNames, save) {
13-
var opts = [command, pluginNames, { save: save }];
14-
15-
return cordovaRun(pluginPromise.bind(this), this.project, opts);
16+
run: function() {
17+
return cordovaRun(cordovaRawPromise.bind(this), this.project, arguments);
1618
}
1719
});

lib/tasks/verify-cordova-installed.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ var cordovaCheckText = '\nYou can check that cordova has been properly ' +
1414

1515
module.exports = Task.extend({
1616
ui: undefined,
17-
command: undefined,
1817
options: undefined,
1918

2019
run: function() {

lib/utils/get-platform-assets.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var path = require('path');
2+
var fs = require('fs');
3+
var cordovaPath = require('./cordova-path');
4+
5+
module.exports = function(project) {
6+
var platform = project.CORDOVA_PLATFORM;
7+
8+
var platformsPath = path.join(cordovaPath(project), 'platforms');
9+
var assetsPath;
10+
11+
if (platform === 'ios') {
12+
assetsPath = path.join(platformsPath, 'ios', 'www');
13+
} else if (platform === 'android') {
14+
assetsPath = path.join(platformsPath, 'android', 'assets', 'www');
15+
} else if (platform === 'browser') {
16+
assetsPath = path.join(platformsPath, 'browser', 'www');
17+
}
18+
19+
var files = ['cordova_plugins.js'];
20+
if (fs.existsSync(path.join(assetsPath, 'plugins'))) {
21+
files.push('plugins/**');
22+
}
23+
24+
return {
25+
path: assetsPath,
26+
files: files
27+
}
28+
};

node-tests/fixtures/ember-cordova-mock/project.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = {
1212
},
1313

1414
project: {
15-
root: path.resolve(__dirname, '..', '..', 'fixtures', 'ember-cordova-mock')
15+
root: path.resolve(__dirname, '..', '..', 'fixtures', 'ember-cordova-mock'),
16+
name: function() { return 'ember-cordova-mock' }
1617
},
1718

1819
config: function() {},

node-tests/unit/blueprint/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const td = require('testdouble');
4+
const mockProject = require('../../fixtures/ember-cordova-mock/project');
5+
const CreateCordova = require('../../../lib/tasks/create-cordova-project');
6+
7+
describe('Blueprint Index', () => {
8+
afterEach(function() {
9+
td.reset();
10+
});
11+
12+
it('attempts to create a cordova project', function() {
13+
let createDouble = td.replace(CreateCordova.prototype, 'run');
14+
let index = require('../../../blueprints/ember-cordova/index');
15+
index.project = mockProject.project;
16+
17+
index.afterInstall({});
18+
19+
td.verify(createDouble());
20+
});
21+
});

node-tests/unit/commands/platform-test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const CdvRawTask = require('../../../lib/tasks/cordova-raw');
66

77
const mockProject = require('../../fixtures/ember-cordova-mock/project');
88
const isAnything = td.matchers.anything();
9-
const isArray = td.matchers.isA(Array);
109

1110
describe('Platform Command', () => {
1211
let rawDouble;
@@ -22,14 +21,14 @@ describe('Platform Command', () => {
2221
td.reset();
2322
});
2423

25-
it('passes command to Plugin Task', () => {
24+
it('passes command to Cordova Raw Task', () => {
2625
PlatformCmd.run({}, ['add', 'cordova-plugin'])
27-
td.verify(rawDouble('add', isArray, isAnything));
26+
td.verify(rawDouble('add', ['cordova-plugin'], isAnything));
2827
});
2928

3029
it('passes the save flag', () => {
3130
var opts = { save: false };
3231
PlatformCmd.run(opts, ['add', 'cordova-plugin']);
33-
td.verify(rawDouble('add', isArray, false));
32+
td.verify(rawDouble('add', ['cordova-plugin'], { save: false }));
3433
});
3534
});

node-tests/unit/commands/plugin-test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const CdvRawTask = require('../../../lib/tasks/cordova-raw');
66

77
const mockProject = require('../../fixtures/ember-cordova-mock/project');
88
const isAnything = td.matchers.anything();
9-
const isArray = td.matchers.isA(Array);
109

1110
describe('Plugin Command', () => {
1211
let rawDouble;
@@ -22,14 +21,14 @@ describe('Plugin Command', () => {
2221
td.reset();
2322
});
2423

25-
it('passes command to Plugin Task', () => {
24+
it('passes command to Cordova Raw', () => {
2625
PluginCmd.run({}, ['add', 'cordova-plugin'])
27-
td.verify(rawDouble('add', isArray, isAnything));
26+
td.verify(rawDouble('add', ['cordova-plugin'], isAnything));
2827
});
2928

3029
it('passes the save flag', () => {
3130
var opts = { save: false };
3231
PluginCmd.run(opts, ['add', 'cordova-plugin']);
33-
td.verify(rawDouble('add', isArray, false));
32+
td.verify(rawDouble('add', ['cordova-plugin'], { save: false }));
3433
});
3534
});

0 commit comments

Comments
 (0)