Skip to content

Commit 6ff7d65

Browse files
authored
Merge pull request #112 from isleofcode/feat/cordova-template
Feat/cordova template
2 parents a2d1aaf + 91763a3 commit 6ff7d65

File tree

8 files changed

+76
-61
lines changed

8 files changed

+76
-61
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
@@ -40,10 +40,12 @@ Build the ember and cordova project together running in the simulator or on a de
4040
#### Available options
4141
+ environment (default:development)
4242
+ platform (default:ios)
43+
+ release (default: debug)
4344

4445
#### Examples
4546
+ `ember cordova:build`
4647
+ `ember cordova:build --environment=production --platform=ios`
48+
+ `ember cordova:build --environment=production --platform=ios --release`
4749

4850
### Link
4951

docs/services/cordova.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ clean up your object's listeners automatically. Usage looks like a standard
1919
import Ember from 'ember';
2020
import subscribe from 'ember-cordova/utils/subscribe';
2121

22-
const { Route } = Ember;
22+
const {
23+
Route,
24+
inject
25+
} = Ember;
2326

2427
export default Route.extend({
2528
cordova: inject.service(),
@@ -39,7 +42,10 @@ For this case use Ember.Evented (below).
3942
import Ember from 'ember';
4043
import subscribe from 'ember-cordova/utils/subscribe';
4144
42-
const { Route } = Ember;
45+
const {
46+
Route,
47+
inject
48+
} = Ember;
4349
4450
export default Route.extend({
4551
cordova: inject.service(),

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. ' +

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
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cordova",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Tooling for cordova and crosswalk hybrid applications built with Ember",
55
"homepage": "https://github.com/isleofcode/ember-cordova",
66
"repository": {

0 commit comments

Comments
 (0)