Skip to content

Commit ec482d1

Browse files
authored
Merge pull request #52 from isleofcode/feat-testing
Feat testing
2 parents df23ab0 + e7c58c9 commit ec482d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+813
-1006
lines changed

dist/.keep

Whitespace-only changes.

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ module.exports = {
4141
},
4242

4343
contentFor: function (type) {
44-
var is = this._isTargetCordova();
4544
if (this._isTargetCordova() && type === 'body') {
4645
return '<script src="cordova.js"></script>';
4746
}

lib/commands/build.js

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

3-
var BuildTask = require('../tasks/build');
3+
var EmberBuildTask = require('../tasks/ember-build');
4+
var CdvBuildTask = require('../tasks/cordova-build');
5+
var LinkTask = require('../tasks/link-environment');
46
var HookTask = require('../tasks/run-hook');
57

68
var path = require('path');
@@ -24,20 +26,30 @@ module.exports = {
2426
run: function(options) {
2527
var platform = options.platform || defaultPlatform(this.project);
2628

27-
var build = new BuildTask({
28-
env: options.environment,
29-
platform: platform,
29+
var hook = new HookTask({
3030
project: this.project,
3131
ui: this.ui
3232
});
3333

34-
var hook = new HookTask({
34+
var emberBuild = new EmberBuildTask({
35+
project: this.project,
36+
ui: this.ui
37+
});
38+
39+
var link = new LinkTask({
40+
project: this.project,
41+
ui: this.ui
42+
});
43+
44+
var cordovaBuild = new CdvBuildTask({
3545
project: this.project,
3646
ui: this.ui
3747
});
3848

3949
return hook.run('beforeBuild')
40-
.then(build.run())
50+
.then(emberBuild.run(options.environment))
51+
.then(link.run())
52+
.then(cordovaBuild.run(platform))
4153
.then(hook.run('afterBuild'));
4254
}
4355
};

lib/commands/cordova.js

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

3-
var CordovaTask = require('../tasks/cordova');
3+
var BashTask = require('../tasks/bash');
4+
var cordovaPath = require('../utils/cordova-path');
45

56
var path = require('path');
67
var chalk = require('chalk');
@@ -45,12 +46,17 @@ module.exports = {
4546
},
4647

4748
run: function(options, rawArgs) {
48-
var cordovaCommand = new CordovaTask({
49-
project: this.project,
50-
rawArgs: rawArgs,
51-
ui: this.ui
52-
});
53-
54-
return cordovaCommand.run();
49+
var joinedArgs = rawArgs.join(' ');
50+
var cdvCommand = 'cordova ' + joinedArgs;
51+
52+
var msg = "Running 'cordova " + joinedArgs + "'";
53+
this.ui.writeLine(msg);
54+
55+
return new BashTask({
56+
command: cdvCommand,
57+
options: {
58+
cwd: cordovaPath(this.project)
59+
}
60+
}).run();
5561
}
5662
};

lib/commands/link.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
var LinkTask = require('../tasks/link-environment');
4-
54
var path = require('path');
65

76
module.exports = {

lib/commands/serve.js

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

3-
var BuildTask = require('../tasks/build');
4-
var BashTask = require('../tasks/bash');
3+
var EmberBuildTask = require('../tasks/ember-build');
4+
var CdvBuildTask = require('../tasks/cordova-build');
5+
var BashTask = require('../tasks/bash');
56

67
module.exports = {
78
name: 'cordova:serve',
@@ -32,16 +33,16 @@ module.exports = {
3233
platform = options.platform || config.platform || "ios";
3334
address = options.reloadUrl || config.reloadUrl || "http://localhost:4200";
3435

35-
//A little loopy, but will make later automation easier
36-
3736
var buildOptions ="EMBER_CORDOVA=true" +
3837
" CORDOVA_RELOAD_ADDRESS=" + address +
3938
" CORDOVA_PLATFORM=" + platform + " ";
4039

41-
var build = new BuildTask({
42-
env: options.env,
43-
platform: platform,
44-
buildOptions: buildOptions,
40+
var emberBuild = new EmberBuildTask({
41+
project: this.project,
42+
ui: this.ui
43+
});
44+
45+
var cdvBuild = new CdvBuildTask({
4546
project: this.project,
4647
ui: this.ui
4748
});
@@ -55,6 +56,8 @@ module.exports = {
5556
}
5657
});
5758

58-
return build.run().then(serve.run());
59+
return emberBuild.run(options.env, buildOptions)
60+
.then(cdvBuild.run(platform))
61+
.then(serve.run());
5962
}
6063
};

lib/tasks/bash.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
'use strict';
22

3-
var Task = require('ember-cli/lib/models/task');
4-
var Promise = require('ember-cli/lib/ext/promise');
3+
var Task = require('ember-cli/lib/models/task');
4+
var Promise = require('ember-cli/lib/ext/promise');
55

6-
//Sequence of tasks matters a lot
7-
var execSync = require('child_process').execSync;
8-
var defaults = require('lodash').defaults;
6+
var childProcess = require('child_process');
7+
var defaults = require('lodash').defaults;
98

10-
module.exports = Task.extend({
9+
var BashTask = Task.extend({
1110
run: function() {
1211
if (!this.options) {
1312
this.options = {};
1413
}
1514

16-
var _this = this;
17-
return new Promise(function(resolve, reject) {
18-
var options = defaults(_this.options, {
15+
//TODO - unresolved promise == problem & bad form
16+
return new Promise(() => {
17+
var options = defaults(this.options, {
1918
maxBuffer: 5000 * 1024,
2019
stdio: 'inherit'
2120
});
2221

23-
execSync(_this.command, options);
22+
this.runCommand(this.command, options);
2423
});
2524
}
2625
});
26+
27+
BashTask.prototype.runCommand = function(command, options) {
28+
childProcess.execSync(command, options);
29+
};
30+
31+
module.exports = BashTask;

lib/tasks/build.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

lib/tasks/cordova-build.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
var Task = require('ember-cli/lib/models/task');
4+
var BashTask = require('../tasks/bash');
5+
var cordovaPath = require('../utils/cordova-path');
6+
7+
module.exports = Task.extend({
8+
run: function(platform, env) {
9+
var cdvCommand = 'cordova build ' + platform;
10+
if (env === 'production') {
11+
cdvCommand += ' --release';
12+
}
13+
14+
var cdvBuild = new BashTask({
15+
command: cdvCommand,
16+
ui: this.ui,
17+
options: {
18+
cwd: cordovaPath(this.project)
19+
}
20+
});
21+
22+
return cdvBuild.run();
23+
}
24+
});

lib/tasks/cordova.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/tasks/create-cordova-project.js

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

3-
var Task = require('ember-cli/lib/models/task');
4-
var BashTask = require('../tasks/bash');
3+
var Task = require('ember-cli/lib/models/task');
4+
var BashTask = require('../tasks/bash');
55

6-
var cordovaPath = require('../utils/cordova-path');
7-
var path = require('path');
8-
var fs = require('fs');
9-
var chalk = require('chalk');
6+
var cordovaPath = require('../utils/cordova-path');
7+
var camelize = require('../../lib/utils/string.js').camelize;
8+
var path = require('path');
9+
var fs = require('fs');
10+
var chalk = require('chalk');
1011

1112
module.exports = Task.extend({
1213
run: function() {
@@ -16,9 +17,13 @@ module.exports = Task.extend({
1617
fs.mkdirSync(emberCdvPath);
1718
}
1819

20+
var id = camelize(this.id);
21+
var name = camelize(this.name);
22+
1923
var cdvPath = path.join(emberCdvPath, 'cordova');
24+
2025
if (!fs.existsSync(cdvPath)) {
21-
var command = 'cordova create cordova ' + this.id + ' ' + this.name;
26+
var command = 'cordova create cordova ' + id + ' ' + name;
2227

2328
var create = new BashTask({
2429
command: command,

lib/tasks/ember-build.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
var Task = require('ember-cli/lib/models/task');
4+
var BashTask = require('../tasks/bash');
5+
6+
module.exports = Task.extend({
7+
run: function(env, buildOptions) {
8+
var buildCommand = '';
9+
10+
if (buildOptions) {
11+
buildCommand = buildOptions + ' ';
12+
}
13+
buildCommand += 'EMBER_CORDOVA=true ember build --environment ' + env;
14+
15+
var emberBuild = new BashTask({
16+
command: buildCommand,
17+
ui: this.ui,
18+
options: {
19+
cwd: this.project.root
20+
}
21+
});
22+
23+
return emberBuild.run();
24+
}
25+
});

lib/tasks/link-environment.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
'use strict';
22

3-
var Task = require('ember-cli/lib/models/task');
4-
var Promise = require('ember-cli/lib/ext/promise');
5-
var DistTask = require('./verify-dist');
6-
7-
var cordovaPath = require('../utils/cordova-path');
8-
var fs = require('fs-extra');
9-
var path = require('path');
10-
var chalk = require('chalk');
3+
var Task = require('ember-cli/lib/models/task');
4+
var Promise = require('ember-cli/lib/ext/promise');
5+
var DistTask = require('./verify-dist');
116

7+
var cordovaPath = require('../utils/cordova-path');
8+
var fs = require('fs-extra');
9+
var path = require('path');
1210

1311
module.exports = Task.extend({
1412
run: function() {
15-
if (!this.project) {
16-
throw new Error('A project must be passed into this function');
17-
}
18-
1913
var verifyDist = new DistTask({
2014
project: this.project
2115
});

0 commit comments

Comments
 (0)