Skip to content

Commit 84331fd

Browse files
authored
Merge pull request #114 from isleofcode/develop
Develop
2 parents 3042cc9 + 64f3a2a commit 84331fd

File tree

9 files changed

+72
-63
lines changed

9 files changed

+72
-63
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ guide](docs/migration-from-ember-cli.md).
3131
ember install ember-cordova
3232
```
3333

34-
You can optionally pass name & cordovaid params, which will set the id &
35-
display name of your Cordova application. If none exist, your Ember Apps
36-
name will be used.
34+
You can optionally pass the following params:
35+
- name: AppName (defaults to your ember app name)
36+
- cordovaid: String (defaults to your app name)
37+
- templatePath: String path to cordova template
3738

38-
If you already have a Cordova project here it will not be overwritten.
39+
```cli
40+
ember install ember-cordova --name=AppName
41+
--cordovaid=com.isleofcode.app --templatePath=../template
42+
```
43+
44+
If you already have a Cordova project at ember-cordova/cordova it will not be overwritten.
3945

4046
1. #### Set your config.locationType to 'hash'.
4147

blueprints/ember-cordova/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ module.exports = {
1313
}, {
1414
name: 'cordovaid',
1515
type: String
16+
}, {
17+
name: 'template-path',
18+
type: String
1619
}
1720
],
1821

@@ -39,6 +42,6 @@ module.exports = {
3942
ui: this.ui
4043
});
4144

42-
return create.run();
45+
return create.run(options.templatePath);
4346
}
4447
};

docs/cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Build the ember and cordova project together running in the simulator or on a de
4141
+ environment (default:development)
4242
+ platform (default:ios)
4343
+ release (default: debug)
44+
+ cordova-output-path (default: ember-cordova/cordova/www)
4445

4546
#### Examples
4647
+ `ember cordova:build`
@@ -101,6 +102,7 @@ here](livereload.md).
101102
#### Available options
102103
+ platform (default:ios)
103104
+ reloadUrl (default:localhost:4200)
105+
+ cordova-output-path (default: ember-cordova/cordova/www)
104106

105107
#### Examples
106108
+ `ember cdv:serve`

lib/commands/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = {
2323
{ name: 'platform', type: String, default: 'ios' },
2424
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
2525
{ name: 'environment', type: String, default: 'development', aliases: ['e', 'env', { 'dev': 'development' }, { 'prod': 'production' }] },
26-
{ name: 'output-path', type: 'Path', default: 'ember-cordova/cordova/www', aliases: ['op', 'out'] },
26+
{ name: 'cordova-output-path', type: 'Path', default: 'ember-cordova/cordova/www', aliases: ['op', 'out'] },
2727
{ name: 'release', type: Boolean, default: false }
2828
],
2929
/* eslint-enable max-len */
@@ -65,7 +65,7 @@ module.exports = {
6565
ui: ui,
6666
project: project,
6767
environment: options.environment,
68-
outputPath: options.outputPath
68+
outputPath: options.cordovaOutputPath
6969
});
7070

7171
cordovaBuild = new CdvBuildTask({

lib/commands/serve.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = {
4646
{ name: 'live-reload-base-url', type: String, aliases: ['lrbu'], description: 'Defaults to baseURL' },
4747
{ name: 'live-reload-port', type: Number, aliases: ['lrp'], description: '(Defaults to port number within [49152...65535])' },
4848
{ name: 'environment', type: String, default: 'development', aliases: ['e', 'env', { 'dev': 'development' }, { 'prod': 'production' }] },
49-
{ name: 'output-path', type: 'Path', default: 'ember-cordova/cordova/www/', aliases: ['op', 'out'] },
49+
{ name: 'cordova-output-path', type: 'Path', default: 'ember-cordova/cordova/www/', aliases: ['op', 'out'] },
5050
{ name: 'ssl', type: Boolean, default: false },
5151
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
5252
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' }
@@ -104,7 +104,7 @@ module.exports = {
104104
ui: this.ui,
105105
project: this.project,
106106
environment: options.environment,
107-
outputPath: options.outputPath
107+
outputPath: options.cordovaOutputPath
108108
});
109109

110110
cordovaBuild = new CdvBuildTask({

lib/tasks/create-cordova-project.js

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

33
var Task = require('./-task');
4-
5-
var cordovaRun = require('../utils/cordova-run');
64
var cordovaPath = require('../utils/cordova-path');
75
var camelize = require('../../lib/utils/string.js').camelize;
86
var path = require('path');
97
var fs = require('fs');
108
var chalk = require('chalk');
119

12-
var Promise = require('ember-cli/lib/ext/promise');
13-
var cordovaCreate = require('cordova-lib/src/cordova/create');
14-
var createPromise = Promise.denodeify(cordovaCreate);
10+
var cordovaProj = require('cordova-lib').cordova;
1511

1612
module.exports = Task.extend({
17-
run: function() {
13+
run: function(templatePath) {
1814
var emberCdvPath = cordovaPath(this.project, true);
1915
if (!fs.existsSync(emberCdvPath)) {
2016
this.ui.writeLine('Initting ember-cordova directory');
@@ -23,17 +19,25 @@ module.exports = Task.extend({
2319

2420
var cdvPath = path.join(emberCdvPath, 'cordova');
2521
if (!fs.existsSync(cdvPath)) {
26-
fs.mkdirSync(cdvPath);
27-
2822
var id = camelize(this.id);
2923
var name = camelize(this.name);
3024

25+
var config = {};
26+
if (templatePath !== undefined) {
27+
config = {
28+
lib: {
29+
www: { url: templatePath, template: true }
30+
}
31+
};
32+
}
33+
3134
//Args must be in specific order for cordova-lib
3235
var args = [];
3336
args.push(cdvPath);
3437
args.push(id);
3538
args.push(name);
36-
return cordovaRun(createPromise, this.project, args);
39+
args.push(config);
40+
return cordovaProj.raw.create.apply(this, args);
3741
} else {
3842
this.ui.writeLine(chalk.yellow(
3943
'Warning: ember-cordova/cordova project already exists. ' +

lib/tasks/ember-build-serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = Task.extend({
2020
run: function(options) {
2121
var builder = new Builder({
2222
ui: this.ui,
23-
outputPath: options.outputPath,
23+
outputPath: options.cordovaOutputPath,
2424
project: this.project,
2525
environment: options.environment
2626
});

node-tests/unit/blueprint/index.js renamed to node-tests/unit/blueprint/index-test.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@ const mockProject = require('../../fixtures/ember-cordova-mock/project');
55
const CreateCordova = require('../../../lib/tasks/create-cordova-project');
66

77
describe('Blueprint Index', () => {
8+
let index, createDouble;
9+
10+
beforeEach(function() {
11+
createDouble = td.replace(CreateCordova.prototype, 'run');
12+
index = require('../../../blueprints/ember-cordova/index');
13+
index.project = mockProject.project;
14+
});
15+
816
afterEach(function() {
917
td.reset();
1018
});
1119

1220
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-
1721
index.afterInstall({});
22+
td.verify(createDouble(undefined));
23+
});
1824

19-
td.verify(createDouble());
25+
it('passes template path', function() {
26+
index.afterInstall({templatePath: 'templatePath'});
27+
td.verify(createDouble('templatePath'));
2028
});
2129
});

node-tests/unit/tasks/create-cordova-project-test.js

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,28 @@ const fs = require('fs');
55
const path = require('path');
66
const expect = require('../../helpers/expect');
77

8+
const cordovaProj = require('cordova-lib').cordova;
89
const mockProject = require('../../fixtures/ember-cordova-mock/project');
910
const isObject = td.matchers.isA(Object);
1011
const isString = td.matchers.isA(String);
11-
const isArray = td.matchers.isA(Array);
12-
13-
const setupCreateTask = function() {
14-
const CreateCdvTask = require('../../../lib/tasks/create-cordova-project');
15-
return new CreateCdvTask(mockProject);
16-
};
1712

1813
describe('Cordova Create Task', () => {
14+
let create, rawDouble;
15+
16+
const setupCreateTask = function() {
17+
rawDouble = td.replace(cordovaProj.raw, 'create');
18+
const CreateCdvTask = require('../../../lib/tasks/create-cordova-project');
19+
create = new CreateCdvTask(mockProject);
20+
};
21+
1922
beforeEach(() => {
2023
td.replace(fs, 'mkdirSync', () => {
2124
return true;
2225
});
26+
27+
td.replace(fs, 'existsSync', function() {
28+
return false;
29+
});
2330
});
2431

2532
afterEach(() => {
@@ -34,46 +41,28 @@ describe('Cordova Create Task', () => {
3441
'ember-cordova'
3542
);
3643

37-
let create = setupCreateTask();
38-
39-
td.replace(fs, 'existsSync', function() {
40-
return false;
41-
});
44+
setupCreateTask();
4245
td.replace(fs, 'mkdirSync');
4346

4447
create.run();
45-
4648
td.verify(fs.mkdirSync(expectedPath));
4749
});
4850

49-
it('generates a cordova build command', () => {
50-
let cdvCreate = td.replace('cordova-lib/src/cordova/create');
51-
52-
td.replace(fs, 'existsSync', function() {
53-
return false;
54-
});
55-
56-
let create = setupCreateTask();
51+
it('calls cordova.create.raw', () => {
52+
setupCreateTask();
5753
create.run();
58-
59-
td.verify(cdvCreate(isString, isString, isString, isObject));
54+
td.verify(rawDouble(isString, isString, isString, {}));
6055
});
6156

6257
it('forces camelcased ids and names', () => {
63-
let cdvCreate = td.replace('cordova-lib/src/cordova/create');
64-
65-
td.replace(fs, 'existsSync', function() {
66-
return false;
67-
});
68-
69-
let create = setupCreateTask();
58+
setupCreateTask();
7059
create.id = 'ember-cordova-app';
7160
create.name = 'ember-cordova-app';
7261

7362
create.run();
7463

7564
/* eslint-disable max-len */
76-
td.verify(cdvCreate(isString, 'emberCordovaApp', 'emberCordovaApp', isObject));
65+
td.verify(rawDouble(isString, 'emberCordovaApp', 'emberCordovaApp', isObject));
7766
/* eslint-enable max-len */
7867
});
7968

@@ -82,21 +71,18 @@ describe('Cordova Create Task', () => {
8271
return true;
8372
});
8473

85-
let create = setupCreateTask();
74+
setupCreateTask();
8675
create.run();
8776

8877
expect(create.ui.output).to.contain('project already exists');
8978
});
9079

91-
it('proxies via cordova run', () => {
92-
const cordovaRun = td.replace('../../../lib/utils/cordova-run');
9380

94-
td.replace(fs, 'existsSync', function() {
95-
return false;
96-
});
81+
it('builds with a template when provided', function() {
82+
setupCreateTask();
83+
create.run('templatePath');
9784

98-
let create = setupCreateTask();
99-
create.run();
100-
td.verify(cordovaRun(isObject, isObject, isArray));
85+
var matcher = td.matchers.contains({lib: { www: { url: 'templatePath'}}});
86+
td.verify(rawDouble(isString, isString, isString, matcher));
10187
});
10288
});

0 commit comments

Comments
 (0)