Skip to content

Commit a5ef28f

Browse files
committed
feat(build): re-adds cordova.js to ember builds
1 parent e521a9f commit a5ef28f

File tree

4 files changed

+80
-62
lines changed

4 files changed

+80
-62
lines changed

lib/commands/build.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const Command = require('./-command');
22
const Hook = require('../tasks/run-hook');
33
const LintIndex = require('../tasks/lint-index');
4+
const AddCordovaJS = require('../tasks/add-cordova-js');
45
const logger = require('../utils/logger');
56
const requireTarget = require('../utils/require-target');
67
const requireFramework = require('../utils/require-framework');
8+
const path = require('path');
79

810
module.exports = Command.extend({
911
name: 'build',
@@ -66,6 +68,10 @@ module.exports = Command.extend({
6668
project: this.project
6769
});
6870

71+
let addCordovaJS = new AddCordovaJS({
72+
source: path.join(options.cordovaOutputPath, 'index.html')
73+
});
74+
6975
let framework = requireFramework(this.project);
7076
let cordovaTarget = requireTarget(this.project, options);
7177

@@ -76,7 +82,7 @@ module.exports = Command.extend({
7682
.then(() => cordovaTarget.validateBuild(options.skipCordovaBuild))
7783
.then(() => {
7884
if (options.skipEmberBuild !== true) {
79-
return framework.build(options);
85+
return framework.build(options).then(() => addCordovaJS.run());
8086
}
8187
})
8288
.then(() => {

lib/frameworks/vue/tasks/build.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const Task = require('../../../tasks/-task');
22
const Bash = require('../../../tasks/bash');
3-
const AddCordovaJS = require('../../../tasks/add-cordova-js');
4-
const path = require('path');
53

64
module.exports = Task.extend({
75
buildCommand: undefined,
@@ -21,12 +19,7 @@ module.exports = Task.extend({
2119
command: `cp -R ${this.buildPath}/* ${this.cordovaOutputPath}`
2220
});
2321

24-
let addCordovaJS = new AddCordovaJS({
25-
source: path.join(this.cordovaOutputPath, 'index.html')
26-
});
27-
2822
return build.run()
29-
.then(copy.prepare())
30-
.then(addCordovaJS.prepare())
23+
.then(copy.prepare());
3124
}
3225
});
Lines changed: 70 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,33 @@
1-
var td = require('testdouble');
1+
const td = require('testdouble');
2+
const expect = require('../../helpers/expect');
3+
const Promise = require('rsvp');
4+
const mockProject = require('../../fixtures/ember-cordova-mock/project');
5+
const mockAnalytics = require('../../fixtures/ember-cordova-mock/analytics');
26

3-
var expect = require('../../helpers/expect');
4-
var Promise = require('rsvp');
5-
6-
var CdvTarget = require('../../../lib/targets/cordova/target');
7-
var HookTask = require('../../../lib/tasks/run-hook');
8-
var LintTask = require('../../../lib/tasks/lint-index');
9-
10-
var mockProject = require('../../fixtures/ember-cordova-mock/project');
11-
var mockAnalytics = require('../../fixtures/ember-cordova-mock/analytics');
12-
13-
var setupBuild = function() {
14-
var BuildCmd = require('../../../lib/commands/build');
7+
describe('Build Command', function() {
8+
let baseOpts, tasks;
9+
let AddCordovaJS, LintTask;
1510

16-
var project = mockProject.project;
17-
project.config = function() {
18-
return {
19-
locationType: 'hash'
11+
beforeEach(function() {
12+
baseOpts = {
13+
cordovaOutputPath: 'ember-cordova/cordova/www',
14+
platform: 'ios'
2015
};
21-
}
22-
23-
var build = new BuildCmd({
24-
project: project
2516
});
26-
build.analytics = mockAnalytics;
27-
28-
return build;
29-
};
3017

31-
describe('Build Command', function() {
3218
afterEach(function() {
3319
td.reset();
3420
});
3521

36-
var tasks;
37-
38-
beforeEach(function() {
39-
mockTasks();
40-
});
41-
42-
function mockTasks() {
22+
function setupBuild() {
23+
let CdvTarget, HookTask;
4324
tasks = [];
4425

26+
CdvTarget = require('../../../lib/targets/cordova/target');
27+
HookTask = require('../../../lib/tasks/run-hook');
28+
AddCordovaJS = td.replace('../../../lib/tasks/add-cordova-js');
29+
LintTask = td.replace('../../../lib/tasks/lint-index');
30+
4531
td.replace('../../../lib/utils/require-framework', function() {
4632
return {
4733
validateBuild: function() {
@@ -75,27 +61,48 @@ describe('Build Command', function() {
7561
tasks.push('cordova-target-build');
7662
return Promise.resolve();
7763
});
64+
65+
td.replace(AddCordovaJS.prototype, 'run', function() {
66+
tasks.push('add-cordova-js');
67+
return Promise.resolve();
68+
});
69+
70+
let BuildCmd = require('../../../lib/commands/build');
71+
let project = mockProject.project;
72+
project.config = function() {
73+
return {
74+
locationType: 'hash'
75+
};
76+
};
77+
78+
let build = new BuildCmd({
79+
project: project
80+
});
81+
build.analytics = mockAnalytics;
82+
83+
return build;
7884
}
7985

8086
it('exits cleanly', function() {
81-
var build = setupBuild();
87+
let build = setupBuild();
8288

8389
return expect(function() {
84-
build.run({});
90+
build.run(baseOpts);
8591
}).not.to.throw(Error);
8692
});
8793

8894
it('runs tasks in the correct order', function() {
89-
var build = setupBuild();
95+
let build = setupBuild();
9096

91-
return build.run({})
97+
return build.run(baseOpts)
9298
.then(function() {
9399
//h-t ember-electron for the pattern
94100
expect(tasks).to.deep.equal([
95101
'hook beforeBuild',
96102
'framework-validate-build',
97103
'cordova-target-validate-build',
98104
'framework-build',
105+
'add-cordova-js',
99106
'cordova-target-build',
100107
'hook afterBuild',
101108
'lint-index'
@@ -104,9 +111,10 @@ describe('Build Command', function() {
104111
});
105112

106113
it('skips ember-build with the --skip-ember-build flag', function() {
107-
var build = setupBuild();
114+
let build = setupBuild();
115+
baseOpts.skipEmberBuild = true;
108116

109-
return build.run({skipEmberBuild: true})
117+
return build.run(baseOpts)
110118
.then(function() {
111119
//h-t ember-electron for the pattern
112120
expect(tasks).to.deep.equal([
@@ -121,19 +129,40 @@ describe('Build Command', function() {
121129
});
122130

123131
it('skips cordova-build with the --skip-cordova-build flag', function() {
124-
var build = setupBuild();
132+
let build = setupBuild();
133+
baseOpts.skipCordovaBuild = true;
125134

126-
return build.run({skipCordovaBuild: true})
135+
return build.run(baseOpts)
127136
.then(function() {
128137
//h-t ember-electron for the pattern
129138
expect(tasks).to.deep.equal([
130139
'hook beforeBuild',
131140
'framework-validate-build',
132141
'cordova-target-validate-build',
133142
'framework-build',
143+
'add-cordova-js',
134144
'hook afterBuild',
135145
'lint-index'
136146
]);
137147
});
138148
});
149+
150+
it('constructs AddCordovaJS as expected', function() {
151+
let build = setupBuild();
152+
return build.run(baseOpts).then(function() {
153+
td.verify(new AddCordovaJS({
154+
source: 'ember-cordova/cordova/www/index.html'
155+
}));
156+
});
157+
});
158+
159+
it('constructs lint index as expected', function() {
160+
let build = setupBuild();
161+
return build.run(baseOpts).then(function() {
162+
td.verify(new LintTask({
163+
source: 'www/index.html',
164+
project: mockProject.project
165+
}));
166+
});
167+
});
139168
});

node-tests/unit/frameworks/vue/tasks/build-test.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ const expect = require('../../../../helpers/expect');
33
const Promise = require('rsvp').Promise;
44

55
describe('Vue Build Task', function() {
6-
let buildTask, tasks, Bash, AddCordovaJS;
6+
let buildTask, tasks, Bash;
77

88
beforeEach(function() {
99
tasks = [];
1010

1111
Bash = td.replace('../../../../../lib/tasks/bash');
12-
AddCordovaJS = td.replace('../../../../../lib/tasks/add-cordova-js');
1312
let Build = require('../../../../../lib/frameworks/vue/tasks/build');
1413

1514
td.replace(Bash.prototype, 'run', function() {
@@ -22,11 +21,6 @@ describe('Vue Build Task', function() {
2221
return Promise.resolve();
2322
});
2423

25-
td.replace(AddCordovaJS.prototype, 'prepare', function() {
26-
tasks.push('add-cordova-js');
27-
return Promise.resolve();
28-
});
29-
3024
buildTask = new Build({
3125
buildCommand: 'fakeBuildCommand',
3226
buildPath: 'fakePath',
@@ -42,8 +36,7 @@ describe('Vue Build Task', function() {
4236
return buildTask.run({cordovaOutputPath: 'fakePath'}).then(function() {
4337
expect(tasks).to.deep.equal([
4438
'bash-task',
45-
'bash-task-2',
46-
'add-cordova-js'
39+
'bash-task-2'
4740
]);
4841
});
4942
});
@@ -53,9 +46,6 @@ describe('Vue Build Task', function() {
5346
buildTask.run({cordovaOutputPath: 'fakePath'});
5447

5548
td.verify(new Bash(captor.capture()));
56-
td.verify(new AddCordovaJS({
57-
source: 'fakeCordovaPath/index.html'
58-
}));
5949

6050
expect(captor.values[0].command).to.equal('fakeBuildCommand');
6151
expect(captor.values[1].command).to.equal(

0 commit comments

Comments
 (0)